How to show or hide “Publish Site” to prevent accidental Site Publish

The Problem: 

One of the CM site users went to the content tree and from the ribbon published the whole site. Now two things might happen

  • the CM site is executing a full site publish and thus can be slow responsive for a specific period of time.
  • a lot of unwanted items ( if proper work flow was not implemented ) will also get published

So what should be done is this scenario?

The Solution:

Its a permission related thing. You can either deny or allow depending on your needs.

The Sitecore role which handles publish related activities is “Sitecore\Sitecore Client Publishing” you have to deny/grant “READ” permission to this user to for the paths – “/sitecore/content/Applications/Content Editor/Menues/Publish/Publish Site” and “/sitecore/content/Documents and settings/All users/Start menu/Left/Publish Site”.

Here are the steps:

Step 1: Switch to “core” database from Sitecore Desktop

Step 2: Open “Access Viewer” and go to : “/sitecore/content/Applications/Content Editor/Menues/Publish/Publish Site” .  Click on “Assign” button in the ribbon to open “Assign Security Rights” properties window. Select the role “Sitecore\Sitecore Client Publishing” and click on the “X”(deny) for “READ” permission.

Stop publish site from ribbon

Step 3: Similarly go to : “/sitecore/content/Documents and settings/All users/Start menu/Left/Publish Site” .  Click on “Assign” button in the ribbon to open “Assign Security Rights” properties window. Select the role “Sitecore\Sitecore Client Publishing” and click on the “X”(deny) for “READ” permission.

Stop publish site from start menu

Step 4: You are done. Go ahead and see that in the ribbon as well as the start menu the “Publish Site” option is not available.

start menu no publish option

How to setup your site in “Live” Mode OR How can I review my site even before publishing (i.e. just after saving)? OR How can I preview items in workflow before they are approved?

 

The Problem:

How to setup your site in “Live” Mode

OR

How can I review my site even before publishing (i.e. just after saving)?

OR

How can I preview items in workflow before they are approved?

This is one of the basic requirements for the content editors to review the site just after they have saved the item/page and before publishing it to web.

The Solution no.1 

Override GetMediaUrl in MediaProvider

 

namespace NaeemSpace.CustomMediaProviders
{

public class MediaProvider : global::Sitecore.Resources.Media.MediaProvider
{
public override string GetMediaUrl(MediaItem item, MediaUrlOptions options)
{
var retUrl = base.GetMediaUrl(item, options);

var query = System.Web.HttpContext.Current.Request.QueryString;
if (query[“sc_mode”] != null)
{
return retUrl + “&sc_mode=” + query[“sc_mode”];
}
else
{
return retUrl;
}

}

}

Update the mediaProvider section in config

<mediaProvider type=”NaeemSpace.CustomMediaProviders.MediaProvider, NaeemSpace.CustomMediaProviders” patch:instead=”mediaProvider[@type=’Sitecore.Resources.Media.MediaProvider, Sitecore.Kernel’]”/>

and ensure the setting “Preview Publishing target” is checked for the preview publishing target. This will ensure that the workflow items not in the final workflow can be published in the preview website and the querystring “sc_mode=preview” will ensure that you are viewing the item from preview database.

Capture

The Solution no 2:

Sitecore provides an out of box functionality to accomplish this.

You need to setup a “review” website with some proper filters so that you can review our changes before publish or even if your workflow items are not approved state.

“Review” site/mode is also called as “Live” Mode (purely meaning that you are not live but are viewing the site as if it is live.

In the review site the items are visible as soon as you save the item.

To your ‘<Sites>’  config uration  section add a review site

<site name=”preview_website” hostName=”preview.website.com” virtualFolder=”/” physicalFolder=”/” rootPath=”/sitecore/content” startItem=”/home” database=”master” domain=”extranet” allowDebug=”true” cacheHtml=”true” htmlCacheSize=”10MB” registryCacheSize=”0″ viewStateCacheSize=”0″ xslCacheSize=”5MB” filteredItemsCacheSize=”2MB” enablePreview=”true” enableWebEdit=”true” enableDebugger=”true” disableClientData=”false” filterItems=”false” enableWorkflow=”true” />

database=”master” will ensure that the contents are loaded from master website

filterItems=”false” will ensure that’s items are not filtered

enableWorkflow=”true” will ensure that it will manage workflow items too.

Any caveats:

Yes this functionality comes up with following restrictions or a caveat

  • It will display only “publishable” items. ( I will not call it as a caveat as the site respects any publishing restrictions including workflow status, item and version visibility)
  • Caching Implications/Restrictions – the live site can’t cache rendering outputs and controls. So you need to clear up the cache as you view the site and

any search indexes pointing to web might not work.