File tree Expand file tree Collapse file tree
src/OrchardCoreContrib.Contents Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using OrchardCore . Security . Permissions ;
2+
3+ namespace OrchardCoreContrib . Contents ;
4+
5+ public sealed class ContentsPermissions
6+ {
7+ public static readonly Permission ShareDraftContent = new ( "ShareDraftContent" , "Share draft content items" ) ;
8+ }
Original file line number Diff line number Diff line change 1- using OrchardCore . ContentManagement ;
1+ using Microsoft . AspNetCore . Authorization ;
2+ using Microsoft . AspNetCore . Http ;
3+ using OrchardCore . ContentManagement ;
24using OrchardCore . ContentManagement . Display . ContentDisplay ;
35using OrchardCore . DisplayManagement . Handlers ;
46using OrchardCore . DisplayManagement . Views ;
57using OrchardCoreContrib . Contents . ViewModels ;
68
79namespace OrchardCoreContrib . Contents . Drivers ;
810
9- public sealed class ShareDraftContentDriver : ContentDisplayDriver
11+ public sealed class ShareDraftContentDriver ( IAuthorizationService authorizationService , IHttpContextAccessor httpContextAccessor ) : ContentDisplayDriver
1012{
1113 public override async Task < IDisplayResult > EditAsync ( ContentItem contentItem , BuildEditorContext context )
12- => Initialize < ShareDraftViewModel > ( "Content_ShareDraftButton" , model => model . ContentItem = contentItem )
14+ {
15+ var user = httpContextAccessor . HttpContext . User ;
16+
17+ if ( ! await authorizationService . AuthorizeAsync ( user , ContentsPermissions . ShareDraftContent ) )
18+ {
19+ return null ;
20+ }
21+
22+ return Initialize < ShareDraftViewModel > ( "Content_ShareDraftButton" , model => model . ContentItem = contentItem )
1323 . RenderWhen ( ( ) => Task . FromResult ( ! contentItem . Published ) )
1424 . Location ( "Actions:30" ) ;
25+ }
1526}
Original file line number Diff line number Diff line change 1+ using OrchardCore ;
2+ using OrchardCore . Security . Permissions ;
3+
4+ namespace OrchardCoreContrib . Contents ;
5+
6+ public class Permissions : IPermissionProvider
7+ {
8+ private readonly IEnumerable < Permission > _allPermissions = [ ContentsPermissions . ShareDraftContent ] ;
9+
10+ public IEnumerable < PermissionStereotype > GetDefaultStereotypes ( ) =>
11+ [
12+ new PermissionStereotype
13+ {
14+ Name = OrchardCoreConstants . Roles . Administrator ,
15+ Permissions = _allPermissions
16+ } ,
17+ new PermissionStereotype
18+ {
19+ Name = OrchardCoreConstants . Roles . Editor ,
20+ Permissions = _allPermissions
21+ }
22+ ] ;
23+
24+ public Task < IEnumerable < Permission > > GetPermissionsAsync ( ) => Task . FromResult ( _allPermissions ) ;
25+ }
Original file line number Diff line number Diff line change 33using OrchardCore . Data ;
44using OrchardCore . Data . Migration ;
55using OrchardCore . Modules ;
6+ using OrchardCore . Security . Permissions ;
67using OrchardCoreContrib . Contents . Drivers ;
78using OrchardCoreContrib . Contents . Indexes ;
89using OrchardCoreContrib . Contents . Services ;
@@ -21,5 +22,6 @@ public override void ConfigureServices(IServiceCollection services)
2122 services . AddIndexProvider < SharedDraftLinkIndexProvider > ( ) ;
2223
2324 services . AddScoped < IContentDisplayDriver , ShareDraftContentDriver > ( ) ;
25+ services . AddPermissionProvider < Permissions > ( ) ;
2426 }
2527}
You can’t perform that action at this time.
0 commit comments