From 46f3b229ee8dd7619d5aa493f4e885056f6f7eb3 Mon Sep 17 00:00:00 2001 From: Miroslav Prasil Date: Wed, 30 May 2018 16:01:56 +0100 Subject: [PATCH] Removed unnecessary checks, simplified the code a bit --- src/api/core/organizations.rs | 43 ++++++++++++++++------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 7d650cf..4cba294 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -193,33 +193,28 @@ fn post_organization_collection_update(org_id: String, col_id: String, headers: } #[post("/organizations//collections//delete-user/")] -fn post_organization_collection_delete_user(org_id: String, col_id: String, org_user_id: String, headers: Headers, conn: DbConn) -> EmptyResult { - match UserOrganization::find_by_user_and_org(&headers.user.uuid, &org_id, &conn) { - None => err!("Not a member of Organization"), - Some(user_org) => if user_org.has_full_access() { - match Collection::find_by_uuid(&col_id, &conn) { - None => err!("Collection not found"), - Some(collection) => if collection.org_uuid == org_id { - match UserOrganization::find_by_uuid(&org_user_id, &conn) { - None => err!("User not found in organization"), - Some(user_org) => { - match CollectionUser::find_by_collection_and_user(&collection.uuid, &user_org.user_uuid, &conn) { - None => err!("User not assigned to collection"), - Some(col_user) => { - match col_user.delete(&conn) { - Ok(()) => Ok(()), - Err(_) => err!("Failed removing user from collection") - } - } - } - } +fn post_organization_collection_delete_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 { + collection + } else { + err!("Collection and Organization id do not match") + } + }; + + match UserOrganization::find_by_uuid(&org_user_id, &conn) { + None => err!("User not found in organization"), + Some(user_org) => { + match CollectionUser::find_by_collection_and_user(&collection.uuid, &user_org.user_uuid, &conn) { + None => err!("User not assigned to collection"), + Some(col_user) => { + match col_user.delete(&conn) { + Ok(()) => Ok(()), + Err(_) => err!("Failed removing user from collection") } - } else { - err!("Collection and Organization id do not match") } } - } else { - err!("Not enough rights to delete Collection") } } }