4

I'm trying to get the property "IsSiteAdmin" from a user object in Javascript JSOM. The app I am programming needs to be able to distinguish normal users from Administrators.

function isUserHostWebAdmin() {

    var hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
    var appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));

    var context = new SP.ClientContext.get_current();
    var hostWebContext = new SP.AppContextSite(context, hostweburl);

    var user = hostWebContext.get_web().get_currentUser();
    context.load(user);

    context.executeQueryAsync(onAppReadySuccess, null);


    function onAppReadySuccess() {
        alert(user.get_isSiteAdmin());
    }
}

The problem here is that I always get "false" as a respond. The current user was always either the SharePoint Online Administrator (for Office 365) or the Administrator for SharePoint On Premise.

Does anyone know how to solve this issue?

btw. I tried to get the user both from the host web context and the app web context.

1 Answer 1

7

I got the answer.

The problem lies within the app permissions. This flags permission is inherited from the app permission given in the AppManifest.

The Minimum permission that has to be given is "Site Collection - Full Control"

Then this flag shows the correct data, Every permission less than this will give a "false".

After I changed that I could use it with no problems.

1
  • Thank you a lot for this! I was searching through the net for 2 days. I can't understand why Read Permissions aren't enough already to determine a Site Collection administrator though
    – Vinz
    Commented Mar 20, 2015 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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