From 40d09ddd2a7cdf5db79646121fe7ffb1f8d2b236 Mon Sep 17 00:00:00 2001 From: Miroslav Prasil Date: Tue, 21 Aug 2018 13:25:52 +0100 Subject: [PATCH 1/2] Add PUT alias for Organization updates --- src/api/core/mod.rs | 1 + src/api/core/organizations.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs index 4206aca2..907b053b 100644 --- a/src/api/core/mod.rs +++ b/src/api/core/mod.rs @@ -86,6 +86,7 @@ pub fn routes() -> Vec { get_org_collections, get_org_collection_detail, get_collection_users, + put_organization, post_organization, post_organization_collections, delete_organization_collection_user, diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index a4568562..c2ecde26 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -111,6 +111,11 @@ fn get_organization(org_id: String, _headers: OwnerHeaders, conn: DbConn) -> Jso } } +#[put("/organizations/", data = "")] +fn put_organization(org_id: String, headers: OwnerHeaders, data: JsonUpcase, conn: DbConn) -> JsonResult { + post_organization(org_id, headers, data, conn) +} + #[post("/organizations/", data = "")] fn post_organization(org_id: String, _headers: OwnerHeaders, data: JsonUpcase, conn: DbConn) -> JsonResult { let data: OrganizationUpdateData = data.into_inner().data; From 9eea0151ba73213f6e2f3f66f7abc415e19e1d65 Mon Sep 17 00:00:00 2001 From: Miroslav Prasil Date: Tue, 21 Aug 2018 13:26:22 +0100 Subject: [PATCH 2/2] Update user revision timestamp on Organization changes --- src/db/models/organization.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/db/models/organization.rs b/src/db/models/organization.rs index 4bb55912..78e381fa 100644 --- a/src/db/models/organization.rs +++ b/src/db/models/organization.rs @@ -1,6 +1,7 @@ use serde_json::Value as JsonValue; use uuid::Uuid; +use super::{User, CollectionUser}; #[derive(Debug, Identifiable, Queryable, Insertable)] #[table_name = "organizations"] @@ -114,6 +115,12 @@ use db::schema::users_organizations; /// Database methods impl Organization { pub fn save(&mut self, conn: &DbConn) -> bool { + UserOrganization::find_by_org(&self.uuid, conn) + .iter() + .for_each(|user_org| { + User::update_uuid_revision(&user_org.user_uuid, conn); + }); + match diesel::replace_into(organizations::table) .values(&*self) .execute(&**conn) { @@ -172,7 +179,6 @@ impl UserOrganization { } pub fn to_json_user_details(&self, conn: &DbConn) -> JsonValue { - use super::User; let user = User::find_by_uuid(&self.user_uuid, conn).unwrap(); json!({ @@ -190,7 +196,6 @@ impl UserOrganization { } pub fn to_json_collection_user_details(&self, read_only: &bool, conn: &DbConn) -> JsonValue { - use super::User; let user = User::find_by_uuid(&self.user_uuid, conn).unwrap(); json!({ @@ -209,7 +214,6 @@ impl UserOrganization { let coll_uuids = if self.access_all { vec![] // If we have complete access, no need to fill the array } else { - use super::CollectionUser; let collections = CollectionUser::find_by_organization_and_user_uuid(&self.org_uuid, &self.user_uuid, conn); collections.iter().map(|c| json!({"Id": c.collection_uuid, "ReadOnly": c.read_only})).collect() }; @@ -228,6 +232,8 @@ impl UserOrganization { } pub fn save(&mut self, conn: &DbConn) -> bool { + User::update_uuid_revision(&self.user_uuid, conn); + match diesel::replace_into(users_organizations::table) .values(&*self) .execute(&**conn) { @@ -237,7 +243,7 @@ impl UserOrganization { } pub fn delete(self, conn: &DbConn) -> QueryResult<()> { - use super::CollectionUser; + User::update_uuid_revision(&self.user_uuid, conn); CollectionUser::delete_all_by_user(&self.user_uuid, &conn)?;