pub fn add_role_to_user(user_uuid: UserUuid, user_role: UserRole, conn: &PgConnection) -> BackendResult<User> {
        use crate::schema::users::{
            self,
            dsl::*,
        };

        let user = User::get_user(user_uuid, conn)?;

        let user_role_id: i32 = i32::from(user_role);
        if user.roles.contains(&user_role_id) {
            // The user already has the id, no need to assign it again.
            return Ok(user);
        } else {
            // Because the user does not have the role, it needs to be added to to its list
            let mut new_roles = user.roles.clone();
            new_roles.push(user_role_id);

            let target = users.filter(users::uuid.eq(user_uuid.0));
            diesel::update(target)
                .set(roles.eq(new_roles))
                .get_result(conn)
                .map_err(handle_err::<User>)
        }
    }
/// Adds a role to the user.
Adds a role to the user.
Adds a role to the user .
pub fn add_role_to_user(user_uuid: UserUuid, user_role: UserRole, conn: &PgConnection) -> BackendResult<User> {
        use crate::schema::users::{
            self,
            dsl::*,
        };
        let user = User::get_user(user_uuid, conn)?;
        let user_role_id: i32 = i32::from(user_role);
        if user.roles.contains(&user_role_id) {
            // The user already has the id, no need to assign it again.
            return Ok(user);
        } else {
            // Because the user does not have the role, it needs to be added to to its list
            let mut new_roles = user.roles.clone();
            new_roles.push(user_role_id);
            let target = users.filter(users::uuid.eq(user_uuid.0));
            diesel::update(target)
                .set(roles.eq(new_roles))
                .get_result(conn)
                .map_err(handle_err::<User>)
        }
    }
pub fn add_role_to_user ( user_uuid : UserUuid , user_role : UserRole , conn : & PgConnection ) -> BackendResult < User > { use crate :: schema :: users :: { self , dsl :: * , } ; let user = User :: get_user ( user_uuid , conn ) ? ; let user_role_id : i32 = i32 :: from ( user_role ) ; if user . roles . contains ( & user_role_id ) { // The user already has the id, no need to assign it again. return Ok ( user ) ; } else { // Because the user does not have the role, it needs to be added to to its list let mut new_roles = user . roles . clone ( ) ; new_roles . push ( user_role_id ) ; let target = users . filter ( users :: uuid . eq ( user_uuid . 0 ) ) ; diesel :: update ( target ) . set ( roles . eq ( new_roles ) ) . get_result ( conn ) . map_err ( handle_err :: < User > ) } }
Adds a role to the user.
Adds a role to the user .
user_uuid
UserUuid
user_role
UserRole
conn
&PgConnection
user_uuid
UserUuid
user_role
UserRole
conn
&PgConnection