Skip to content

Commit a13a5bd

Browse files
authored
Merge pull request dani-garcia#3315 from BlackDex/issue-3311
Fix web-vault Member UI show/edit/save
2 parents 3b34b42 + 10c5476 commit a13a5bd

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/api/core/organizations.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,6 @@ struct GetOrgUserData {
748748
include_groups: Option<bool>,
749749
}
750750

751-
// includeCollections
752-
// includeGroups
753751
#[get("/organizations/<org_id>/users?<data..>")]
754752
async fn get_org_users(
755753
data: GetOrgUserData,
@@ -1229,21 +1227,33 @@ async fn _confirm_invite(
12291227
save_result
12301228
}
12311229

1232-
#[get("/organizations/<org_id>/users/<org_user_id>")]
1233-
async fn get_user(org_id: String, org_user_id: String, _headers: AdminHeaders, mut conn: DbConn) -> JsonResult {
1230+
#[get("/organizations/<org_id>/users/<org_user_id>?<data..>")]
1231+
async fn get_user(
1232+
org_id: String,
1233+
org_user_id: String,
1234+
data: GetOrgUserData,
1235+
_headers: AdminHeaders,
1236+
mut conn: DbConn,
1237+
) -> JsonResult {
12341238
let user = match UserOrganization::find_by_uuid_and_org(&org_user_id, &org_id, &mut conn).await {
12351239
Some(user) => user,
12361240
None => err!("The specified user isn't a member of the organization"),
12371241
};
12381242

1239-
Ok(Json(user.to_json_details(&mut conn).await))
1243+
// In this case, when groups are requested we also need to include collections.
1244+
// Else these will not be shown in the interface, and could lead to missing collections when saved.
1245+
let include_groups = data.include_groups.unwrap_or(false);
1246+
Ok(Json(
1247+
user.to_json_user_details(data.include_collections.unwrap_or(include_groups), include_groups, &mut conn).await,
1248+
))
12401249
}
12411250

12421251
#[derive(Deserialize)]
12431252
#[allow(non_snake_case)]
12441253
struct EditUserData {
12451254
Type: NumberOrString,
12461255
Collections: Option<Vec<CollectionData>>,
1256+
Groups: Option<Vec<String>>,
12471257
AccessAll: bool,
12481258
}
12491259

@@ -1342,6 +1352,13 @@ async fn edit_user(
13421352
}
13431353
}
13441354

1355+
GroupUser::delete_all_by_user(&user_to_edit.uuid, &mut conn).await?;
1356+
1357+
for group in data.Groups.iter().flatten() {
1358+
let mut group_entry = GroupUser::new(String::from(group), user_to_edit.uuid.clone());
1359+
group_entry.save(&mut conn).await?;
1360+
}
1361+
13451362
log_event(
13461363
EventType::OrganizationUserUpdated as i32,
13471364
&user_to_edit.uuid,

0 commit comments

Comments
 (0)