Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Set Site action menu based on user permission SharePoint 2013

$
0
0

following script works fine for admin users. whenever admin users login in site, it detects users permission and set username with site action menu item but it does not work with others users who are part of members or visitor group permissions.

how can i set username (Last name, First name) as login name whenever they login and i want to display site action menu item only for admin users. others users can get only my site option. 

ExecuteOrDelayUntilScriptLoaded(CustomFun, "sp.js");
        function CustomFun() {

            var web,clientContext,currentUser,oList,perMask;
            clientContext = new SP.ClientContext.get_current();
            web = clientContext.get_web();
            currentUser = web.get_currentUser();    
            clientContext.load(currentUser); 
            clientContext.load(web);        
            clientContext.executeQueryAsync(function(){
               var loginName = currentUser.get_title();
                 $('.ms-siteactions-imgspan').text(loginName);
                $('#suiteBarButtons').find('span[title="Settings"]').appendTo($('#ActionContainer'));
                var isAdmin=currentUser.get_isSiteAdmin ();
                if (!isAdmin){              
                   $("<style>").prop("type", "text/css").html(".ms-core-menu-list>li[text=\"Show Ribbon\"]{"+ "display:none !important;"+"}").appendTo("head");
                 $("<style>").prop("type", "text/css").html(".ms-core-menu-list>li[text=\"Shared with...\"]{"+ "display:none !important;"+"}").appendTo("head");
                 $("<style>").prop("type", "text/css").html(".ms-core-menu-list>li[text=\"Edit page\"]{"+ "display:none !important;"+ "}").appendTo("head");
              $("<style>").prop("type", "text/css").html(".ms-core-menu-list>li[text=\"Add a Page\"]{"+ "display:none !important;"+ "}").appendTo("head");
         $("<style>").prop("type", "text/css").html(".ms-core-menu-list>li[text=\"Add an app\"]{"+ "display:none !important;"+"}").appendTo("head");
 $("<style>").prop("type", "text/css").html(".ms-core-menu-list>li[text=\"Site contents\"]{"+ "display:none !important;"+ "}").appendTo("head");
 $("<style>").prop("type", "text/css").html(".ms-core-menu-list>li[text=\"Design Manager\"]{"+ "display:none !important;"+ "}").appendTo("head");
 $("<style>").prop("type", "text/css").html(".ms-core-menu-list>li[text=\"Site settings\"]{"+ "display:none !important;"+ "}").appendTo("head");
 // $(".ms-core-menu-box, .ms-core-menu-boxBig").hide();
               }   
            }, function(sender, args){
                alert('request failed ' + args.get_message() + '\n'+ args.get_stackTrace());
            });
        }
       Thanks,

Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>