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

Move Media Permissions to Media.Core #16493

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
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
60 changes: 60 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Media/PermissionProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using OrchardCore.Security.Permissions;

namespace OrchardCore.Media;

public sealed class PermissionProvider : IPermissionProvider
{
private readonly IEnumerable<Permission> _allPermissions =
[
Permissions.ManageMedia,
Permissions.ManageMediaFolder,
Permissions.ManageOthersMedia,
Permissions.ManageOwnMedia,
Permissions.ManageAttachedMediaFieldsFolder,
Permissions.ManageMediaProfiles,
Permissions.ViewMediaOptions,
];

private readonly IEnumerable<Permission> _generalPermissions =
[
Permissions.ManageOwnMedia,
];

public Task<IEnumerable<Permission>> GetPermissionsAsync()
=> Task.FromResult(_allPermissions);

public IEnumerable<PermissionStereotype> GetDefaultStereotypes() =>
[
new PermissionStereotype
{
Name = OrchardCoreConstants.Roles.Administrator,
Permissions =
[
Permissions.ManageMediaFolder,
Permissions.ManageMediaProfiles,
Permissions.ViewMediaOptions,
],
},
new PermissionStereotype
{
Name = OrchardCoreConstants.Roles.Editor,
Permissions =
[
Permissions.ManageMedia,
Permissions.ManageOwnMedia,
],
},
new PermissionStereotype
{
Name = OrchardCoreConstants.Roles.Author,
Permissions = _generalPermissions,
},
new PermissionStereotype
{
Name = OrchardCoreConstants.Roles.Contributor,
Permissions = _generalPermissions,
},
];
}
68 changes: 0 additions & 68 deletions src/OrchardCore.Modules/OrchardCore.Media/Permissions.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Media/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public override void ConfigureServices(IServiceCollection services)
return new DefaultMediaFileStore(fileStore, mediaUrlBase, mediaOptions.CdnBaseUrl, mediaEventHandlers, mediaCreatingEventHandlers, logger);
});

services.AddScoped<IPermissionProvider, Permissions>();
services.AddScoped<IPermissionProvider, PermissionProvider>();
services.AddScoped<IAuthorizationHandler, ManageMediaFolderAuthorizationHandler>();
services.AddScoped<INavigationProvider, AdminMenu>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<ProjectReference Include="..\OrchardCore.FileStorage.Abstractions\OrchardCore.FileStorage.Abstractions.csproj" />
<ProjectReference Include="..\OrchardCore.Infrastructure.Abstractions\OrchardCore.Infrastructure.Abstractions.csproj" />
<ProjectReference Include="..\OrchardCore.Media.Abstractions\OrchardCore.Media.Abstractions.csproj" />
</ItemGroup>

Expand Down
20 changes: 20 additions & 0 deletions src/OrchardCore/OrchardCore.Media.Core/Permissions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using OrchardCore.Security.Permissions;

namespace OrchardCore.Media;

public static class Permissions
{
public static readonly Permission ManageMediaFolder = new("ManageMediaFolder", "Manage All Media Folders");

public static readonly Permission ManageOthersMedia = new("ManageOthersMediaContent", "Manage Media For Others", [ManageMediaFolder]);

public static readonly Permission ManageOwnMedia = new("ManageOwnMediaContent", "Manage Own Media", [ManageOthersMedia]);

public static readonly Permission ManageMedia = new("ManageMediaContent", "Manage Media", [ManageOwnMedia]);

public static readonly Permission ManageAttachedMediaFieldsFolder = new("ManageAttachedMediaFieldsFolder", "Manage Attached Media Fields Folder", [ManageMediaFolder]);

public static readonly Permission ManageMediaProfiles = new("ManageMediaProfiles", "Manage Media Profiles");

public static readonly Permission ViewMediaOptions = new("ViewMediaOptions", "View Media Options");
}