├── .gitignore ├── Assets.json ├── Assets └── scss │ └── content-approval.scss ├── Common └── Settings.cs ├── Drivers └── ContentApprovalPartDisplayDriver.cs ├── Handlers └── ContentApprovalPartHandler.cs ├── Indexes └── ContentApprovalPartIndex.cs ├── LICENSE ├── Manifest.cs ├── Migrations.cs ├── Models └── ContentApprovalPart.cs ├── Permissions.cs ├── README.md ├── Rework.ContentApproval.csproj ├── Shapes └── ContentShapes.cs ├── Startup.cs ├── ViewModels ├── ApprovalRequestViewModel.cs └── ApprovalResponseViewModel.cs ├── Views ├── ContentApprovalPart.Edit.ApprovalRequest.cshtml ├── ContentApprovalPart.Edit.ApprovalResponse.cshtml ├── Items │ ├── ApprovalRequestEvent.Fields.Design.cshtml │ ├── ApprovalRequestEvent.Fields.Edit.cshtml │ ├── ApprovalRequestEvent.Fields.Thumbnail.cshtml │ ├── ApprovalResponseEvent.Fields.Design.cshtml │ ├── ApprovalResponseEvent.Fields.Edit.cshtml │ └── ApprovalResponseEvent.Fields.Thumbnail.cshtml └── _ViewImports.cshtml ├── Workflows ├── Activities │ ├── ApprovalRequestEvent.cs │ └── ApprovalResponseEvent.cs ├── Drivers │ ├── ApprovalRequestEventDisplay.cs │ └── ApprovalResponseEventDisplay.cs ├── Startup.cs └── ViewModels │ ├── ApprovalRequestEventViewModel.cs │ └── ApprovalResponseEventViewModel.cs └── wwwroot └── Styles ├── content-approval.css └── content-approval.min.css /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /Assets.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "generateSourceMaps": false, 4 | "inputs": [ 5 | "Assets/scss/content-approval.scss" 6 | ], 7 | "output": "wwwroot/Styles/content-approval.css" 8 | } 9 | ] 10 | -------------------------------------------------------------------------------- /Assets/scss/content-approval.scss: -------------------------------------------------------------------------------- 1 | .btn-content-approval { 2 | white-space: nowrap; 3 | } 4 | 5 | .btn-group-approval { 6 | border: 1px solid lightgray; 7 | padding: 3px; 8 | border-radius: 4px; 9 | 10 | .status { 11 | width: 100%; 12 | min-width: 200px; 13 | line-height: 38px; 14 | margin-left: 6px; 15 | } 16 | .dropdown-menu { 17 | left: auto!important; 18 | right: 0px!important; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Common/Settings.cs: -------------------------------------------------------------------------------- 1 | namespace Rework.ContentApproval.Common 2 | { 3 | public class Settings 4 | { 5 | public static readonly string RequestContentApprovalPermission = "Request content approval"; 6 | 7 | // Status Options 8 | public static readonly string ContentApprovalRequested = "Approval Requested"; 9 | public static readonly string ContentApproved = "Approved"; 10 | public static readonly string ContentNeedsRevised = "Needs Revised"; 11 | public static readonly string ContentRejected = "Rejected"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Drivers/ContentApprovalPartDisplayDriver.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Http; 3 | using OrchardCore.ContentManagement.Display.ContentDisplay; 4 | using OrchardCore.ContentManagement.Display.Models; 5 | using OrchardCore.DisplayManagement.ModelBinding; 6 | using OrchardCore.DisplayManagement.Views; 7 | using Rework.ContentApproval.Common; 8 | using Rework.ContentApproval.Models; 9 | using Rework.ContentApproval.ViewModels; 10 | using Rework.ContentApproval.Workflows.Activities; 11 | using System.Threading.Tasks; 12 | 13 | namespace Rework.ContentApproval.Drivers 14 | { 15 | public class ContentApprovalPartDisplayDriver : ContentPartDisplayDriver 16 | { 17 | private readonly IHttpContextAccessor _httpContextAccessor; 18 | private readonly IAuthorizationService _authorizationService; 19 | 20 | public ContentApprovalPartDisplayDriver( 21 | IHttpContextAccessor httpContextAccessor, 22 | IAuthorizationService authorizationService) 23 | { 24 | _httpContextAccessor = httpContextAccessor; 25 | _authorizationService = authorizationService; 26 | } 27 | 28 | public override async Task EditAsync(ContentApprovalPart part, BuildPartEditorContext context) 29 | { 30 | var httpContext = _httpContextAccessor.HttpContext; 31 | var baseShapeName = GetEditorShapeType(context); 32 | 33 | // Have to do Publish Content permissions first 34 | if (await _authorizationService.AuthorizeAsync(httpContext?.User, OrchardCore.Contents.Permissions.PublishContent, part.ContentItem)) 35 | { 36 | var shapeName = $"{ baseShapeName }_ApprovalResponse"; 37 | return Initialize(shapeName, 38 | model => PopulateApprovalResponseViewModel(part, model)) 39 | .Location("Actions:First"); 40 | } 41 | else if (await _authorizationService.AuthorizeAsync(httpContext?.User, Permissions.RequestApproval, part.ContentItem)) 42 | { 43 | var shapeName = $"{ baseShapeName }_ApprovalRequest"; 44 | return Initialize(shapeName, 45 | model => PopulateApprovalRequestViewModel(part, model)) 46 | .Location("Actions:Last"); 47 | } 48 | 49 | return null; 50 | } 51 | 52 | public override async Task UpdateAsync(ContentApprovalPart part, IUpdateModel updater) 53 | { 54 | var httpContext = _httpContextAccessor.HttpContext; 55 | 56 | // Have to do Publish Content permissions first 57 | if (await _authorizationService.AuthorizeAsync(httpContext?.User, OrchardCore.Contents.Permissions.PublishContent, part.ContentItem)) 58 | { 59 | var viewModel = new ApprovalResponseViewModel(); 60 | 61 | await updater.TryUpdateModelAsync(viewModel, Prefix); 62 | 63 | if (httpContext.Request.Form["submit.Publish"] == "submit.Publish" 64 | || httpContext.Request.Form["submit.Publish"] == "submit.PublishAndContinue") 65 | { 66 | part.Status = Settings.ContentApproved; 67 | part.NotificationNeeded = nameof(ApprovalResponseEvent); 68 | } 69 | else if (httpContext.Request.Form["submit.Publish"] == "submit.Approved") 70 | { 71 | part.Status = Settings.ContentApproved; 72 | part.Notes = viewModel.Notes; 73 | part.NotificationNeeded = nameof(ApprovalResponseEvent); 74 | } 75 | else if (httpContext.Request.Form["submit.Save"] == "submit.NeedsRevised") 76 | { 77 | part.Status = Settings.ContentNeedsRevised; 78 | part.Notes = viewModel.Notes; 79 | part.NotificationNeeded = nameof(ApprovalResponseEvent); 80 | } 81 | else if (httpContext.Request.Form["submit.Save"] == "submit.Rejected") 82 | { 83 | part.Status = Settings.ContentRejected; 84 | part.Notes = viewModel.Notes; 85 | part.NotificationNeeded = nameof(ApprovalResponseEvent); 86 | } 87 | } 88 | else if (await _authorizationService.AuthorizeAsync(httpContext?.User, Permissions.RequestApproval, part.ContentItem)) 89 | { 90 | var viewModel = new ApprovalRequestViewModel(); 91 | 92 | await updater.TryUpdateModelAsync(viewModel, Prefix); 93 | 94 | if (httpContext.Request.Form["submit.Save"] == "submit.RequestApproval") 95 | { 96 | part.Status = Settings.ContentApprovalRequested; 97 | part.Notes = viewModel.Notes; 98 | part.NotificationNeeded = nameof(ApprovalRequestEvent); 99 | } 100 | } 101 | 102 | 103 | return Edit(part); 104 | } 105 | 106 | private void PopulateApprovalRequestViewModel(ContentApprovalPart part, ApprovalRequestViewModel viewModel) 107 | { 108 | viewModel.Status = part.Status; 109 | viewModel.Notes = part.Notes; 110 | } 111 | 112 | private void PopulateApprovalResponseViewModel(ContentApprovalPart part, ApprovalResponseViewModel viewModel) 113 | { 114 | viewModel.Status = part.Status; 115 | viewModel.Notes = part.Notes; 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Handlers/ContentApprovalPartHandler.cs: -------------------------------------------------------------------------------- 1 | using OrchardCore.ContentManagement.Handlers; 2 | using OrchardCore.Workflows.Services; 3 | using Rework.ContentApproval.Models; 4 | using System.Threading.Tasks; 5 | 6 | namespace Rework.ContentApproval.Handlers 7 | { 8 | public class ContentApprovalPartHandler : ContentPartHandler 9 | { 10 | private readonly IWorkflowManager _workflowManager; 11 | 12 | public ContentApprovalPartHandler(IWorkflowManager workflowManager) 13 | { 14 | _workflowManager = workflowManager; 15 | } 16 | 17 | public override Task CreatedAsync(CreateContentContext context, ContentApprovalPart part) 18 | { 19 | return HandleNotification(part); 20 | } 21 | 22 | public override Task UpdatedAsync(UpdateContentContext context, ContentApprovalPart part) 23 | { 24 | return HandleNotification(part); 25 | } 26 | 27 | private Task HandleNotification(ContentApprovalPart part) 28 | { 29 | return !string.IsNullOrWhiteSpace(part.NotificationNeeded) 30 | ? _workflowManager.TriggerEventAsync(part.NotificationNeeded, 31 | input: new { ContentItem = part.ContentItem }, 32 | correlationId: part.ContentItem.ContentItemId 33 | ) 34 | : Task.CompletedTask; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Indexes/ContentApprovalPartIndex.cs: -------------------------------------------------------------------------------- 1 | using OrchardCore.ContentManagement; 2 | using Rework.ContentApproval.Models; 3 | using YesSql.Indexes; 4 | 5 | namespace Rework.ContentApproval.Indexes 6 | { 7 | public class ContentApprovalPartIndex : MapIndex 8 | { 9 | public string Status { get; set; } 10 | } 11 | 12 | public class ContentApprovalPartIndexProvider : IndexProvider 13 | { 14 | public override void Describe(DescribeContext context) 15 | { 16 | context.For() 17 | .When(c => c.Has()) 18 | .Map(contentItem => 19 | { 20 | var contentApprovalPart = contentItem.As(); 21 | if (contentApprovalPart == null) 22 | { 23 | return null; 24 | } 25 | 26 | return new ContentApprovalPartIndex 27 | { 28 | Status = contentApprovalPart.Status ?? string.Empty 29 | }; 30 | }); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, Jeff Olmstead 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Manifest.cs: -------------------------------------------------------------------------------- 1 | using OrchardCore.Modules.Manifest; 2 | 3 | [assembly: Module( 4 | Name = "Rework: Content Approval", 5 | Author = "Endless Mountain Solutions", 6 | Website = "https://www.endlessmountainsolutions.com", 7 | Version = "0.0.1", 8 | Description = "Adds ability to have some users without publish permissions to request content approval (via workflow if workflow enabled).", 9 | Category = "Content Management", 10 | Dependencies = new[] { "OrchardCore.Contents" } 11 | )] -------------------------------------------------------------------------------- /Migrations.cs: -------------------------------------------------------------------------------- 1 | using OrchardCore.ContentManagement.Metadata; 2 | using OrchardCore.ContentManagement.Metadata.Settings; 3 | using OrchardCore.Data.Migration; 4 | using Rework.ContentApproval.Common; 5 | using Rework.ContentApproval.Indexes; 6 | using Rework.ContentApproval.Models; 7 | using YesSql.Sql; 8 | 9 | namespace Rework.ContentApproval 10 | { 11 | public class Migrations : DataMigration 12 | { 13 | private readonly IContentDefinitionManager _contentDefinitionManager; 14 | 15 | public Migrations(IContentDefinitionManager contentDefinitionManager) 16 | { 17 | _contentDefinitionManager = contentDefinitionManager; 18 | } 19 | 20 | public int Create() 21 | { 22 | _contentDefinitionManager.AlterPartDefinition(nameof(ContentApprovalPart), builder => builder 23 | .Attachable() 24 | .WithDescription($"Adds the ability for users with '{Settings.RequestContentApprovalPermission}' permission to initiate a request for approval.")); 25 | 26 | SchemaBuilder.CreateMapIndexTable(table => table 27 | .Column(nameof(ContentApprovalPartIndex.Status)) 28 | ); 29 | 30 | SchemaBuilder.AlterTable(nameof(ContentApprovalPartIndex), table => table 31 | .CreateIndex( 32 | $"IDX_{nameof(ContentApprovalPartIndex)}_{nameof(ContentApprovalPartIndex.Status)}", 33 | nameof(ContentApprovalPartIndex.Status)) 34 | ); 35 | 36 | return 1; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Models/ContentApprovalPart.cs: -------------------------------------------------------------------------------- 1 | using OrchardCore.ContentManagement; 2 | using Rework.ContentApproval.Common; 3 | 4 | namespace Rework.ContentApproval.Models 5 | { 6 | public class ContentApprovalPart : ContentPart 7 | { 8 | public string Status { get; set; } 9 | public string Notes { get; set; } 10 | public string NotificationNeeded { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Permissions.cs: -------------------------------------------------------------------------------- 1 | using OrchardCore.Security.Permissions; 2 | using Rework.ContentApproval.Common; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Rework.ContentApproval 8 | { 9 | public class Permissions : IPermissionProvider 10 | { 11 | public static readonly Permission RequestApproval = new Permission("RequestApproval", Settings.RequestContentApprovalPermission); 12 | 13 | public IEnumerable GetDefaultStereotypes() 14 | { 15 | // Not defaulting any role to this permission 16 | return Enumerable.Empty(); 17 | } 18 | 19 | public Task> GetPermissionsAsync() 20 | { 21 | return Task.FromResult(new[] { RequestApproval }.AsEnumerable()); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rework.ContentApproval 2 | Extends Orchard Core content management with a content approval process. 3 | 4 | ## Steps to Utilize 5 | 1. Enable Feature "Rework: Content Approval" 6 | 2. Add "Content Approval" part to the content type you want to have function under an approval process 7 | 3. Users with "Publish" permissions will now see this on the content type: 8 | ![image](https://user-images.githubusercontent.com/1848585/88558342-5f3f1f00-cff9-11ea-8833-e10e6377c75d.png) 9 | 4. For users who need to "Request Approval", navigate to their Role (e.g. Contributor) and check "Allow" for "Request content approval". This user should NOT have "Publish" permissions for this content type. 10 | 5. Users with "Request content approval" permissions will now see this on the content type: 11 | ![image](https://user-images.githubusercontent.com/1848585/88558250-47679b00-cff9-11ea-851a-6d03282c7794.png) 12 | 13 | ## Workflows 14 | If you have workflows enabled, you will also have access to two new events: 15 | 1. Approval Request - fires when content has requested approval 16 | 2. Approval Response - fires when content has been responded 17 | 18 | These are often used to send out email notifications to the alternate party in the approval process. 19 | 20 | ## Index Support 21 | In addition, there is an index that is managed as part of this module called "Content Approval Part Index". This could be used in generating lists via the query module. 22 | -------------------------------------------------------------------------------- /Rework.ContentApproval.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Shapes/ContentShapes.cs: -------------------------------------------------------------------------------- 1 | using OrchardCore.ContentManagement; 2 | using OrchardCore.DisplayManagement.Descriptors; 3 | using Rework.ContentApproval.Common; 4 | using Rework.ContentApproval.Models; 5 | 6 | namespace Rework.ContentApproval.Shapes 7 | { 8 | public class ContentShapes : IShapeTableProvider 9 | { 10 | public void Discover(ShapeTableBuilder builder) 11 | { 12 | builder.Describe("Content_Edit") 13 | .OnDisplaying(context => 14 | { 15 | dynamic shape = context.Shape; 16 | var contentItem = (ContentItem)shape.ContentItem; 17 | if (contentItem != null && contentItem.Has()) 18 | { 19 | dynamic actions = shape.Actions; 20 | actions.Remove("Content_PublishButton"); 21 | 22 | var contentApprovalPart = contentItem.As(); 23 | if (contentApprovalPart.Status == Settings.ContentApprovalRequested) 24 | { 25 | actions.Remove("Content_SaveDraftButton"); 26 | } 27 | } 28 | }); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using OrchardCore.ContentManagement; 3 | using OrchardCore.ContentManagement.Display.ContentDisplay; 4 | using OrchardCore.Data.Migration; 5 | using OrchardCore.DisplayManagement.Descriptors; 6 | using OrchardCore.Modules; 7 | using OrchardCore.Security.Permissions; 8 | using Rework.ContentApproval.Drivers; 9 | using Rework.ContentApproval.Handlers; 10 | using Rework.ContentApproval.Indexes; 11 | using Rework.ContentApproval.Models; 12 | using Rework.ContentApproval.Shapes; 13 | using YesSql.Indexes; 14 | 15 | namespace Rework.ContentApproval 16 | { 17 | public class Startup : StartupBase 18 | { 19 | public override void ConfigureServices(IServiceCollection services) 20 | { 21 | services 22 | .AddContentPart() 23 | .UseDisplayDriver(); 24 | services.AddScoped(); 25 | services.AddSingleton(); 26 | services.AddScoped(); 27 | services.AddScoped(); 28 | } 29 | } 30 | 31 | [RequireFeatures("OrchardCore.Workflows")] 32 | public class StartupWithWorkflows : StartupBase 33 | { 34 | public override void ConfigureServices(IServiceCollection services) 35 | { 36 | services.AddContentPart() 37 | .AddHandler(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /ViewModels/ApprovalRequestViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace Rework.ContentApproval.ViewModels 2 | { 3 | public class ApprovalRequestViewModel 4 | { 5 | public string Status { get; set; } 6 | public string Notes { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ViewModels/ApprovalResponseViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace Rework.ContentApproval.ViewModels 2 | { 3 | public class ApprovalResponseViewModel 4 | { 5 | public string Status { get; set; } 6 | public string Notes { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Views/ContentApprovalPart.Edit.ApprovalRequest.cshtml: -------------------------------------------------------------------------------- 1 | @model ApprovalRequestViewModel 2 | 3 | 4 | 5 |
6 | Status: @Model.Status 7 | 8 | 9 |
-------------------------------------------------------------------------------- /Views/ContentApprovalPart.Edit.ApprovalResponse.cshtml: -------------------------------------------------------------------------------- 1 | @model ApprovalResponseViewModel 2 | 3 | 4 | 5 |
6 | Status: @Model.Status 7 | 8 | 9 | 12 | 16 |
-------------------------------------------------------------------------------- /Views/Items/ApprovalRequestEvent.Fields.Design.cshtml: -------------------------------------------------------------------------------- 1 | @model ApprovalRequestEventViewModel 2 | 3 |
4 |

@Model.Activity.GetTitleOrDefault(() => T["Approval Request"])

5 |
-------------------------------------------------------------------------------- /Views/Items/ApprovalRequestEvent.Fields.Edit.cshtml: -------------------------------------------------------------------------------- 1 | @model ApprovalRequestEventViewModel -------------------------------------------------------------------------------- /Views/Items/ApprovalRequestEvent.Fields.Thumbnail.cshtml: -------------------------------------------------------------------------------- 1 | 

@T["Approval Request"]

2 |

@T["Approval is requested."]

-------------------------------------------------------------------------------- /Views/Items/ApprovalResponseEvent.Fields.Design.cshtml: -------------------------------------------------------------------------------- 1 | @model ApprovalResponseEventViewModel 2 | 3 |
4 |

@Model.Activity.GetTitleOrDefault(() => T["Approval Response"])

5 |
-------------------------------------------------------------------------------- /Views/Items/ApprovalResponseEvent.Fields.Edit.cshtml: -------------------------------------------------------------------------------- 1 | @model ApprovalResponseEventViewModel -------------------------------------------------------------------------------- /Views/Items/ApprovalResponseEvent.Fields.Thumbnail.cshtml: -------------------------------------------------------------------------------- 1 | 

@T["Approval Response"]

2 |

@T["Approval response is provided."]

-------------------------------------------------------------------------------- /Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @inherits OrchardCore.DisplayManagement.Razor.RazorPage 2 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 3 | @addTagHelper *, OrchardCore.DisplayManagement 4 | @addTagHelper *, OrchardCore.ResourceManagement 5 | @addTagHelper *, OrchardCore.Contents 6 | 7 | @using Rework.ContentApproval.Common; 8 | @using Rework.ContentApproval.Models; 9 | @using Rework.ContentApproval.ViewModels; 10 | @using Rework.ContentApproval.Workflows.ViewModels; 11 | @using OrchardCore.ContentManagement; 12 | @using OrchardCore.DisplayManagement.Views; 13 | @using OrchardCore.Workflows.Helpers -------------------------------------------------------------------------------- /Workflows/Activities/ApprovalRequestEvent.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Localization; 2 | using OrchardCore.Workflows.Abstractions.Models; 3 | using OrchardCore.Workflows.Activities; 4 | using OrchardCore.Workflows.Models; 5 | using System.Collections.Generic; 6 | 7 | namespace Rework.ContentApproval.Workflows.Activities 8 | { 9 | public class ApprovalRequestEvent : EventActivity 10 | { 11 | public static string EventName => nameof(ApprovalRequestEvent); 12 | 13 | private readonly IStringLocalizer S; 14 | 15 | public ApprovalRequestEvent( 16 | IStringLocalizer localizer 17 | ) 18 | { 19 | S = localizer; 20 | } 21 | 22 | public override string Name => EventName; 23 | public override LocalizedString DisplayText => S["Approval Request Event"]; 24 | public override LocalizedString Category => S["Content"]; 25 | 26 | public override bool CanExecute(WorkflowExecutionContext workflowContext, ActivityContext activityContext) 27 | { 28 | return true; 29 | } 30 | 31 | public override IEnumerable GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext) 32 | { 33 | return Outcomes(S["Done"]); 34 | } 35 | 36 | public override ActivityExecutionResult Resume(WorkflowExecutionContext workflowContext, ActivityContext activityContext) 37 | { 38 | return Outcomes("Done"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Workflows/Activities/ApprovalResponseEvent.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Localization; 2 | using OrchardCore.Workflows.Abstractions.Models; 3 | using OrchardCore.Workflows.Activities; 4 | using OrchardCore.Workflows.Models; 5 | using System.Collections.Generic; 6 | 7 | namespace Rework.ContentApproval.Workflows.Activities 8 | { 9 | public class ApprovalResponseEvent : EventActivity 10 | { 11 | public static string EventName => nameof(ApprovalResponseEvent); 12 | 13 | private readonly IStringLocalizer S; 14 | 15 | public ApprovalResponseEvent( 16 | IStringLocalizer localizer 17 | ) 18 | { 19 | S = localizer; 20 | } 21 | 22 | public override string Name => EventName; 23 | public override LocalizedString DisplayText => S["Approval Response Event"]; 24 | public override LocalizedString Category => S["Content"]; 25 | 26 | public override bool CanExecute(WorkflowExecutionContext workflowContext, ActivityContext activityContext) 27 | { 28 | return true; 29 | } 30 | 31 | public override IEnumerable GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext) 32 | { 33 | return Outcomes(S["Done"]); 34 | } 35 | 36 | public override ActivityExecutionResult Resume(WorkflowExecutionContext workflowContext, ActivityContext activityContext) 37 | { 38 | return Outcomes("Done"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Workflows/Drivers/ApprovalRequestEventDisplay.cs: -------------------------------------------------------------------------------- 1 | using OrchardCore.DisplayManagement.Views; 2 | using OrchardCore.Workflows.Display; 3 | using Rework.ContentApproval.Workflows.Activities; 4 | using Rework.ContentApproval.Workflows.ViewModels; 5 | 6 | namespace Rework.ContentApproval.Workflows.Drivers 7 | { 8 | public class ApprovalRequestEventDisplay : ActivityDisplayDriver 9 | { 10 | public override IDisplayResult Display(ApprovalRequestEvent activity) 11 | { 12 | return Combine( 13 | Shape("ApprovalRequestEvent_Fields_Thumbnail", new ApprovalRequestEventViewModel(activity)).Location("Thumbnail", "Content"), 14 | Factory("ApprovalRequestEvent_Fields_Design", ctx => 15 | { 16 | var shape = new ApprovalRequestEventViewModel 17 | { 18 | Activity = activity 19 | }; 20 | return shape; 21 | }).Location("Design", "Content") 22 | ); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Workflows/Drivers/ApprovalResponseEventDisplay.cs: -------------------------------------------------------------------------------- 1 | using OrchardCore.DisplayManagement.Views; 2 | using OrchardCore.Workflows.Display; 3 | using Rework.ContentApproval.Workflows.Activities; 4 | using Rework.ContentApproval.Workflows.ViewModels; 5 | 6 | namespace Rework.ContentApproval.Workflows.Drivers 7 | { 8 | public class ApprovalResponseEventDisplay : ActivityDisplayDriver 9 | { 10 | public override IDisplayResult Display(ApprovalResponseEvent activity) 11 | { 12 | // Return a shape rather than a view 13 | return Combine( 14 | Shape("ApprovalResponseEvent_Fields_Thumbnail", new ApprovalResponseEventViewModel(activity)).Location("Thumbnail", "Content"), 15 | Factory("ApprovalResponseEvent_Fields_Design", ctx => 16 | { 17 | var shape = new ApprovalResponseEventViewModel 18 | { 19 | Activity = activity 20 | }; 21 | return shape; 22 | }).Location("Design", "Content") 23 | ); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Workflows/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Rework.ContentApproval.Workflows.Activities; 3 | using Rework.ContentApproval.Workflows.Drivers; 4 | using OrchardCore.Workflows.Helpers; 5 | using OrchardCore.Modules; 6 | 7 | namespace Rework.ContentApproval.Workflows 8 | { 9 | [RequireFeatures("OrchardCore.Workflows")] 10 | public class Startup : StartupBase 11 | { 12 | public override void ConfigureServices(IServiceCollection services) 13 | { 14 | services.AddActivity(); 15 | services.AddActivity(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Workflows/ViewModels/ApprovalRequestEventViewModel.cs: -------------------------------------------------------------------------------- 1 | using OrchardCore.Workflows.ViewModels; 2 | using Rework.ContentApproval.Workflows.Activities; 3 | 4 | namespace Rework.ContentApproval.Workflows.ViewModels 5 | { 6 | public class ApprovalRequestEventViewModel : ActivityViewModel 7 | { 8 | public ApprovalRequestEventViewModel() 9 | { 10 | } 11 | 12 | public ApprovalRequestEventViewModel(ApprovalRequestEvent activity) : base(activity) 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Workflows/ViewModels/ApprovalResponseEventViewModel.cs: -------------------------------------------------------------------------------- 1 | using OrchardCore.Workflows.ViewModels; 2 | using Rework.ContentApproval.Workflows.Activities; 3 | 4 | namespace Rework.ContentApproval.Workflows.ViewModels 5 | { 6 | public class ApprovalResponseEventViewModel : ActivityViewModel 7 | { 8 | public ApprovalResponseEventViewModel() 9 | { 10 | } 11 | 12 | public ApprovalResponseEventViewModel(ApprovalResponseEvent activity) : base(activity) 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /wwwroot/Styles/content-approval.css: -------------------------------------------------------------------------------- 1 | /* 2 | ** NOTE: This file is generated by Gulp and should not be edited directly! 3 | ** Any changes made directly to this file will be overwritten next time its asset group is processed by Gulp. 4 | */ 5 | 6 | .btn-content-approval { 7 | white-space: nowrap; 8 | } 9 | 10 | .btn-group-approval { 11 | border: 1px solid lightgray; 12 | padding: 3px; 13 | border-radius: 4px; 14 | } 15 | .btn-group-approval .status { 16 | width: 100%; 17 | min-width: 200px; 18 | line-height: 38px; 19 | margin-left: 6px; 20 | } 21 | .btn-group-approval .dropdown-menu { 22 | left: auto !important; 23 | right: 0px !important; 24 | } 25 | -------------------------------------------------------------------------------- /wwwroot/Styles/content-approval.min.css: -------------------------------------------------------------------------------- 1 | .btn-content-approval{white-space:nowrap}.btn-group-approval{border:1px solid #d3d3d3;padding:3px;border-radius:4px}.btn-group-approval .status{width:100%;min-width:200px;line-height:38px;margin-left:6px}.btn-group-approval .dropdown-menu{left:auto!important;right:0!important} 2 | --------------------------------------------------------------------------------