Interaction with UserRole enum and its endpoints - ita-social-projects/WhatBackend GitHub Wiki
NotAssigned = 0,
Student = 1,
Mentor = 2,
Admin = 4,
Secretary = 8
- When you create account it gets role NotAssigned.
- Account can be assign role of Student, Mentor or Secretary. After assigning it will gets one of roles.
- You can grant to role of account other roles.
- You can't grant role to account if it already has this role. For example if account has role of Mentor you can append role of Student or Secretary but can't append role of Mentor.
- You can't grant role of Admin or role NotAssigned.
- You can't grant role to Admin or to NotAssigned account.
- You can grant only one role in one pass.
- After your granting of role account will be added to list of this role.
- You can revoke roles.
- You can revoke only one role in one pass.
- If account has only one role you can't remove it.
PUT /api/accounts/role/grant
PUT /api/accounts/role/revoke
It enum has extension methods for using
- method
bool UserRole.Is(UserRole checkingRole)
checks is this role has flag of checking role - method
bool UserRole.IsNotAssigned()
checks is this role not assigned - method
bool UserRole.IsAdmin()
checks is this role admin - method
Task<bool> Account.GrantAccountRoleAsync(UserRole role)
tries grant role to account and return bool result of it - method
Task<bool> Account.RevokeAccountRoleAsync(UserRole role)
tries revoke role to account and return bool result of it
Because this way you avoid a lot of checks and avoid potential exceptions