commit/galaxy-central: 2 new changesets
2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/17b09bab9eea/ Changeset: 17b09bab9eea User: remy_d1 Date: 2013-03-05 17:22:20 Summary: add userskeys feature/controller which is usefull to manage user's API key through admin panel Affected #: 4 files diff -r dbe53e2c1eab2b377880e87c4d2bd770dc470b80 -r 17b09bab9eead7e90f0981cdeee033dd860df72a lib/galaxy/webapps/galaxy/controllers/userskeys.py --- /dev/null +++ b/lib/galaxy/webapps/galaxy/controllers/userskeys.py @@ -0,0 +1,108 @@ +""" +Contains the user interface in the Universe class +""" + +import glob +import logging +import os +import socket +import string +import random +import pprint + +from galaxy import web +from galaxy import util, model +from galaxy.model.orm import and_ +from galaxy.security.validate_user_input import validate_email, validate_publicname, validate_password, transform_publicname +from galaxy.util.json import from_json_string, to_json_string +from galaxy.web import url_for +from galaxy.web.base.controller import BaseUIController, UsesFormDefinitionsMixin +from galaxy.web.form_builder import CheckboxField, build_select_field +from galaxy.web.framework.helpers import time_ago, grids + +from inspect import getmembers + +log = logging.getLogger( __name__ ) + +require_login_template = """ +<p> + This %s has been configured such that only users who are logged in may use it.%s +</p> +<p/> +""" + +class UserOpenIDGrid( grids.Grid ): + use_panels = False + title = "OpenIDs linked to your account" + model_class = model.UserOpenID + template = '/user/openid_manage.mako' + default_filter = { "openid" : "All" } + default_sort_key = "-create_time" + columns = [ + grids.TextColumn( "OpenID URL", key="openid", link=( lambda x: dict( action='openid_auth', login_button="Login", openid_url=x.openid if not x.provider else '', openid_provider=x.provider, auto_associate=True ) ) ), + grids.GridColumn( "Created", key="create_time", format=time_ago ), + ] + operations = [ + grids.GridOperation( "Delete", async_compatible=True ), + ] + def build_initial_query( self, trans, **kwd ): + return trans.sa_session.query( self.model_class ).filter( self.model_class.user_id == trans.user.id ) + +class User( BaseUIController, UsesFormDefinitionsMixin ): + user_openid_grid = UserOpenIDGrid() + installed_len_files = None + + + @web.expose + @web.require_login() + @web.require_admin + def index( self, trans, cntrller, **kwd ): + return trans.fill_template( 'webapps/galaxy/user/list_users.mako', action='all_users', cntrller=cntrller ) + + + + @web.expose + @web.require_login() + @web.require_admin + def api_keys( self, trans, cntrller, uid, **kwd ): + params = util.Params( kwd ) + message = util.restore_text( params.get( 'message', '' ) ) + status = params.get( 'status', 'done' ) + uid = params.get('uid', uid) + pprint.pprint(uid) + if params.get( 'new_api_key_button', False ): + new_key = trans.app.model.APIKeys() + new_key.user_id = uid + new_key.key = trans.app.security.get_new_guid() + trans.sa_session.add( new_key ) + trans.sa_session.flush() + message = "Generated a new web API key" + status = "done" + return trans.fill_template( 'webapps/galaxy/user/ok_admin_api_keys.mako', + cntrller=cntrller, + message=message, + status=status ) + + + @web.expose + @web.require_login() + @web.require_admin + def all_users( self, trans, cntrller="userskeys", **kwd ): + params = util.Params( kwd ) + message = util.restore_text( params.get( 'message', '' ) ) + status = params.get( 'status', 'done' ) + users = [] + for user in trans.sa_session.query( trans.app.model.User ) \ + .filter( trans.app.model.User.table.c.deleted==False ) \ + .order_by( trans.app.model.User.table.c.email ): + uid = int(user.id) + userkey = "" + for api_user in trans.sa_session.query(trans.app.model.APIKeys) \ + .filter( trans.app.model.APIKeys.user_id == uid): + userkey = api_user.key + users.append({'uid':uid, 'email':user.email, 'key':userkey}) + return trans.fill_template( 'webapps/galaxy/user/list_users.mako', + cntrller=cntrller, + users=users, + message=message, + status=status ) diff -r dbe53e2c1eab2b377880e87c4d2bd770dc470b80 -r 17b09bab9eead7e90f0981cdeee033dd860df72a templates/webapps/galaxy/admin/index.mako --- a/templates/webapps/galaxy/admin/index.mako +++ b/templates/webapps/galaxy/admin/index.mako @@ -45,6 +45,7 @@ <div class="toolTitle"><a href="${h.url_for( controller='admin', action='users' )}" target="galaxy_main">Manage users</a></div><div class="toolTitle"><a href="${h.url_for( controller='admin', action='groups' )}" target="galaxy_main">Manage groups</a></div><div class="toolTitle"><a href="${h.url_for( controller='admin', action='roles' )}" target="galaxy_main">Manage roles</a></div> + <div class="toolTitle"><a href="${h.url_for( controller='userskeys', action='all_users' )}" target="galaxy_main">Manage users API keys</a></div> %if trans.app.config.allow_user_impersonation: <div class="toolTitle"><a href="${h.url_for( controller='admin', action='impersonate' )}" target="galaxy_main">Impersonate a user</a></div> %endif diff -r dbe53e2c1eab2b377880e87c4d2bd770dc470b80 -r 17b09bab9eead7e90f0981cdeee033dd860df72a templates/webapps/galaxy/user/list_users.mako --- /dev/null +++ b/templates/webapps/galaxy/user/list_users.mako @@ -0,0 +1,37 @@ +<%inherit file="/base.mako"/> + +%if message: + ${render_msg( message, status )} +%endif + + +%if users: + <div class="toolForm"> + <div class="toolFormTitle">Users informations</div> + <table> + <thead><th>UID</th><th>email</th></thead> + <tbody> + %for user in users: + <tr> + <td>${user['uid']}</td> + <td>${user['email']}</td> + <td>${user['key']}</td> + <td> + <form action="${h.url_for( controller='userskeys', action='api_keys', cntrller=cntrller )}" method="POST"> + <input type="hidden" name="uid" value=${user['uid']} /> + <input type="submit" name="new_api_key_button" value="Generate a new key now" /> + </form> + </td> + </tr> + %endfor + </tbody> + </table> + <div style="clear: both"></div> + </div> +%else: + <div>No informations available</div> +%endif + + +<p/> + diff -r dbe53e2c1eab2b377880e87c4d2bd770dc470b80 -r 17b09bab9eead7e90f0981cdeee033dd860df72a templates/webapps/galaxy/user/ok_admin_api_keys.mako --- /dev/null +++ b/templates/webapps/galaxy/user/ok_admin_api_keys.mako @@ -0,0 +1,28 @@ +<%inherit file="/base.mako"/> +<%namespace file="/message.mako" import="render_msg" /> + +<br/><br/> +<ul class="manage-table-actions"> + <li> + <a class="action-button" href="${h.url_for( controller='userskeys', action='all_users', cntrller=cntrller )}">List users API keys</a> + </li> +</ul> + +%if message: + ${render_msg( message, status )} +%endif + + <div> + <div style="clear: both;"> + SUCCESS. A new API key has been generated. + </div> + + + <div style="clear: both;"> + An API key will allow you to access Galaxy via its web + API (documentation forthcoming). Please note that + <strong>this key acts as an alternate means to access + your account, and should be treated with the same care + as your login password</strong>. + </div> + </div> https://bitbucket.org/galaxy/galaxy-central/commits/a1a06f6deb41/ Changeset: a1a06f6deb41 User: remy_d1 Date: 2013-03-05 17:50:40 Summary: modified method name 'api_keys' to 'admin_api_keys' for user vs userskeys controller Affected #: 2 files diff -r 17b09bab9eead7e90f0981cdeee033dd860df72a -r a1a06f6deb410e1c50b4cb86c28e97a75df4f91b lib/galaxy/webapps/galaxy/controllers/userskeys.py --- a/lib/galaxy/webapps/galaxy/controllers/userskeys.py +++ b/lib/galaxy/webapps/galaxy/controllers/userskeys.py @@ -64,7 +64,7 @@ @web.expose @web.require_login() @web.require_admin - def api_keys( self, trans, cntrller, uid, **kwd ): + def admin_api_keys( self, trans, cntrller, uid, **kwd ): params = util.Params( kwd ) message = util.restore_text( params.get( 'message', '' ) ) status = params.get( 'status', 'done' ) diff -r 17b09bab9eead7e90f0981cdeee033dd860df72a -r a1a06f6deb410e1c50b4cb86c28e97a75df4f91b templates/webapps/galaxy/user/list_users.mako --- a/templates/webapps/galaxy/user/list_users.mako +++ b/templates/webapps/galaxy/user/list_users.mako @@ -17,7 +17,7 @@ <td>${user['email']}</td><td>${user['key']}</td><td> - <form action="${h.url_for( controller='userskeys', action='api_keys', cntrller=cntrller )}" method="POST"> + <form action="${h.url_for( controller='userskeys', action='admin_api_keys', cntrller=cntrller )}" method="POST"><input type="hidden" name="uid" value=${user['uid']} /><input type="submit" name="new_api_key_button" value="Generate a new key now" /></form> Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org