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

Function set_initial_users

core/station/impl/src/services/system.rs:1005–1064  ·  view source on GitHub ↗

Registers the newly added users of the canister.

(
        users: Vec<InitUserInput>,
        default_groups: &[UUID],
    )

Source from the content-addressed store, hash-verified

1003
1004 /// Registers the newly added users of the canister.
1005 pub fn set_initial_users(
1006 users: Vec<InitUserInput>,
1007 default_groups: &[UUID],
1008 ) -> Result<(), ApiError> {
1009 if users.is_empty() {
1010 Err(SystemError::NoUsersSpecified)?;
1011 }
1012
1013 if users.len() > u16::MAX as usize {
1014 Err(SystemError::TooManyUsersSpecified {
1015 max: u16::MAX as usize,
1016 })?;
1017 }
1018
1019 print(format!("Registering {} users", users.len()));
1020 for user in users {
1021 let user_id = user
1022 .id
1023 .map(|id_str| HelperMapper::to_uuid(id_str).map(|uuid| *uuid.as_bytes()))
1024 .transpose()?;
1025
1026 let groups = user
1027 .groups
1028 .map(|ids| {
1029 ids.into_iter()
1030 .map(|id| {
1031 HelperMapper::to_uuid(id.clone()).map(|uuid| uuid.as_bytes().to_owned())
1032 })
1033 .collect::<Result<Vec<_>, _>>()
1034 })
1035 .transpose()?
1036 .unwrap_or_else(|| default_groups.to_vec());
1037
1038 let identities = user
1039 .identities
1040 .iter()
1041 .map(|identity| identity.identity.to_owned())
1042 .collect::<Vec<_>>();
1043
1044 let user = USER_SERVICE.add_user_with_id(
1045 AddUserOperationInput {
1046 groups,
1047 name: user.name.to_owned(),
1048 status: user.status.into(),
1049 identities,
1050 },
1051 user_id,
1052 )?;
1053
1054 print(format!(
1055 "Added user with principals {:?} and user id {}",
1056 user.identities
1057 .iter()
1058 .map(|identity| identity.to_text())
1059 .collect::<Vec<_>>(),
1060 Uuid::from_bytes(user.id).hyphenated()
1061 ));
1062 }

Calls 7

printFunction · 0.85
mapMethod · 0.80
to_vecMethod · 0.80
iterMethod · 0.80
add_user_with_idMethod · 0.80
is_emptyMethod · 0.45
lenMethod · 0.45