Skip to content

Commit

Permalink
Add APIKey generation operation to user grid.
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed May 21, 2018
1 parent 3bd8b3b commit ce2893d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/galaxy/webapps/galaxy/controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def get_value(self, trans, grid, user):
else:
return 'N'

class APIKeyColumn(grids.GridColumn):
def get_value(self, trans, grid, user):
if user.api_keys:
return user.api_keys[0].key
else:
return ""

# Grid definition
title = "Users"
title_id = "users-grid"
Expand All @@ -122,6 +129,7 @@ def get_value(self, trans, grid, user):
StatusColumn("Status", attach_popup=False),
TimeCreatedColumn("Created", attach_popup=False),
ActivatedColumn("Activated", attach_popup=False),
APIKeyColumn("API Key", attach_popup=False),
# Columns that are valid for filtering but are not visible.
grids.DeletedColumn("Deleted", key="deleted", visible=False, filterable="advanced")
]
Expand Down Expand Up @@ -149,7 +157,13 @@ def get_value(self, trans, grid, user):
target="top"),
grids.GridOperation("Recalculate Disk Usage",
condition=(lambda item: not item.deleted),
allow_multiple=False)
allow_multiple=False),
grids.GridOperation(
"Generate New API Key",
allow_multiple=False,
async_compatible=True
)

]
standard_filters = [
grids.GridColumnFilter("Active", args=dict(deleted=False)),
Expand Down Expand Up @@ -581,6 +595,8 @@ def users_list(self, trans, **kwd):
message, status = self._purge_user(trans, ids)
elif operation == 'recalculate disk usage':
message, status = self._recalculate_user(trans, id)
elif operation == 'generate new api key':
message, status = self._new_user_apikey(trans, id)
if trans.app.config.allow_user_deletion:
if self.delete_operation not in self.user_list_grid.operations:
self.user_list_grid.operations.append(self.delete_operation)
Expand Down Expand Up @@ -1551,6 +1567,15 @@ def _recalculate_user(self, trans, user_id):
message = 'Usage has changed by %s to %s.' % (nice_size(new - current), nice_size(new))
return (message, 'done')

def _new_user_apikey(self, trans, uid):
new_key = trans.app.model.APIKeys(
user_id=trans.security.decode_id(uid),
key=trans.app.security.get_new_guid()
)
trans.sa_session.add(new_key)
trans.sa_session.flush()
return ('New key %s generated for requested user.', 'done')

@web.expose_api
@web.require_admin
def manage_roles_and_groups_for_user(self, trans, payload=None, **kwd):
Expand Down

0 comments on commit ce2893d

Please sign in to comment.