MCPcopy Create free account
hub / github.com/dfinity/orbit / remove_admin

Method remove_admin

core/station/impl/src/services/user.rs:95–107  ·  view source on GitHub ↗

Removes the admin role from the given identity if it has an associated user.

(&self, identity: &Principal, ctx: &CallContext)

Source from the content-addressed store, hash-verified

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 ///

Callers 2

can_remove_adminFunction · 0.80
fail_remove_self_adminFunction · 0.80

Calls 4

callerMethod · 0.45
find_by_identityMethod · 0.45
insertMethod · 0.45
to_keyMethod · 0.45

Tested by

no test coverage detected