/// Calculates the effective permissions based on the groups and roles this
/// user is assigned.
Calculates the effective permissions based on the groups and roles this
user is assigned.
Calculates the effective permissions based on the groups and roles this user is assigned .
pub async fn effective_permissions<C: Connection>(
        &self,
        admin: &C,
    ) -> Result<Permissions, crate::Error> {
        // List all of the groups that this user belongs to because of role associations.
        let role_groups = if self.roles.is_empty() {
            Vec::default()
        } else {
            let roles = admin.get_multiple::<role::Role>(&self.groups).await?;
            let role_groups = roles
                .into_iter()
                .map(|doc| doc.contents::<role::Role>().map(|role| role.groups))
                .collect::<Result<Vec<Vec<u64>>, _>>()?;
            role_groups
                .into_iter()
                .flat_map(Vec::into_iter)
                .collect::<Vec<u64>>()
        };
        // Retrieve all of the groups.
        let groups = if role_groups.is_empty() {
            admin
                .get_multiple::<group::PermissionGroup>(&self.groups)
                .await?
        } else {
            let mut all_groups = role_groups;
            all_groups.extend(self.groups.iter().copied());
            all_groups.dedup();
            admin
                .get_multiple::<group::PermissionGroup>(&all_groups)
                .await?
        };
        // Combine the permissions from all the groups into one.
        let merged_permissions = Permissions::merged(
            groups
                .into_iter()
                .map(|group| {
                    group
                        .contents::<group::PermissionGroup>()
                        .map(|group| Permissions::from(group.statements))
                })
                .collect::<Result<Vec<_>, _>>()?
                .iter(),
        );
        Ok(merged_permissions)
    }
pub async fn effective_permissions < C : Connection > ( & self , admin : & C , ) -> Result < Permissions , crate :: Error > { // List all of the groups that this user belongs to because of role associations. let role_groups = if self . roles . is_empty ( ) { Vec :: default ( ) } else { let roles = admin . get_multiple :: < role :: Role > ( & self . groups ) . await ? ; let role_groups = roles . into_iter ( ) . map ( | doc | doc . contents :: < role :: Role > ( ) . map ( | role | role . groups ) ) . collect :: < Result < Vec < Vec < u64 > > , _ > > ( ) ? ; role_groups . into_iter ( ) . flat_map ( Vec :: into_iter ) . collect :: < Vec < u64 > > ( ) } ; // Retrieve all of the groups. let groups = if role_groups . is_empty ( ) { admin . get_multiple :: < group :: PermissionGroup > ( & self . groups ) . await ? } else { let mut all_groups = role_groups ; all_groups . extend ( self . groups . iter ( ) . copied ( ) ) ; all_groups . dedup ( ) ; admin . get_multiple :: < group :: PermissionGroup > ( & all_groups ) . await ? } ; // Combine the permissions from all the groups into one. let merged_permissions = Permissions :: merged ( groups . into_iter ( ) . map ( | group | { group . contents :: < group :: PermissionGroup > ( ) . map ( | group | Permissions :: from ( group . statements ) ) } ) . collect :: < Result < Vec < _ > , _ > > ( ) ? . iter ( ) , ) ; Ok ( merged_permissions ) }
Calculates the effective permissions based on the groups and roles this
user is assigned.
Calculates the effective permissions based on the groups and roles this user is assigned .
&self
admin
&C