locked
User rights in group RRS feed

  • Question

  • Hello!

    I want to know If the user has read access, full control etc in the current group.

            Dim myWeb As SPWeb = SPContext.Current.Web  
            For Each item As SPGroup In myWeb.CurrentUser.Groups 

    What comes efter the for each?

    Cheers!

    /Eskil
    Monday, November 3, 2008 10:46 AM

Answers

  • Heya,
    as I said in my previous post try something like this:
    foreach(SPGroup group in SPContext.Current.Web.CurrentUser.Groups) {  
      Console.WriteLine(group.Name);  
      foreach(SPRoleDefinition roledef in SPContext.Current.Web.RoleAssignments.GetAssignmentByPrincipal((SPPrincipal)group).RoleDefinitionBindings ) {  
        Console.WriteLine("\t" + roledef.BasePermissions.ToString());  
      }  
    }  
     
    /WW
    • Marked as answer by IgotStuckAgain Tuesday, November 4, 2008 10:03 AM
    Monday, November 3, 2008 12:29 PM

All replies

  • Hi,
    what you want after the for-each depends on what you want to check permissions for; a site, a list?
    For a Site (and similar for lists) you should get the RoleAssignments property and then get the GetAssignmentByPrincipal and pass in the SPGroup object (which inherits from SPPrincipal). Then you can examine the assignments to get the SPRoleDefinition objects which contains the BasePermissions, this property contains the actual permissions of the role which the group (or user) has.

    Hope that this helps

    /WW
    • Marked as answer by IgotStuckAgain Monday, November 3, 2008 11:19 AM
    • Marked as answer by IgotStuckAgain Monday, November 3, 2008 11:19 AM
    • Unmarked as answer by IgotStuckAgain Monday, November 3, 2008 11:36 AM
    Monday, November 3, 2008 11:12 AM
  • What I want the permissions for is the group. What permissions has the current user got in the current group.
    Something like: for each item as SpGroup in aGroupCollection
                                        if item.hasUserReadAccess = true then
                                            'do something
                                        elseif item.hasUserFullPermissionAccess = true then
                                            'do something else

    So, I'm only interested in groups.

    Cheers!

    /Eskil
    Monday, November 3, 2008 11:23 AM
  • Hello again,

    The following works:
                For Each item As SPGroup In myWeb.CurrentUser.Groups  
                    For Each subItem As Object In item.Roles  
                        lblText.Text &= subItem.ToString() & "<br/>"  
                    Next  
                Next 

    But item.Roles is obsolete and I should use the SPRoleAssignment Class instead. Any ideas on how to do this?

    Cheers!

    /Eskil
    Monday, November 3, 2008 12:14 PM
  • Heya,
    as I said in my previous post try something like this:
    foreach(SPGroup group in SPContext.Current.Web.CurrentUser.Groups) {  
      Console.WriteLine(group.Name);  
      foreach(SPRoleDefinition roledef in SPContext.Current.Web.RoleAssignments.GetAssignmentByPrincipal((SPPrincipal)group).RoleDefinitionBindings ) {  
        Console.WriteLine("\t" + roledef.BasePermissions.ToString());  
      }  
    }  
     
    /WW
    • Marked as answer by IgotStuckAgain Tuesday, November 4, 2008 10:03 AM
    Monday, November 3, 2008 12:29 PM
  • Hello and thanks,

    I'm guessing that will work (but since I can't get it to execute I really don't know). I've started a new thread based on your answer, since I can't get it going:

    http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/5c46f5d1-eee1-4b16-9982-74f950d551f0

    Cheers!

    /Eskil
    Tuesday, November 4, 2008 10:04 AM