mirror of
https://github.com/ViViDboarder/bitwarden_rs.git
synced 2024-11-22 05:06:37 +00:00
Implement leave organization (accessed from the bottom of the user's settings page)
This commit is contained in:
parent
e88d8c856d
commit
1cb67eee69
@ -65,6 +65,7 @@ pub fn routes() -> Vec<Route> {
|
||||
get_organization,
|
||||
create_organization,
|
||||
delete_organization,
|
||||
leave_organization,
|
||||
get_user_collections,
|
||||
get_org_collections,
|
||||
get_org_collection_detail,
|
||||
|
@ -73,6 +73,29 @@ fn delete_organization(org_id: String, data: JsonUpcase<PasswordData>, headers:
|
||||
}
|
||||
}
|
||||
|
||||
#[post("/organizations/<org_id>/leave")]
|
||||
fn leave_organization(org_id: String, headers: Headers, conn: DbConn) -> EmptyResult {
|
||||
match UserOrganization::find_by_user_and_org(&headers.user.uuid, &org_id, &conn) {
|
||||
None => err!("User not part of organization"),
|
||||
Some(user_org) => {
|
||||
if user_org.type_ == UserOrgType::Owner as i32 {
|
||||
let num_owners = UserOrganization::find_by_org_and_type(
|
||||
&org_id, UserOrgType::Owner as i32, &conn)
|
||||
.len();
|
||||
|
||||
if num_owners <= 1 {
|
||||
err!("The last owner can't leave")
|
||||
}
|
||||
}
|
||||
|
||||
match user_org.delete(&conn) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(_) => err!("Failed leaving the organization")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/organizations/<org_id>")]
|
||||
fn get_organization(org_id: String, _headers: OwnerHeaders, conn: DbConn) -> JsonResult {
|
||||
match Organization::find_by_uuid(&org_id, &conn) {
|
||||
|
Loading…
Reference in New Issue
Block a user