0

I have a NavBar at my master page that will only be displayed to the SCA (Site Collection Administrators). I'm using jquery SPServices to do that validation, but the only examples that i found suggest to do this by validating the users group. And with some more research, I also discovered that the SCA aren't a group.

   $(document).ready( function ()
            {
                var isUserOnly = false; //User group member only
              var isAdmin=false;
        var ADMINGROUP = "Administradores de conjunto de sites";  // SPGroup named “Admin”

                $().SPServices
                ({
                  operation: "GetGroupCollectionFromUser", //Calling GetGroupCollectionFromUser.asmx web service
                  userLoginName: $().SPServices.SPGetCurrentUser(), //Calling Current User
                  async: false,
                  completefunc: function(xData, Status)
                  {                           $(xData.responseXML).find("Groups").each(function() //Retrieving the values from Group method of Web Service
                                    {
                                         $(this).find("Group").each(function()  //Parsing through all the groups the current user belongs to
                                         {
                    //Checking whether Current User belongs to Admin Group
                                              if(($(this).attr("Name").toLowerCase() === ADMINGROUP.toLowerCase()))
                                                isAdmin = true;

                    //If Current User does not belong to Admin, then definitely a normal user
                      else
                        isUserOnly=true;
                                         });
                                    });
                     }
               }); // Closing SPServices Method
    if(!isAdmin){document.getElementById('sideNavBox').style.visibility = 'hidden';}
    });`

I Also found this one, but i'm not quite sure how to use it (i tried):

    function isCurrentUserSiteAdmin(OnSuccess,OnError)
    {
    var context = SP.ClientContext.get_current();
    var user = context.get_web().get_currentUser();
        context.load(user);

        context.executeQueryAsync(
            function() {
              var isSiteAdmin = user.get_isSiteAdmin();  
              OnSuccess(isSiteAdmin);
            },
            OnError
        );
    }

    //Usage
    isCurrentUserSiteAdmin(function(isAdmin){
            console.log(isAdmin);
        },function(sender,args){
            console.log('An error occured: ' + args.get_message());
        }
    );

Any help is welcome! Thanks in advance.

P.S: if you know another way, let me know too!

0

You should be able to use this too,

$().SPServices({
      operation: "GetUserInfo",
      userLoginName: $().SPServices.SPGetCurrentUser(),
      completefunc: function(xData, Status) {
        console.log($(xData.responseXML).find("User").attr("IsSiteAdmin"))
      }
  });

Note though, if your SCAs are defined by an AD group, this shows false, as in the case in our environment.

  • Ok, i'll try this one out – Lucas Gomes Mar 2 '15 at 16:27
  • It's working now. Thanks! Just a minor mistake i did. :p – Lucas Gomes Mar 2 '15 at 19:55
1

For 2013, Check this out

using (var ctx = new ClientContext(webUri))
{
    var currentUser = ctx.Web.CurrentUser;
    ctx.Load(currentUser);
    ctx.ExecuteQuery();

    Console.WriteLine(currentUser.IsSiteAdmin);
}

Greetings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.