Skip to content

SudoSOS Back-end API / rbac / AssignedRole

Class: AssignedRole ​

The AssignedRole entity represents the many-to-many relationship between users and roles in the Role-Based Access Control (RBAC) system. This entity allows individual users to be assigned specific roles, granting them the permissions associated with those roles.

Purpose and Usage ​

While the RBAC system primarily uses user types for automatic role assignment (via RoleUserType), AssignedRole provides explicit role assignment for individual users. This is useful for:

  • Custom Role Assignments: Granting specific roles to individual users
  • Testing: Assigning roles for testing purposes
  • Legacy Support: Maintaining compatibility with existing role assignment systems
  • Administrative Overrides: Manually assigning roles that differ from user type defaults

Relationship Model ​

  • User: Each assignment is linked to a specific user
  • Role: Each assignment grants a specific role to the user
  • Composite Key: The combination of userId and roleId forms a unique constraint

Role Assignment Hierarchy ​

Users can receive roles through multiple mechanisms:

  1. User Type Assignment: Automatic roles based on user type (RoleUserType)
  2. Individual Assignment: Explicit role assignment (AssignedRole)
  3. Organ Membership: Additional roles through organ membership (OrganMembership)

Database Design ​

The entity uses a composite primary key (userId, roleId) to ensure that each user can only have one instance of each role. The relationship includes cascade delete behavior to maintain referential integrity.

Integration with Role Manager ​

The RoleManager's getRoles() method considers both user type assignments and individual role assignments when determining a user's effective roles.

Extends ​

Constructors ​

Constructor ​

ts
new AssignedRole(): AssignedRole;

Returns ​

AssignedRole

Inherited from ​

BaseEntityWithoutId.constructor

Properties ​

PropertyModifierTypeDescriptionInherited from
createdAtreadonlyDateThe creation date of the object.BaseEntityWithoutId.createdAt
rolepublicRole--
roleIdpublicnumber--
updatedAtreadonlyDateThe last update date of the object.BaseEntityWithoutId.updatedAt
userpublicUser--
userIdpublicnumber--
versionreadonlynumberThe current version of the object.BaseEntityWithoutId.version