Created
February 27, 2020 03:45
-
-
Save ktskumar/bc6a36c94cc7965dcfcea5eb7cfda99d to your computer and use it in GitHub Desktop.
Check whether the current user has permission to create promoted site page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Check whether the current user has permission to create promoted site page | |
getRequest("https://domain.sharepoint.com/sites/name/_api/sitepages/cancreatepromotedpage").then(function(output) { | |
var cancreatepage = JSON.parse(output.response); | |
if (cancreatepage) { | |
window.location.href = "https://domain.sharepoint.com/sites/name/_layouts/15/CreateSitePage.aspx?promotedState=1"; | |
} else { | |
alert("You didn't have permission to create promotes news post site page"); | |
} | |
}); | |
//getRequest method reference | |
//https://gist.github.com/ktskumar/a9e9df497673e9fd26ead8532b9ff425 | |
function getRequest(url) { | |
var request = new XMLHttpRequest(); | |
return new Promise(function(resolve, reject) { | |
request.onreadystatechange = function() { | |
if (request.readyState !== 4) return; | |
if (request.status >= 200 && request.status < 300) { | |
resolve(request); | |
} else { | |
reject({ | |
status: request.status, | |
statusText: request.statusText | |
}); | |
} | |
}; | |
request.open('GET', url, true); | |
request.setRequestHeader("Content-Type", "application/json;charset=utf-8"); | |
request.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal"); | |
request.setRequestHeader("ODATA-VERSION", "4.0"); | |
request.send(); | |
}); | |
} | |
//Author: Shantha Kumar T | |
//Web: https://www.ktskumar.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment