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

Method edit_user

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

Edits the user associated with the given user id and returns the updated user. This method should only be called by a system call (self canister call or controller).

(&self, input: EditUserOperationInput)

Source from the content-addressed store, hash-verified

148 ///
149 /// This method should only be called by a system call (self canister call or controller).
150 pub async fn edit_user(&self, input: EditUserOperationInput) -> ServiceResult<User> {
151 let mut user = self.get_user(&input.user_id)?;
152
153 if let Some(identities) = &input.identities {
154 for identity in identities.iter() {
155 self.assert_identity_has_no_associated_user(identity, Some(user.id))?;
156 }
157 }
158
159 if let Some(name) = &input.name {
160 self.assert_name_has_no_associated_user(name, Some(user.id))?;
161 }
162
163 let cancel_pending_requests = input.cancel_pending_requests;
164
165 user.update_with(input)?;
166 user.validate()?;
167
168 self.user_repository.insert(user.to_key(), user.to_owned());
169
170 if let Some(true) = cancel_pending_requests {
171 let pending_requests: Vec<_> = self
172 .request_repository
173 .find_by_status(RequestStatusCode::Created, None, None)
174 .into_iter()
175 .filter(|r| r.requested_by == user.id)
176 .collect();
177 for request in pending_requests {
178 assert_eq!(request.status, RequestStatus::Created);
179 self.request_repository.cancel_request(
180 request,
181 "The request has been cancelled by an `EditUserOperation`.".to_string(),
182 next_time(),
183 );
184 }
185 }
186
187 Ok(user)
188 }
189
190 /// Returns the list of active users in the given groups.
191 pub fn get_active_users_in_groups(&self, group_ids: &[UserGroupId]) -> Vec<User> {

Calls 11

iterMethod · 0.80
next_timeFunction · 0.50
get_userMethod · 0.45
update_withMethod · 0.45
validateMethod · 0.45
insertMethod · 0.45
to_keyMethod · 0.45
find_by_statusMethod · 0.45
cancel_requestMethod · 0.45

Tested by

no test coverage detected