Sitecore Custom Publish Restriction

Sitecore has the functionality of allowing publish restrictions on items. By using the publish restrictions, you can prevent an item or its versions to be published on the desired database. For example, restriction is set on Item A to prevent it from being published on the Web Database

restriction

This feature is accessible to all users and you can disallow access to this feature using the Access Manager and the Security Editor. However, when disallowing the access, the user will not be able to see this feature.

There was a question raised on StackOverflow in which the user wanted to disable the access for specific tab. In this post, I will explain to you how to disable the access to specific tab.

First of all, you will need to override the Sitecore UI Set Publishing. The path to this xml file is found at Website\sitecore\shell\Applications\Content Manager\Dialogs\Set Publishing. When overriding the xml file, you will need to copy the Set Publishing.xml to the folder Override found at Website\sitecore\shell\Override.

Note: In the folder Override, there is no directory structure for the Set Publishing. For standard, create the directory structure same as the original directory as follows: Website\sitecore\shell\Override\Applications\Content Manager\Dialogs\Set Publishing.

Now, in your Project Solution, create a class named OverrideSetPublishing which will inherit the SetPublishingForm as shown below:

public class OverrideSetPublishing : SetPublishingForm
{
    
}

You need to override the OnLoad Method because it is at this point that the different tabs are being rendered. Below is a screenshot of the current SetPublishingForm which is found in the assembly Sitecore.Client.dll.

decompile

As you see in the screenshot above, it is the this.RenderItemTab, this.RenderVersions and this.RenderTargetTab that are loading the different tabs. So, you can easily disable access to those tabs based on the user role as shown below:

using Sitecore.Shell.Applications.ContentManager.Dialogs.SetPublishing;
using Sitecore.Web.UI.HtmlControls;

public class OverrideSetPublishing : SetPublishingForm
{
    private Tab TargetsTab;

    private Tab VersionsTab;

    private Tab ItemTab;

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        if (Context.User.IsInRole("Specify your role here"))
        {
            this.TargetsTab.Visible = false;
            this.VersionsTab.Visible = false;
            this.ItemTab.Visible = false;
        }            
    }
}

This piece of code will remove the visibility of the tab base on the user role that will be specified in the IF Statement. You can easily change this piece of code to suit your needs. For example, you may want a user in role Webmaster to have access to the Version Tab and not the Targets Tab.

Advertisements

11 thoughts on “Sitecore Custom Publish Restriction

  1. Syed Rahman says:

    Had implemented as mentioned above but it created problem for non admin users. When there are multiple versions and when the last version is unchecked under VERSIONS tab then the whole item becomes unpublishable.

    Like

      • Syed Rahman says:

        Enabled is not working. Not sure whats wrong

        protected override void OnLoad(EventArgs e)
        {
        base.OnLoad(e);
        if (!Context.User.IsAdministrator)
        {
        this.TargetsTab.Enabled = false;
        this.VersionsTab.Visible = true;
        this.ItemTab.Enabled = false;
        this.VersionsTab.Active = true;
        }
        else
        {
        this.VersionsTab.Active = true;
        this.TargetsTab.Visible = true;
        this.VersionsTab.Visible = true;
        this.ItemTab.Visible = true;
        }
        }

        Like

  2. Syed Rahman says:

    The issue is with non Admin users. Since the ITEMS tab is visible false and hence the publishable checkbox value will always be false and as soon as you uncheck any item version it immediately makes the item unpublishable

    Like

Leave a 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s