From 0b2690a0e46601f146df8401b53017e8f589284c Mon Sep 17 00:00:00 2001 From: ZhengJie Date: Mon, 9 Dec 2024 15:12:11 +0800 Subject: [PATCH 01/10] =?UTF-8?q?1.=20**`PermissionManager.razor`=20?= =?UTF-8?q?=E5=92=8C=20`PermissionManager.razor.cs`**=20=20=20=20-=20?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=8A=A8=E6=80=81=20`RenderFragment`=20?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=20`Tree`=20=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E7=9B=B4=E6=8E=A5=E9=80=9A=E8=BF=87=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E6=96=B9=E5=BC=8F=E5=AE=9E=E7=8E=B0=E6=A0=91?= =?UTF-8?q?=E5=BD=A2=E7=BB=84=E4=BB=B6=E7=BB=91=E5=AE=9A=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2. **`AddRole.razor`** - 将模态框属性 `Resizable` 替换为 `DestroyOnClose`,确保关闭模态框时销毁组件实例。 3. **`BasicLayout.razor` 和 `BasicLayout.razor.cs`** - 基于用户权限动态加载菜单项,通过 `IPermissionChecker` 检查当前用户是否具备访问权限。 - 引入新的 `PermissionMenuDataItem` 类型,支持绑定权限代码。 --- .../Identity/PermissionManager.razor | 91 +++++++------ .../Identity/PermissionManager.razor.cs | 48 ++----- .../Components/Identity/Role/AddRole.razor | 2 +- .../Layouts/BasicLayout.razor | 62 ++++----- .../Layouts/BasicLayout.razor.cs | 122 +++++++++++++----- .../Program.cs | 2 +- 6 files changed, 182 insertions(+), 145 deletions(-) diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor index 7ce2f6b..3aeb832 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor @@ -1,44 +1,59 @@ @{ - const string buttonType = ButtonType.Dashed; - // ReSharper disable once AccessToStaticMemberViaDerivedType - const string buttonSize = ButtonSize.Small; + const string buttonType = ButtonType.Dashed; + // ReSharper disable once AccessToStaticMemberViaDerivedType + const string buttonSize = ButtonSize.Small; } - - - - - - + + + + + + - + - @foreach (var permissionGroup in PermissionGroups) - { - - - -

@permissionGroup.Name

-
- - - - - - -
- - @BuildTree(permissionGroup) -
- } + @foreach (var permissionGroup in PermissionGroups) + { + + + +

@permissionGroup.Name

+
+ + + + + + +
+ + +
+ }
\ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor.cs b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor.cs index 9e56b75..4f558f4 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor.cs +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor.cs @@ -11,7 +11,7 @@ public sealed partial class PermissionManager : ComponentBase private readonly Dictionary> _treeDir = []; private readonly Dictionary> _treeKeysDir = []; - private readonly Dictionary>> _treeOnChangeEventDir = []; + private readonly Dictionary, Task>> _treeOnChangeEventDir = []; private PermissionGroup[] PermissionGroups { get; set; } = []; private Guid Id { get; set; } @@ -23,18 +23,17 @@ protected override void OnInitialized() var treeId = group.Name; _treeDir.Add(treeId, default!); _treeKeysDir.Add(treeId, group.PermissionsWithChildren.Select(p => p.Code)); - _treeOnChangeEventDir.Add(treeId, EventCallback.Factory.Create>(this, - async args => + _treeOnChangeEventDir.Add(treeId, async args => + { + foreach (var key in _treeKeysDir[args.Tree.Id]) { - foreach (var key in _treeKeysDir[args.Tree.Id]) - { - AssignedPermissionCodes.Remove(key); - } + AssignedPermissionCodes.Remove(key); + } - AssignedPermissionCodes.AddRange(args.Tree.CheckedKeys); + AssignedPermissionCodes.AddRange(args.Tree.CheckedKeys); - await AssignedPermissionCodesChanged.InvokeAsync(AssignedPermissionCodes); - })); + await AssignedPermissionCodesChanged.InvokeAsync(AssignedPermissionCodes); + }); } } @@ -42,33 +41,4 @@ public void Update() { Id = Guid.NewGuid(); } - - private RenderFragment BuildTree(PermissionGroup permissionGroup) => builder => - { - var treeId = permissionGroup.Name; - - builder.OpenComponent>(0); // 动态创建 Tree 组件 - builder.AddAttribute(2, "Id", treeId); // 设置树的 Id - builder.AddAttribute(3, "Checkable", true); // 启用 Checkable 属性 - builder.AddAttribute(4, "DataSource", permissionGroup.Permissions); // 设置 DataSource 为 Permissions - builder.AddAttribute(5, "TitleExpression", - (Func, string>)(x => x.DataItem.DisplayName)); // 设置显示名称 - builder.AddAttribute(6, "KeyExpression", - (Func, string>)(x => x.DataItem.Code)); // 设置 KeyExpression - builder.AddAttribute(7, "ChildrenExpression", - (Func, IEnumerable>)(x => x.DataItem.Children)); // 设置 ChildrenExpression - builder.AddAttribute(8, "DefaultCheckedKeys", - AssignedPermissionCodes.Intersect(_treeKeysDir[treeId]).ToArray()); // 设置默认选中的项 - builder.AddAttribute(9, "DisabledExpression", - (Func, bool>)(x => - DisabledPermissionCodes.Contains(x.DataItem.Code) || !x.DataItem.IsEnabled)); // 设置禁用规则 - builder.AddAttribute(10, "CheckStrictly", true); // 精确检查 treeNode;父树节点和子树节点没有关联 - builder.AddAttribute(11, "DefaultExpandAll", true); // 默认展开全部节点 - builder.AddAttribute(12, "OnCheck", _treeOnChangeEventDir[treeId]); // 设置 OnCheck 事件处理程序 - - // 捕获组件的引用 - builder.AddComponentReferenceCapture(13, treeRef => { _treeDir[treeId] = (Tree)treeRef; }); - - builder.CloseComponent(); // 关闭 Tree 组件 - }; } \ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/Role/AddRole.razor b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/Role/AddRole.razor index 97fabf1..9fbe5f3 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/Role/AddRole.razor +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/Role/AddRole.razor @@ -6,7 +6,7 @@ OnOk="() => _form.Submit()" OnCancel="CloseModal" ConfirmLoading="@_modalConfirmLoading" - Resizable = "@(true)"> + DestroyOnClose="@(true)"> diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Layouts/BasicLayout.razor b/src/NetCorePal.D3Shop.Web.Admin.Client/Layouts/BasicLayout.razor index 565e089..451ea22 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Layouts/BasicLayout.razor +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Layouts/BasicLayout.razor @@ -5,16 +5,16 @@ Title="D3Shop" BaseURL="/admin" Logo="@("https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg")" - MenuData="_menuData" + MenuData="_menuData.ToArray()" MenuAccordion - @bind-Collapsed="collapsed"> + @bind-Collapsed="_collapsed"> - + - + @@ -28,39 +28,39 @@ - + @code{ - bool collapsed; + bool _collapsed; - public LinkItem[] Links = - { - new LinkItem - { - Key = "Ant Design Blazor", - Title = "Ant Design Blazor", - Href = "https://antblazor.com", - BlankTarget = true, - }, - new LinkItem - { - Key = "github", - Title = (RenderFragment)(@), - Href = "https://github.com/ant-design-blazor/ant-design-pro-blazor", - BlankTarget = true, - }, - new LinkItem - { - Key = "Blazor", - Title = "Blazor", - Href = "https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor?WT.mc_id=DT-MVP-5003987", - BlankTarget = true, - } - }; + public readonly LinkItem[] Links = + [ + new() + { + Key = "Ant Design Blazor", + Title = "Ant Design Blazor", + Href = "https://antblazor.com", + BlankTarget = true, + }, + new() + { + Key = "github", + Title = (RenderFragment)(@), + Href = "https://github.com/ant-design-blazor/ant-design-pro-blazor", + BlankTarget = true, + }, + new() + { + Key = "Blazor", + Title = "Blazor", + Href = "https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor?WT.mc_id=DT-MVP-5003987", + BlankTarget = true, + } + ]; void Toggle() { - collapsed = !collapsed; + _collapsed = !_collapsed; } } \ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Layouts/BasicLayout.razor.cs b/src/NetCorePal.D3Shop.Web.Admin.Client/Layouts/BasicLayout.razor.cs index 9060eaa..a553373 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Layouts/BasicLayout.razor.cs +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Layouts/BasicLayout.razor.cs @@ -1,49 +1,101 @@ -using AntDesign.ProLayout; +using System.Security.Claims; +using AntDesign.ProLayout; +using Microsoft.AspNetCore.Components.Authorization; +using NetCorePal.D3Shop.Admin.Shared.Authorization; +using NetCorePal.D3Shop.Admin.Shared.Permission; +using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; -namespace NetCorePal.D3Shop.Web.Admin.Client.Layouts +namespace NetCorePal.D3Shop.Web.Admin.Client.Layouts; + +public partial class BasicLayout : LayoutComponentBase { - public partial class BasicLayout : LayoutComponentBase, IDisposable + private PermissionMenuDataItem[] _menuData = []; + private PermissionMenuDataItem[] _allMenuDate = []; + + [Inject] private ReuseTabsService TabService { get; set; } = default!; + [Inject] private IPermissionChecker PermissionChecker { get; set; } = default!; + + [Inject] private AuthenticationStateProvider AuthenticationStateProvider { get; set; } = default!; + + protected override async Task OnInitializedAsync() { - private MenuDataItem[] _menuData = Array.Empty(); + _allMenuDate = + [ + new PermissionMenuDataItem + { + Path = "/admin", + Name = "welcome", + Key = "welcome", + Icon = "smile" + }, + new PermissionMenuDataItem + { + Path = "/admin/users", + Name = "用户管理", + Key = "users", + Icon = "crown", + BoundPermissionCode = PermissionCodes.AdminUserManagement + }, + new PermissionMenuDataItem + { + Path = "/admin/roles", + Name = "角色管理", + Key = "roles", + Icon = "crown", + BoundPermissionCode = PermissionCodes.RoleManagement + } + ]; - [Inject] private ReuseTabsService TabService { get; set; } = default!; + var user = (await AuthenticationStateProvider.GetAuthenticationStateAsync()).User; + if (user.Identity?.IsAuthenticated is null or false) return; - protected override async Task OnInitializedAsync() + // 系统默认用户不校验权限 + var userName = user.Claims.Single(c => c.Type == ClaimTypes.Name).Value; + if (userName == AppDefaultCredentials.Name) { - _menuData = new[] { - new MenuDataItem - { - Path = "/admin", - Name = "welcome", - Key = "welcome", - Icon = "smile", - }, - new MenuDataItem - { - Path = "/admin/users", - Name = "用户管理", - Key = "users", - Icon = "crown", - }, - new MenuDataItem - { - Path = "/admin/roles", - Name = "角色管理", - Key = "roles", - Icon = "crown", - }, - }; + _menuData = _allMenuDate; + return; } - void Reload() - { - TabService.ReloadPage(); - } + _menuData = await GetAccessibleMenusAsync(user, _allMenuDate); // 过滤出用户有权限的菜单项 + } + + private async Task GetAccessibleMenusAsync(ClaimsPrincipal user, + PermissionMenuDataItem[] menus) + { + var accessibleMenus = new List(); - public void Dispose() + foreach (var menu in menus) { - // Method intentionally left empty. + if (menu.BoundPermissionCode is not null && + !await PermissionChecker.HasPermissionAsync(user, menu.BoundPermissionCode)) continue; + + var accessibleChildren = await GetAccessibleMenusAsync(user, menu.Children); + + accessibleMenus.Add(new PermissionMenuDataItem + { + Path = menu.Path, + Name = menu.Name, + Key = menu.Key, + Icon = menu.Icon, + BoundPermissionCode = menu.BoundPermissionCode, + Children = accessibleChildren + }); } + return accessibleMenus.ToArray(); + } + + + private void Reload() + { + TabService.ReloadPage(); } } + +internal sealed class PermissionMenuDataItem : MenuDataItem +{ + public string? BoundPermissionCode { get; init; } + + public new PermissionMenuDataItem[] Children { get; init; } = []; +} \ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Program.cs b/src/NetCorePal.D3Shop.Web.Admin.Client/Program.cs index bb52a4a..69c39e9 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Program.cs +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Program.cs @@ -8,7 +8,7 @@ namespace NetCorePal.D3Shop.Web.Admin.Client { - public class Program + public static class Program { public static async Task Main(string[] args) { From 12dbc8694a5a5314e541cdd0c1cd095460d0f22b Mon Sep 17 00:00:00 2001 From: ZhengJie Date: Wed, 11 Dec 2024 08:27:48 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=B8=BAQuery=E6=98=BE=E7=A4=BA=E6=8C=87?= =?UTF-8?q?=E5=AE=9AAsNoTracking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Queries/Identity/AdminUserQuery.cs | 19 ++++++++++--------- .../Application/Queries/Identity/RoleQuery.cs | 15 +++++++++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs index e5eeb8b..7a5d029 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs @@ -19,7 +19,7 @@ public class AdminUserQuery(ApplicationDbContext applicationDbContext, IMemoryCa public async Task GetUserCredentialsIfExists(AdminUserId id, CancellationToken cancellationToken) { - return await AdminUserSet + return await AdminUserSet.AsNoTracking() .Where(au => au.Id == id) .Select(au => new AdminUserCredentials(au.Id, au.Password)) .FirstOrDefaultAsync(cancellationToken); @@ -27,7 +27,7 @@ public class AdminUserQuery(ApplicationDbContext applicationDbContext, IMemoryCa public async Task> GetAssignedRoleIdsAsync(AdminUserId id, CancellationToken cancellationToken) { - return await AdminUserSet + return await AdminUserSet.AsNoTracking() .Where(u => u.Id == id) .SelectMany(u => u.Roles.Select(ur => ur.RoleId)) .ToListAsync(cancellationToken); @@ -36,7 +36,7 @@ public async Task> GetAssignedRoleIdsAsync(AdminUserId id, Cancella public async Task> GetAssignedPermissionsAsync(AdminUserId id, CancellationToken cancellationToken) { - return await AdminUserSet + return await AdminUserSet.AsNoTracking() .Where(au => au.Id == id) .SelectMany(au => au.Permissions) .Select(aup => new AdminUserAssignedPermissionResponse(aup.PermissionCode, aup.SourceRoleIds.Count > 0)) @@ -46,7 +46,7 @@ public async Task> GetAssignedPermissi public async Task GetUserInfoForLoginAsync(string name, CancellationToken cancellationToken) { - return await AdminUserSet + return await AdminUserSet.AsNoTracking() .Where(au => au.Name == name) .Select(au => new AuthenticationUserInfo(au.Id, au.Name, au.Password, au.Phone)) .FirstOrDefaultAsync(cancellationToken: cancellationToken); @@ -55,7 +55,7 @@ public async Task> GetAssignedPermissi public async Task> GetAllAdminUsersAsync(AdminUserQueryRequest queryRequest, CancellationToken cancellationToken) { - var adminUsers = await AdminUserSet + var adminUsers = await AdminUserSet.AsNoTracking() .WhereIf(!queryRequest.Name.IsNullOrWhiteSpace(), au => au.Name.Contains(queryRequest.Name!)) .WhereIf(!queryRequest.Phone.IsNullOrWhiteSpace(), au => au.Phone.Contains(queryRequest.Phone!)) .Select(au => new AdminUserResponse(au.Id, au.Name, au.Phone)) @@ -66,7 +66,7 @@ public async Task> GetAllAdminUsersAsync(AdminUserQ public async Task> GetAdminUserIdsByRoleIdAsync(RoleId roleId, CancellationToken cancellationToken) { - return await applicationDbContext.AdminUsers + return await AdminUserSet.AsNoTracking() .Where(x => x.Roles.Any(r => r.RoleId == roleId)) .Select(x => x.Id) .ToListAsync(cancellationToken); @@ -74,12 +74,13 @@ public async Task> GetAdminUserIdsByRoleIdAsync(RoleId roleId, public async Task DoesAdminUserExist(string userName, CancellationToken cancellationToken) { - return await AdminUserSet.AnyAsync(au => au.Name == userName, cancellationToken); + return await AdminUserSet.AsNoTracking() + .AnyAsync(au => au.Name == userName, cancellationToken); } public async Task DoesAdminUserExist(RoleId roleId, CancellationToken cancellationToken) { - return await AdminUserSet + return await AdminUserSet.AsNoTracking() .AnyAsync(x => x.Roles.Any(r => r.RoleId == roleId), cancellationToken: cancellationToken); } @@ -89,7 +90,7 @@ public async Task DoesAdminUserExist(RoleId roleId, CancellationToken canc var adminUserPermissions = await memoryCache.GetOrCreateAsync(cacheKey, async entry => { entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30); - return await applicationDbContext.AdminUsers + return await AdminUserSet.AsNoTracking() .Where(au => au.Id == id) .SelectMany(au => au.Permissions.Select(p => p.PermissionCode)) .ToListAsync(); diff --git a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs index 879e454..27fa1ce 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs @@ -16,7 +16,7 @@ public class RoleQuery(ApplicationDbContext dbContext) : IQuery public async Task> GetAllRolesAsync(RoleQueryRequest query, CancellationToken cancellationToken) { - return await RoleSet + return await RoleSet.AsNoTracking() .WhereIf(!query.Name.IsNullOrWhiteSpace(), r => r.Name.Contains(query.Name!)) .WhereIf(!query.Description.IsNullOrWhiteSpace(), r => r.Description.Contains(query.Description!)) .Select(r => new RoleResponse(r.Id, r.Name, r.Description)) @@ -25,7 +25,7 @@ public async Task> GetAllRolesAsync(RoleQueryRequest que public async Task> GetAllAdminUserRolesAsync(CancellationToken cancellationToken) { - return await RoleSet + return await RoleSet.AsNoTracking() .Select(r => new AdminUserRoleResponse(r.Id, r.Name, false)) .ToListAsync(cancellationToken: cancellationToken); } @@ -33,7 +33,7 @@ public async Task> GetAllAdminUserRolesAsync(Cancell public async Task> GetAdminRolesForAssignmentAsync(IEnumerable ids, CancellationToken cancellationToken) { - return await RoleSet + return await RoleSet.AsNoTracking() .Where(r => ids.Contains(r.Id)) .Select(r => new AssignAdminUserRoleDto( r.Id, @@ -46,18 +46,21 @@ public async Task> GetAdminRolesForAssignmentAsync( public async Task> GetAssignedPermissionCodes(RoleId id, CancellationToken cancellationToken) { - return await RoleSet.Where(r => r.Id == id) + return await RoleSet.AsNoTracking() + .Where(r => r.Id == id) .SelectMany(r => r.Permissions.Select(rp => rp.PermissionCode)) .ToListAsync(cancellationToken); } public async Task RoleExistsByNameAsync(string name, CancellationToken cancellationToken) { - return await RoleSet.AnyAsync(r => r.Name == name, cancellationToken); + return await RoleSet.AsNoTracking() + .AnyAsync(r => r.Name == name, cancellationToken); } public async Task RoleExistsByNameAsync(string name, RoleId id, CancellationToken cancellationToken) { - return await RoleSet.AnyAsync(r => r.Name == name && r.Id != id, cancellationToken); + return await RoleSet.AsNoTracking() + .AnyAsync(r => r.Name == name && r.Id != id, cancellationToken); } } \ No newline at end of file From 1459a64e114f0c90cd1cc708372ed616de38edf7 Mon Sep 17 00:00:00 2001 From: ZhengJie Date: Wed, 11 Dec 2024 08:33:51 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E8=B0=83=E6=95=B4Dto=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Application/Queries/Identity/AdminUserQuery.cs | 2 +- .../Blazor/Components/Account/Login.razor.cs | 2 +- .../Controllers/Identity/AdminUserAccountController.cs | 2 +- .../Identity/Dto}/AdminUserCredentials.cs | 2 +- .../Identity/Dto}/AuthenticationUserInfo.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename src/NetCorePal.D3Shop.Web/{Application/Queries/Identity/QueryResult => Controllers/Identity/Dto}/AdminUserCredentials.cs (66%) rename src/NetCorePal.D3Shop.Web/{Application/Queries/Identity/QueryResult => Controllers/Identity/Dto}/AuthenticationUserInfo.cs (70%) diff --git a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs index 7a5d029..58c31a5 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs @@ -4,8 +4,8 @@ using NetCorePal.D3Shop.Admin.Shared.Responses; using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.RoleAggregate; -using NetCorePal.D3Shop.Web.Application.Queries.Identity.QueryResult; using NetCorePal.D3Shop.Web.Const; +using NetCorePal.D3Shop.Web.Controllers.Identity.Dto; using NetCorePal.D3Shop.Web.Extensions; using NetCorePal.Extensions.Dto; using NetCorePal.Extensions.Primitives; diff --git a/src/NetCorePal.D3Shop.Web/Blazor/Components/Account/Login.razor.cs b/src/NetCorePal.D3Shop.Web/Blazor/Components/Account/Login.razor.cs index c35fb88..3fa798b 100644 --- a/src/NetCorePal.D3Shop.Web/Blazor/Components/Account/Login.razor.cs +++ b/src/NetCorePal.D3Shop.Web/Blazor/Components/Account/Login.razor.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Options; using NetCorePal.D3Shop.Admin.Shared.Requests; using NetCorePal.D3Shop.Web.Application.Queries.Identity; -using NetCorePal.D3Shop.Web.Application.Queries.Identity.QueryResult; +using NetCorePal.D3Shop.Web.Controllers.Identity.Dto; using NetCorePal.D3Shop.Web.Helper; namespace NetCorePal.D3Shop.Web.Blazor.Components.Account; diff --git a/src/NetCorePal.D3Shop.Web/Controllers/Identity/AdminUserAccountController.cs b/src/NetCorePal.D3Shop.Web/Controllers/Identity/AdminUserAccountController.cs index dff5f33..781db62 100644 --- a/src/NetCorePal.D3Shop.Web/Controllers/Identity/AdminUserAccountController.cs +++ b/src/NetCorePal.D3Shop.Web/Controllers/Identity/AdminUserAccountController.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Options; using NetCorePal.D3Shop.Admin.Shared.Requests; using NetCorePal.D3Shop.Web.Application.Queries.Identity; -using NetCorePal.D3Shop.Web.Application.Queries.Identity.QueryResult; +using NetCorePal.D3Shop.Web.Controllers.Identity.Dto; using NetCorePal.D3Shop.Web.Helper; using NetCorePal.Extensions.Dto; using NetCorePal.Extensions.Primitives; diff --git a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/QueryResult/AdminUserCredentials.cs b/src/NetCorePal.D3Shop.Web/Controllers/Identity/Dto/AdminUserCredentials.cs similarity index 66% rename from src/NetCorePal.D3Shop.Web/Application/Queries/Identity/QueryResult/AdminUserCredentials.cs rename to src/NetCorePal.D3Shop.Web/Controllers/Identity/Dto/AdminUserCredentials.cs index 6e19846..efc31dd 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/QueryResult/AdminUserCredentials.cs +++ b/src/NetCorePal.D3Shop.Web/Controllers/Identity/Dto/AdminUserCredentials.cs @@ -1,5 +1,5 @@ using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; -namespace NetCorePal.D3Shop.Web.Application.Queries.Identity.QueryResult; +namespace NetCorePal.D3Shop.Web.Controllers.Identity.Dto; public record AdminUserCredentials(AdminUserId Id, string Password); \ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/QueryResult/AuthenticationUserInfo.cs b/src/NetCorePal.D3Shop.Web/Controllers/Identity/Dto/AuthenticationUserInfo.cs similarity index 70% rename from src/NetCorePal.D3Shop.Web/Application/Queries/Identity/QueryResult/AuthenticationUserInfo.cs rename to src/NetCorePal.D3Shop.Web/Controllers/Identity/Dto/AuthenticationUserInfo.cs index 3918ef6..cdb2891 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/QueryResult/AuthenticationUserInfo.cs +++ b/src/NetCorePal.D3Shop.Web/Controllers/Identity/Dto/AuthenticationUserInfo.cs @@ -1,5 +1,5 @@ using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; -namespace NetCorePal.D3Shop.Web.Application.Queries.Identity.QueryResult; +namespace NetCorePal.D3Shop.Web.Controllers.Identity.Dto; public record AuthenticationUserInfo(AdminUserId Id,string Name,string Password,string Phone); \ No newline at end of file From c8dc84e07a90fca9d912e309ff0bf1e8259cf350 Mon Sep 17 00:00:00 2001 From: ZhengJie Date: Wed, 11 Dec 2024 14:39:40 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E6=98=BE=E5=BC=8F=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Application/Queries/Identity/AdminUserQuery.cs | 1 + .../Application/Queries/Identity/RoleQuery.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs index 58c31a5..4803a84 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs @@ -58,6 +58,7 @@ public async Task> GetAllAdminUsersAsync(AdminUserQ var adminUsers = await AdminUserSet.AsNoTracking() .WhereIf(!queryRequest.Name.IsNullOrWhiteSpace(), au => au.Name.Contains(queryRequest.Name!)) .WhereIf(!queryRequest.Phone.IsNullOrWhiteSpace(), au => au.Phone.Contains(queryRequest.Phone!)) + .OrderBy(au => au.Id) .Select(au => new AdminUserResponse(au.Id, au.Name, au.Phone)) .ToPagedDataAsync(queryRequest, cancellationToken); return adminUsers; diff --git a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs index 27fa1ce..bb2ab8a 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs @@ -19,6 +19,7 @@ public async Task> GetAllRolesAsync(RoleQueryRequest que return await RoleSet.AsNoTracking() .WhereIf(!query.Name.IsNullOrWhiteSpace(), r => r.Name.Contains(query.Name!)) .WhereIf(!query.Description.IsNullOrWhiteSpace(), r => r.Description.Contains(query.Description!)) + .OrderBy(r => r.Id) .Select(r => new RoleResponse(r.Id, r.Name, r.Description)) .ToPagedDataAsync(query, cancellationToken: cancellationToken); } From d2d5b3538174bb8995645b6684377ed0c6ea4bb0 Mon Sep 17 00:00:00 2001 From: ZhengJie Date: Wed, 11 Dec 2024 15:37:36 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8DPermissionManager?= =?UTF-8?q?=E7=BB=84=E4=BB=B6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Identity/PermissionManager.razor | 32 ++++---- .../Identity/PermissionManager.razor.cs | 81 ++++++++++++++----- .../Identity/Role/EditRolePermissions.razor | 2 +- .../Identity/User/EditUserPermissions.razor | 2 +- 4 files changed, 82 insertions(+), 35 deletions(-) diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor index 3aeb832..7fd8cf3 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor @@ -6,54 +6,56 @@ - + @foreach (var permissionGroup in PermissionGroups) { - - + var groupName = permissionGroup.Name; + + + -

@permissionGroup.Name

+

@groupName

- - + + OnCheck="args => OnTreeChange(args,groupName)"/>
}
\ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor.cs b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor.cs index 4f558f4..3e59f92 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor.cs +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/PermissionManager.razor.cs @@ -9,36 +9,81 @@ public sealed partial class PermissionManager : ComponentBase [Parameter] public EventCallback> AssignedPermissionCodesChanged { get; set; } public string[] DisabledPermissionCodes { get; set; } = []; - private readonly Dictionary> _treeDir = []; - private readonly Dictionary> _treeKeysDir = []; - private readonly Dictionary, Task>> _treeOnChangeEventDir = []; + private readonly Dictionary> _treeDir = new(); + private readonly Dictionary> _treeKeysDir = new(); private PermissionGroup[] PermissionGroups { get; set; } = []; - private Guid Id { get; set; } + private Guid TreeComponentKey { get; set; } protected override void OnInitialized() { PermissionGroups = PermissionDefinitionContext.PermissionGroups.ToArray(); foreach (var group in PermissionGroups) { - var treeId = group.Name; - _treeDir.Add(treeId, default!); - _treeKeysDir.Add(treeId, group.PermissionsWithChildren.Select(p => p.Code)); - _treeOnChangeEventDir.Add(treeId, async args => + var groupName = group.Name; + _treeDir[groupName] = default!; + _treeKeysDir[groupName] = group.PermissionsWithChildren.Select(p => p.Code); + } + } + + private async Task OnTreeChange(TreeEventArgs args, string groupName) + { + foreach (var key in _treeKeysDir[groupName]) + { + AssignedPermissionCodes.Remove(key); + } + AssignedPermissionCodes.AddRange(args.Tree.CheckedKeys); + + await AssignedPermissionCodesChanged.InvokeAsync(AssignedPermissionCodes); + } + + private async Task HandleCheckAll(bool isChecked, string? groupName = null) + { + if (groupName == null) + { + foreach (var tree in _treeDir.Values) { - foreach (var key in _treeKeysDir[args.Tree.Id]) - { - AssignedPermissionCodes.Remove(key); - } + if (isChecked) + tree.CheckAll(); + else + tree.UncheckAll(); + } - AssignedPermissionCodes.AddRange(args.Tree.CheckedKeys); + AssignedPermissionCodes.Clear(); + if (isChecked) + { + AssignedPermissionCodes.AddRange(_treeKeysDir.Values.SelectMany(k => k)); + } + } + else + { + if (_treeDir.TryGetValue(groupName, out var tree)) + { + if (isChecked) + tree.CheckAll(); + else + tree.UncheckAll(); + } - await AssignedPermissionCodesChanged.InvokeAsync(AssignedPermissionCodes); - }); + AssignedPermissionCodes.RemoveAll(code => _treeKeysDir[groupName].Contains(code)); + if (isChecked) + { + AssignedPermissionCodes.AddRange(_treeKeysDir[groupName]); + } } + + await AssignedPermissionCodesChanged.InvokeAsync(AssignedPermissionCodes); } - public void Update() + private Task OnCheckAll() => HandleCheckAll(true); + + private Task OnUncheckAll() => HandleCheckAll(false); + + private Task OnCheckGroupAll(string groupName) => HandleCheckAll(true, groupName); + + private Task OnUncheckGroupAll(string groupName) => HandleCheckAll(false, groupName); + + public void ReRenderTree() { - Id = Guid.NewGuid(); + TreeComponentKey = Guid.NewGuid(); } -} \ No newline at end of file +} diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/Role/EditRolePermissions.razor b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/Role/EditRolePermissions.razor index 7a17fbe..c1c8414 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/Role/EditRolePermissions.razor +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/Role/EditRolePermissions.razor @@ -25,7 +25,7 @@ { _modalVisible = true; _assignedPermissionCodes = await GetAssignedPermissionCodes(Row.Id); - _permissionManagerComponent.Update(); + _permissionManagerComponent.ReRenderTree(); } private async Task> GetAssignedPermissionCodes(RoleId id) diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/User/EditUserPermissions.razor b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/User/EditUserPermissions.razor index 4430638..fb30104 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/User/EditUserPermissions.razor +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/User/EditUserPermissions.razor @@ -34,7 +34,7 @@ _assignedPermissionCodes = adminUserPermissions.Select(p => p.Code).ToList(); _permissionManagerComponent.DisabledPermissionCodes = _permissionCodesFromRoles; - _permissionManagerComponent.Update(); + _permissionManagerComponent.ReRenderTree(); } private async Task GetAssignedPermissions(AdminUserId id) From f00cba0529922f0f7ef618d6451a90d03394dbf6 Mon Sep 17 00:00:00 2001 From: ZhengJie Date: Wed, 11 Dec 2024 15:41:26 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E5=8F=96=E6=B6=88=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=A7=92=E8=89=B2=E6=97=B6=E7=9A=84=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E9=9D=9E=E7=A9=BA=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Application/Commands/Identity/UpdateAdminUserRolesCommand.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolesCommand.cs b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolesCommand.cs index 9d0259c..28edca7 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolesCommand.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolesCommand.cs @@ -14,7 +14,6 @@ public class UpdateAdminUserRolesCommandValidator : AbstractValidator x.AdminUserId).NotEmpty(); - RuleFor(x => x.RolesToBeAssigned).NotEmpty(); } } From d8f480aec2fc30ea5eda7c32992acc3d591712e0 Mon Sep 17 00:00:00 2001 From: ZhengJie Date: Thu, 12 Dec 2024 09:21:48 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E4=B8=BAtable=E6=B7=BB=E5=8A=A0loading?= =?UTF-8?q?=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.Razor.cs | 5 +++++ src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.razor | 3 ++- src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor | 3 ++- src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor.cs | 5 +++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.Razor.cs b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.Razor.cs index a261178..2132d69 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.Razor.cs +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.Razor.cs @@ -14,6 +14,8 @@ public sealed partial class Roles private readonly RoleQueryRequest _roleQueryRequest = new() { CountTotal = true }; + private bool _loading; + protected override void OnAfterRender(bool firstRender) { if (!firstRender) return; @@ -65,11 +67,14 @@ private async Task Confirm(string message) private async Task OnSearch() { + _roleQueryRequest.PageIndex = 1; await GetPagedRoles(); } private async Task Table_OnChange(QueryModel obj) { + _loading = true; await GetPagedRoles(); + _loading = false; } } \ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.razor b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.razor index e5e19f1..933fbcc 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.razor +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.razor @@ -11,7 +11,8 @@ Total="_pagedRoles.Total" @bind-PageIndex="_roleQueryRequest.PageIndex" @bind-PageSize="_roleQueryRequest.PageSize" - OnChange="Table_OnChange"> + OnChange="Table_OnChange" + Loading="_loading"> + OnChange="Table_OnChange" + Loading="_loading"> Confirm(string message) private async Task OnSearch() { + _adminUserQueryRequest.PageIndex = 1; await GetPagedAdminUsers(); } private async Task Table_OnChange(QueryModel obj) { + _loading = true; await GetPagedAdminUsers(); + _loading = false; } } \ No newline at end of file From e10a68f0f9ef0df5dc568953bd774aa225afb39d Mon Sep 17 00:00:00 2001 From: ZhengJie Date: Fri, 13 Dec 2024 09:35:42 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E7=A7=BB=E9=99=A4AdminUserPermission?= =?UTF-8?q?=E5=92=8CRolePermission=E4=B8=AD=E5=86=97=E4=BD=99=E7=9A=84Perm?= =?UTF-8?q?issionRemark;=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=A7=92=E8=89=B2=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Responses/AdminUserResponse.cs | 3 ++- .../AdminUserAggregate/AdminUserPermssion.cs | 4 +--- .../Identity/RoleAggregate/RolePermission.cs | 11 ++++++----- .../Components/Identity/User/EditUserRoles.razor | 6 ++++++ .../Pages/Roles.razor | 4 ---- .../Pages/Users.razor | 12 +++++++----- .../Pages/Users.razor.cs | 7 +++++++ .../Commands/Identity/CreateAdminUserCommand.cs | 8 ++------ .../Commands/Identity/CreateRoleCommand.cs | 6 ++---- .../Commands/Identity/Dto/AdminUserPermissionDto.cs | 7 ------- .../Commands/Identity/Dto/AssignAdminUserRoleDto.cs | 2 +- .../Commands/Identity/Dto/RolePermissionDto.cs | 7 ------- .../Identity/SetAdminUserSpecificPermissions.cs | 5 ++--- .../UpdateAdminUserRolePermissionsCommand.cs | 6 ++---- .../Commands/Identity/UpdateAdminUserRolesCommand.cs | 5 ++--- .../Identity/UpdateRolePermissionsCommand.cs | 6 ++---- .../RolePermissionsChangedDomainEventHandler.cs | 6 +++--- .../Application/Queries/Identity/AdminUserQuery.cs | 2 +- .../Application/Queries/Identity/RoleQuery.cs | 4 +--- .../Controllers/Identity/AdminUserController.cs | 3 +-- .../Controllers/Identity/RoleController.cs | 5 ++--- .../Identity/AdminUserTests.cs | 2 +- .../Identity/RoleTests.cs | 2 +- .../Identity/AuthTests.cs | 2 +- 24 files changed, 53 insertions(+), 72 deletions(-) delete mode 100644 src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/AdminUserPermissionDto.cs delete mode 100644 src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/RolePermissionDto.cs diff --git a/src/NetCorePal.D3Shop.Admin.Shared/Responses/AdminUserResponse.cs b/src/NetCorePal.D3Shop.Admin.Shared/Responses/AdminUserResponse.cs index bb61d95..cc5e808 100644 --- a/src/NetCorePal.D3Shop.Admin.Shared/Responses/AdminUserResponse.cs +++ b/src/NetCorePal.D3Shop.Admin.Shared/Responses/AdminUserResponse.cs @@ -2,9 +2,10 @@ namespace NetCorePal.D3Shop.Admin.Shared.Responses; -public class AdminUserResponse(AdminUserId id, string name, string phone) +public class AdminUserResponse(AdminUserId id, string name, string phone, IEnumerable roles) { public AdminUserId Id { get; } = id; public string Name { get; set; } = name; public string Phone { get; set; } = phone; + public IEnumerable Roles { get; set; } = roles; } \ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/AdminUserAggregate/AdminUserPermssion.cs b/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/AdminUserAggregate/AdminUserPermssion.cs index 0966ad9..c778022 100644 --- a/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/AdminUserAggregate/AdminUserPermssion.cs +++ b/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/AdminUserAggregate/AdminUserPermssion.cs @@ -10,13 +10,11 @@ protected AdminUserPermission() public AdminUserId AdminUserId { get; private set; } = default!; public string PermissionCode { get; private set; } = string.Empty; - public string PermissionRemark { get; private set; } = string.Empty; public List SourceRoleIds { get; } = []; - public AdminUserPermission(string permissionCode, string permissionRemark, RoleId? sourceRoleId = null) + public AdminUserPermission(string permissionCode, RoleId? sourceRoleId = null) { PermissionCode = permissionCode; - PermissionRemark = permissionRemark; if (sourceRoleId is not null) { SourceRoleIds.Add(sourceRoleId); diff --git a/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/RoleAggregate/RolePermission.cs b/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/RoleAggregate/RolePermission.cs index 39905bc..a30ac4a 100644 --- a/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/RoleAggregate/RolePermission.cs +++ b/src/NetCorePal.D3Shop.Domain/AggregatesModel/Identity/RoleAggregate/RolePermission.cs @@ -2,15 +2,16 @@ { public class RolePermission { - protected RolePermission() { } + protected RolePermission() + { + } + public RoleId RoleId { get; internal set; } = default!; public string PermissionCode { get; private set; } = string.Empty; - public string PermissionRemark { get; private set; } = string.Empty; - public RolePermission(string permissionCode, string permissionRemark) + public RolePermission(string permissionCode) { PermissionCode = permissionCode; - PermissionRemark = permissionRemark; } } -} +} \ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/User/EditUserRoles.razor b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/User/EditUserRoles.razor index 5da9680..3e0a6a3 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/User/EditUserRoles.razor +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Components/Identity/User/EditUserRoles.razor @@ -18,6 +18,9 @@ private CheckboxOption[] _roleOptions = []; private RoleId[] _selectedRoleIds = []; + + public record RolesUpdateSucceededEventArgs(AdminUserId AdminUserId, IEnumerable RoleNames); + [Parameter] public EventCallback OnUpdateSucceeded { get; set; } private bool _modalVisible; private bool _modalConfirmLoading; @@ -52,6 +55,9 @@ { _modalVisible = false; _ = Message.Success("更新成功!"); + await OnUpdateSucceeded.InvokeAsync(new RolesUpdateSucceededEventArgs( + Row.Id, + _roleOptions.Where(r => _selectedRoleIds.Contains(r.Value)).Select(r => r.Label))); } else { diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.razor b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.razor index 933fbcc..830f850 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.razor +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.razor @@ -50,16 +50,12 @@ } - - @if (context.CheckPermission(PermissionCodes.RoleUpdatePermissions)) { } - - @if (context.CheckPermission(PermissionCodes.RoleDelete)) { 删除 diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor index 78fce70..1a34f3f 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor @@ -41,25 +41,27 @@ + + @foreach (var roleName in row.Roles) + { + @roleName + } + @if (context.CheckPermission(PermissionCodes.AdminUserUpdateRoles)) { - + } - - @if (context.CheckPermission(PermissionCodes.AdminUserSetPermissions)) { } - - @if (context.CheckPermission(PermissionCodes.AdminUserDelete)) { 删除 diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor.cs b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor.cs index 9bcf8a3..726480e 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor.cs +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor.cs @@ -1,4 +1,5 @@ using AntDesign.TableModels; +using NetCorePal.D3Shop.Web.Admin.Client.Components.Identity.User; namespace NetCorePal.D3Shop.Web.Admin.Client.Pages; @@ -39,6 +40,12 @@ private async Task HandleItemAdded() await GetPagedAdminUsers(); } + private void HandleRolesUpdate(EditUserRoles.RolesUpdateSucceededEventArgs args) + { + var userItem = _pagedAdminUsers.Items.Single(au => au.Id == args.AdminUserId); + userItem.Roles = args.RoleNames; + } + private async Task Delete(AdminUserResponse row) { if (!await Confirm($"确认删除用户:{row.Name}?")) diff --git a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/CreateAdminUserCommand.cs b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/CreateAdminUserCommand.cs index 180d2ec..6862264 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/CreateAdminUserCommand.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/CreateAdminUserCommand.cs @@ -34,14 +34,10 @@ public async Task Handle(CreateAdminUserCommand request, Cancellati List adminUserRoles = []; List adminUserPermissions = []; - foreach (var (roleId, roleName, permissions) in request.RolesToBeAssigned) + foreach (var (roleId, roleName, permissionCodes) in request.RolesToBeAssigned) { adminUserRoles.Add(new AdminUserRole(roleId, roleName)); - - adminUserPermissions.AddRange( - permissions.Select(permission => - new AdminUserPermission(permission.PermissionCode, permission.PermissionRemark, roleId)) - ); + adminUserPermissions.AddRange(permissionCodes.Select(code => new AdminUserPermission(code, roleId))); } var adminUser = new AdminUser(request.Name, request.Phone, request.Password, diff --git a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/CreateRoleCommand.cs b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/CreateRoleCommand.cs index e601781..18092b8 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/CreateRoleCommand.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/CreateRoleCommand.cs @@ -1,13 +1,12 @@ using FluentValidation; using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.RoleAggregate; using NetCorePal.D3Shop.Infrastructure.Repositories.Identity; -using NetCorePal.D3Shop.Web.Application.Commands.Identity.Dto; using NetCorePal.D3Shop.Web.Application.Queries.Identity; using NetCorePal.Extensions.Primitives; namespace NetCorePal.D3Shop.Web.Application.Commands.Identity; -public record CreateRoleCommand(string Name, string Description, IEnumerable Permissions) +public record CreateRoleCommand(string Name, string Description, IEnumerable PermissionCodes) : ICommand; public class CreateRoleCommandValidator : AbstractValidator @@ -24,8 +23,7 @@ public class CreateRoleCommandHandler(IRoleRepository roleRepository) : ICommand { public async Task Handle(CreateRoleCommand request, CancellationToken cancellationToken) { - var permissions = request.Permissions - .Select(p => new RolePermission(p.PermissionCode, p.PermissionRemark)); + var permissions = request.PermissionCodes.Select(code => new RolePermission(code)); var role = new Role(request.Name, request.Description, permissions); diff --git a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/AdminUserPermissionDto.cs b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/AdminUserPermissionDto.cs deleted file mode 100644 index 5784cb7..0000000 --- a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/AdminUserPermissionDto.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace NetCorePal.D3Shop.Web.Application.Commands.Identity.Dto; - -public readonly struct AdminUserPermissionDto(string permissionCode, string permissionRemark) -{ - public string PermissionCode { get; } = permissionCode; - public string PermissionRemark { get; } = permissionRemark; -} \ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/AssignAdminUserRoleDto.cs b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/AssignAdminUserRoleDto.cs index 0758013..0232eda 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/AssignAdminUserRoleDto.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/AssignAdminUserRoleDto.cs @@ -2,5 +2,5 @@ namespace NetCorePal.D3Shop.Web.Application.Commands.Identity.Dto { - public record AssignAdminUserRoleDto(RoleId RoleId, string RoleName, IEnumerable Permissions); + public record AssignAdminUserRoleDto(RoleId RoleId, string RoleName, IEnumerable PermissionCodes); } diff --git a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/RolePermissionDto.cs b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/RolePermissionDto.cs deleted file mode 100644 index bbd61e7..0000000 --- a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/Dto/RolePermissionDto.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace NetCorePal.D3Shop.Web.Application.Commands.Identity.Dto; - -public class RolePermissionDto(string permissionCode, string permissionRemark) -{ - public string PermissionCode { get; } = permissionCode; - public string PermissionRemark { get; } = permissionRemark; -} \ No newline at end of file diff --git a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/SetAdminUserSpecificPermissions.cs b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/SetAdminUserSpecificPermissions.cs index 19c5600..ea3b92d 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/SetAdminUserSpecificPermissions.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/SetAdminUserSpecificPermissions.cs @@ -5,7 +5,7 @@ namespace NetCorePal.D3Shop.Web.Application.Commands.Identity; -public record SetAdminUserSpecificPermissions(AdminUserId Id, IEnumerable Permissions) +public record SetAdminUserSpecificPermissions(AdminUserId Id, IEnumerable PermissionCodes) : ICommand; public class SetAdminUserSpecificPermissionsCommandHandler(IAdminUserRepository adminUserRepository) @@ -16,8 +16,7 @@ public async Task Handle(SetAdminUserSpecificPermissions request, CancellationTo var adminUser = await adminUserRepository.GetAsync(request.Id, cancellationToken) ?? throw new KnownException($"用户不存在,AdminUserId={request.Id}"); - var permissions = request.Permissions - .Select(p => new AdminUserPermission(p.PermissionCode, p.PermissionRemark)); + var permissions = request.PermissionCodes.Select(code => new AdminUserPermission(code)); adminUser.SetSpecificPermissions(permissions); } diff --git a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolePermissionsCommand.cs b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolePermissionsCommand.cs index a77ac48..d70f10c 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolePermissionsCommand.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolePermissionsCommand.cs @@ -1,7 +1,6 @@ using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.AdminUserAggregate; using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.RoleAggregate; using NetCorePal.D3Shop.Infrastructure.Repositories.Identity; -using NetCorePal.D3Shop.Web.Application.Commands.Identity.Dto; using NetCorePal.Extensions.Primitives; namespace NetCorePal.D3Shop.Web.Application.Commands.Identity; @@ -9,7 +8,7 @@ namespace NetCorePal.D3Shop.Web.Application.Commands.Identity; public record UpdateAdminUserRolePermissionsCommand( AdminUserId AdminUserId, RoleId RoleId, - IEnumerable Permissions) : ICommand; + IEnumerable PermissionCodes) : ICommand; public class UpdateAdminUserRolePermissionsCommandHandler(IAdminUserRepository adminUserRepository) : ICommandHandler @@ -19,8 +18,7 @@ public async Task Handle(UpdateAdminUserRolePermissionsCommand request, Cancella var adminUser = await adminUserRepository.GetAsync(request.AdminUserId, cancellationToken) ?? throw new KnownException($"用户不存在,AdminUserId={request.AdminUserId}"); - var permissions = request.Permissions.Select(p => - new AdminUserPermission(p.PermissionCode, p.PermissionRemark, request.RoleId)); + var permissions = request.PermissionCodes.Select(code => new AdminUserPermission(code, request.RoleId)); adminUser.UpdateRolePermissions(request.RoleId, permissions); } diff --git a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolesCommand.cs b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolesCommand.cs index 28edca7..373aa3e 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolesCommand.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateAdminUserRolesCommand.cs @@ -31,9 +31,8 @@ public async Task Handle(UpdateAdminUserRolesCommand request, CancellationToken foreach (var assignAdminUserRoleDto in request.RolesToBeAssigned) { roles.Add(new AdminUserRole(assignAdminUserRoleDto.RoleId, assignAdminUserRoleDto.RoleName)); - permissions.AddRange(assignAdminUserRoleDto.Permissions.Select(permission => - new AdminUserPermission(permission.PermissionCode, permission.PermissionRemark, - assignAdminUserRoleDto.RoleId))); + permissions.AddRange(assignAdminUserRoleDto.PermissionCodes.Select(code => + new AdminUserPermission(code, assignAdminUserRoleDto.RoleId))); } adminUser.UpdateRoles(roles, permissions); diff --git a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateRolePermissionsCommand.cs b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateRolePermissionsCommand.cs index 54fe94b..9f48f7a 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateRolePermissionsCommand.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Commands/Identity/UpdateRolePermissionsCommand.cs @@ -1,11 +1,10 @@ using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.RoleAggregate; using NetCorePal.D3Shop.Infrastructure.Repositories.Identity; -using NetCorePal.D3Shop.Web.Application.Commands.Identity.Dto; using NetCorePal.Extensions.Primitives; namespace NetCorePal.D3Shop.Web.Application.Commands.Identity; -public record UpdateRolePermissionsCommand(RoleId RoleId, IEnumerable Permissions) : ICommand; +public record UpdateRolePermissionsCommand(RoleId RoleId, IEnumerable PermissionCodes) : ICommand; public class UpdateRolePermissionsCommandHandler(IRoleRepository roleRepository) : ICommandHandler @@ -15,8 +14,7 @@ public async Task Handle(UpdateRolePermissionsCommand request, CancellationToken var role = await roleRepository.GetAsync(request.RoleId, cancellationToken) ?? throw new KnownException($"角色不存在,RoleId={request.RoleId}"); - var permissions = request.Permissions - .Select(p => new RolePermission(p.PermissionCode, p.PermissionRemark)); + var permissions = request.PermissionCodes.Select(code => new RolePermission(code)); role.UpdateRolePermissions(permissions); } diff --git a/src/NetCorePal.D3Shop.Web/Application/DomainEventHandlers/Identity/RolePermissionsChangedDomainEventHandler.cs b/src/NetCorePal.D3Shop.Web/Application/DomainEventHandlers/Identity/RolePermissionsChangedDomainEventHandler.cs index 55cb41b..b166e2e 100644 --- a/src/NetCorePal.D3Shop.Web/Application/DomainEventHandlers/Identity/RolePermissionsChangedDomainEventHandler.cs +++ b/src/NetCorePal.D3Shop.Web/Application/DomainEventHandlers/Identity/RolePermissionsChangedDomainEventHandler.cs @@ -18,14 +18,14 @@ public async Task Handle(RolePermissionChangedDomainEvent notification, Cancella { var roleId = notification.Role.Id; var adminUserIds = await adminUserQuery.GetAdminUserIdsByRoleIdAsync(roleId, cancellationToken); - var permissions = notification.Role.Permissions - .Select(p => new AdminUserPermissionDto(p.PermissionCode, p.PermissionRemark)) + var permissionCodes = notification.Role.Permissions + .Select(p => p.PermissionCode) .ToArray(); foreach (var adminUserId in adminUserIds) { memoryCache.Remove($"{CacheKeys.AdminUserPermissions}:{adminUserId}"); - await mediator.Send(new UpdateAdminUserRolePermissionsCommand(adminUserId, roleId, permissions), + await mediator.Send(new UpdateAdminUserRolePermissionsCommand(adminUserId, roleId, permissionCodes), cancellationToken); } } diff --git a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs index 4803a84..b02d7c3 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/AdminUserQuery.cs @@ -59,7 +59,7 @@ public async Task> GetAllAdminUsersAsync(AdminUserQ .WhereIf(!queryRequest.Name.IsNullOrWhiteSpace(), au => au.Name.Contains(queryRequest.Name!)) .WhereIf(!queryRequest.Phone.IsNullOrWhiteSpace(), au => au.Phone.Contains(queryRequest.Phone!)) .OrderBy(au => au.Id) - .Select(au => new AdminUserResponse(au.Id, au.Name, au.Phone)) + .Select(au => new AdminUserResponse(au.Id, au.Name, au.Phone, au.Roles.Select(r => r.RoleName))) .ToPagedDataAsync(queryRequest, cancellationToken); return adminUsers; } diff --git a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs index bb2ab8a..835190c 100644 --- a/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs +++ b/src/NetCorePal.D3Shop.Web/Application/Queries/Identity/RoleQuery.cs @@ -39,9 +39,7 @@ public async Task> GetAdminRolesForAssignmentAsync( .Select(r => new AssignAdminUserRoleDto( r.Id, r.Name, - r.Permissions.Select(rp => - new AdminUserPermissionDto(rp.PermissionCode, rp.PermissionRemark))) - ) + r.Permissions.Select(rp => rp.PermissionCode))) .ToListAsync(cancellationToken: cancellationToken); } diff --git a/src/NetCorePal.D3Shop.Web/Controllers/Identity/AdminUserController.cs b/src/NetCorePal.D3Shop.Web/Controllers/Identity/AdminUserController.cs index 2332e1d..626a36e 100644 --- a/src/NetCorePal.D3Shop.Web/Controllers/Identity/AdminUserController.cs +++ b/src/NetCorePal.D3Shop.Web/Controllers/Identity/AdminUserController.cs @@ -7,7 +7,6 @@ using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.RoleAggregate; using NetCorePal.D3Shop.Web.Admin.Client.Services; using NetCorePal.D3Shop.Web.Application.Commands.Identity; -using NetCorePal.D3Shop.Web.Application.Commands.Identity.Dto; using NetCorePal.D3Shop.Web.Application.Queries.Identity; using NetCorePal.D3Shop.Web.Auth; using NetCorePal.D3Shop.Web.Blazor; @@ -81,7 +80,7 @@ public async Task SetAdminUserSpecificPermissions(AdminUserId id, .Select(code => { var permission = PermissionDefinitionContext.GetPermission(code); - return new AdminUserPermissionDto(permission.Code, permission.DisplayName); + return permission.Code; }); await mediator.Send(new SetAdminUserSpecificPermissions(id, permissionsToBeAssigned), CancellationToken); return new ResponseData(); diff --git a/src/NetCorePal.D3Shop.Web/Controllers/Identity/RoleController.cs b/src/NetCorePal.D3Shop.Web/Controllers/Identity/RoleController.cs index 116226c..8ebc0b0 100644 --- a/src/NetCorePal.D3Shop.Web/Controllers/Identity/RoleController.cs +++ b/src/NetCorePal.D3Shop.Web/Controllers/Identity/RoleController.cs @@ -6,7 +6,6 @@ using NetCorePal.D3Shop.Domain.AggregatesModel.Identity.RoleAggregate; using NetCorePal.D3Shop.Web.Admin.Client.Services; using NetCorePal.D3Shop.Web.Application.Commands.Identity; -using NetCorePal.D3Shop.Web.Application.Commands.Identity.Dto; using NetCorePal.D3Shop.Web.Application.Queries.Identity; using NetCorePal.D3Shop.Web.Auth; using NetCorePal.D3Shop.Web.Blazor; @@ -30,7 +29,7 @@ public async Task> CreateRole([FromBody] CreateRoleRequest .Select(code => { var permission = PermissionDefinitionContext.GetPermission(code); - return new RolePermissionDto(permission.Code, permission.DisplayName); + return permission.Code; }); var roleId = await mediator.Send( @@ -76,7 +75,7 @@ public async Task UpdateRolePermissions([FromRoute] RoleId id, .Select(code => { var permission = PermissionDefinitionContext.GetPermission(code); - return new RolePermissionDto(permission.Code, permission.DisplayName); + return permission.Code; }); await mediator.Send( diff --git a/test/NetCorePal.D3Shop.Domain.Tests/Identity/AdminUserTests.cs b/test/NetCorePal.D3Shop.Domain.Tests/Identity/AdminUserTests.cs index f4149fd..a3bbff6 100644 --- a/test/NetCorePal.D3Shop.Domain.Tests/Identity/AdminUserTests.cs +++ b/test/NetCorePal.D3Shop.Domain.Tests/Identity/AdminUserTests.cs @@ -14,7 +14,7 @@ public void EditRole_Test() const string rolePermission = "testPermission"; _testUser.UpdateRoles( [new AdminUserRole(new RoleId(1), roleName)], - [new AdminUserPermission(rolePermission, "test", new RoleId(1))] + [new AdminUserPermission(rolePermission, new RoleId(1))] ); Assert.Contains(_testUser.Roles, r => r.RoleName == roleName); Assert.True(_testUser.IsInRole(roleName)); diff --git a/test/NetCorePal.D3Shop.Domain.Tests/Identity/RoleTests.cs b/test/NetCorePal.D3Shop.Domain.Tests/Identity/RoleTests.cs index 9df1b67..aa68df6 100644 --- a/test/NetCorePal.D3Shop.Domain.Tests/Identity/RoleTests.cs +++ b/test/NetCorePal.D3Shop.Domain.Tests/Identity/RoleTests.cs @@ -8,7 +8,7 @@ public class RoleTests public void EditRolePermission_Test() { const string rolePermission = "testPermission"; - var role = new Role("testRole", "", [new RolePermission(rolePermission, "test")]); + var role = new Role("testRole", "", [new RolePermission(rolePermission)]); Assert.Contains(role.Permissions, p => p.PermissionCode == rolePermission); role.UpdateRolePermissions([]); Assert.Empty(role.Permissions); diff --git a/test/NetCorePal.D3Shop.Web.Tests/Identity/AuthTests.cs b/test/NetCorePal.D3Shop.Web.Tests/Identity/AuthTests.cs index 12f0f6d..b626d14 100644 --- a/test/NetCorePal.D3Shop.Web.Tests/Identity/AuthTests.cs +++ b/test/NetCorePal.D3Shop.Web.Tests/Identity/AuthTests.cs @@ -18,7 +18,7 @@ public AuthTests(MyWebApplicationFactory factory) { var db = scope.ServiceProvider.GetRequiredService(); _testUser.SetPassword(PasswordHasher.HashPassword(AppDefaultCredentials.Password)); - _testUser.SetSpecificPermissions([new AdminUserPermission("AdminUserAuth_Test_Get", "")]); + _testUser.SetSpecificPermissions([new AdminUserPermission("AdminUserAuth_Test_Get")]); db.AdminUsers.Add(_testUser); db.SaveChanges(); } From 63473d0e1aacaccfde87c7772cd24225c4b79e1d Mon Sep 17 00:00:00 2001 From: ZhengJie Date: Fri, 13 Dec 2024 13:56:18 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=A1=86=E6=9E=B6?= =?UTF-8?q?=E8=BD=AF=E4=BB=B6=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Build.targets | 2 +- src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.Razor.cs | 2 +- src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index bfc132b..acf0802 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,6 +1,6 @@ - 2.0.0-preview.1.2411260738 + 2.0.0-preview.1.2412130327 8.0.10 8.0.0 8.0.0 diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.Razor.cs b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.Razor.cs index 2132d69..a95d399 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.Razor.cs +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Roles.Razor.cs @@ -8,7 +8,7 @@ public sealed partial class Roles [Inject] private MessageService Message { get; set; } = default!; [Inject] private ConfirmService ConfirmService { get; set; } = default!; - private PagedData _pagedRoles = new(default!, default, default, default); + private PagedData _pagedRoles = PagedData.Empty; private ITable _table = default!; diff --git a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor.cs b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor.cs index 726480e..70e5c98 100644 --- a/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor.cs +++ b/src/NetCorePal.D3Shop.Web.Admin.Client/Pages/Users.razor.cs @@ -9,7 +9,7 @@ public sealed partial class Users [Inject] private MessageService Message { get; set; } = default!; [Inject] private ConfirmService ConfirmService { get; set; } = default!; - private PagedData _pagedAdminUsers = new(default!, default, default, default); + private PagedData _pagedAdminUsers = PagedData.Empty; private Table _table = default!; From f6a42c8f9bc655a4a2a3525a0b14fb14bc261b15 Mon Sep 17 00:00:00 2001 From: witskeeper Date: Mon, 16 Dec 2024 09:37:07 +0800 Subject: [PATCH 10/10] Update Directory.Build.targets --- Directory.Build.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.targets b/Directory.Build.targets index acf0802..fbf13af 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,6 +1,6 @@ - 2.0.0-preview.1.2412130327 + 2.0.0 8.0.10 8.0.0 8.0.0