From 43f9038325b2729016d066fcdaa22799b444dd0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Thu, 7 Mar 2019 21:08:33 +0100 Subject: [PATCH] Add option to force resync clients in admin panel --- src/api/admin.rs | 6 ++++++ src/db/models/user.rs | 14 ++++++++++++++ src/static/templates/admin/page.hbs | 22 +++++++++++++++++----- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/api/admin.rs b/src/api/admin.rs index 8b84d09..c40f523 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -26,6 +26,7 @@ pub fn routes() -> Vec { invite_user, delete_user, deauth_user, + update_revision_users, post_config, delete_config, ] @@ -177,6 +178,11 @@ fn deauth_user(uuid: String, _token: AdminToken, conn: DbConn) -> EmptyResult { user.save(&conn) } +#[post("/users/update_revision")] +fn update_revision_users(_token: AdminToken, conn: DbConn) -> EmptyResult { + User::update_all_revisions(&conn) +} + #[post("/config", data = "")] fn post_config(data: Json, _token: AdminToken) -> EmptyResult { let data: ConfigBuilder = data.into_inner(); diff --git a/src/db/models/user.rs b/src/db/models/user.rs index c447a92..91d018d 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -178,6 +178,20 @@ impl User { } } + pub fn update_all_revisions(conn: &DbConn) -> EmptyResult { + let updated_at = Utc::now().naive_utc(); + + crate::util::retry( + || { + diesel::update(users::table) + .set(users::updated_at.eq(updated_at)) + .execute(&**conn) + }, + 10, + ) + .map_res("Error updating revision date for all users") + } + pub fn update_revision(&mut self, conn: &DbConn) -> EmptyResult { self.updated_at = Utc::now().naive_utc(); diff --git a/src/static/templates/admin/page.hbs b/src/static/templates/admin/page.hbs index 646a0fd..7ce1667 100644 --- a/src/static/templates/admin/page.hbs +++ b/src/static/templates/admin/page.hbs @@ -37,9 +37,14 @@ - - Reload users - +
+ + + +
@@ -58,8 +63,9 @@
Configuration
- NOTE: The settings here override the environment variables. Once saved, it's recommended to stop setting them - to avoid confusion. This does not apply to the read-only section, which can only be set through the environment. + NOTE: The settings here override the environment variables. Once saved, it's recommended to stop setting + them to avoid confusion. This does not apply to the read-only section, which can only be set through the + environment.
{{#each config}} @@ -213,6 +219,12 @@ "Error deauthorizing sessions"); return false; } + function updateRevisions() { + _post("/admin/users/update_revision", + "Success, clients will sync next time they connect", + "Error forcing clients to sync"); + return false; + } function inviteUser() { inv = $("#email-invite"); data = JSON.stringify({ "email": inv.val() });