diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Blazor/Components/PermissionManagementModal.razor.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Blazor/Components/PermissionManagementModal.razor.cs index 8a5c82e734e..4a55b75df8e 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Blazor/Components/PermissionManagementModal.razor.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Blazor/Components/PermissionManagementModal.razor.cs @@ -17,7 +17,7 @@ public partial class PermissionManagementModal [Inject] protected ICurrentApplicationConfigurationCacheResetService CurrentApplicationConfigurationCacheResetService { get; set; } [Inject] protected IOptions LocalizationOptions { get; set; } - + protected Modal _modal; protected string _providerName; @@ -71,7 +71,7 @@ protected bool GrantAll { } } } - + protected Dictionary _permissionDepths = new Dictionary(); public PermissionManagementModal() @@ -137,7 +137,7 @@ protected virtual async Task SaveAsync() { try { - + var updateDto = new UpdatePermissionsDto { Permissions = _groups @@ -145,7 +145,7 @@ protected virtual async Task SaveAsync() .Select(p => new UpdatePermissionDto { IsGranted = p.IsGranted, Name = p.Name }) .ToArray() }; - + if (!updateDto.Permissions.Any(x => x.IsGranted)) { if (!await Message.Confirm(L["SaveWithoutAnyPermissionsWarningMessage"].Value)) @@ -182,7 +182,7 @@ protected virtual void SetPermissionDepths(List permissi } } } - + protected virtual int GetPermissionDepthOrDefault(string name) { return _permissionDepths.GetValueOrDefault(name, 0); @@ -207,7 +207,7 @@ protected virtual void PermissionChanged(bool value, PermissionGroupDto permissi { SetParentPermissionGrant(permissionGroup, permission); } - else if (value == false) + else { var childPermissions = GetChildPermissions(permissionGroup, permission); @@ -229,7 +229,7 @@ private void SetParentPermissionGrant(PermissionGroupDto permissionGroup, Permis SetPermissionGrant(parentPermission, true); SetParentPermissionGrant(permissionGroup, parentPermission); - + } private void SetPermissionGrant(PermissionGrantInfoDto permission, bool value) @@ -260,7 +260,25 @@ protected PermissionGrantInfoDto GetParentPermission(PermissionGroupDto permissi protected List GetChildPermissions(PermissionGroupDto permissionGroup, PermissionGrantInfoDto permission) { - return permissionGroup.Permissions.Where(x => x.Name.StartsWith(permission.Name)).ToList(); + var childPermissions = new List(); + GetChildPermissions(childPermissions, permissionGroup.Permissions, permission); + return childPermissions; + } + + protected void GetChildPermissions(List allChildPermissions, List permissions, PermissionGrantInfoDto permission) + { + var childPermissions = permissions.Where(x => x.ParentName == permission.Name).ToList(); + if (childPermissions.Count == 0) + { + return; + } + + allChildPermissions.AddRange(childPermissions); + + foreach (var childPermission in childPermissions) + { + GetChildPermissions(allChildPermissions, permissions, childPermission); + } } protected bool IsDisabledPermission(PermissionGrantInfoDto permissionGrantInfo)