Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get child permissions by parent instead name. #18743

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading