Skip to content

Commit

Permalink
Get child permissions by parent instead name.
Browse files Browse the repository at this point in the history
  • Loading branch information
maliming committed Jan 10, 2024
1 parent f831835 commit 2ebbf01
Showing 1 changed file with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class PermissionManagementModal
[Inject] protected ICurrentApplicationConfigurationCacheResetService CurrentApplicationConfigurationCacheResetService { get; set; }

[Inject] protected IOptions<AbpLocalizationOptions> LocalizationOptions { get; set; }

protected Modal _modal;

protected string _providerName;
Expand Down Expand Up @@ -71,7 +71,7 @@ protected bool GrantAll {
}
}
}

protected Dictionary<string, int> _permissionDepths = new Dictionary<string, int>();

public PermissionManagementModal()
Expand Down Expand Up @@ -137,15 +137,15 @@ protected virtual async Task SaveAsync()
{
try
{

var updateDto = new UpdatePermissionsDto
{
Permissions = _groups
.SelectMany(g => g.Permissions)
.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))
Expand Down Expand Up @@ -182,7 +182,7 @@ protected virtual void SetPermissionDepths(List<PermissionGrantInfoDto> permissi
}
}
}

protected virtual int GetPermissionDepthOrDefault(string name)
{
return _permissionDepths.GetValueOrDefault(name, 0);
Expand All @@ -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);

Expand All @@ -229,7 +229,7 @@ private void SetParentPermissionGrant(PermissionGroupDto permissionGroup, Permis
SetPermissionGrant(parentPermission, true);

SetParentPermissionGrant(permissionGroup, parentPermission);

}

private void SetPermissionGrant(PermissionGrantInfoDto permission, bool value)
Expand Down Expand Up @@ -260,7 +260,25 @@ protected PermissionGrantInfoDto GetParentPermission(PermissionGroupDto permissi

protected List<PermissionGrantInfoDto> GetChildPermissions(PermissionGroupDto permissionGroup, PermissionGrantInfoDto permission)
{
return permissionGroup.Permissions.Where(x => x.Name.StartsWith(permission.Name)).ToList();
var childPermissions = new List<PermissionGrantInfoDto>();
GetChildPermissions(childPermissions, permissionGroup.Permissions, permission);
return childPermissions;
}

protected void GetChildPermissions(List<PermissionGrantInfoDto> allChildPermissions, List<PermissionGrantInfoDto> 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)
Expand Down

0 comments on commit 2ebbf01

Please sign in to comment.