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
permissionsConfigIOptions<PermissionSettings>loggerILogger<PermissionService>displayServiceLazy<IDisplayService>userRepositoryLazy<IUserRepository>authorityRepositoryLazy<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
displayDisplayThe display whose permissions are being resolved; matched against the user's authorized display and unit identifiers.
userUserThe 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
userstringThe 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
userUserThe 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
unitIdstringThe identifier of the unit whose permissions should be resolved.
userUserThe 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
usernamestringThe username used to look up the user attempting to access the display.
userRolePermissionEnum.RolesTypeThe role of the user, used in the role-based access evaluation against the display.
sourcePermissionEnum.SourcePermissionsEnumThe source permission context used when evaluating access to the display.
displayIdstringThe 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
usernamestringThe username of the user to check.
userRolePermissionEnum.RolesTypeThe role required to access the panel.
sourcePermissionEnum.SourcePermissionsEnumThe source permission context used for the access check.
Returns
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
usernamestringThe username of the user whose access is being verified.
userRolePermissionEnum.RolesTypeThe role type to be matched against the user's authorities for the target unit.
sourcePermissionEnum.SourcePermissionsEnumThe source permission context associated with the access evaluation.
unitIdstringThe identifier of the unit to check access against.