|
|
@ -14,17 +14,17 @@ use crate::{ |
|
|
auth::{ |
|
|
auth::{ |
|
|
AccessImportExportHeaders, AdminHeaders, CollectionAction, CollectionDeleteHeaders, CollectionReadHeaders, |
|
|
AccessImportExportHeaders, AdminHeaders, CollectionAction, CollectionDeleteHeaders, CollectionReadHeaders, |
|
|
CollectionUsersReadHeaders, Headers, ManageGroupsHeaders, ManagePoliciesHeaders, ManageResetPasswordHeaders, |
|
|
CollectionUsersReadHeaders, Headers, ManageGroupsHeaders, ManagePoliciesHeaders, ManageResetPasswordHeaders, |
|
|
ManageUsersHeaders, ManagerHeaders, ManagerHeadersLoose, OrgMemberHeaders, OwnerHeaders, custom_member_may, |
|
|
ManageUsersHeaders, ManagerHeaders, ManagerHeadersLoose, OrgMemberHeaders, OwnerHeaders, decode_invite, |
|
|
decode_invite, |
|
|
member_may, |
|
|
}, |
|
|
}, |
|
|
db::{ |
|
|
db::{ |
|
|
DbConn, |
|
|
DbConn, |
|
|
models::{ |
|
|
models::{ |
|
|
Cipher, CipherAccessScope, CipherId, Collection, CollectionCipher, CollectionGroup, CollectionId, |
|
|
Cipher, CipherAccessScope, CipherId, Collection, CollectionCipher, CollectionGroup, CollectionId, |
|
|
CollectionUser, CustomPermission, Device, EventType, FillAssistPolicyData, Group, GroupId, GroupUser, |
|
|
CollectionMembership, CollectionUser, CustomPermission, Device, EventType, FillAssistPolicyData, Group, |
|
|
Invitation, KeyId, Membership, MembershipId, MembershipStatus, MembershipType, OrgPolicy, OrgPolicyType, |
|
|
GroupId, GroupUser, Invitation, KeyId, Membership, MembershipId, MembershipStatus, MembershipType, |
|
|
Organization, OrganizationApiKey, OrganizationId, TwoFactor, TwoFactorType, User, UserId, |
|
|
OrgPolicy, OrgPolicyType, Organization, OrganizationApiKey, OrganizationId, TwoFactor, TwoFactorType, User, |
|
|
custom_roles_enabled, |
|
|
UserId, custom_roles_enabled, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
mail, |
|
|
mail, |
|
|
@ -217,13 +217,14 @@ async fn create_organization(headers: Headers, data: Json<OrgData>, conn: DbConn |
|
|
let collection = Collection::new(org.uuid.clone(), data.collection_name, None); |
|
|
let collection = Collection::new(org.uuid.clone(), data.collection_name, None); |
|
|
|
|
|
|
|
|
member.akey = data.key; |
|
|
member.akey = data.key; |
|
|
member.access_all = true; |
|
|
|
|
|
member.atype = MembershipType::Owner as i32; |
|
|
member.atype = MembershipType::Owner as i32; |
|
|
member.status = MembershipStatus::Confirmed as i32; |
|
|
member.status = MembershipStatus::Confirmed as i32; |
|
|
|
|
|
|
|
|
org.save(&conn).await?; |
|
|
org.save(&conn).await?; |
|
|
member.save(&conn).await?; |
|
|
member.save(&conn).await?; |
|
|
collection.save(&conn).await?; |
|
|
collection.save(&conn).await?; |
|
|
|
|
|
// Like upstream, the owner manages the default collection, which puts it in their vault
|
|
|
|
|
|
CollectionUser::save(&member.user_uuid, &collection.uuid, false, false, true, &conn).await?; |
|
|
|
|
|
|
|
|
Ok(Json(org.to_json())) |
|
|
Ok(Json(org.to_json())) |
|
|
} |
|
|
} |
|
|
@ -375,8 +376,8 @@ async fn get_org_collections(org_id: OrganizationId, headers: ManagerHeadersLoos |
|
|
|
|
|
|
|
|
let collections = if headers.membership.can_list_all_collections() { |
|
|
let collections = if headers.membership.can_list_all_collections() { |
|
|
get_org_collections_impl(&org_id, &conn).await |
|
|
get_org_collections_impl(&org_id, &conn).await |
|
|
} else if headers.membership.has_type(MembershipType::Custom) { |
|
|
} else { |
|
|
// A Custom member gets the collections they may manage
|
|
|
// Everyone else gets the collections they manage
|
|
|
let manageable = |
|
|
let manageable = |
|
|
Collection::find_explicitly_manageable_by_user(&org_id, &headers.membership.user_uuid, &conn).await; |
|
|
Collection::find_explicitly_manageable_by_user(&org_id, &headers.membership.user_uuid, &conn).await; |
|
|
Collection::find_by_organization(&org_id, &conn) |
|
|
Collection::find_by_organization(&org_id, &conn) |
|
|
@ -385,8 +386,6 @@ async fn get_org_collections(org_id: OrganizationId, headers: ManagerHeadersLoos |
|
|
.filter(|collection| manageable.contains(&collection.uuid)) |
|
|
.filter(|collection| manageable.contains(&collection.uuid)) |
|
|
.map(Collection::to_json) |
|
|
.map(Collection::to_json) |
|
|
.collect::<Value>() |
|
|
.collect::<Value>() |
|
|
} else { |
|
|
|
|
|
err_code!("Resource not found.", "User does not have full access", Status::NotFound.code); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Ok(Json(json!({ |
|
|
Ok(Json(json!({ |
|
|
@ -408,18 +407,10 @@ async fn get_org_collections_details(org_id: OrganizationId, headers: ManagerHea |
|
|
|
|
|
|
|
|
// get all collection memberships for the current organization
|
|
|
// get all collection memberships for the current organization
|
|
|
let col_users = CollectionUser::find_by_organization_swap_user_uuid_with_member_uuid(&org_id, &conn).await; |
|
|
let col_users = CollectionUser::find_by_organization_swap_user_uuid_with_member_uuid(&org_id, &conn).await; |
|
|
// Generate a HashMap to get the correct MembershipType 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
|
|
|
// As in Bitwarden, a member who may not read the access of every collection only gets those they manage. Manage
|
|
|
// This lists other members for admins, so it must not depend on the membership status
|
|
|
// users and Manage groups may read collection access details without editing collection metadata.
|
|
|
let membership_type: HashMap<MembershipId, i32> = |
|
|
let manageable_collections = if !member.can_view_all_collection_access_details() |
|
|
Membership::find_by_org(&org_id, &conn).await.into_iter().map(|m| (m.uuid, m.atype)).collect(); |
|
|
|
|
|
|
|
|
|
|
|
// check if current user has full access to the organization (either directly or via any group)
|
|
|
|
|
|
let has_full_access_to_org = member.has_full_access() |
|
|
|
|
|
|| (CONFIG.org_groups_enabled() && GroupUser::has_full_access_by_member(&org_id, &member.uuid, &conn).await); |
|
|
|
|
|
// Manage users and Manage groups may read collection access details without editing collection metadata.
|
|
|
|
|
|
let custom_collections = if member.has_type(MembershipType::Custom) |
|
|
|
|
|
&& !member.can_view_all_collection_access_details() |
|
|
|
|
|
&& !member.has_custom_permission(CustomPermission::ManageGroups) |
|
|
&& !member.has_custom_permission(CustomPermission::ManageGroups) |
|
|
{ |
|
|
{ |
|
|
Some(Collection::find_explicitly_manageable_by_user(&org_id, &member.user_uuid, &conn).await) |
|
|
Some(Collection::find_explicitly_manageable_by_user(&org_id, &member.user_uuid, &conn).await) |
|
|
@ -427,68 +418,32 @@ async fn get_org_collections_details(org_id: OrganizationId, headers: ManagerHea |
|
|
None |
|
|
None |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// Get all admins, owners and managers who can manage/access all
|
|
|
|
|
|
// Those are currently not listed in the col_users but need to be listed too.
|
|
|
|
|
|
let manage_all_members: Vec<Value> = Membership::find_confirmed_and_manage_all_by_org(&org_id, &conn) |
|
|
|
|
|
.await |
|
|
|
|
|
.into_iter() |
|
|
|
|
|
.map(|member| { |
|
|
|
|
|
json!({ |
|
|
|
|
|
"id": member.uuid, |
|
|
|
|
|
"readOnly": false, |
|
|
|
|
|
"hidePasswords": false, |
|
|
|
|
|
"manage": true, |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
.collect(); |
|
|
|
|
|
|
|
|
|
|
|
let mut data = Vec::new(); |
|
|
let mut data = Vec::new(); |
|
|
for col in Collection::find_by_organization(&org_id, &conn).await { |
|
|
for col in Collection::find_by_organization(&org_id, &conn).await { |
|
|
// check whether the current user has access to the given collection
|
|
|
if manageable_collections.as_ref().is_some_and(|manageable| !manageable.contains(&col.uuid)) { |
|
|
let assigned = has_full_access_to_org |
|
|
|
|
|
|| CollectionUser::has_access_to_collection_by_user(&col.uuid, &member.user_uuid, &conn).await |
|
|
|
|
|
|| (CONFIG.org_groups_enabled() |
|
|
|
|
|
&& GroupUser::has_access_to_collection_by_member(&col.uuid, &member.uuid, &conn).await); |
|
|
|
|
|
|
|
|
|
|
|
// If the user is a manager, and is not assigned to this collection, skip this and continue with the next collection
|
|
|
|
|
|
let listed = if member.has_type(MembershipType::Custom) { |
|
|
|
|
|
custom_collections.as_ref().is_none_or(|manageable| manageable.contains(&col.uuid)) |
|
|
|
|
|
} else { |
|
|
|
|
|
assigned |
|
|
|
|
|
}; |
|
|
|
|
|
if !listed { |
|
|
|
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// get the users assigned directly to the given collection
|
|
|
// the members assigned directly to the given collection
|
|
|
let mut users: Vec<Value> = col_users |
|
|
let collection_members: Vec<&CollectionMembership> = |
|
|
.iter() |
|
|
col_users.iter().filter(|collection_member| collection_member.collection_uuid == col.uuid).collect(); |
|
|
.filter(|collection_member| collection_member.collection_uuid == col.uuid) |
|
|
let users: Vec<Value> = collection_members.iter().map(|cm| cm.to_json_details_for_member()).collect(); |
|
|
.map(|collection_member| { |
|
|
|
|
|
collection_member.to_json_details_for_member( |
|
|
|
|
|
*membership_type.get(&collection_member.membership_uuid).unwrap_or(&(MembershipType::User as i32)), |
|
|
|
|
|
) |
|
|
|
|
|
}) |
|
|
|
|
|
.collect(); |
|
|
|
|
|
users.extend_from_slice(&manage_all_members); |
|
|
|
|
|
|
|
|
|
|
|
// get the group details for the given collection
|
|
|
// the groups assigned to the given collection
|
|
|
let groups: Vec<Value> = if CONFIG.org_groups_enabled() { |
|
|
let collection_groups = if CONFIG.org_groups_enabled() { |
|
|
CollectionGroup::find_by_collection(&col.uuid, &conn) |
|
|
CollectionGroup::find_by_collection(&col.uuid, &conn).await |
|
|
.await |
|
|
|
|
|
.iter() |
|
|
|
|
|
.map(CollectionGroup::to_json_details_for_group) |
|
|
|
|
|
.collect() |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
Vec::new() |
|
|
Vec::new() |
|
|
}; |
|
|
}; |
|
|
|
|
|
let groups: Vec<Value> = collection_groups.iter().map(CollectionGroup::to_json_details_for_group).collect(); |
|
|
|
|
|
|
|
|
let mut json_object = col.to_json_details(&headers.user.uuid, None, &conn).await; |
|
|
let mut json_object = col.to_json_details(&headers.user.uuid, None, &conn).await; |
|
|
json_object["assigned"] = json!(assigned); |
|
|
// Like Bitwarden, whether the current user is assigned to it themselves, the role doesn't count
|
|
|
|
|
|
json_object["assigned"] = json!(Collection::is_assigned(&member, &col.uuid, &conn).await); |
|
|
json_object["users"] = json!(users); |
|
|
json_object["users"] = json!(users); |
|
|
json_object["groups"] = json!(groups); |
|
|
json_object["groups"] = json!(groups); |
|
|
json_object["object"] = json!("collectionAccessDetails"); |
|
|
json_object["object"] = json!("collectionAccessDetails"); |
|
|
json_object["unmanaged"] = json!(false); |
|
|
json_object["unmanaged"] = json!(is_unmanaged(&collection_members, &collection_groups)); |
|
|
data.push(json_object); |
|
|
data.push(json_object); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -499,6 +454,12 @@ async fn get_org_collections_details(org_id: OrganizationId, headers: ManagerHea |
|
|
}))) |
|
|
}))) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Whether no member and no group may manage a collection, given everyone assigned to it, like Bitwarden's `Unmanaged`.
|
|
|
|
|
|
/// The Admin Console offers to add access to such a collection.
|
|
|
|
|
|
fn is_unmanaged(members: &[&CollectionMembership], groups: &[CollectionGroup]) -> bool { |
|
|
|
|
|
!members.iter().any(|member| member.manage) && !groups.iter().any(|group| group.manage) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
async fn get_org_collections_impl(org_id: &OrganizationId, conn: &DbConn) -> Value { |
|
|
async fn get_org_collections_impl(org_id: &OrganizationId, conn: &DbConn) -> Value { |
|
|
Collection::find_by_organization(org_id, conn).await.iter().map(Collection::to_json).collect::<Value>() |
|
|
Collection::find_by_organization(org_id, conn).await.iter().map(Collection::to_json).collect::<Value>() |
|
|
} |
|
|
} |
|
|
@ -516,9 +477,9 @@ async fn post_organization_collections( |
|
|
let data: FullCollectionData = data.into_inner(); |
|
|
let data: FullCollectionData = data.into_inner(); |
|
|
data.validate(&org_id, &conn).await?; |
|
|
data.validate(&org_id, &conn).await?; |
|
|
|
|
|
|
|
|
if (headers.membership.atype == MembershipType::Manager && !headers.membership.access_all) |
|
|
// The clients are told collection creation is limited
|
|
|
|| (headers.membership.has_type(MembershipType::Custom) |
|
|
if !headers.membership.has_full_access() |
|
|
&& !headers.membership.has_custom_permission(CustomPermission::CreateNewCollections)) |
|
|
&& !headers.membership.has_custom_permission(CustomPermission::CreateNewCollections) |
|
|
{ |
|
|
{ |
|
|
err!("You don't have permission to create collections") |
|
|
err!("You don't have permission to create collections") |
|
|
} |
|
|
} |
|
|
@ -548,10 +509,6 @@ async fn post_organization_collections( |
|
|
err!("User is not part of organization") |
|
|
err!("User is not part of organization") |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if member.access_all { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CollectionUser::save( |
|
|
CollectionUser::save( |
|
|
&member.user_uuid, |
|
|
&member.user_uuid, |
|
|
&collection.uuid, |
|
|
&collection.uuid, |
|
|
@ -604,13 +561,9 @@ async fn post_bulk_access_collections( |
|
|
err_code!("One or more collections not found.", Status::NotFound.code) |
|
|
err_code!("One or more collections not found.", Status::NotFound.code) |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
let manageable = if headers.membership.has_type(MembershipType::Custom) { |
|
|
let manageable = member_may(CollectionAction::Edit, &headers.membership, &collection.uuid, &conn).await |
|
|
custom_member_may(CollectionAction::Edit, &headers.membership, &collection.uuid, &conn).await |
|
|
|| (headers.membership.has_custom_permission(CustomPermission::ManageUsers) |
|
|
|| (headers.membership.has_custom_permission(CustomPermission::ManageUsers) |
|
|
&& headers.membership.has_custom_permission(CustomPermission::ManageGroups)); |
|
|
&& headers.membership.has_custom_permission(CustomPermission::ManageGroups)) |
|
|
|
|
|
} else { |
|
|
|
|
|
collection.is_manageable_by_user(&headers.membership.user_uuid, &conn).await |
|
|
|
|
|
}; |
|
|
|
|
|
if !manageable { |
|
|
if !manageable { |
|
|
err_code!( |
|
|
err_code!( |
|
|
"Resource not found.", |
|
|
"Resource not found.", |
|
|
@ -659,10 +612,6 @@ async fn post_bulk_access_collections( |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (user, member) in data.users.iter().zip(&members) { |
|
|
for (user, member) in data.users.iter().zip(&members) { |
|
|
if member.access_all { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CollectionUser::save(&member.user_uuid, &col_id, user.read_only, user.hide_passwords, user.manage, &conn) |
|
|
CollectionUser::save(&member.user_uuid, &col_id, user.read_only, user.hide_passwords, user.manage, &conn) |
|
|
.await?; |
|
|
.await?; |
|
|
} |
|
|
} |
|
|
@ -727,10 +676,6 @@ async fn put_organization_collection_update( |
|
|
err!("User is not part of organization") |
|
|
err!("User is not part of organization") |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if member.access_all { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CollectionUser::save(&member.user_uuid, &col_id, user.read_only, user.hide_passwords, user.manage, &conn) |
|
|
CollectionUser::save(&member.user_uuid, &col_id, user.read_only, user.hide_passwords, user.manage, &conn) |
|
|
.await?; |
|
|
.await?; |
|
|
} |
|
|
} |
|
|
@ -827,44 +772,31 @@ async fn get_org_collection_detail( |
|
|
err!("Collection is not owned by organization") |
|
|
err!("Collection is not owned by organization") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
let groups: Vec<Value> = if CONFIG.org_groups_enabled() { |
|
|
// The Bitwarden clients seem to call this API regardless of whether groups are enabled,
|
|
|
CollectionGroup::find_by_collection(&collection.uuid, &conn) |
|
|
// so just act as if there are no groups.
|
|
|
.await |
|
|
let collection_groups = if CONFIG.org_groups_enabled() { |
|
|
.iter() |
|
|
CollectionGroup::find_by_collection(&collection.uuid, &conn).await |
|
|
.map(CollectionGroup::to_json_details_for_group) |
|
|
|
|
|
.collect() |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// The Bitwarden clients seem to call this API regardless of whether groups are enabled,
|
|
|
|
|
|
// so just act as if there are no groups.
|
|
|
|
|
|
Vec::new() |
|
|
Vec::new() |
|
|
}; |
|
|
}; |
|
|
|
|
|
let groups: Vec<Value> = collection_groups.iter().map(CollectionGroup::to_json_details_for_group).collect(); |
|
|
|
|
|
|
|
|
// Generate a HashMap to get the correct MembershipType per user to determine the manage permission
|
|
|
let collection_members = |
|
|
// We use the uuid instead of the user_uuid here, since that is what is used in CollectionUser
|
|
|
|
|
|
// This lists other members for admins, so it must not depend on the membership status
|
|
|
|
|
|
let membership_type: HashMap<MembershipId, i32> = |
|
|
|
|
|
Membership::find_by_org(&org_id, &conn).await.into_iter().map(|m| (m.uuid, m.atype)).collect(); |
|
|
|
|
|
|
|
|
|
|
|
let users: Vec<Value> = |
|
|
|
|
|
CollectionUser::find_by_org_and_coll_swap_user_uuid_with_member_uuid(&org_id, &collection.uuid, &conn) |
|
|
CollectionUser::find_by_org_and_coll_swap_user_uuid_with_member_uuid(&org_id, &collection.uuid, &conn) |
|
|
.await |
|
|
.await; |
|
|
.iter() |
|
|
let users: Vec<Value> = |
|
|
.map(|collection_member| { |
|
|
collection_members.iter().map(CollectionMembership::to_json_details_for_member).collect(); |
|
|
collection_member.to_json_details_for_member( |
|
|
|
|
|
*membership_type |
|
|
// Like Bitwarden, whether the current user is assigned to it themselves, the role doesn't count
|
|
|
.get(&collection_member.membership_uuid) |
|
|
let assigned = Collection::is_assigned(&member, &collection.uuid, &conn).await; |
|
|
.unwrap_or(&(MembershipType::User as i32)), |
|
|
let unmanaged = is_unmanaged(&collection_members.iter().collect::<Vec<_>>(), &collection_groups); |
|
|
) |
|
|
|
|
|
}) |
|
|
|
|
|
.collect(); |
|
|
|
|
|
|
|
|
|
|
|
let assigned = Collection::can_access_collection(&member, &collection.uuid, &conn).await; |
|
|
|
|
|
|
|
|
|
|
|
let mut json_object = collection.to_json_details(&headers.user.uuid, None, &conn).await; |
|
|
let mut json_object = collection.to_json_details(&headers.user.uuid, None, &conn).await; |
|
|
json_object["assigned"] = json!(assigned); |
|
|
json_object["assigned"] = json!(assigned); |
|
|
json_object["users"] = json!(users); |
|
|
json_object["users"] = json!(users); |
|
|
json_object["groups"] = json!(groups); |
|
|
json_object["groups"] = json!(groups); |
|
|
json_object["object"] = json!("collectionAccessDetails"); |
|
|
json_object["object"] = json!("collectionAccessDetails"); |
|
|
|
|
|
json_object["unmanaged"] = json!(unmanaged); |
|
|
|
|
|
|
|
|
Ok(Json(json_object)) |
|
|
Ok(Json(json_object)) |
|
|
} |
|
|
} |
|
|
@ -1025,7 +957,6 @@ async fn get_members( |
|
|
if recovery_only && (!u.has_status(MembershipStatus::Confirmed) || u.reset_password_key.is_none()) { |
|
|
if recovery_only && (!u.has_status(MembershipStatus::Confirmed) || u.reset_password_key.is_none()) { |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
// The user can be a manager instead of an admin, but we've checked above that they have full access
|
|
|
|
|
|
users_json.push( |
|
|
users_json.push( |
|
|
u.to_json_details_for_admin( |
|
|
u.to_json_details_for_admin( |
|
|
data.include_collections.unwrap_or(false), |
|
|
data.include_collections.unwrap_or(false), |
|
|
@ -1174,19 +1105,16 @@ async fn send_invite( |
|
|
let data: InviteData = data.into_inner(); |
|
|
let data: InviteData = data.into_inner(); |
|
|
data.validate(&org_id, &conn).await?; |
|
|
data.validate(&org_id, &conn).await?; |
|
|
|
|
|
|
|
|
// HACK: We need the raw user-type to be sure custom role is selected to determine the access_all permission
|
|
|
let Some(new_type) = MembershipType::from_str(&data.r#type.into_string()) else { |
|
|
// Unless Custom roles are enabled, a custom role (4) is converted to a manager role (3)
|
|
|
|
|
|
let raw_type = &data.r#type.into_string(); |
|
|
|
|
|
let Some(requested_type) = MembershipType::from_str(raw_type) else { |
|
|
|
|
|
err!("Invalid type") |
|
|
err!("Invalid type") |
|
|
}; |
|
|
}; |
|
|
|
|
|
MembershipType::check_requested(new_type, None)?; |
|
|
// Checked before anything is created, so a rejected permission leaves nothing behind
|
|
|
// Checked before anything is created, so a rejected permission leaves nothing behind
|
|
|
let custom_permissions = if requested_type == MembershipType::Custom && custom_roles_enabled() { |
|
|
let custom_permissions = if new_type == MembershipType::Custom { |
|
|
Some(CustomPermission::requested(&data.permissions)?) |
|
|
Some(CustomPermission::requested(&data.permissions)?) |
|
|
} else { |
|
|
} else { |
|
|
None |
|
|
None |
|
|
}; |
|
|
}; |
|
|
let new_type = MembershipType::requested(requested_type, None, custom_permissions.as_ref()); |
|
|
|
|
|
|
|
|
|
|
|
check_role_manageable(headers.membership_type, new_type as i32)?; |
|
|
check_role_manageable(headers.membership_type, new_type as i32)?; |
|
|
if headers.membership_type == MembershipType::Custom { |
|
|
if headers.membership_type == MembershipType::Custom { |
|
|
@ -1196,16 +1124,6 @@ async fn send_invite( |
|
|
.await?; |
|
|
.await?; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 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 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
|
|
|
|
|
|
let access_all = new_type >= MembershipType::Admin |
|
|
|
|
|
|| (new_type == MembershipType::Manager |
|
|
|
|
|
&& raw_type.eq("4") |
|
|
|
|
|
&& data.permissions.get("editAnyCollection") == Some(&json!(true)) |
|
|
|
|
|
&& data.permissions.get("deleteAnyCollection") == Some(&json!(true)) |
|
|
|
|
|
&& data.permissions.get("createNewCollections") == Some(&json!(true))); |
|
|
|
|
|
|
|
|
|
|
|
let mut user_created: bool; |
|
|
let mut user_created: bool; |
|
|
for email in &data.emails { |
|
|
for email in &data.emails { |
|
|
let mut member_status = MembershipStatus::Invited as i32; |
|
|
let mut member_status = MembershipStatus::Invited as i32; |
|
|
@ -1248,7 +1166,6 @@ async fn send_invite( |
|
|
|
|
|
|
|
|
let mut new_member = Membership::new(user.uuid.clone(), org_id.clone(), Some(headers.user.email.clone())); |
|
|
let mut new_member = Membership::new(user.uuid.clone(), org_id.clone(), Some(headers.user.email.clone())); |
|
|
new_member.set_type(new_type); |
|
|
new_member.set_type(new_type); |
|
|
new_member.access_all = access_all; |
|
|
|
|
|
if let Some(permissions) = &custom_permissions { |
|
|
if let Some(permissions) = &custom_permissions { |
|
|
new_member.set_custom_permissions(permissions); |
|
|
new_member.set_custom_permissions(permissions); |
|
|
} |
|
|
} |
|
|
@ -1293,22 +1210,19 @@ async fn send_invite( |
|
|
) |
|
|
) |
|
|
.await; |
|
|
.await; |
|
|
|
|
|
|
|
|
// If no accessAll, add the collections received
|
|
|
for col in data.collections.iter().flatten() { |
|
|
if !access_all { |
|
|
match Collection::find_by_uuid_and_org(&col.id, &org_id, &conn).await { |
|
|
for col in data.collections.iter().flatten() { |
|
|
None => err!("Collection not found in Organization"), |
|
|
match Collection::find_by_uuid_and_org(&col.id, &org_id, &conn).await { |
|
|
Some(collection) => { |
|
|
None => err!("Collection not found in Organization"), |
|
|
CollectionUser::save( |
|
|
Some(collection) => { |
|
|
&user.uuid, |
|
|
CollectionUser::save( |
|
|
&collection.uuid, |
|
|
&user.uuid, |
|
|
col.read_only, |
|
|
&collection.uuid, |
|
|
col.hide_passwords, |
|
|
col.read_only, |
|
|
col.manage, |
|
|
col.hide_passwords, |
|
|
&conn, |
|
|
col.manage, |
|
|
) |
|
|
&conn, |
|
|
.await?; |
|
|
) |
|
|
|
|
|
.await?; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -1626,8 +1540,8 @@ async fn get_org_user_mini_details(org_id: OrganizationId, headers: ManagerHeade |
|
|
if org_id != headers.membership.org_uuid { |
|
|
if org_id != headers.membership.org_uuid { |
|
|
err!("Organization not found", "Organization id's do not match"); |
|
|
err!("Organization not found", "Organization id's do not match"); |
|
|
} |
|
|
} |
|
|
// A Custom member may also need basic member details for event logs or reports.
|
|
|
// Besides those assigning collection access, a Custom member may need basic member details for event logs or reports.
|
|
|
if headers.membership.has_type(MembershipType::Custom) |
|
|
if !headers.membership.has_full_access() |
|
|
&& !headers.membership.has_custom_permission(CustomPermission::AccessEventLogs) |
|
|
&& !headers.membership.has_custom_permission(CustomPermission::AccessEventLogs) |
|
|
&& !headers.membership.has_custom_permission(CustomPermission::AccessReports) |
|
|
&& !headers.membership.has_custom_permission(CustomPermission::AccessReports) |
|
|
&& !may_assign_collection_access(&headers.membership, &conn).await |
|
|
&& !may_assign_collection_access(&headers.membership, &conn).await |
|
|
@ -1692,40 +1606,20 @@ async fn edit_member( |
|
|
} |
|
|
} |
|
|
let data: EditUserData = data.into_inner(); |
|
|
let data: EditUserData = data.into_inner(); |
|
|
|
|
|
|
|
|
// HACK: We need the raw user-type to be sure custom role is selected to determine the access_all permission
|
|
|
let Some(new_type) = MembershipType::from_str(&data.r#type.into_string()) else { |
|
|
// Unless Custom roles are enabled, a custom role (4) is converted to a manager role (3)
|
|
|
|
|
|
let raw_type = &data.r#type.into_string(); |
|
|
|
|
|
let Some(requested_type) = MembershipType::from_str(raw_type) else { |
|
|
|
|
|
err!("Invalid type") |
|
|
err!("Invalid type") |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
let Some(mut member_to_edit) = Membership::find_by_uuid_and_org(&member_id, &org_id, &conn).await else { |
|
|
let Some(mut member_to_edit) = Membership::find_by_uuid_and_org(&member_id, &org_id, &conn).await else { |
|
|
err!("The specified user isn't member of the organization") |
|
|
err!("The specified user isn't member of the organization") |
|
|
}; |
|
|
}; |
|
|
|
|
|
MembershipType::check_requested(new_type, Some(&member_to_edit))?; |
|
|
// While Custom roles are disabled, a Custom member keeps their stored permissions untouched
|
|
|
// While Custom roles are disabled, a Custom member keeps their stored permissions untouched
|
|
|
let custom_permissions = if requested_type == MembershipType::Custom && custom_roles_enabled() { |
|
|
let custom_permissions = if new_type == MembershipType::Custom && custom_roles_enabled() { |
|
|
Some(CustomPermission::requested(&data.permissions)?) |
|
|
Some(CustomPermission::requested(&data.permissions)?) |
|
|
} else { |
|
|
} else { |
|
|
None |
|
|
None |
|
|
}; |
|
|
}; |
|
|
let new_type = MembershipType::requested(requested_type, Some(&member_to_edit), custom_permissions.as_ref()); |
|
|
|
|
|
// A Manager whose permissions are changed only becomes a Custom member if that keeps what they may do
|
|
|
|
|
|
if new_type == MembershipType::Custom |
|
|
|
|
|
&& let Some(permissions) = &custom_permissions |
|
|
|
|
|
&& let Some(loss) = member_to_edit.custom_role_conversion_loss(permissions, &conn).await |
|
|
|
|
|
{ |
|
|
|
|
|
err!(loss) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 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 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
|
|
|
|
|
|
let access_all = new_type >= MembershipType::Admin |
|
|
|
|
|
|| (new_type == MembershipType::Manager |
|
|
|
|
|
&& raw_type.eq("4") |
|
|
|
|
|
&& data.permissions.get("editAnyCollection") == Some(&json!(true)) |
|
|
|
|
|
&& data.permissions.get("deleteAnyCollection") == Some(&json!(true)) |
|
|
|
|
|
&& data.permissions.get("createNewCollections") == Some(&json!(true))); |
|
|
|
|
|
|
|
|
|
|
|
// Both the current and the requested role must be one the caller may manage
|
|
|
// Both the current and the requested role must be one the caller may manage
|
|
|
check_role_manageable(headers.membership_type, member_to_edit.atype)?; |
|
|
check_role_manageable(headers.membership_type, member_to_edit.atype)?; |
|
|
@ -1757,7 +1651,6 @@ async fn edit_member( |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
member_to_edit.set_type(new_type); |
|
|
member_to_edit.set_type(new_type); |
|
|
member_to_edit.access_all = access_all; |
|
|
|
|
|
if let Some(permissions) = custom_permissions.as_ref().filter(|_| new_type == MembershipType::Custom) { |
|
|
if let Some(permissions) = custom_permissions.as_ref().filter(|_| new_type == MembershipType::Custom) { |
|
|
member_to_edit.set_custom_permissions(permissions); |
|
|
member_to_edit.set_custom_permissions(permissions); |
|
|
} |
|
|
} |
|
|
@ -1771,22 +1664,19 @@ async fn edit_member( |
|
|
c.delete(&conn).await?; |
|
|
c.delete(&conn).await?; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// If no accessAll, add the collections received
|
|
|
for col in data.collections.iter().flatten() { |
|
|
if !access_all { |
|
|
match Collection::find_by_uuid_and_org(&col.id, &org_id, &conn).await { |
|
|
for col in data.collections.iter().flatten() { |
|
|
None => err!("Collection not found in Organization"), |
|
|
match Collection::find_by_uuid_and_org(&col.id, &org_id, &conn).await { |
|
|
Some(collection) => { |
|
|
None => err!("Collection not found in Organization"), |
|
|
CollectionUser::save( |
|
|
Some(collection) => { |
|
|
&member_to_edit.user_uuid, |
|
|
CollectionUser::save( |
|
|
&collection.uuid, |
|
|
&member_to_edit.user_uuid, |
|
|
col.read_only, |
|
|
&collection.uuid, |
|
|
col.hide_passwords, |
|
|
col.read_only, |
|
|
col.manage, |
|
|
col.hide_passwords, |
|
|
&conn, |
|
|
col.manage, |
|
|
) |
|
|
&conn, |
|
|
.await?; |
|
|
) |
|
|
|
|
|
.await?; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -2014,10 +1904,7 @@ async fn validate_org_import_collections( |
|
|
) -> ApiResult<HashMap<CollectionId, Collection>> { |
|
|
) -> ApiResult<HashMap<CollectionId, Collection>> { |
|
|
let existing: HashMap<CollectionId, Collection> = |
|
|
let existing: HashMap<CollectionId, Collection> = |
|
|
Collection::find_by_organization(org_id, conn).await.into_iter().map(|c| (c.uuid.clone(), c)).collect(); |
|
|
Collection::find_by_organization(org_id, conn).await.into_iter().map(|c| (c.uuid.clone(), c)).collect(); |
|
|
let manageable = if membership.atype < MembershipType::Admin |
|
|
let manageable = if membership.atype < MembershipType::Admin && !membership.can_edit_any_collection() { |
|
|
&& !membership.can_edit_any_collection() |
|
|
|
|
|
&& !membership.has_type(MembershipType::Manager) |
|
|
|
|
|
{ |
|
|
|
|
|
Some( |
|
|
Some( |
|
|
Collection::find_explicitly_manageable_by_user(org_id, &membership.user_uuid, conn) |
|
|
Collection::find_explicitly_manageable_by_user(org_id, &membership.user_uuid, conn) |
|
|
.await |
|
|
.await |
|
|
@ -2029,18 +1916,12 @@ async fn validate_org_import_collections( |
|
|
}; |
|
|
}; |
|
|
for col in imported { |
|
|
for col in imported { |
|
|
if let Some(collection) = col.id.as_ref().and_then(|id| existing.get(id)) { |
|
|
if let Some(collection) = col.id.as_ref().and_then(|id| existing.get(id)) { |
|
|
if membership.atype < MembershipType::Admin && !membership.can_edit_any_collection() { |
|
|
if let Some(manageable) = &manageable |
|
|
let can_import = if let Some(manageable) = &manageable { |
|
|
&& !manageable.contains(&collection.uuid) |
|
|
manageable.contains(&collection.uuid) |
|
|
{ |
|
|
} else { |
|
|
err!(Compact, "The current user isn't allowed to manage this collection") |
|
|
collection.is_writable_by_user(&membership.user_uuid, conn).await |
|
|
|
|
|
}; |
|
|
|
|
|
if !can_import { |
|
|
|
|
|
err!(Compact, "The current user isn't allowed to manage this collection") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} else if membership.atype <= MembershipType::Manager |
|
|
} else if !membership.has_full_access() |
|
|
&& !membership.has_full_access() |
|
|
|
|
|
&& !membership.has_custom_permission(CustomPermission::CreateNewCollections) |
|
|
&& !membership.has_custom_permission(CustomPermission::CreateNewCollections) |
|
|
&& !import_export |
|
|
&& !import_export |
|
|
{ |
|
|
{ |
|
|
@ -2083,7 +1964,6 @@ async fn post_org_import( |
|
|
collections: imported_collections, |
|
|
collections: imported_collections, |
|
|
.. |
|
|
.. |
|
|
} = data; |
|
|
} = data; |
|
|
let grant_new_collection_manage = headers.membership.has_type(MembershipType::Custom); |
|
|
|
|
|
let importer_uuid = headers.membership.user_uuid.clone(); |
|
|
let importer_uuid = headers.membership.user_uuid.clone(); |
|
|
let OrgMemberHeaders { |
|
|
let OrgMemberHeaders { |
|
|
host, |
|
|
host, |
|
|
@ -2111,9 +1991,8 @@ async fn post_org_import( |
|
|
} else { |
|
|
} else { |
|
|
let new_collection = Collection::new(org_id.clone(), col.name, col.external_id); |
|
|
let new_collection = Collection::new(org_id.clone(), col.name, col.external_id); |
|
|
new_collection.save(&conn).await?; |
|
|
new_collection.save(&conn).await?; |
|
|
if grant_new_collection_manage { |
|
|
// Like upstream, the importer manages the collections they create
|
|
|
CollectionUser::save(&importer_uuid, &new_collection.uuid, false, false, true, &conn).await?; |
|
|
CollectionUser::save(&importer_uuid, &new_collection.uuid, false, false, true, &conn).await?; |
|
|
} |
|
|
|
|
|
new_collection.uuid |
|
|
new_collection.uuid |
|
|
}; |
|
|
}; |
|
|
collections.push(collection_uuid); |
|
|
collections.push(collection_uuid); |
|
|
@ -2170,7 +2049,7 @@ mod org_import_tests { |
|
|
("admin", MembershipType::Admin, CustomPermission::CreateNewCollections), |
|
|
("admin", MembershipType::Admin, CustomPermission::CreateNewCollections), |
|
|
("cipher", MembershipType::Custom, CustomPermission::CreateNewCollections), |
|
|
("cipher", MembershipType::Custom, CustomPermission::CreateNewCollections), |
|
|
("custom", MembershipType::Custom, CustomPermission::CreateNewCollections), |
|
|
("custom", MembershipType::Custom, CustomPermission::CreateNewCollections), |
|
|
("legacy", MembershipType::Manager, CustomPermission::CreateNewCollections), |
|
|
("user", MembershipType::User, CustomPermission::CreateNewCollections), |
|
|
("authorization", MembershipType::Custom, CustomPermission::CreateNewCollections), |
|
|
("authorization", MembershipType::Custom, CustomPermission::CreateNewCollections), |
|
|
("rollback", MembershipType::Custom, CustomPermission::CreateNewCollections), |
|
|
("rollback", MembershipType::Custom, CustomPermission::CreateNewCollections), |
|
|
("index", MembershipType::Custom, CustomPermission::CreateNewCollections), |
|
|
("index", MembershipType::Custom, CustomPermission::CreateNewCollections), |
|
|
@ -2185,9 +2064,7 @@ mod org_import_tests { |
|
|
} else { |
|
|
} else { |
|
|
vec![] |
|
|
vec![] |
|
|
}; |
|
|
}; |
|
|
let (user, mut membership) = test_db::member(&conn, &org.uuid, role, &permissions).await; |
|
|
let (user, membership) = test_db::member(&conn, &org.uuid, role, &permissions).await; |
|
|
membership.access_all = role == MembershipType::Manager; |
|
|
|
|
|
membership.save(&conn).await.unwrap(); |
|
|
|
|
|
let mut payload = json!({"ciphers":[{"name":"Cipher","type":2,"encryptedFor":user.uuid,"secureNote":{"type":0}}], |
|
|
let mut payload = json!({"ciphers":[{"name":"Cipher","type":2,"encryptedFor":user.uuid,"secureNote":{"type":0}}], |
|
|
"collections":[{"name":"New"}],"collectionRelationships":[{"key":0,"value":0}]}); |
|
|
"collections":[{"name":"New"}],"collectionRelationships":[{"key":0,"value":0}]}); |
|
|
match case { |
|
|
match case { |
|
|
@ -2227,17 +2104,14 @@ mod org_import_tests { |
|
|
) |
|
|
) |
|
|
.await; |
|
|
.await; |
|
|
conn.run(|c| c.batch_execute("DROP TRIGGER IF EXISTS reject_link")).await.unwrap(); |
|
|
conn.run(|c| c.batch_execute("DROP TRIGGER IF EXISTS reject_link")).await.unwrap(); |
|
|
let success = matches!(case, "owner" | "admin" | "custom" | "legacy" | "export"); |
|
|
let success = matches!(case, "owner" | "admin" | "custom" | "export"); |
|
|
assert_eq!(result.is_ok(), success, "{case}"); |
|
|
assert_eq!(result.is_ok(), success, "{case}"); |
|
|
assert_eq!( |
|
|
assert_eq!( |
|
|
Collection::find_by_organization(&org.uuid, &conn).await.len(), |
|
|
Collection::find_by_organization(&org.uuid, &conn).await.len(), |
|
|
usize::from(success || case == "authorization") |
|
|
usize::from(success || case == "authorization") |
|
|
); |
|
|
); |
|
|
assert_eq!(Cipher::find_by_org(&org.uuid, &conn).await.len(), usize::from(success)); |
|
|
assert_eq!(Cipher::find_by_org(&org.uuid, &conn).await.len(), usize::from(success)); |
|
|
assert_eq!( |
|
|
assert_eq!(CollectionUser::find_by_user(&user_id, &conn).await.len(), usize::from(success)); |
|
|
CollectionUser::find_by_user(&user_id, &conn).await.len(), |
|
|
|
|
|
usize::from(success && role == MembershipType::Custom) |
|
|
|
|
|
); |
|
|
|
|
|
assert_eq!( |
|
|
assert_eq!( |
|
|
Cipher::get_collections_with_cipher_by_organization(&org.uuid, &conn).await.len(), |
|
|
Cipher::get_collections_with_cipher_by_organization(&org.uuid, &conn).await.len(), |
|
|
usize::from(success && case != "export") |
|
|
usize::from(success && case != "export") |
|
|
@ -2883,13 +2757,9 @@ async fn get_groups_data( |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// The details view (group→collection/user mappings) needs full org access; the plain list only
|
|
|
// The details view (group→collection/user mappings) needs full org access; the plain list only
|
|
|
// needs manage access to a collection, so a manager of a collection (directly or via a group)
|
|
|
// needs manage access to a collection, so a member who manages one (directly or via a group)
|
|
|
// can load it to assign groups.
|
|
|
// can load it to assign groups.
|
|
|
// A group with access to all collections gives a Custom member access to them, but not to the Admin Console.
|
|
|
let has_full_access = headers.membership.has_full_access(); |
|
|
let has_full_access = headers.membership.has_full_access() |
|
|
|
|
|
|| (CONFIG.org_groups_enabled() |
|
|
|
|
|
&& !headers.membership.has_type(MembershipType::Custom) |
|
|
|
|
|
&& GroupUser::has_full_access_by_member(&org_id, &headers.membership.uuid, &conn).await); |
|
|
|
|
|
let allowed = if details { |
|
|
let allowed = if details { |
|
|
has_full_access |
|
|
has_full_access |
|
|
|| headers.membership.has_custom_permission(CustomPermission::ManageUsers) |
|
|
|| headers.membership.has_custom_permission(CustomPermission::ManageUsers) |
|
|
@ -2954,7 +2824,6 @@ async fn get_groups_details(org_id: OrganizationId, headers: ManagerHeadersLoose |
|
|
#[serde(rename_all = "camelCase")] |
|
|
#[serde(rename_all = "camelCase")] |
|
|
struct GroupRequest { |
|
|
struct GroupRequest { |
|
|
name: String, |
|
|
name: String, |
|
|
access_all: Option<bool>, |
|
|
|
|
|
external_id: Option<String>, |
|
|
external_id: Option<String>, |
|
|
collections: Vec<CollectionData>, |
|
|
collections: Vec<CollectionData>, |
|
|
users: Vec<MembershipId>, |
|
|
users: Vec<MembershipId>, |
|
|
@ -2962,14 +2831,11 @@ struct GroupRequest { |
|
|
|
|
|
|
|
|
impl GroupRequest { |
|
|
impl GroupRequest { |
|
|
pub fn to_group(&self, org_uuid: &OrganizationId) -> Group { |
|
|
pub fn to_group(&self, org_uuid: &OrganizationId) -> Group { |
|
|
Group::new(org_uuid.clone(), self.name.clone(), self.access_all.unwrap_or(false), self.external_id.clone()) |
|
|
Group::new(org_uuid.clone(), self.name.clone(), self.external_id.clone()) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn update_group(&self, mut group: Group) -> Group { |
|
|
pub fn update_group(&self, mut group: Group) -> Group { |
|
|
group.name.clone_from(&self.name); |
|
|
group.name.clone_from(&self.name); |
|
|
if let Some(access_all) = self.access_all { |
|
|
|
|
|
group.access_all = access_all; |
|
|
|
|
|
} |
|
|
|
|
|
// Group Updates do not support changing the external_id
|
|
|
// Group Updates do not support changing the external_id
|
|
|
// These input fields are in a disabled state, and can only be updated/added via ldap_import
|
|
|
// These input fields are in a disabled state, and can only be updated/added via ldap_import
|
|
|
|
|
|
|
|
|
@ -3856,6 +3722,25 @@ mod tests { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
fn collections_no_member_or_group_manages_are_unmanaged() { |
|
|
|
|
|
let member = |manage| CollectionMembership { |
|
|
|
|
|
membership_uuid: String::from("member").into(), |
|
|
|
|
|
collection_uuid: String::from("collection").into(), |
|
|
|
|
|
read_only: false, |
|
|
|
|
|
hide_passwords: false, |
|
|
|
|
|
manage, |
|
|
|
|
|
}; |
|
|
|
|
|
let group = |manage| { |
|
|
|
|
|
CollectionGroup::new(String::from("collection").into(), String::from("group").into(), false, false, manage) |
|
|
|
|
|
}; |
|
|
|
|
|
let (editor, manager) = (member(false), member(true)); |
|
|
|
|
|
assert!(is_unmanaged(&[], &[])); |
|
|
|
|
|
assert!(is_unmanaged(&[&editor], &[group(false)])); |
|
|
|
|
|
assert!(!is_unmanaged(&[&editor, &manager], &[group(false)])); |
|
|
|
|
|
assert!(!is_unmanaged(&[&editor], &[group(false), group(true)])); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
#[cfg(sqlite)] |
|
|
#[cfg(sqlite)] |
|
|
#[test] |
|
|
#[test] |
|
|
fn manage_users_grants_are_confined_to_permission_and_organization() { |
|
|
fn manage_users_grants_are_confined_to_permission_and_organization() { |
|
|
@ -3865,7 +3750,7 @@ mod tests { |
|
|
let foreign = test_db::organization(&conn).await; |
|
|
let foreign = test_db::organization(&conn).await; |
|
|
for org_id in [&org.uuid, &foreign.uuid] { |
|
|
for org_id in [&org.uuid, &foreign.uuid] { |
|
|
let collection = test_db::collection(&conn, org_id).await; |
|
|
let collection = test_db::collection(&conn, org_id).await; |
|
|
let mut group = Group::new(org_id.clone(), "Group".into(), true, None); |
|
|
let mut group = Group::new(org_id.clone(), "Group".into(), None); |
|
|
group.save(&conn).await.unwrap(); |
|
|
group.save(&conn).await.unwrap(); |
|
|
let empty = HashSet::new(); |
|
|
let empty = HashSet::new(); |
|
|
for (collections, groups) in [ |
|
|
for (collections, groups) in [ |
|
|
@ -3873,7 +3758,6 @@ mod tests { |
|
|
(&[][..], HashSet::from([group.uuid.clone()])), |
|
|
(&[][..], HashSet::from([group.uuid.clone()])), |
|
|
(&[&collection.uuid][..], HashSet::from([group.uuid])), |
|
|
(&[&collection.uuid][..], HashSet::from([group.uuid])), |
|
|
] { |
|
|
] { |
|
|
// A group with access to all collections may be given as well, as in Bitwarden
|
|
|
|
|
|
assert_eq!( |
|
|
assert_eq!( |
|
|
check_custom_member_grants(&member, None, collections, &groups, &conn).await.is_ok(), |
|
|
check_custom_member_grants(&member, None, collections, &groups, &conn).await.is_ok(), |
|
|
org_id == &org.uuid |
|
|
org_id == &org.uuid |
|
|
@ -3881,18 +3765,18 @@ mod tests { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
let collection = test_db::collection(&conn, &org.uuid).await; |
|
|
let collection = test_db::collection(&conn, &org.uuid).await; |
|
|
assert!(!Collection::can_access_collection(&member, &collection.uuid, &conn).await); |
|
|
assert!(!Collection::is_assigned(&member, &collection.uuid, &conn).await); |
|
|
let escalated = HashSet::from([CustomPermission::EditAnyCollection]); |
|
|
let escalated = HashSet::from([CustomPermission::EditAnyCollection]); |
|
|
let empty = HashSet::new(); |
|
|
let empty = HashSet::new(); |
|
|
for (enabled, status) in [(true, 2), (true, 1), (true, -126), (false, 2)] { |
|
|
for (enabled, status) in [(true, 2), (true, 1), (true, -126), (false, 2)] { |
|
|
test_flag::CUSTOM_ROLES_ENABLED.set(Some(enabled)); |
|
|
test_flag::CUSTOM_ROLES_ENABLED.set(Some(enabled)); |
|
|
member.status = status; |
|
|
member.status = status; |
|
|
assert_eq!( |
|
|
assert_eq!( |
|
|
custom_member_may(CollectionAction::Read, &member, &collection.uuid, &conn).await, |
|
|
member_may(CollectionAction::Read, &member, &collection.uuid, &conn).await, |
|
|
enabled && status == 2 |
|
|
enabled && status == 2 |
|
|
); |
|
|
); |
|
|
assert!(!custom_member_may(CollectionAction::Edit, &member, &collection.uuid, &conn).await); |
|
|
assert!(!member_may(CollectionAction::Edit, &member, &collection.uuid, &conn).await); |
|
|
assert!(!custom_member_may(CollectionAction::ReadAccess, &member, &collection.uuid, &conn).await); |
|
|
assert!(!member_may(CollectionAction::ReadAccess, &member, &collection.uuid, &conn).await); |
|
|
assert_eq!( |
|
|
assert_eq!( |
|
|
check_custom_member_grants(&member, None, &[], &empty, &conn).await.is_ok(), |
|
|
check_custom_member_grants(&member, None, &[], &empty, &conn).await.is_ok(), |
|
|
enabled && status == 2 |
|
|
enabled && status == 2 |
|
|
@ -3947,7 +3831,7 @@ mod tests { |
|
|
} |
|
|
} |
|
|
#[cfg(sqlite)] |
|
|
#[cfg(sqlite)] |
|
|
#[test] |
|
|
#[test] |
|
|
fn group_requests_stay_in_their_organization_and_keep_access_all() { |
|
|
fn group_requests_stay_in_their_organization() { |
|
|
test_db::run(async |db| { |
|
|
test_db::run(async |db| { |
|
|
let conn = db.conn(); |
|
|
let conn = db.conn(); |
|
|
let (org, _, member) = test_db::custom_member(&conn, CustomPermission::ManageGroups).await; |
|
|
let (org, _, member) = test_db::custom_member(&conn, CustomPermission::ManageGroups).await; |
|
|
@ -3958,13 +3842,9 @@ mod tests { |
|
|
{"id":collection.uuid,"readOnly":false,"hidePasswords":false,"manage":true}],"users":[]})) |
|
|
{"id":collection.uuid,"readOnly":false,"hidePasswords":false,"manage":true}],"users":[]})) |
|
|
.unwrap(); |
|
|
.unwrap(); |
|
|
assert_eq!(request.validate(&org.uuid, &conn).await.is_ok(), org_id == &org.uuid); |
|
|
assert_eq!(request.validate(&org.uuid, &conn).await.is_ok(), org_id == &org.uuid); |
|
|
assert!(!Collection::can_access_collection(&member, &collection.uuid, &conn).await); |
|
|
assert!(!Collection::is_assigned(&member, &collection.uuid, &conn).await); |
|
|
assert!(!custom_member_may(CollectionAction::Edit, &member, &collection.uuid, &conn).await); |
|
|
assert!(!member_may(CollectionAction::Edit, &member, &collection.uuid, &conn).await); |
|
|
} |
|
|
} |
|
|
let group = Group::new(org.uuid.clone(), "Group".into(), true, None); |
|
|
|
|
|
let omitted: GroupRequest = |
|
|
|
|
|
serde_json::from_value(json!({"name":"Group","collections":[],"users":[member.uuid]})).unwrap(); |
|
|
|
|
|
assert!(omitted.update_group(group).access_all); |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -4092,7 +3972,7 @@ mod tests { |
|
|
for (role, permissions) in [ |
|
|
for (role, permissions) in [ |
|
|
(Owner, vec![]), |
|
|
(Owner, vec![]), |
|
|
(Admin, vec![]), |
|
|
(Admin, vec![]), |
|
|
(Manager, vec![]), |
|
|
(User, vec![]), |
|
|
(User, vec![]), |
|
|
(User, vec![]), |
|
|
(Custom, vec![ManageResetPassword]), |
|
|
(Custom, vec![ManageResetPassword]), |
|
|
(Custom, vec![ManageResetPassword, ManageUsers]), |
|
|
(Custom, vec![ManageResetPassword, ManageUsers]), |
|
|
@ -4100,7 +3980,7 @@ mod tests { |
|
|
members.push(test_db::member(&conn, &org.uuid, role, &permissions).await.1); |
|
|
members.push(test_db::member(&conn, &org.uuid, role, &permissions).await.1); |
|
|
} |
|
|
} |
|
|
// Who may recover whom: a row per caller, a column per target, both in the order above
|
|
|
// Who may recover whom: a row per caller, a column per target, both in the order above
|
|
|
for (caller, row) in members.iter().zip(["111111", "011111", "000000", "000000", "000110", "000111"]) { |
|
|
for (caller, row) in members.iter().zip(["111111", "011111", "000000", "000000", "001110", "001111"]) { |
|
|
for (target, allowed) in members.iter().zip(row.chars()) { |
|
|
for (target, allowed) in members.iter().zip(row.chars()) { |
|
|
assert_eq!( |
|
|
assert_eq!( |
|
|
may_recover_account(caller, target), |
|
|
may_recover_account(caller, target), |
|
|
|