Skip to content

Commit

Permalink
Mark duplicate permissions as Obsolete (#16176)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Zoltán Lehóczky <[email protected]>
  • Loading branch information
MikeAlhayek and Piedone authored May 29, 2024
1 parent 167dffb commit b527fb5
Show file tree
Hide file tree
Showing 30 changed files with 177 additions and 117 deletions.
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Admin/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OrchardCore.Admin;

public class Permissions : IPermissionProvider
{
[Obsolete("This property will be removed in future release. Instead use 'AdminPermissions.AccessAdminPanel'.")]
[Obsolete("This will be removed in a future release. Instead use 'AdminPermissions.AccessAdminPanel'.")]
public static readonly Permission AccessAdminPanel = AdminPermissions.AccessAdminPanel;

private readonly IEnumerable<Permission> _allPermissions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
.Add(S["Configuration"], configuration => configuration
.Add(S["GraphiQL"], S["GraphiQL"].PrefixPosition(), graphiQL => graphiQL
.Action("Index", "Admin", "OrchardCore.Apis.GraphQL")
.Permission(Permissions.ExecuteGraphQL)
.Permission(CommonPermissions.ExecuteGraphQL)
.LocalNav()
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
context.User = authenticateResult.Principal;
}
var authorizationService = context.RequestServices.GetService<IAuthorizationService>();
var authorized = await authorizationService.AuthorizeAsync(context.User, Permissions.ExecuteGraphQL);
var authorized = await authorizationService.AuthorizeAsync(context.User, CommonPermissions.ExecuteGraphQL);

if (authorized)
{
Expand Down
10 changes: 7 additions & 3 deletions src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/Permissions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OrchardCore.Security.Permissions;
Expand All @@ -6,13 +7,16 @@ namespace OrchardCore.Apis.GraphQL;

public class Permissions : IPermissionProvider
{
[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Apis.GraphQL.CommonPermissions.ExecuteGraphQLMutations'.")]
public static readonly Permission ExecuteGraphQLMutations = CommonPermissions.ExecuteGraphQLMutations;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Apis.GraphQL.CommonPermissions.ExecuteGraphQL'.")]
public static readonly Permission ExecuteGraphQL = CommonPermissions.ExecuteGraphQL;

private readonly IEnumerable<Permission> _allPermissions =
[
ExecuteGraphQL,
ExecuteGraphQLMutations,
CommonPermissions.ExecuteGraphQL,
CommonPermissions.ExecuteGraphQLMutations,
];
public Task<IEnumerable<Permission>> GetPermissionsAsync()
Expand All @@ -25,7 +29,7 @@ public IEnumerable<PermissionStereotype> GetDefaultStereotypes() =>
Name = OrchardCoreConstants.Roles.Administrator,
Permissions =
[
ExecuteGraphQLMutations,
CommonPermissions.ExecuteGraphQLMutations,
],
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async ValueTask<INodeVisitor> ValidateAsync(ValidationContext validationC

private async Task AuthorizeOperationAsync(ASTNode node, ValidationContext validationContext, GraphQLUserContext userContext, OperationType? operationType, string operationName)
{
if (operationType == OperationType.Mutation && !(await _authorizationService.AuthorizeAsync(userContext.User, Permissions.ExecuteGraphQLMutations)))
if (operationType == OperationType.Mutation && !(await _authorizationService.AuthorizeAsync(userContext.User, CommonPermissions.ExecuteGraphQLMutations)))
{
validationContext.ReportError(new ValidationError(
validationContext.Document.Source,
Expand Down
8 changes: 6 additions & 2 deletions src/OrchardCore.Modules/OrchardCore.AuditTrail/Permissions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OrchardCore.Security.Permissions;
Expand All @@ -6,13 +7,16 @@ namespace OrchardCore.AuditTrail;

public class Permissions : IPermissionProvider
{
[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.AuditTrail.AuditTrailPermissions.ViewAuditTrail'.")]
public static readonly Permission ViewAuditTrail = AuditTrailPermissions.ViewAuditTrail;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.AuditTrail.AuditTrailPermissions.ManageAuditTrailSettings'.")]
public static readonly Permission ManageAuditTrailSettings = AuditTrailPermissions.ManageAuditTrailSettings;

private readonly IEnumerable<Permission> _allPermissions =
[
ViewAuditTrail,
ManageAuditTrailSettings,
AuditTrailPermissions.ViewAuditTrail,
AuditTrailPermissions.ManageAuditTrailSettings,
];
public Task<IEnumerable<Permission>> GetPermissionsAsync()
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ await content.AddAsync(S["Content Items"], S["Content Items"].PrefixPosition(),
{
if (!await _authorizationService.AuthorizeContentTypeDefinitionsAsync(context.User, CommonPermissions.ListContent, contentTypes, _contentManager))
{
contentItems.Permission(Permissions.ListContent);
contentItems.Permission(CommonPermissions.ListContent);
}
contentItems.Action(nameof(AdminController.List), typeof(AdminController).ControllerName(), _routeValues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public async Task<IActionResult> List(
new SelectListItem(S["All versions"], nameof(ContentsStatus.AllVersions)),
];

if (await IsAuthorizedAsync(Permissions.ListContent))
if (await IsAuthorizedAsync(CommonPermissions.ListContent))
{
options.ContentStatuses.Insert(1, new SelectListItem(S["Owned by me"], nameof(ContentsStatus.Owner)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static async Task<IResult> HandleAsync(
HttpContext httpContext,
bool draft = false)
{
if (!await authorizationService.AuthorizeAsync(httpContext.User, Permissions.AccessContentApi))
if (!await authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.AccessContentApi))
{
return httpContext.ChallengeOrForbid("Api");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static async Task<IResult> HandleAsync(
IAuthorizationService authorizationService,
HttpContext httpContext)
{
if (!await authorizationService.AuthorizeAsync(httpContext.User, Permissions.AccessContentApi))
if (!await authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.AccessContentApi))
{
return httpContext.ChallengeOrForbid("Api");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static async Task<IResult> HandleAsync(
IAuthorizationService authorizationService,
HttpContext httpContext)
{
if (!await authorizationService.AuthorizeAsync(httpContext.User, Permissions.AccessContentApi))
if (!await authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.AccessContentApi))
{
return httpContext.ChallengeOrForbid("Api");
}
Expand Down
106 changes: 68 additions & 38 deletions src/OrchardCore.Modules/OrchardCore.Contents/Permissions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OrchardCore.Security.Permissions;
Expand All @@ -11,44 +12,73 @@ public class Permissions : IPermissionProvider

// EditOwn is the permission that is ultimately required to create new content. See how the Create() method is implemented in the AdminController.

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.PublishContent'.")]
public static readonly Permission PublishContent = CommonPermissions.PublishContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.PublishOwnContent'.")]
public static readonly Permission PublishOwnContent = CommonPermissions.PublishOwnContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.EditContent'.")]
public static readonly Permission EditContent = CommonPermissions.EditContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.EditOwnContent'.")]
public static readonly Permission EditOwnContent = CommonPermissions.EditOwnContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.DeleteContent'.")]
public static readonly Permission DeleteContent = CommonPermissions.DeleteContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.DeleteOwnContent'.")]
public static readonly Permission DeleteOwnContent = CommonPermissions.DeleteOwnContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.ViewContent'.")]
public static readonly Permission ViewContent = CommonPermissions.ViewContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.ViewOwnContent'.")]
public static readonly Permission ViewOwnContent = CommonPermissions.ViewOwnContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.PreviewContent'.")]
public static readonly Permission PreviewContent = CommonPermissions.PreviewContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.PreviewOwnContent'.")]
public static readonly Permission PreviewOwnContent = CommonPermissions.PreviewOwnContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.CloneContent'.")]
public static readonly Permission CloneContent = CommonPermissions.CloneContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.CloneOwnContent'.")]
public static readonly Permission CloneOwnContent = CommonPermissions.CloneOwnContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.ListContent'.")]
public static readonly Permission ListContent = CommonPermissions.ListContent;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.EditContentOwner'.")]
public static readonly Permission EditContentOwner = CommonPermissions.EditContentOwner;

[Obsolete("This will be removed in a future release. Instead use 'OrchardCore.Contents.CommonPermissions.AccessContentApi'.")]
public static readonly Permission AccessContentApi = new("AccessContentApi", "Access content via the api");

private readonly IEnumerable<Permission> _readerPermissions =
[
ViewContent,
CommonPermissions.ViewContent,
];
private readonly IEnumerable<Permission> _allPermissions =
[
EditContent,
EditOwnContent,
PublishContent,
PublishOwnContent,
DeleteContent,
DeleteOwnContent,
ViewContent,
ViewOwnContent,
PreviewContent,
PreviewOwnContent,
CloneContent,
CloneOwnContent,
AccessContentApi,
ListContent,
EditContentOwner,
CommonPermissions.EditContent,
CommonPermissions.EditOwnContent,
CommonPermissions.PublishContent,
CommonPermissions.PublishOwnContent,
CommonPermissions.DeleteContent,
CommonPermissions.DeleteOwnContent,
CommonPermissions.ViewContent,
CommonPermissions.ViewOwnContent,
CommonPermissions.PreviewContent,
CommonPermissions.PreviewOwnContent,
CommonPermissions.CloneContent,
CommonPermissions.CloneOwnContent,
CommonPermissions.AccessContentApi,
CommonPermissions.ListContent,
CommonPermissions.EditContentOwner,
];
public Task<IEnumerable<Permission>> GetPermissionsAsync()
Expand All @@ -61,49 +91,49 @@ public IEnumerable<PermissionStereotype> GetDefaultStereotypes() =>
Name = OrchardCoreConstants.Roles.Administrator,
Permissions =
[
PublishContent,
EditContent,
DeleteContent,
PreviewContent,
CloneContent,
AccessContentApi,
ListContent,
EditContentOwner,
CommonPermissions.PublishContent,
CommonPermissions.EditContent,
CommonPermissions.DeleteContent,
CommonPermissions.PreviewContent,
CommonPermissions.CloneContent,
CommonPermissions.AccessContentApi,
CommonPermissions.ListContent,
CommonPermissions.EditContentOwner,
],
},
new PermissionStereotype
{
Name = OrchardCoreConstants.Roles.Editor,
Permissions =
[
PublishContent,
EditContent,
DeleteContent,
PreviewContent,
CloneContent,
ListContent,
CommonPermissions.PublishContent,
CommonPermissions.EditContent,
CommonPermissions.DeleteContent,
CommonPermissions.PreviewContent,
CommonPermissions.CloneContent,
CommonPermissions.ListContent,
],
},
new PermissionStereotype
{
Name = OrchardCoreConstants.Roles.Author,
Permissions =
[
PublishOwnContent,
EditOwnContent,
DeleteOwnContent,
PreviewOwnContent,
CloneOwnContent,
CommonPermissions.PublishOwnContent,
CommonPermissions.EditOwnContent,
CommonPermissions.DeleteOwnContent,
CommonPermissions.PreviewOwnContent,
CommonPermissions.CloneOwnContent,
],
},
new PermissionStereotype
{
Name = OrchardCoreConstants.Roles.Contributor,
Permissions =
[
EditOwnContent,
PreviewOwnContent,
CloneOwnContent,
CommonPermissions.EditOwnContent,
CommonPermissions.PreviewOwnContent,
CommonPermissions.CloneOwnContent,
],
},
new PermissionStereotype
Expand Down
6 changes: 3 additions & 3 deletions src/OrchardCore.Modules/OrchardCore.Deployment/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
.Add(S["Import/Export"], S["Import/Export"].PrefixPosition(), import => import
.Add(S["Deployment Plans"], S["Deployment Plans"].PrefixPosition(), deployment => deployment
.Action("Index", "DeploymentPlan", "OrchardCore.Deployment")
.Permission(Permissions.Export)
.Permission(CommonPermissions.Export)
.LocalNav()
)
.Add(S["Package Import"], S["Package Import"].PrefixPosition(), deployment => deployment
.Action("Index", "Import", "OrchardCore.Deployment")
.Permission(Permissions.Import)
.Permission(CommonPermissions.Import)
.LocalNav()
)
.Add(S["JSON Import"], S["JSON Import"].PrefixPosition(), deployment => deployment
.Action("Json", "Import", "OrchardCore.Deployment")
.Permission(Permissions.Import)
.Permission(CommonPermissions.Import)
.LocalNav()
)
)
Expand Down
Loading

0 comments on commit b527fb5

Please sign in to comment.