From 3bd8b3b18b6032e8844795fae488e501074cd573 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Fri, 18 May 2018 14:26:13 -0400 Subject: [PATCH] Impersonation refactoring, condense functionality into user grid, optimize some stuff. --- .../galaxy/scripts/apps/panels/admin-panel.js | 6 -- .../webapps/galaxy/controllers/admin.py | 28 ++++----- templates/admin/impersonate.mako | 58 ------------------- templates/webapps/galaxy/admin/center.mako | 7 +-- 4 files changed, 13 insertions(+), 86 deletions(-) delete mode 100644 templates/admin/impersonate.mako diff --git a/client/galaxy/scripts/apps/panels/admin-panel.js b/client/galaxy/scripts/apps/panels/admin-panel.js index 7ee9e69c1d7..5c6b1098b52 100644 --- a/client/galaxy/scripts/apps/panels/admin-panel.js +++ b/client/galaxy/scripts/apps/panels/admin-panel.js @@ -82,12 +82,6 @@ var AdminPanel = Backbone.View.extend({ url: "admin/api_keys", target: "__use_router__", id: "admin-link-api-keys" - }, - { - title: _l("Impersonate a user"), - url: "admin/impersonate", - enabled: self.config.allow_user_impersonation, - id: "admin-link-impersonate" } ] }, diff --git a/lib/galaxy/webapps/galaxy/controllers/admin.py b/lib/galaxy/webapps/galaxy/controllers/admin.py index 8251c598062..d302f242598 100644 --- a/lib/galaxy/webapps/galaxy/controllers/admin.py +++ b/lib/galaxy/webapps/galaxy/controllers/admin.py @@ -796,27 +796,23 @@ class AdminGalaxy(controller.JSAppLauncher, AdminActions, UsesQuotaMixin, QuotaP @web.expose @web.require_admin - def impersonate(self, trans, email=None, **kwd): + def impersonate(self, trans, **kwd): if not trans.app.config.allow_user_impersonation: return trans.show_error_message("User impersonation is not enabled in this instance of Galaxy.") - message = '' - status = 'done' - show_emails = True user = None user_id = kwd.get('id', None) if user_id is not None: - user = trans.sa_session.query(trans.app.model.User).get(trans.security.decode_id(user_id)) - elif email is not None: - user = trans.sa_session.query(trans.app.model.User).filter_by(email=email).first() - if user: - trans.handle_user_logout() - trans.handle_user_login(user) - message = 'You are now logged in as %s, return to the home page' % (user.email, url_for(controller='root')) - show_emails = False - elif user_id or email: - message = 'Invalid user selected' - status = 'error' - return trans.fill_template('admin/impersonate.mako', show_emails=show_emails, message=message, status=status) + try: + user = trans.sa_session.query(trans.app.model.User).get(trans.security.decode_id(user_id)) + if user: + trans.handle_user_logout() + trans.handle_user_login(user) + return trans.show_message('You are now logged in as %s, return to the home page' % (user.email, url_for(controller='root')), use_panels=True) + except Exception: + log.exception("Error fetching user for impersonation") + return trans.response.send_redirect(web.url_for(controller='admin', + action='users', + message="Invalid user selected", status="error")) def check_for_tool_dependencies(self, trans, migration_stage): # Get the 000x_tools.xml file associated with migration_stage. diff --git a/templates/admin/impersonate.mako b/templates/admin/impersonate.mako deleted file mode 100644 index 969aeabdee7..00000000000 --- a/templates/admin/impersonate.mako +++ /dev/null @@ -1,58 +0,0 @@ -<%inherit file="/base.mako"/> -<%namespace file="/message.mako" import="render_msg" /> - -%if message: - ${render_msg( message, status )} -%endif - -%if show_emails: -
-
Impersonate another user
-
-
-
- - - -
-
- -
-
-
-
- -%endif diff --git a/templates/webapps/galaxy/admin/center.mako b/templates/webapps/galaxy/admin/center.mako index 39b650ae836..77e10529c00 100644 --- a/templates/webapps/galaxy/admin/center.mako +++ b/templates/webapps/galaxy/admin/center.mako @@ -30,7 +30,7 @@ Please visit the Galax

User Management

Tool Management