Skip to content

Commit

Permalink
Rename function to mention swapping uuid's
Browse files Browse the repository at this point in the history
Signed-off-by: BlackDex <black.dex@gmail.com>
  • Loading branch information
BlackDex committed Jan 4, 2025
1 parent 296e45b commit 48116b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/api/core/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ async fn get_org_collections_details(org_id: &str, headers: ManagerHeadersLoose,
};

// get all collection memberships for the current organization
let coll_users = CollectionUser::find_by_organization(org_id, &mut conn).await;
let coll_users = CollectionUser::find_by_organization_swap_user_uuid_with_org_user_uuid(org_id, &mut conn).await;
// Generate a HashMap to get the correct UserOrgType per user to determine the manage permission
// We use the uuid instead of the user_uuid here, since that is what is used in CollectionUser
let users_org_type: HashMap<String, i32> = UserOrganization::find_confirmed_by_org(org_id, &mut conn)
Expand Down Expand Up @@ -871,7 +871,7 @@ struct InviteData {
async fn send_invite(org_id: &str, data: Json<InviteData>, headers: AdminHeaders, mut conn: DbConn) -> EmptyResult {
let mut data: InviteData = data.into_inner();

// HACK: We need the raw user-type be be sure custom role is selected to determine the access_all permission
// HACK: We need the raw user-type to be sure custom role is selected to determine the access_all permission
// The from_str() will convert the custom role type into a manager role type
let raw_type = &data.r#type.into_string();
// UserOrgType::from_str will convert custom (4) to manager (3)
Expand All @@ -885,7 +885,7 @@ async fn send_invite(org_id: &str, data: Json<InviteData>, headers: AdminHeaders
}

// HACK: This converts the Custom role which has the `Manage all collections` box checked into an access_all flag
// Since the parent checkbox is not send to the server we need to check and verify the child checkboxes
// Since the parent checkbox is not sent to the server we need to check and verify the child checkboxes
// If the box is not checked, the user will still be a manager, but not with the access_all permission
if raw_type.eq("4")
&& data.permissions.get("editAnyCollection") == Some(&json!(true))
Expand Down Expand Up @@ -1371,7 +1371,7 @@ async fn edit_user(
) -> EmptyResult {
let mut data: EditUserData = data.into_inner();

// HACK: We need the raw user-type be be sure custom role is selected to determine the access_all permission
// HACK: We need the raw user-type to be sure custom role is selected to determine the access_all permission
// The from_str() will convert the custom role type into a manager role type
let raw_type = &data.r#type.into_string();
// UserOrgType::from_str will convert custom (4) to manager (3)
Expand All @@ -1380,7 +1380,7 @@ async fn edit_user(
};

// HACK: This converts the Custom role which has the `Manage all collections` box checked into an access_all flag
// Since the parent checkbox is not send to the server we need to check and verify the child checkboxes
// Since the parent checkbox is not sent to the server we need to check and verify the child checkboxes
// If the box is not checked, the user will still be a manager, but not with the access_all permission
if raw_type.eq("4")
&& data.permissions.get("editAnyCollection") == Some(&json!(true))
Expand Down Expand Up @@ -3011,7 +3011,7 @@ async fn put_reset_password_enrollment(
if reset_request.reset_password_key.is_none()
&& OrgPolicy::org_is_reset_password_auto_enroll(org_id, &mut conn).await
{
err!("Reset password can't be withdrawed due to an enterprise policy");
err!("Reset password can't be withdrawn due to an enterprise policy");
}

if reset_request.reset_password_key.is_some() {
Expand Down
5 changes: 4 additions & 1 deletion src/db/models/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,10 @@ impl CollectionUser {
}}
}

pub async fn find_by_organization(org_uuid: &str, conn: &mut DbConn) -> Vec<Self> {
pub async fn find_by_organization_swap_user_uuid_with_org_user_uuid(
org_uuid: &str,
conn: &mut DbConn,
) -> Vec<Self> {
db_run! { conn: {
users_collections::table
.inner_join(collections::table.on(collections::uuid.eq(users_collections::collection_uuid)))
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/organization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ impl UserOrganization {
pub async fn to_json_mini_details(&self, conn: &mut DbConn) -> Value {
let user = User::find_by_uuid(&self.user_uuid, conn).await.unwrap();

// Because BitWarden want the status to be -1 for revoked users we need to catch that here.
// Because Bitwarden wants the status to be -1 for revoked users we need to catch that here.
// We subtract/add a number so we can restore/activate the user to it's previous state again.
let status = if self.status < UserOrgStatus::Revoked as i32 {
UserOrgStatus::Revoked as i32
Expand Down

0 comments on commit 48116b0

Please sign in to comment.