From 912901780eb2585ac0b182e72a0a05a30c3cdb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Thu, 15 Feb 2018 01:07:57 +0100 Subject: [PATCH] Updated modified date when saving and removed hardcoded attachment domain --- src/api/core/folders.rs | 2 +- src/db/models/attachment.rs | 7 +------ src/db/models/cipher.rs | 6 +++--- src/db/models/device.rs | 6 +++--- src/db/models/folder.rs | 6 +++--- src/db/models/user.rs | 6 +++--- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/api/core/folders.rs b/src/api/core/folders.rs index fdf717c2..bce831e6 100644 --- a/src/api/core/folders.rs +++ b/src/api/core/folders.rs @@ -41,7 +41,7 @@ fn post_folders(data: Json, headers: Headers, conn: DbConn) -> Result JsonValue { use util::get_display_size; - // TODO: Change all references to localhost (maybe put it in .env?) - let host = "http://localhost:8000"; - - let web_path = format!("{}/attachments/{}/{}", host, self.cipher_uuid, self.id); + let web_path = format!("/attachments/{}/{}", self.cipher_uuid, self.id); let display_size = get_display_size(self.file_size); json!({ @@ -57,8 +54,6 @@ use db::schema::attachments; /// Database methods impl Attachment { pub fn save(&self, conn: &DbConn) -> bool { - // TODO: Update modified date - match diesel::replace_into(attachments::table) .values(self) .execute(&**conn) { diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index 20b7b861..b81dec0d 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -82,11 +82,11 @@ impl Cipher { }) } - pub fn save(&self, conn: &DbConn) -> bool { - // TODO: Update modified date + pub fn save(&mut self, conn: &DbConn) -> bool { + self.updated_at = Utc::now().naive_utc(); match diesel::replace_into(ciphers::table) - .values(self) + .values(&*self) .execute(&**conn) { Ok(1) => true, // One row inserted _ => false, diff --git a/src/db/models/device.rs b/src/db/models/device.rs index a22f45fd..346b5d2c 100644 --- a/src/db/models/device.rs +++ b/src/db/models/device.rs @@ -82,11 +82,11 @@ use db::schema::devices; /// Database methods impl Device { - pub fn save(&self, conn: &DbConn) -> bool { - // TODO: Update modified date + pub fn save(&mut self, conn: &DbConn) -> bool { + self.updated_at = Utc::now().naive_utc(); match diesel::replace_into(devices::table) - .values(self) + .values(&*self) .execute(&**conn) { Ok(1) => true, // One row inserted _ => false, diff --git a/src/db/models/folder.rs b/src/db/models/folder.rs index 18561768..0dea434c 100644 --- a/src/db/models/folder.rs +++ b/src/db/models/folder.rs @@ -51,11 +51,11 @@ use db::schema::folders; /// Database methods impl Folder { - pub fn save(&self, conn: &DbConn) -> bool { - // TODO: Update modified date + pub fn save(&mut self, conn: &DbConn) -> bool { + self.updated_at = Utc::now().naive_utc(); match diesel::replace_into(folders::table) - .values(self) + .values(&*self) .execute(&**conn) { Ok(1) => true, // One row inserted _ => false, diff --git a/src/db/models/user.rs b/src/db/models/user.rs index ce6807a3..f1aecd68 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -138,11 +138,11 @@ use db::schema::users; /// Database methods impl User { - pub fn save(&self, conn: &DbConn) -> bool { - // TODO: Update modified date + pub fn save(&mut self, conn: &DbConn) -> bool { + self.updated_at = Utc::now().naive_utc(); match diesel::replace_into(users::table) // Insert or update - .values(self) + .values(&*self) .execute(&**conn) { Ok(1) => true, // One row inserted _ => false,