Created
October 3, 2017 13:46
-
-
Save durgesh97025/91322e57d4a2aa3ca69a873e1f4873ef to your computer and use it in GitHub Desktop.
Current User Permission Check on SPWeb
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
$(document).ready(function(){ | |
$.when(checkPermissions()).then(function(isOnlyContributor){ | |
if (isOnlyContributor){ | |
setInterval(HideSiteContents, 1000); | |
} | |
}); | |
}); | |
function HideSiteContents(){ | |
console.log($("SPAN:contains('Site contents')").length + " called"); | |
var siteConObj = $("SPAN:contains('Site contents')"); | |
siteConObj.closest("DIV[role='menuitem']").remove(); | |
siteConObj.remove(); | |
} | |
function checkPermissions() { | |
var def1 = $.Deferred(); | |
var call = jQuery.ajax({ | |
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/effectiveBasePermissions", | |
type: "GET", | |
dataType: "json", | |
headers: { | |
Accept: "application/json;odata=verbose" | |
} | |
}); | |
call.done(function (data, textStatus, jqXHR) { | |
SP.SOD.executeOrDelayUntilScriptLoaded(function(){; | |
var manageListsPerms = new SP.BasePermissions(); | |
manageListsPerms.initPropertiesFromJson(data.d.EffectiveBasePermissions); | |
var isOnlyContributor = manageListsPerms.has(SP.PermissionKind.editListItems); | |
var isManager = manageListsPerms.has(SP.PermissionKind.manageLists); | |
if (isManager == true){ | |
isOnlyContributor = false; | |
} | |
console.log("isOnlyContributor: " + isOnlyContributor + " & Manage Lists:"+isManager); | |
def1.resolve(isOnlyContributor) | |
}, "SP.js") | |
}); | |
return def1.promise(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment