commit/galaxy-central: natefoo: Set and allow modification of the public username if use_remote_user = True
1 new changeset in galaxy-central: http://bitbucket.org/galaxy/galaxy-central/changeset/7c101a11d261/ changeset: r5469:7c101a11d261 user: natefoo date: 2011-04-28 17:33:07 summary: Set and allow modification of the public username if use_remote_user = True affected #: 5 files (2.5 KB) --- a/lib/galaxy/web/controllers/user.py Thu Apr 28 11:10:41 2011 -0400 +++ b/lib/galaxy/web/controllers/user.py Thu Apr 28 11:33:07 2011 -0400 @@ -735,6 +735,38 @@ webapp=webapp, message=message, status=status ) + # For REMOTE_USER, we need the ability to just edit the username + @web.expose + @web.require_login( "to manage the public name" ) + def edit_username( self, trans, cntrller, **kwd ): + params = util.Params( kwd ) + is_admin = cntrller == 'admin' and trans.user_is_admin() + webapp = params.get( 'webapp', 'galaxy' ) + message = util.restore_text( params.get( 'message', '' ) ) + status = params.get( 'status', 'done' ) + user_id = params.get( 'user_id', None ) + if user_id and is_admin: + user = trans.sa_session.query( trans.app.model.User ).get( trans.security.decode_id( user_id ) ) + else: + user = trans.user + if user and params.get( 'change_username_button', False ): + username = kwd.get( 'username', '' ) + if username: + message = self.__validate_username( trans, username, user ) + if message: + status = 'error' + else: + user.username = username + trans.sa_session.add( user ) + trans.sa_session.flush() + message = 'The username has been updated with the changes.' + return trans.fill_template( '/user/username.mako', + cntrller=cntrller, + user=user, + username=user.username, + webapp=webapp, + message=message, + status=status ) @web.expose def edit_info( self, trans, cntrller, **kwd ): params = util.Params( kwd ) @@ -743,12 +775,15 @@ message = util.restore_text( params.get( 'message', '' ) ) status = params.get( 'status', 'done' ) user_id = params.get( 'user_id', None ) - #new_kwd = dict( webapp=webapp ) - if user_id: + if user_id and is_admin: user = trans.sa_session.query( trans.app.model.User ).get( trans.security.decode_id( user_id ) ) + elif user_id and ( not trans.user or trans.user.id != trans.security.decode_id( user_id ) ): + message = 'Invalid user id' + status = 'error' + user = None else: user = trans.user - if params.get( 'login_info_button', False ): + if user and params.get( 'login_info_button', False ): # Editing email and username email = util.restore_text( params.get( 'email', '' ) ) username = util.restore_text( params.get( 'username', '' ) ).lower() @@ -769,7 +804,7 @@ trans.sa_session.add_all( ( user, private_role ) ) trans.sa_session.flush() message = 'The login information has been updated with the changes.' - elif params.get( 'change_password_button', False ): + elif user and params.get( 'change_password_button', False ): # Editing password. Do not sanitize passwords, so get from kwd # and not params (which were sanitized). password = kwd.get( 'password', '' ) @@ -794,7 +829,7 @@ trans.sa_session.flush() trans.log_event( "User change password" ) message = 'The password has been changed.' - elif params.get( 'edit_user_info_button', False ): + elif user and params.get( 'edit_user_info_button', False ): # Edit user information - webapp MUST BE 'galaxy' user_type_fd_id = params.get( 'user_type_fd_id', 'none' ) if user_type_fd_id not in [ 'none' ]: @@ -809,7 +844,7 @@ else: values = {} flush_needed = False - if user.values: + if user.values: # Editing the user info of an existing user with existing user info user.values.content = values trans.sa_session.add( user.values ) @@ -823,7 +858,7 @@ trans.sa_session.add( user ) trans.sa_session.flush() message = "The user information has been updated with the changes." - if webapp == 'galaxy' and is_admin: + if user and webapp == 'galaxy' and is_admin: kwd[ 'user_id' ] = trans.security.encode_id( user.id ) kwd[ 'id' ] = user_id if message: --- a/lib/galaxy/web/framework/__init__.py Thu Apr 28 11:10:41 2011 -0400 +++ b/lib/galaxy/web/framework/__init__.py Thu Apr 28 11:33:07 2011 -0400 @@ -437,10 +437,18 @@ if not user.default_permissions: self.app.security_agent.user_set_default_permissions( user, history=True, dataset=True ) elif user is None: + username = remote_user_email.split( '@', 1 )[0] random.seed() user = self.app.model.User( email=remote_user_email ) user.set_password_cleartext( ''.join( random.sample( string.letters + string.digits, 12 ) ) ) user.external = True + # Find a unique username - user can change it later + if ( self.sa_session.query( self.app.model.User ).filter_by( username=username ).first() ): + i = 0 + while ( self.sa_session.query( self.app.model.User ).filter_by( username=(username + '-' + str(i) ) ).first() ): + i += 1 + username += '-' + str(i) + user.username = username self.sa_session.add( user ) self.sa_session.flush() self.app.security_agent.create_private_user_role( user ) --- a/lib/galaxy/web/framework/middleware/remoteuser.py Thu Apr 28 11:10:41 2011 -0400 +++ b/lib/galaxy/web/framework/middleware/remoteuser.py Thu Apr 28 11:33:07 2011 -0400 @@ -97,6 +97,8 @@ pass # admins can create users elif path_info.startswith( '/user/api_keys' ): pass # api keys can be managed when remote_user is in use + elif path_info.startswith( '/user/edit_username' ): + pass # username can be managed when remote_user is in use elif path_info.startswith( '/user/dbkeys' ): pass # dbkeys can be managed when remote_user is in use elif path_info.startswith( '/user' ): --- a/templates/webapps/galaxy/base_panels.mako Thu Apr 28 11:10:41 2011 -0400 +++ b/templates/webapps/galaxy/base_panels.mako Thu Apr 28 11:33:07 2011 -0400 @@ -149,6 +149,8 @@ menu_options.append( [ 'Saved Pages', h.url_for( controller='/page', action='list' ), "_top" ] ) if app.config.enable_api: menu_options.append( [ 'API Keys', h.url_for( controller='/user', action='api_keys', cntrller='user' ), "galaxy_main" ] ) + if app.config.use_remote_user: + menu_options.append( [ 'Public Name', h.url_for( controller='/user', action='edit_username', cntrller='user' ), "galaxy_main" ] ) extra_class = "loggedin-only" visible = ( trans.user != None ) 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)
-
Bitbucket