diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNodeDriver.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNodeDriver.cs index a4ed3f15cae..bf6c6c697ef 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNodeDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/LinkAdminNodeDriver.cs @@ -31,8 +31,6 @@ public override IDisplayResult Edit(LinkAdminNode treeNode, BuildEditorContext c model.IconClass = treeNode.IconClass; model.Target = treeNode.Target; - var permissions = await _permissionService.GetPermissionsAsync(); - var selectedPermissions = await _permissionService.FindByNamesAsync(treeNode.PermissionNames); model.SelectedItems = selectedPermissions @@ -41,6 +39,9 @@ public override IDisplayResult Edit(LinkAdminNode treeNode, BuildEditorContext c Name = p.Name, DisplayText = p.Description }).ToArray(); + + var permissions = await _permissionService.GetPermissionsAsync(); + model.AllItems = permissions .Select(p => new PermissionViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/PlaceholderAdminNodeDriver.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/PlaceholderAdminNodeDriver.cs index 42e46c045f8..d6f9fa45b82 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/PlaceholderAdminNodeDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminNodes/PlaceholderAdminNodeDriver.cs @@ -29,8 +29,6 @@ public override IDisplayResult Edit(PlaceholderAdminNode treeNode, BuildEditorCo model.LinkText = treeNode.LinkText; model.IconClass = treeNode.IconClass; - var permissions = await _permissionService.GetPermissionsAsync(); - var selectedPermissions = await _permissionService.FindByNamesAsync(treeNode.PermissionNames); model.SelectedItems = selectedPermissions @@ -39,6 +37,9 @@ public override IDisplayResult Edit(PlaceholderAdminNode treeNode, BuildEditorCo Name = p.Name, DisplayText = p.Description }).ToArray(); + + var permissions = await _permissionService.GetPermissionsAsync(); + model.AllItems = permissions .Select(p => new PermissionViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/Drivers/MenuItemPermissionPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Menu/Drivers/MenuItemPermissionPartDisplayDriver.cs index 6cd017c89a7..005b5ce8160 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/Drivers/MenuItemPermissionPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/Drivers/MenuItemPermissionPartDisplayDriver.cs @@ -20,9 +20,7 @@ public override IDisplayResult Edit(MenuItemPermissionPart part, BuildPartEditor { return Initialize("MenuItemPermissionPart_Edit", async model => { - var permissions = await _permissionService.GetPermissionsAsync(); - - var selectedPermissions = permissions.Where(p => part.PermissionNames.Contains(p.Name)); + var selectedPermissions = await _permissionService.FindByNamesAsync(part.PermissionNames); model.SelectedItems = selectedPermissions .Select(p => new PermissionViewModel @@ -31,6 +29,8 @@ public override IDisplayResult Edit(MenuItemPermissionPart part, BuildPartEditor DisplayText = p.Description }).ToArray(); + var permissions = await _permissionService.GetPermissionsAsync(); + model.AllItems = permissions .Select(p => new PermissionViewModel { @@ -50,10 +50,9 @@ await context.Updater.TryUpdateModelAsync(model, Prefix, ? [] : model.SelectedPermissionNames.Split(',', StringSplitOptions.RemoveEmptyEntries); - var permissions = await _permissionService.GetPermissionsAsync(); - part.PermissionNames = permissions - .Where(p => selectedPermissions.Contains(p.Name)) - .Select(p => p.Name).ToArray(); + var permissions = await _permissionService.FindByNamesAsync(selectedPermissions); + + part.PermissionNames = permissions.Select(x => x.Name).ToArray(); return Edit(part, context); } diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Security/Permissions/DefaultPermissionService.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Security/Permissions/DefaultPermissionService.cs index b9cd732faff..d3e350d774a 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Security/Permissions/DefaultPermissionService.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Security/Permissions/DefaultPermissionService.cs @@ -31,13 +31,11 @@ public async ValueTask FindByNameAsync(string name) public async ValueTask> GetPermissionsAsync() { - if (_permissions != null) + if (_permissions == null) { - return _permissions.Values; + await LoadPermissionsAsync(); } - await LoadPermissionsAsync(); - return _permissions.Values; }