From 3f5a99916a3d8487df00e196e19627b25616e930 Mon Sep 17 00:00:00 2001 From: Miroslav Prasil Date: Mon, 13 Aug 2018 10:58:39 +0100 Subject: [PATCH] Implement update_revision trigger --- src/api/core/ciphers.rs | 6 +++++- src/db/models/user.rs | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 95df5a0..43c5c78 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -242,7 +242,11 @@ fn post_ciphers_import(data: JsonUpcase, headers: Headers, conn: DbC cipher.move_to_folder(folder_uuid, &headers.user.uuid.clone(), &conn).ok(); } - Ok(()) + let mut user = headers.user; + match user.update_revision(&conn) { + Ok(()) => Ok(()), + Err(_) => err!("Failed to update the revision, please log out and log back in to finish import.") + } } #[post("/ciphers//admin", data = "")] diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 2c30c52..9378824 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -154,6 +154,16 @@ impl User { } } + pub fn update_revision(&mut self, conn: &DbConn) -> QueryResult<()> { + diesel::update( + users::table.filter( + users::uuid.eq(&self.uuid) + ) + ) + .set(users::updated_at.eq(Utc::now().naive_utc())) + .execute(&**conn).and(Ok(())) + } + pub fn find_by_mail(mail: &str, conn: &DbConn) -> Option { let lower_mail = mail.to_lowercase(); users::table