SPList.DoesUserHavePermissions method (SPUser, SPBasePermissions)
Indica se o usuário especificado tem o conjunto de permissões especificado na lista.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'Declaração
Public Function DoesUserHavePermissions ( _
user As SPUser, _
permissionMask As SPBasePermissions _
) As Boolean
'Uso
Dim instance As SPList
Dim user As SPUser
Dim permissionMask As SPBasePermissions
Dim returnValue As Boolean
returnValue = instance.DoesUserHavePermissions(user, _
permissionMask)
public bool DoesUserHavePermissions(
SPUser user,
SPBasePermissions permissionMask
)
Parâmetros
user
Type: Microsoft.SharePoint.SPUserUm usuário para o qual verificar permissões.
permissionMask
Type: Microsoft.SharePoint.SPBasePermissionsUma combinação bit a bit dos valores de enumeração que especifica um conjunto de permissões.
Valor retornado
Type: System.Boolean
true se o usuário tem as permissões; Caso contrário, false.
Exceptions
Exception | Condition |
---|---|
UnauthorizedAccessException | O usuário atual não tem o direito de EnumeratePermissions . |
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 um determinado conjunto de permissões na lista de documentos compartilhados.
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using site As SPSite = New SPSite("https://localhost")
Using web As SPWeb = site.RootWeb
Dim perms As SPBasePermissions = SPBasePermissions.AddListItems _
Or SPBasePermissions.ApproveItems _
Or SPBasePermissions.CancelCheckout _
Or SPBasePermissions.DeleteListItems _
Or SPBasePermissions.DeleteVersions _
Or SPBasePermissions.EditListItems _
Or SPBasePermissions.Open _
Or SPBasePermissions.OpenItems _
Or SPBasePermissions.ViewListItems _
Or SPBasePermissions.ViewVersions
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
' Check another user's permissions.
Dim hasPermission As Boolean = list.DoesUserHavePermissions(user, perms)
Console.WriteLine("{0, -5} {1}", hasPermission, user.LoginName)
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 ConsoleApp
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://localhost"))
{
using (SPWeb web = site.RootWeb)
{
SPBasePermissions perms = SPBasePermissions.AddListItems
| SPBasePermissions.ApproveItems
| SPBasePermissions.CancelCheckout
| SPBasePermissions.DeleteListItems
| SPBasePermissions.DeleteVersions
| SPBasePermissions.EditListItems
| SPBasePermissions.Open
| SPBasePermissions.OpenItems
| SPBasePermissions.ViewListItems
| SPBasePermissions.ViewVersions;
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)
{
// Check another user's permissions.
bool hasPermission = list.DoesUserHavePermissions(user, perms);
Console.WriteLine("{0, -5} {1}", hasPermission, user.LoginName);
}
}
}
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}