diff --git a/src/OrchardCore.Modules/OrchardCore.Media/PermissionProvider.cs b/src/OrchardCore.Modules/OrchardCore.Media/PermissionProvider.cs new file mode 100644 index 00000000000..df89cdeffe2 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Media/PermissionProvider.cs @@ -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 _allPermissions = + [ + Permissions.ManageMedia, + Permissions.ManageMediaFolder, + Permissions.ManageOthersMedia, + Permissions.ManageOwnMedia, + Permissions.ManageAttachedMediaFieldsFolder, + Permissions.ManageMediaProfiles, + Permissions.ViewMediaOptions, + ]; + + private readonly IEnumerable _generalPermissions = + [ + Permissions.ManageOwnMedia, + ]; + + public Task> GetPermissionsAsync() + => Task.FromResult(_allPermissions); + + public IEnumerable 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, + }, + ]; +} diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Permissions.cs b/src/OrchardCore.Modules/OrchardCore.Media/Permissions.cs deleted file mode 100644 index 07189c033e7..00000000000 --- a/src/OrchardCore.Modules/OrchardCore.Media/Permissions.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using OrchardCore.Security.Permissions; - -namespace OrchardCore.Media; - -public sealed class Permissions : IPermissionProvider -{ - 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"); - - private readonly IEnumerable _allPermissions = - [ - ManageMedia, - ManageMediaFolder, - ManageOthersMedia, - ManageOwnMedia, - ManageAttachedMediaFieldsFolder, - ManageMediaProfiles, - ViewMediaOptions, - ]; - - private readonly IEnumerable _generalPermissions = - [ - ManageOwnMedia, - ]; - - public Task> GetPermissionsAsync() - => Task.FromResult(_allPermissions); - - public IEnumerable GetDefaultStereotypes() => - [ - new PermissionStereotype - { - Name = OrchardCoreConstants.Roles.Administrator, - Permissions = - [ - ManageMediaFolder, - ManageMediaProfiles, - ViewMediaOptions, - ], - }, - new PermissionStereotype - { - Name = OrchardCoreConstants.Roles.Editor, - Permissions = - [ - ManageMedia, - ManageOwnMedia, - ], - }, - new PermissionStereotype - { - Name = OrchardCoreConstants.Roles.Author, - Permissions = _generalPermissions, - }, - new PermissionStereotype - { - Name = OrchardCoreConstants.Roles.Contributor, - Permissions = _generalPermissions, - }, - ]; -} diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs index 6e10cdd0447..7e71d267ffc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs @@ -137,7 +137,7 @@ public override void ConfigureServices(IServiceCollection services) return new DefaultMediaFileStore(fileStore, mediaUrlBase, mediaOptions.CdnBaseUrl, mediaEventHandlers, mediaCreatingEventHandlers, logger); }); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/OrchardCore/OrchardCore.Media.Core/OrchardCore.Media.Core.csproj b/src/OrchardCore/OrchardCore.Media.Core/OrchardCore.Media.Core.csproj index 7d26603eee8..907a06719de 100644 --- a/src/OrchardCore/OrchardCore.Media.Core/OrchardCore.Media.Core.csproj +++ b/src/OrchardCore/OrchardCore.Media.Core/OrchardCore.Media.Core.csproj @@ -15,6 +15,7 @@ + diff --git a/src/OrchardCore/OrchardCore.Media.Core/Permissions.cs b/src/OrchardCore/OrchardCore.Media.Core/Permissions.cs new file mode 100644 index 00000000000..e9b16efff45 --- /dev/null +++ b/src/OrchardCore/OrchardCore.Media.Core/Permissions.cs @@ -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"); +}