Class PermissionSet
Represents a permission set and provides methods for managing permissions and rules.
Inherited Members
Namespace: DataWeb.Authorization
Assembly: DataWeb.Core.dll
Syntax
public sealed class PermissionSet
Remarks
This class manages the permissions and authorization rules for a user. It loads permission sets from the store, initializes permission rules, and provides methods to check permissions.
Constructors
PermissionSet(IReflectionService, IAppErrorService, IServiceProvider, IPermissionSetStore)
Represents a permission set and provides methods for managing permissions and rules.
Declaration
public PermissionSet(IReflectionService reflectionService, IAppErrorService appErrorService, IServiceProvider serviceProvider, IPermissionSetStore permissionSetStore)
Parameters
| Type | Name | Description |
|---|---|---|
| IReflectionService | reflectionService | |
| IAppErrorService | appErrorService | |
| IServiceProvider | serviceProvider | |
| IPermissionSetStore | permissionSetStore |
Remarks
This class manages the permissions and authorization rules for a user. It loads permission sets from the store, initializes permission rules, and provides methods to check permissions.
Properties
IdMaster
Gets or sets the unique identifier.
Declaration
public string IdMaster { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Name
Gets or sets the name of the permission set.
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
PermissionRule
Gets or sets the instance of the permission rule.
Declaration
public IPermissionRule PermissionRule { get; set; }
Property Value
| Type | Description |
|---|---|
| IPermissionRule |
Remarks
This property holds the dynamically loaded permission rule implementation. It is populated during initialization based on the RuleClass property.
Permissions
Gets or sets the list of permissions.
Declaration
public IEnumerable<PermissionSet.Permission> Permissions { get; set; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<PermissionSet.Permission> |
RuleClass
Gets or sets the class name of the permission rule.
Declaration
public string RuleClass { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
User
Gets or sets the user to check permissions for.
Declaration
public IUser User { get; set; }
Property Value
| Type | Description |
|---|---|
| IUser |
Methods
GetRuleIsVisibleFilter(string)
Retrieves a filter expression for the specified table based on the visibility rules implemented by the PermissionRule.
Declaration
public string GetRuleIsVisibleFilter(string tableName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | tableName | The name of the table for which the filter expression should be retrieved. |
Returns
| Type | Description |
|---|---|
| string | Returns the filter expression if the PermissionRule is not null, otherwise returns null. |
GetRuleIsWrite(NavigationContext, ContextItem)
Determines if the current user has write permissions for the specified context item based on the PermissionRule.
Declaration
public Task<bool> GetRuleIsWrite(NavigationContext navigationContext, ContextItem contextItem)
Parameters
| Type | Name | Description |
|---|---|---|
| NavigationContext | navigationContext | The NavigationContext instance representing the navigation context. |
| ContextItem | contextItem | The ContextItem instance representing the context item for which the write permission should be checked. |
Returns
| Type | Description |
|---|---|
| Task<bool> | A task that represents the asynchronous operation. Returns true if the user has write permissions, otherwise false. |
InitAsync(PermissionSetData, IUser, CancellationToken)
Initializes the PermissionSet instance asynchronously using the specified PermissionSetData and user.
Declaration
public Task InitAsync(PermissionSetData permissionSetData, IUser user, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| PermissionSetData | permissionSetData | The PermissionSetData instance containing the permission set information. |
| IUser | user | The IUser instance representing the current user. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task | A task that represents the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when user is null. |
InitAsync(string, IUser, CancellationToken)
Initializes the PermissionSet instance asynchronously using the specified name and user.
Declaration
public Task InitAsync(string name, IUser user, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the permission set to retrieve. |
| IUser | user | The IUser instance representing the current user. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task | A task that represents the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when name is null or empty, or user is null. |
| InvalidOperationException | Thrown when the permission set is not found. |
Is(string)
Checks if the current user has the specified permission.
Declaration
public bool Is(string permissionName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | permissionName | The name of the permission to check. |
Returns
| Type | Description |
|---|---|
| bool | Returns true if the user has the specified permission, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| Exception | Thrown when the permission set does not contain the specified permission name. |