(SPUser, SPBasePermissions) del método SPList.DoesUserHavePermissions
Indica si el usuario especificado tiene el conjunto de permisos especificado en la lista.
Espacio de nombres: Microsoft.SharePoint
Ensamblado: Microsoft.SharePoint (en Microsoft.SharePoint.dll)
Sintaxis
'Declaración
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
Tipo: Microsoft.SharePoint.SPUserUn usuario para el que se va a comprobar los permisos.
permissionMask
Tipo: Microsoft.SharePoint.SPBasePermissionsUna combinación bit a bit de valores de enumeración que especifica un conjunto de permisos.
Valor devuelto
Tipo: System.Boolean
true si el usuario tiene los permisos; en caso contrario, false.
Excepciones
Excepción | Condición |
---|---|
UnauthorizedAccessException | El usuario actual no tiene el derecho de EnumeratePermissions . |
Ejemplos
En el siguiente ejemplo es una aplicación de consola que enumera todos los usuarios de todos los grupos de un sitio Web, comprobar si cada usuario tiene un conjunto concreto de permisos en la lista documentos compartidos.
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();
}
}
}