Removes the admin role from the given identity if it has an associated user.
(&self, identity: &Principal, ctx: &CallContext)
| 93 | |
| 94 | /// Removes the admin role from the given identity if it has an associated user. |
| 95 | pub async fn remove_admin(&self, identity: &Principal, ctx: &CallContext) -> ServiceResult<()> { |
| 96 | if ctx.caller() == *identity { |
| 97 | Err(UserError::CannotRemoveOwnAdminRole)? |
| 98 | } |
| 99 | |
| 100 | let user = self.user_repository.find_by_identity(identity); |
| 101 | if let Some(mut user) = user { |
| 102 | user.groups.retain(|group| *group != *ADMIN_GROUP_ID); |
| 103 | self.user_repository.insert(user.to_key(), user.to_owned()); |
| 104 | } |
| 105 | |
| 106 | Ok(()) |
| 107 | } |
| 108 | |
| 109 | /// Creates a new user with the given user details and returns the created user. |
| 110 | /// |
no test coverage detected