How could I hide some menu items from a ECB menu in a Sharepoint add-in, based on permissions? My Sharepoint application is Sharepoint hosted not provider hosted, so the javascript injection method wouldn't work.
Thanks
How could I hide some menu items from a ECB menu in a Sharepoint add-in, based on permissions? My Sharepoint application is Sharepoint hosted not provider hosted, so the javascript injection method wouldn't work.
Thanks
Function to check if user is member of specified group
function IsCurrentUserMemberOfGroup(groupName, OnComplete) {
var currentContext = new SP.ClientContext.get_current();
var currentWeb = currentContext.get_web();
var currentUser = currentContext.get_web().get_currentUser();
currentContext.load(currentUser);
var allGroups = currentWeb.get_siteGroups();
currentContext.load(allGroups);
var group = allGroups.getByName(groupName);
currentContext.load(group);
var groupUsers = group.get_users();
currentContext.load(groupUsers);
currentContext.executeQueryAsync(OnSuccess,OnFailure);
function OnSuccess(sender, args) {
var userInGroup = false;
var groupUserEnumerator = groupUsers.getEnumerator();
while (groupUserEnumerator.moveNext()) {
var groupUser = groupUserEnumerator.get_current();
if (groupUser.get_id() == currentUser.get_id()) {
userInGroup = true;
break;
}
}
OnComplete(userInGroup);
}
function OnFailure(sender, args) {
OnComplete(false);
}
}
usage
function IsCurrentUserHasContribPerms()
{
IsCurrentUserMemberOfGroup("Members", function (isCurrentUserInGroup) {
if(isCurrentUserInGroup)
{
// The current user is in the [Members] group!
}
});
}
ExecuteOrDelayUntilScriptLoaded(IsCurrentUserHasContribPerms, 'SP.js');
Source from here
thank you for your help. Finally I've got what I wanted to customize in my page. I've overriden the CreateMenuOption in core.js by creating another file (I've used Chrome to get the code). I've used the following js file too : https://spservices.codeplex.com/ in order to get the group of the connected user.