Skip to content

Commit adf6905

Browse files
committed
Add "Trusted Plugin" feature with backend and UI updates
Introduced a new "Trusted Plugin" feature to the application. - Added `IsTrusted` property to backend entities and responses. - Updated `IPluginService` with methods to manage trusted plugins. - Implemented `AllTrustedPlugins` and `SetTrustedStatus` methods. - Updated Razor views to display badges/icons for trusted plugins. - Added CSS styles for "Trusted Plugin" visual elements. - Fixed a minor grammatical issue in `Plugins.razor`. #43
1 parent a9e04cc commit adf6905

13 files changed

Lines changed: 125 additions & 10 deletions

File tree

src/FlowSynx.PluginRegistry.Application/Features/Plugins/Query/PluginDetails/PluginDetailsHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public async Task<Result<PluginDetailsResponse>> Handle(PluginDetailsRequest req
4444
LastUpdated = plugin.LastModifiedOn ?? plugin.CreatedOn,
4545
TotalDownload = plugin.Statistics.Count,
4646
Checksum = plugin.Checksum,
47+
IsTrusted = plugin.Plugin.IsTrusted,
4748
Tags = plugin.PluginVersionTags.Select(x=>x.Tag!.Name),
4849
MinimumFlowSynxVersion = plugin.MinimumFlowSynxVersion,
4950
TargetFlowSynxVersion = plugin.TargetFlowSynxVersion,

src/FlowSynx.PluginRegistry.Application/Features/Plugins/Query/PluginDetails/PluginDetailsResponse.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class PluginDetailsResponse
1616
public string? TargetFlowSynxVersion { get; set; }
1717
public DateTime LastUpdated { get; set; }
1818
public int TotalDownload { get; set; } = 0;
19+
public bool IsTrusted { get; set; } = false;
1920
public IEnumerable<string> Tags { get; set; } = new List<string>();
2021
public IEnumerable<string> Versions { get; set; } = new List<string>();
2122
public IEnumerable<string> Owners { get; set; } = new List<string>();

src/FlowSynx.PluginRegistry.Application/Features/Plugins/Query/PluginsList/PluginsListHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public async Task<PaginatedResult<PluginsListResponse>> Handle(PluginsListReques
4242
CategoryTitle = p.LatestVersion.PluginCategory.Title,
4343
LastUpdated = p.LastModifiedOn ?? p.CreatedOn,
4444
Tags = p.LatestVersion!.PluginVersionTags.Select(x => x.Tag!.Name),
45-
TotalDownload = p.Versions.Sum(x=>x.Statistics.Count)
45+
TotalDownload = p.Versions.Sum(x=>x.Statistics.Count),
46+
IsTrusted = p.IsTrusted
4647
}).ToList();
4748

4849
return PaginatedResult<PluginsListResponse>.Success(response, plugins.TotalCount, request.Page ?? 1, plugins.PageSize);

src/FlowSynx.PluginRegistry.Application/Features/Plugins/Query/PluginsList/PluginsListResponse.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ public class PluginsListResponse
1010
public string? CategoryTitle { get; set; }
1111
public DateTime LastUpdated { get; set; }
1212
public int TotalDownload { get; set; } = 0;
13+
public bool IsTrusted { get; set; } = false;
1314
}

src/FlowSynx.PluginRegistry.Application/Features/Plugins/Query/PluginsListByProfile/PluginsListByProfileHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public async Task<PaginatedResult<PluginsListByProfileResponse>> Handle(PluginsL
4040
Description = p.LatestVersion!.Description,
4141
LastUpdated = p.LastModifiedOn ?? p.CreatedOn,
4242
Tags = p.LatestVersion!.PluginVersionTags.Select(x => x.Tag!.Name),
43-
TotalDownload = p.Versions.Sum(x => x.Statistics.Count)
43+
TotalDownload = p.Versions.Sum(x => x.Statistics.Count),
44+
IsTrusted = p.IsTrusted
4445
}).ToList();
4546

4647
return PaginatedResult<PluginsListByProfileResponse>.Success(response, plugins.TotalCount, request.Page ?? 1, plugins.PageSize);

src/FlowSynx.PluginRegistry.Application/Features/Plugins/Query/PluginsListByProfile/PluginsListByProfileResponse.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ public class PluginsListByProfileResponse
1010
public string? CategoryTitle { get; set; }
1111
public DateTime LastUpdated { get; set; }
1212
public long TotalDownload { get; set; } = 0;
13+
public bool IsTrusted { get; set; } = false;
1314
}

src/FlowSynx.PluginRegistry.Domain/Plugin/IPluginService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ public interface IPluginService
77
Task<Pagination<PluginEntity>> AllBySeachQuery(string? query, int page, CancellationToken cancellationToken);
88
Task<Pagination<PluginEntity>> AllBySeachTags(string? tag, int page, CancellationToken cancellationToken);
99
Task<Pagination<PluginEntity>> AllByProfileUserName(string username, int page, CancellationToken cancellationToken);
10+
Task<Pagination<PluginEntity>> AllTrustedPlugins(int page, CancellationToken cancellationToken);
1011
Task Add(PluginEntity pluginEntity, CancellationToken cancellationToken);
1112
Task Update(PluginEntity pluginEntity, CancellationToken cancellationToken);
1213
Task<bool> Delete(PluginEntity pluginEntity, CancellationToken cancellationToken);
14+
Task<bool> SetTrustedStatus(string pluginType, bool isTrusted, CancellationToken cancellationToken);
1315
}

src/FlowSynx.PluginRegistry.Domain/Plugin/PluginEntity.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class PluginEntity : AuditableEntity<Guid>, ISoftDeletable
88
public required string Type { get; set; }
99
public Guid? LatestVersionId { get; set; }
1010
public bool IsDeleted { get; set; } = false;
11+
public bool IsTrusted { get; set; } = false;
1112

1213
public PluginVersionEntity? LatestVersion { get; set; }
1314
public ICollection<PluginVersionEntity> Versions { get; set; } = new List<PluginVersionEntity>();

src/FlowSynx.PluginRegistry.Infrastructure/Services/PluginService.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,35 @@ public async Task<Pagination<PluginEntity>> AllByProfileUserName(string username
180180
}
181181
}
182182

183+
public async Task<Pagination<PluginEntity>> AllTrustedPlugins(int page, CancellationToken cancellationToken)
184+
{
185+
try
186+
{
187+
await using var context = await _appContextFactory.CreateDbContextAsync(cancellationToken);
188+
IQueryable<PluginEntity> pluginEntities = context.Plugins
189+
.Include(p => p.LatestVersion).ThenInclude(i => i!.PluginVersionTags).ThenInclude(i => i.Tag)
190+
.Include(p => p.LatestVersion).ThenInclude(i => i!.Statistics)
191+
.Include(p => p.LatestVersion).ThenInclude(i => i!.PluginCategory)
192+
.Include(i => i.Owners).ThenInclude(i => i.Profile)
193+
.Include(p => p.Versions.Where(v => !v.IsDeleted && v.IsActive)).ThenInclude(v => v.Statistics)
194+
.Where(p => !p.IsDeleted && p.LatestVersion != null && p.IsTrusted);
195+
196+
var totalCount = await pluginEntities.CountAsync(cancellationToken).ConfigureAwait(false);
197+
198+
var skip = (page - 1) * _pageSize;
199+
pluginEntities = pluginEntities.OrderBy(p => p.Type)
200+
.Skip(skip)
201+
.Take(_pageSize);
202+
203+
var result = await pluginEntities.ToListAsync(cancellationToken).ConfigureAwait(false);
204+
return new Pagination<PluginEntity>(result, totalCount, page, _pageSize);
205+
}
206+
catch (Exception ex)
207+
{
208+
throw new Exception(ex.Message);
209+
}
210+
}
211+
183212
public async Task Add(PluginEntity pluginEntity, CancellationToken cancellationToken)
184213
{
185214
try
@@ -236,4 +265,26 @@ await context
236265
throw new Exception(ex.Message);
237266
}
238267
}
268+
269+
public async Task<bool> SetTrustedStatus(string pluginType, bool isTrusted, CancellationToken cancellationToken)
270+
{
271+
try
272+
{
273+
await using var context = await _appContextFactory.CreateDbContextAsync(cancellationToken);
274+
var plugin = await context.Plugins
275+
.FirstOrDefaultAsync(p => p.Type.ToLower() == pluginType.ToLower() && !p.IsDeleted, cancellationToken)
276+
.ConfigureAwait(false);
277+
278+
if (plugin == null)
279+
return false;
280+
281+
plugin.IsTrusted = isTrusted;
282+
await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
283+
return true;
284+
}
285+
catch (Exception ex)
286+
{
287+
throw new Exception(ex.Message);
288+
}
289+
}
239290
}

src/FlowSynx.Pluginregistry/Components/Pages/Plugins/Plugins.razor

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</div>
5050
<div class="card p-5">
5151
<h4 class="text-muted">No plugins found</h4>
52-
<p class="text-secondary">We couldnt find anything matching your search.</p>
52+
<p class="text-secondary">We couldn't find anything matching your search.</p>
5353
</div>
5454
</div>
5555
}
@@ -68,7 +68,13 @@
6868
</div>
6969
<div class="col">
7070
<div class="card-body">
71-
<h4 class="card-title"><a href="/plugins/@plugin.Type/@plugin.Version">@plugin.Type</a></h4>
71+
<h4 class="card-title">
72+
<a href="/plugins/@plugin.Type/@plugin.Version">@plugin.Type</a>
73+
@if (plugin.IsTrusted)
74+
{
75+
<i class="bi bi-patch-check-fill trusted-plugin-icon-small ms-2" title="Trusted Plugin"></i>
76+
}
77+
</h4>
7278
@if (plugin.Owners.Any())
7379
{
7480
<div>

0 commit comments

Comments
 (0)