Why is my List.GetUserEffectivePermissions () method not working?

I am developing a process in C # with a SharePoint 2013 client-side object model. I need to get the permissions of a SharePoint list for a given user that will be different from the user running the code.

using SP = Microsoft.SharePoint.Client;

SP.ClientContext SpContext = new SP.ClientContext("SITEURL");
SP.Web SiteWeb = SpContext.Web;
SP.List Lst = SpContext.Web.Lists.GetByTitle("LIST");
var ClientUserEffPerms = Lst.GetUserEffectivePermissions(@"<domain>\<username>");

SpContext.Load(SiteWeb, S => S.EffectiveBasePermissions);
SpContext.Load(Lst, L => L.EffectiveBasePermissions);
SpContext.ExecuteQuery();

      

After running this code, the ClientUserEffPerms.Value (BasePermissions) object does not correctly match this user's permissions. The object is not null, but it represents the user as having any permissions. The user has minimum view and edit permissions and I can confirm this by viewing / editing the list items using the web browser as that user.

The user executing the code has permission to enumerate permissions at the Web and List level. I have verified this with the code below and booleans resolve to true.

bool SvcUserHasSiteEnumPermsPerm = SiteWeb.EffectiveBasePermissions.Has(SP.PermissionKind.EnumeratePermissions);
bool SvcUserHasListEnumPermsPerm = Lst.EffectiveBasePermissions.Has(SP.PermissionKind.EnumeratePermissions);

      

Can anyone help me determine what is wrong with my GetUserEffectivePermissions () method?

+3


source to share


1 answer


When you call GetUserEffectivePermissions, you need to pass in the full version of the login tokens, which looks something like this:

i: 0 # .W | domain \ user

You can get this by loading the LoginName property into a custom object:



clientContext.Load(clientContext.Web.CurrentUser, i => i.LoginName);
clientContext.ExecuteQuery();

      

Of course, this is for the current user, so you need to acquire the user you really want first.

+1


source







All Articles