Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've solved something similar - my method checks if user is assigned a specific role. Here's the algorithm first:</p> <ol> <li>Check if user is directly assigned a role at a site</li> <li>If yes - cool, if not - get all the groups the user is a member of and get all the groups that have that role assigned to them.</li> <li>Compare the two. If there is a matching - cool, if not - user is not assigned a role at that site level. </li> </ol> <p>And the code: </p> <pre><code>public bool IsAssignedAPermission(string premissionName, string userLoginName) { XmlNode nodes; bool isAssignedAPermission; isAssignedAPermission = false; //Check if user is directly assigned a Full Control role try { nodes = userGroupService.GetRoleCollectionFromUser(userLoginName); using (XmlNodeReader reader = new XmlNodeReader(nodes)) { DataSet ds = new DataSet(); ds.ReadXml(reader); DataTable dt = ds.Tables[1]; foreach (DataRow row in dt.Rows) { string permission = row[1].ToString(); if (permission == premissionName) { isAssignedAPermission = true; break; } } } } catch { List&lt;string&gt; groupMemberships; List&lt;string&gt; fullControlGroups; //Check if user is a member of a Full Control group //This is done in three steps: //1. Get the list of groups the user is member of groupMemberships = new List&lt;string&gt;(); nodes = userGroupService.GetGroupCollectionFromUser(userLoginName); using (XmlNodeReader reader = new XmlNodeReader(nodes)) { DataSet ds = new DataSet(); ds.ReadXml(reader); DataTable dt = ds.Tables[1]; foreach (DataRow row in dt.Rows) { string groupName = row[1].ToString(); groupMemberships.Add(groupName); } } //2. Get the list of groups that have Full Control permissions fullControlGroups = new List&lt;string&gt;(); nodes = userGroupService.GetGroupCollectionFromRole(premissionName); using (XmlNodeReader reader = new XmlNodeReader(nodes)) { DataSet ds = new DataSet(); ds.ReadXml(reader); DataTable dt = ds.Tables[1]; foreach (DataRow row in dt.Rows) { string groupName = row[1].ToString(); fullControlGroups.Add(groupName); } } //3. Check if user belongs to any of the Full Control groups foreach (string membership in groupMemberships) { if (fullControlGroups.Contains(membership)) { isAssignedAPermission = true; break; } } } return isAssignedAPermission; } </code></pre> <p>Method parameter userLoginName should be in a form domain\username, e.g. SHAREPOINT\Boris. I hope I helped. Cheers</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload