Saturday, 10 January 2015

How to hide actions menu from SharePoint ribbon to all user other than site owners group members( or group members)

In this blog you will see how to hide site actions button in the top ribbon if the logged in user not exists in a particular SharePoint group using ECMAScript.


<script type="text/javascript">  
ExecuteOrDelayUntilScriptLoaded(IsUserExists, "sp.js");  
  
var group;  
var users;  
var ctx;   
var groupCollection;  
var user;  
var currentuser;  
  
function IsUserExists() {  
   ctx = SP.ClientContext.get_current();  
   groupCollection = ctx.get_web().get_siteGroups();  
   currentuser=ctx.get_web().get_currentUser();
   // var oGroup = collGroup.getByName(projGroup);  
   group = groupCollection.getByName("UKREDDY SharePointApp Journey Owners");  
   ctx.load(group);  
   ctx.load(currentuser);  
   ctx.executeQueryAsync(Function.createDelegate(this, this.OnGetGroupSuccess), Function.createDelegate(this, OnFailure));  
}  
  
function OnGetGroupSuccess() {  
    users=group.get_users();  
    ctx.load(users);  
    ctx.executeQueryAsync(Function.createDelegate(this, this.OnGetuserSuccess), Function.createDelegate(this, OnFailure));   
}  
  
function OnGetuserSuccess() {     
    var userEnumerator = users.getEnumerator();    
    while (userEnumerator.moveNext()) {  
           var user = userEnumerator.get_current();  
           if (user.get_id() == currentuser.get_id() || currentuser.get_title()=='Administrator' || currentuser.get_title()=='System Account' ) {  
                   document.getElementById('siteactiontd').style.display='inline';    
                   break;  
                }  
                else  
                {                     
                document.getElementById('siteactiontd').style.display='none';
                }  
            }  
         }  
  
function OnFailure(sender, args) {  
   
}  
</script>      



No comments:

Post a Comment