Class Groups
Namespace: TecnoPack.UsersManager.Models
Assembly: CO0002_Templ_FlowpackHMI_V00_26_M.dll
Provides utility functions and constants for managing user groups, determining group hierarchies, and validating user permissions.
public static class Groups
Inheritance
object ← Groups
Remarks
This static class includes:
- Hierarchical definitions of user groups, including predefined access levels.
- Methods to retrieve subgroups for a given group.
- Methods to retrieve all groups associated with a user and determine their access level.
- Validation logic to enforce access control rules between users based on group levels.
Fields
ProjectGroups
Cached list of all group objects defined in the project under the
public static Group[] ProjectGroups
Field Value
Group[]
Methods
GetGroupFromLevel(int)
Retrieves a group object from the cached
public static Group GetGroupFromLevel(int level)
Parameters
level int
The level of the group to retrieve.
Returns
Group
A
Exceptions
InvalidOperationException
Thrown if no group with the specified level exists in the
GetGroupLevel(Group)
Retrieves the numeric level of a group, as defined by its "Level" variable.
public static int GetGroupLevel(this Group group)
Parameters
group Group
The group whose level is to be retrieved.
Returns
int
The integer value representing the group's hierarchical level.
GetSubGroups(Group)
Retrieves all subgroups of a specified base group, based on hierarchical level.
public static Group[] GetSubGroups(Group group)
Parameters
group Group
The base group object for which to retrieve subgroups.
Returns
Group[]
An array of
GetUserGroups(User)
Retrieves all groups associated with a given user.
public static Group[] GetUserGroups(this User user)
Parameters
user User
The user whose group memberships will be returned.
Returns
Group[]
An array of
GetUserLevel(User)
Determines the highest group level assigned to a user.
public static int GetUserLevel(this User user)
Parameters
user User
The user whose level will be calculated.
Returns
int
The numeric value of the highest-level group the user belongs to.
ValidateOperation(int, int)
Determines whether an operation is allowed based on the current and target group levels.
public static bool ValidateOperation(int currentLevel, int targetLevel)
Parameters
currentLevel int
The numeric level of the user performing the operation.
targetLevel int
The numeric level of the target user or group.
Returns
bool
true if the operation is allowed; otherwise, false.
Remarks
- Users with level >=
can perform any operation. - Users with level >=
can operate on targets with level less than or equal to their own. - Users below the administrator level can operate only on targets with a strictly lower level.
ValidateOperation(User, User)
Determines whether the currentUser is allowed to perform
an operation on operationUser based on their group levels.
public static bool ValidateOperation(User currentUser, User operationUser)
Parameters
currentUser User
The user attempting the operation.
operationUser User
The target user on whom the operation is attempted.
Returns
bool
true if the operation is permitted; otherwise, false.
ValidateOperation(Session, User)
Determines whether the user associated with a session
is allowed to perform an operation on a target user.
public static bool ValidateOperation(Session session, User operationUser)
Parameters
session Session
The current session containing the active user.
operationUser User
The target user on whom the operation is attempted.
Returns
bool
true if the session's user has sufficient permissions; otherwise, false.
ValidateOperation(Session, Group)
Determines whether the user associated with a session
is allowed to perform an operation on a target group.
public static bool ValidateOperation(Session session, Group targetGroup)
Parameters
session Session
The current session containing the active user.
targetGroup Group
The target group being validated.
Returns
bool
true if the session's user has sufficient level to operate on the target group;
otherwise, false.
ValidateOperation(User, Group)
Determines whether the currentUser is allowed to perform
an operation on a group.
public static bool ValidateOperation(User currentUser, Group targetGroup)
Parameters
currentUser User
The user attempting the operation.
targetGroup Group
The target group being validated.
Returns
bool
true if the session's user has sufficient level to operate on the target group;
otherwise, false.