Enable / Disable Page Customization Access

SP.Site (JS) is an object from SharePoint javascript api, which is used to retrieve the collection of site collections and its sub sites from the web application.

There are some useful properties and methods available in SP.Site object, that can do some unique tasks in Site Collection level. Here, we are going to see the property which is used to attach / detach pages from site definition.

We can categorize the Page Customization in two types,

  1. If the user edit the page in advanced mode in share Point designer
    • Page customized from Site Definition. Entire page is stored to the Content Database.
  2. If the user edit the page in normal mode in share Point designer or in browser
    • Page not customized from Site Definition. Only the added contents stored to the Content Database.

Properties Used: SP.Site.allowRevertFromTemplate (SP.js)
Supports: SharePoint Online, SharePoint 2010+

Gets or sets a value that specifies whether this site collection can be reverted to its base template.

SP.Site.get_allowRevertFromTemplate Used to get the Boolean value, whether the Site collection provides access for advanced customization
SP.Site.set_allowRevertFromTemplate(true) Enables the access to users (Site Owners / Designers) to customize the pages in advanced mode on Site Collection scope.
SP.Site.set_allowRevertFromTemplate(false) Disables the access to users (Site Owners / Designers) to customize the pages in advanced mode on Site Collection scope.

Note: This property doesn’t affect the Site Collection Administrators. They always have access to customize the pages in advanced mode across the site collection.

Identify Page Customization access:
The below example identifies whether customizing the page in advanced mode is allowed on the current site collection

[code lang=”js”]
//Author: Shantha Kumar T
//Property used: SP.Site.allowRevertFromTemplate (sp.js)
//Supports SharePoint 2010 + and SharePoint Online

function getPageCustomizationAccess() {
var clientContext = new SP.ClientContext();
oSite = clientContext.get_site();

clientContext.load(oSite);
clientContext.executeQueryAsync(
Function.createDelegate(this, function() {
var siteInfo = ”;
//The below line get the boolean value of customizing pages is allowed on this site collection
if (oSite.get_allowRevertFromTemplate())
siteInfo = ‘Advanced Customization of pages using SharePoint Designer : Allowed’;
else
siteInfo = ‘Advanced Customization of pages using SharePoint Designer: Not Allowed’;
alert(siteInfo.toString());
}),
Function.createDelegate(this, function(sender, args) {
alert(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
}));
}

function injectMethod() {
getPageCustomizationAccess();
}
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");

[/code]
Code also available in github

Enable Master Page Customization:
The below example enables the access to users to customize the pages in advanced mode in the current site collection level.
[code lang=”js”]
//Author: Shantha Kumar T
//Property used: SP.Site.allowRevertFromTemplate (sp.js)
//Supports SharePoint 2010 + and SharePoint Online

function enablePageCustomizationAccess() {
var clientContext = new SP.ClientContext();
oSite = clientContext.get_site();

//The below line helps to enables the page customization access
oSite.set_allowRevertFromTemplate(true);

clientContext.load(oSite);
clientContext.executeQueryAsync(
Function.createDelegate(this, function() {
var siteInfo = ”;
//The below line get the boolean value of customizing pages is allowed on this site collection
if (oSite.get_allowRevertFromTemplate())
siteInfo = ‘Advanced Customization of pages using SharePoint Designer : Allowed’;
else
siteInfo = ‘Advanced Customization of pages using SharePoint Designer: Not Allowed’;
alert(siteInfo.toString());
}),
Function.createDelegate(this, function(sender, args) {
alert(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
}));
}

function injectMethod() {
enablePageCustomizationAccess();
}
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");

[/code]
Code also available in github

Disable Master Page Customization:
The below example disables the access to users to customize the pages in advanced mode in the current site collection level.
[code lang=”js”]
//Author: Shantha Kumar T
//Property used: SP.Site.allowRevertFromTemplate (sp.js)
//Supports SharePoint 2010 + and SharePoint Online

function disablePageCustomizationAccess() {
var clientContext = new SP.ClientContext();
oSite = clientContext.get_site();

//The below line helps to disables the page customization access
oSite.set_allowRevertFromTemplate(false);

clientContext.load(oSite);
clientContext.executeQueryAsync(
Function.createDelegate(this, function() {
var siteInfo = ”;
//The below line get the boolean value of customizing pages is allowed on this site collection
if (oSite.get_allowRevertFromTemplate())
siteInfo = ‘Advanced Customization of pages using SharePoint Designer : Allowed’;
else
siteInfo = ‘Advanced Customization of pages using SharePoint Designer: Not Allowed’;
alert(siteInfo.toString());
}),
Function.createDelegate(this, function(sender, args) {
alert(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
}));
}

function injectMethod() {
disablePageCustomizationAccess();
}
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");

[/code]
Code also available in github

Shantha Kumar
Shantha Kumar
Articles: 280