Compartilhar via


SPList.GetUserEffectivePermissions method

Obtém as permissões efetivas que um usuário especificado na lista.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaração
Public Overrides Function GetUserEffectivePermissions ( _
    userName As String _
) As SPBasePermissions
'Uso
Dim instance As SPList
Dim userName As String
Dim returnValue As SPBasePermissions

returnValue = instance.GetUserEffectivePermissions(userName)
public override SPBasePermissions GetUserEffectivePermissions(
    string userName
)

Parâmetros

  • userName
    Type: System.String

    O nome do usuário cujas permissões devem ser retornadas.

Valor retornado

Type: Microsoft.SharePoint.SPBasePermissions
Uma combinação bit a bit dos valores de enumeração que especifica um conjunto de permissões.

Exceptions

Exception Condition
UnauthorizedAccessException

O usuário atual não tem a permissão para enumerar permissões.

Examples

O exemplo a seguir é um aplicativo de console que enumera todos os usuários em todos os grupos de um site, verificando se cada usuário tem a permissão de ApproveItems na biblioteca de documentos compartilhados. Para obter um exemplo mostrando outra abordagem para a mesma tarefa, consulte o método DoesUserHavePermissions(SPUser, SPBasePermissions) .

Imports System
Imports Microsoft.SharePoint

Module Test

    Sub Main()
        Using site As SPSite = New SPSite("https://localhost")
            Using web As SPWeb = site.OpenWeb()

                ' Get a list to check permissions on.
                Dim listUrl As String = web.RootFolder.ServerRelativeUrl + "shared documents"
                Dim list As SPList = web.GetList(listUrl)

                ' Be sure the current user has permission to check permissions.
                If web.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions) Then

                    For Each group As SPGroup In web.Groups
                        For Each user As SPUser In group.Users

                            ' Get the rights mask for a user.
                            Dim permMask As SPBasePermissions = list.GetUserEffectivePermissions(user.LoginName)

                            ' Check if the user has a specific right.
                            Dim hasPermission As Boolean = (permMask & SPBasePermissions.ApproveItems) <> 0
                            Console.WriteLine("{0} {1} permission to approve items.", _
                                              user.LoginName, IIf(hasPermission, "has", "does not have"))
                        Next
                    Next

                End If

            End Using
        End Using
        Console.Write(vbCrLf + "Press ENTER to continue...")
        Console.ReadLine()
    End Sub

End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("https://localhost"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    // Get a list to check permissions on.
                    string listUrl = web.RootFolder.ServerRelativeUrl + "shared documents";
                    SPList list = web.GetList(listUrl);

                    // Be sure the current user has permission to check permissions.
                    if (web.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions))
                    {
                        foreach (SPGroup group in web.Groups)
                        {
                            foreach (SPUser user in group.Users)
                            {
                                // Get the rights mask for a user.
                                SPBasePermissions permMask = list.GetUserEffectivePermissions(user.LoginName);

                                // Check if the user has a specific right.
                                bool hasPermission = (permMask & SPBasePermissions.ApproveItems) != 0;
                                Console.WriteLine("{0} {1} permission to approve items.", 
                                                  user.LoginName, hasPermission ? "has" : "does not have");
                            }
                        }
                    }
                }
            }
            Console.Write("\nPress ENTER to continue...");
            Console.ReadLine();
        }
    }
}

Ver também

Referência

SPList class

SPList members

Microsoft.SharePoint namespace

EffectiveBasePermissions

GetUserEffectivePermissionInfo(String)