1

I have a user set up as a site collection admin at the root level of my sharepoint site, and all subsites inherit these permissions. I have also verified that my user admin1 has FULL CONTROL rights to the entire site...so why do both IsUserAdmin and ManageWeb permissions return false??

If I run this code against my global tenant admin user, both values return true. What gives? I do not believe the App-only policy applies here.

using (
    var ctx = TokenHelper.GetClientContextWithAccessToken(
        webUrl, sharePointAuthResult.AccessToken))
{
    var spWeb = ctx.Web;
    var user = ctx.Web.EnsureUser(accessInfo.UserEmail);
    ctx.Load(spWeb, w => w.EffectiveBasePermissions);
    ctx.Load(user);
    ctx.ExecuteQuery();

    var managePermission = new Permission(
        "Manage",               
        ctx.Web.EffectiveBasePermissions.Has(PermissionKind.ManageWeb));

    var isAdmin = user.IsSiteAdmin;

    /*

        managePermission.IsGranted == false    (why?)
        isAdmin                    == false    (why?)

    */
}

enter image description here

In case it's useful, I am developing an Office 365 snap-in app for Word, so I am using the OAuth2 Authorization Code Grant Flow to allow the user to grant consent to the app for read / write permissions.

0

A related answer was posted here by Vadim Gremyachev. It turns out checking the IsSiteAdmin property on the current user object directly isn't a reliable result; instead, checking for the property on Site.RootWeb.SiteUserInfoList was a reliable approach for me.

CurrentUser.IsSiteAdmin should be true but returns false

Another way to determine whether user is site collection administrator Supported in SharePoint 2010/2013

public static bool IsUserSiteAdmin(ClientContext ctx,int userId)
{
   var userInfoList = ctx.Site.RootWeb.SiteUserInfoList;
   var item = userInfoList.GetItemById(userId);
   ctx.Load(item);
   ctx.ExecuteQuery();
   return (bool)item["IsSiteAdmin"];
}                  

Usage

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

    var isCurrentUserSiteAdmin = IsUserSiteAdmin(ctx, currentUser.Id);
}

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.