From 6ede1743ac837b67586ebc7190e91a523d000826 Mon Sep 17 00:00:00 2001 From: Miroslav Prasil Date: Mon, 13 Aug 2018 16:00:10 +0100 Subject: [PATCH 1/2] add alias for PUT collections-admin --- src/api/core/ciphers.rs | 5 +++++ src/api/core/mod.rs | 1 + 2 files changed, 6 insertions(+) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 0e2d5a75..2c60f0d2 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -291,6 +291,11 @@ fn post_collections_update(uuid: String, data: JsonUpcase, post_collections_admin(uuid, data, headers, conn) } +#[put("/ciphers//collections-admin", data = "")] +fn put_collections_admin(uuid: String, data: JsonUpcase, headers: Headers, conn: DbConn) -> EmptyResult { + post_collections_admin(uuid, data, headers, conn) +} + #[post("/ciphers//collections-admin", data = "")] fn post_collections_admin(uuid: String, data: JsonUpcase, headers: Headers, conn: DbConn) -> EmptyResult { let data: CollectionsAdminData = data.into_inner().data; diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs index 4d37f24d..f1659315 100644 --- a/src/api/core/mod.rs +++ b/src/api/core/mod.rs @@ -90,6 +90,7 @@ pub fn routes() -> Vec { post_organization_collection_delete, post_collections_update, post_collections_admin, + put_collections_admin, get_org_details, get_org_users, send_invite, From 0dfd9c7670fabc794e967cfe141277b52ae6582f Mon Sep 17 00:00:00 2001 From: Miroslav Prasil Date: Mon, 13 Aug 2018 16:45:30 +0100 Subject: [PATCH 2/2] Add couple more aliases for PUTs and DELETEs --- src/api/core/mod.rs | 6 ++++ src/api/core/organizations.rs | 56 +++++++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs index f1659315..6c2966c2 100644 --- a/src/api/core/mod.rs +++ b/src/api/core/mod.rs @@ -78,6 +78,7 @@ pub fn routes() -> Vec { get_organization, create_organization, delete_organization, + post_delete_organization, leave_organization, get_user_collections, get_org_collections, @@ -85,8 +86,11 @@ pub fn routes() -> Vec { get_collection_users, post_organization, post_organization_collections, + delete_organization_collection_user, post_organization_collection_delete_user, post_organization_collection_update, + put_organization_collection_update, + delete_organization_collection, post_organization_collection_delete, post_collections_update, post_collections_admin, @@ -97,7 +101,9 @@ pub fn routes() -> Vec { confirm_invite, get_user, edit_user, + put_organization_user, delete_user, + post_delete_user, clear_device_token, put_device_token, diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 74be5591..fe7313e9 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -55,7 +55,7 @@ fn create_organization(headers: Headers, data: JsonUpcase, conn: DbConn Ok(Json(org.to_json())) } -#[post("/organizations//delete", data = "")] +#[delete("/organizations/", data = "")] fn delete_organization(org_id: String, data: JsonUpcase, headers: OwnerHeaders, conn: DbConn) -> EmptyResult { let data: PasswordData = data.into_inner().data; let password_hash = data.MasterPasswordHash; @@ -73,6 +73,11 @@ fn delete_organization(org_id: String, data: JsonUpcase, headers: } } +#[post("/organizations//delete", data = "")] +fn post_delete_organization(org_id: String, data: JsonUpcase, headers: OwnerHeaders, conn: DbConn) -> EmptyResult { + delete_organization(org_id, data, headers, conn) +} + #[post("/organizations//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) { @@ -164,6 +169,11 @@ fn post_organization_collections(org_id: String, _headers: AdminHeaders, data: J Ok(Json(collection.to_json())) } +#[put("/organizations//collections/", data = "")] +fn put_organization_collection_update(org_id: String, col_id: String, headers: AdminHeaders, data: JsonUpcase, conn: DbConn) -> JsonResult { + post_organization_collection_update(org_id, col_id, headers, data, conn) +} + #[post("/organizations//collections/", data = "")] fn post_organization_collection_update(org_id: String, col_id: String, _headers: AdminHeaders, data: JsonUpcase, conn: DbConn) -> JsonResult { let data: NewCollectionData = data.into_inner().data; @@ -188,8 +198,9 @@ fn post_organization_collection_update(org_id: String, col_id: String, _headers: Ok(Json(collection.to_json())) } -#[post("/organizations//collections//delete-user/")] -fn post_organization_collection_delete_user(org_id: String, col_id: String, org_user_id: String, _headers: AdminHeaders, conn: DbConn) -> EmptyResult { + +#[delete("/organizations//collections//user/")] +fn delete_organization_collection_user(org_id: String, col_id: String, org_user_id: String, _headers: AdminHeaders, conn: DbConn) -> EmptyResult { let collection = match Collection::find_by_uuid(&col_id, &conn) { None => err!("Collection not found"), Some(collection) => if collection.org_uuid == org_id { @@ -215,17 +226,13 @@ fn post_organization_collection_delete_user(org_id: String, col_id: String, org_ } } -#[derive(Deserialize, Debug)] -#[allow(non_snake_case)] -struct DeleteCollectionData { - Id: String, - OrgId: String, +#[post("/organizations//collections//delete-user/")] +fn post_organization_collection_delete_user(org_id: String, col_id: String, org_user_id: String, headers: AdminHeaders, conn: DbConn) -> EmptyResult { + delete_organization_collection_user(org_id, col_id, org_user_id, headers, conn) } -#[post("/organizations//collections//delete", data = "")] -fn post_organization_collection_delete(org_id: String, col_id: String, _headers: AdminHeaders, data: JsonUpcase, conn: DbConn) -> EmptyResult { - let _data: DeleteCollectionData = data.into_inner().data; - +#[delete("/organizations//collections/")] +fn delete_organization_collection(org_id: String, col_id: String, _headers: AdminHeaders, conn: DbConn) -> EmptyResult { match Collection::find_by_uuid(&col_id, &conn) { None => err!("Collection not found"), Some(collection) => if collection.org_uuid == org_id { @@ -239,6 +246,18 @@ fn post_organization_collection_delete(org_id: String, col_id: String, _headers: } } +#[derive(Deserialize, Debug)] +#[allow(non_snake_case)] +struct DeleteCollectionData { + Id: String, + OrgId: String, +} + +#[post("/organizations//collections//delete", data = "<_data>")] +fn post_organization_collection_delete(org_id: String, col_id: String, headers: AdminHeaders, _data: JsonUpcase, conn: DbConn) -> EmptyResult { + delete_organization_collection(org_id, col_id, headers, conn) +} + #[get("/organizations//collections//details")] fn get_org_collection_detail(org_id: String, coll_id: String, headers: AdminHeaders, conn: DbConn) -> JsonResult { match Collection::find_by_uuid_and_user(&coll_id, &headers.user.uuid, &conn) { @@ -428,6 +447,12 @@ struct EditUserData { AccessAll: bool, } + +#[put("/organizations//users/", data = "", rank = 1)] +fn put_organization_user(org_id: String, user_id: String, data: JsonUpcase, headers: AdminHeaders, conn: DbConn) -> EmptyResult { + edit_user(org_id, user_id, data, headers, conn) +} + #[post("/organizations//users/", data = "", rank = 1)] fn edit_user(org_id: String, user_id: String, data: JsonUpcase, headers: AdminHeaders, conn: DbConn) -> EmptyResult { let data: EditUserData = data.into_inner().data; @@ -494,7 +519,7 @@ fn edit_user(org_id: String, user_id: String, data: JsonUpcase, he Ok(()) } -#[post("/organizations//users//delete")] +#[delete("/organizations//users/")] fn delete_user(org_id: String, user_id: String, headers: AdminHeaders, conn: DbConn) -> EmptyResult { let user_to_delete = match UserOrganization::find_by_uuid(&user_id, &conn) { Some(user) => user, @@ -521,4 +546,9 @@ fn delete_user(org_id: String, user_id: String, headers: AdminHeaders, conn: DbC Ok(()) => Ok(()), Err(_) => err!("Failed deleting user from organization") } +} + +#[post("/organizations//users//delete")] +fn post_delete_user(org_id: String, user_id: String, headers: AdminHeaders, conn: DbConn) -> EmptyResult { + delete_user(org_id, user_id, headers, conn) } \ No newline at end of file