Sitecore Workflow: How to Restrict Self-Approval and Publishing

Posted by

In Sitecore workflow it is very easy to restrict content authors from approving (and therefore publishing) their own content changes. All you need to do is create a custom workflow action and a very simple C# class.

Create a Custom Workflow Action

Create a new action item beneath the approve step in your workflow, based on the /sitecore/templates/System/Workflow/Action template.

Validate Approver workflow item

In the “Type String” field, specify the assembly to our custom class:

Sitecore.Feature.Common.Workflow.Actions.ValidateApprover, Sitecore.Feature.Common.Workflow

ValidateApprover Class

namespace Sitecore.Feature.Common.Workflow.Actions
{
    ///
<summary>
    /// Workflow action that ensures the user who created or updated a post cannot approve     their own post
    /// </summary>

    public class ValidateApprover
    {
        public void Process(Sitecore.Workflows.Simple.WorkflowPipelineArgs args)
        {
            if (string.Compare(args.DataItem.Statistics.UpdatedBy,                 Sitecore.Context.User.Name,       true) != 0)
            {
                return;
            }

            Sitecore.Web.UI.Sheer.SheerResponse.Alert("You cannot approve your own changes.");

            args.AbortPipeline();
        }
    }
}

See it in Action

When a content author tries to approve their own change, they will get an alert, and are blocked from approving. The workflow state does not change.

workflow alert.JPG

Note that the content author can still reject their own change. In most cases this is a good thing, so they can undo a mistake they might have made. If you want to prevent this, just copy the “Validate Approver” item underneath the “Reject” command.

References

 

One comment

  1. I found that this no longer worked (as of 2 Jan 2019) and that the solution was to set the “Type String” field to “Sitecore.Feature.Common.Workflow.Actions.ValidateApprover” instead of “Sitecore.Feature.Common.Workflow.Actions.ValidateApprover, Sitecore.Feature.Common.Workflow”

Leave a Reply to Saxon Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s