From d97ceb1d72970577c38bae1c61a37bf6fdaceae5 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Fri, 6 Jun 2014 13:02:52 +1000 Subject: [PATCH] FEATURE: log_out endpoint for admins --- app/assets/javascripts/admin/models/admin_user.js | 11 +++++++++++ .../admin/templates/user_index.js.handlebars | 6 ++++++ app/controllers/admin/users_controller.rb | 7 +++++++ config/locales/client.en.yml | 2 ++ config/routes.rb | 1 + 5 files changed, 27 insertions(+) diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js index c219fa88f61..f84cc9a3bd4 100644 --- a/app/assets/javascripts/admin/models/admin_user.js +++ b/app/assets/javascripts/admin/models/admin_user.js @@ -174,6 +174,17 @@ Discourse.AdminUser = Discourse.User.extend({ }); }, + log_out: function(){ + Discourse.ajax("/admin/users/" + this.id + "/log_out", { + type: 'POST', + data: { username_or_email: this.get('username') } + }).then( + function(){ + bootbox.alert(I18n.t("admin.user.logged_out")); + } + ); + }, + impersonate: function() { Discourse.ajax("/admin/impersonate", { type: 'POST', diff --git a/app/assets/javascripts/admin/templates/user_index.js.handlebars b/app/assets/javascripts/admin/templates/user_index.js.handlebars index c6d2708ff29..76cf69cdbd7 100644 --- a/app/assets/javascripts/admin/templates/user_index.js.handlebars +++ b/app/assets/javascripts/admin/templates/user_index.js.handlebars @@ -14,6 +14,12 @@ {{i18n admin.user.impersonate}} {{/if}} + {{#if currentUser.admin}} + + {{/if}} diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 3c4de5d9aaa..2103515b53c 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -7,6 +7,7 @@ class Admin::UsersController < Admin::AdminController before_filter :fetch_user, only: [:suspend, :unsuspend, :refresh_browsers, + :log_out, :revoke_admin, :grant_admin, :revoke_moderation, @@ -56,6 +57,12 @@ class Admin::UsersController < Admin::AdminController render nothing: true end + def log_out + @user.auth_token = nil + @user.save! + render nothing: true + end + def refresh_browsers refresh_browser @user render nothing: true diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 3c855f799f7..61930d6f204 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1704,6 +1704,8 @@ en: refresh_browsers: "Force browser refresh" show_public_profile: "Show Public Profile" impersonate: 'Impersonate' + log_out: "Log Out" + logged_out: "User was logged out on all devices" revoke_admin: 'Revoke Admin' grant_admin: 'Grant Admin' revoke_moderation: 'Revoke Moderation' diff --git a/config/routes.rb b/config/routes.rb index 880c561feee..d75b6f56409 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -62,6 +62,7 @@ Discourse::Application.routes.draw do put "grant_moderation", constraints: AdminConstraint.new put "approve" post "refresh_browsers", constraints: AdminConstraint.new + post "log_out", constraints: AdminConstraint.new put "activate" put "deactivate" put "block"