Table of Contents

Class PermissionService

Namespace
adas_core.Application.Services
Assembly
adas-core.Application.dll
public class PermissionService : IPermissionService
Inheritance
PermissionService
Implements
Inherited Members
Extension Methods

Constructors

PermissionService(IOptions<PermissionSettings>, ILogger<PermissionService>, Lazy<IDisplayService>, Lazy<IUserRepository>, Lazy<IAuthorityRepository>)

public PermissionService(IOptions<PermissionSettings> permissionsConfig, ILogger<PermissionService> logger, Lazy<IDisplayService> displayService, Lazy<IUserRepository> userRepository, Lazy<IAuthorityRepository> authorityRepository)

Parameters

permissionsConfig IOptions<PermissionSettings>
logger ILogger<PermissionService>
displayService Lazy<IDisplayService>
userRepository Lazy<IUserRepository>
authorityRepository Lazy<IAuthorityRepository>

Methods

GetPermissionsForDisplay(Display, User)

Retrieves the display permission configuration for the specified user based on their authorization roles. Loads the user's authorities from the repository if not already cached, matches the display or its unit against the authorities, and maps the role to the corresponding display permission set (Guest, Admin, Developer, DoctorChief, Doctor, NursingSupervisor, or Nurse).

public Task<DisplayPermissionTypes> GetPermissionsForDisplay(Display display, User user)

Parameters

display Display

The display whose permissions are being resolved; matched against the user's authorized display and unit identifiers.

user User

The user whose authorizations and roles are evaluated to determine the applicable display permissions.

Returns

Task<DisplayPermissionTypes>

A Task<TResult> containing the display permission configuration corresponding to the matched role.

Exceptions

ForbbidenException

Thrown when the user has no authorizations available, or when none of the user's authorities match the given display or its unit.

GetPermissionsForPanel(string)

Retrieves the panel permissions for the specified user, including their assigned authorities.

public Task<PanelPermissionTypes> GetPermissionsForPanel(string user)

Parameters

user string

The username of the user whose panel permissions are being requested.

Returns

Task<PanelPermissionTypes>

The PanelPermissionTypes that apply to the user based on their authorities.

Exceptions

ForbbidenException

Thrown when no user is found with the specified username.

GetPermissionsForPanel(User)

Retrieves the panel permissions assigned to a user based on their authorization role. Iterates through the user's authorities, identifies the first entry with panel authorization, and maps the role to the corresponding PanelPermissionTypes configuration (Guest, Admin, Developer, DoctorChief, Doctor, NursingSupervisor, or Nurse).

public PanelPermissionTypes GetPermissionsForPanel(User user)

Parameters

user User

The user whose panel permissions are being resolved; must carry authorization data.

Returns

PanelPermissionTypes

The PanelPermissionTypes associated with the matched role.

Exceptions

ForbbidenException

Thrown when the user has no authorities or no authority grants panel access.

GetPermissionsForUnit(string, User)

Retrieves the permission set associated with a specific unit for the given user, based on the user's role within that unit. Iterates the user's authorizations to find a matching unit, parses the role, and returns the corresponding configured permissions (Guest, Admin, Developer, DoctorChief, Doctor, NursingSupervisor, or Nurse).

public Task<DisplayPermissionTypes> GetPermissionsForUnit(string unitId, User user)

Parameters

unitId string

The identifier of the unit whose permissions should be resolved.

user User

The user whose authorizations and role are used to determine the permissions for the unit.

Returns

Task<DisplayPermissionTypes>

A Task<TResult> that resolves to the permission configuration matching the user's role for the specified unit.

Exceptions

ForbbidenException

Thrown when the user has no authorizations, or when no authorization entry matches the provided unitId.

HasAccessToDisplay(string, RolesType, SourcePermissionsEnum, string)

Determines whether the specified user has access to a given display, based on the user's role, authorities, and the display record. Returns false if the display identifier is not a valid ObjectId, or if either the user or the display cannot be found. The user's authorization set is loaded from the authority repository before evaluating access through role checks against the display.

public Task<bool> HasAccessToDisplay(string username, PermissionEnum.RolesType userRole, PermissionEnum.SourcePermissionsEnum source, string displayId)

Parameters

username string

The username used to look up the user attempting to access the display.

userRole PermissionEnum.RolesType

The role of the user, used in the role-based access evaluation against the display.

source PermissionEnum.SourcePermissionsEnum

The source permission context used when evaluating access to the display.

displayId string

The string identifier of the display; must be parseable as an ObjectId or access is denied.

Returns

Task<bool>

A task that resolves to true if the user's role and authorities grant access to the specified display; otherwise, false.

HasAccessToPanel(string, RolesType, SourcePermissionsEnum)

Determines whether the specified user has access to a panel by resolving their authorities and checking the required role. Returns false if the user is not found.

public Task<bool> HasAccessToPanel(string username, PermissionEnum.RolesType userRole, PermissionEnum.SourcePermissionsEnum source)

Parameters

username string

The username of the user to check.

userRole PermissionEnum.RolesType

The role required to access the panel.

source PermissionEnum.SourcePermissionsEnum

The source permission context used for the access check.

Returns

Task<bool>

true if the user exists and has the required role within the panel; otherwise, false.

HasAccessToUnit(string, RolesType, SourcePermissionsEnum, string)

Determines whether the specified user has access to a given unit based on their role and assigned authorities. Returns false when the user cannot be found by username; otherwise delegates the final check to the role-in-unit search using the retrieved authorities.

public Task<bool> HasAccessToUnit(string username, PermissionEnum.RolesType userRole, PermissionEnum.SourcePermissionsEnum source, string unitId)

Parameters

username string

The username of the user whose access is being verified.

userRole PermissionEnum.RolesType

The role type to be matched against the user's authorities for the target unit.

source PermissionEnum.SourcePermissionsEnum

The source permission context associated with the access evaluation.

unitId string

The identifier of the unit to check access against.

Returns

Task<bool>

A task that resolves to true if the user has the required access to the unit; otherwise, false.