From 9520ca7f51db029ddd2b16f4d2bc96a1ed216d07 Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Tue, 28 Apr 2009 09:44:35 -0400 Subject: [PATCH] Can now optionally create a new group with the same name as a role when creating the role, along with more cleanup on the various users / groups / roles templates. --- lib/galaxy/web/controllers/admin.py | 40 ++++++----------- .../dataset_security/deleted_groups.mako | 37 ++++++---------- .../admin/dataset_security/deleted_roles.mako | 43 ++++++++----------- templates/admin/dataset_security/group.mako | 8 ++-- .../admin/dataset_security/group_create.mako | 11 ++--- templates/admin/dataset_security/role.mako | 8 ++-- .../admin/dataset_security/role_create.mako | 19 +++++--- templates/admin/dataset_security/user.mako | 8 ++-- templates/admin/user/create.mako | 2 +- 9 files changed, 74 insertions(+), 102 deletions(-) diff --git a/lib/galaxy/web/controllers/admin.py b/lib/galaxy/web/controllers/admin.py index 596cbd48a3e..c6bd4df6643 100644 --- a/lib/galaxy/web/controllers/admin.py +++ b/lib/galaxy/web/controllers/admin.py @@ -60,6 +60,7 @@ class Admin( BaseController ): description = util.restore_text( params.description ) in_users = util.listify( params.get( 'in_users', [] ) ) in_groups = util.listify( params.get( 'in_groups', [] ) ) + create_group_for_role = params.get( 'create_group_for_role', 'no' ) if not name or not description: msg = "Enter a valid name and a description" elif trans.app.model.Role.filter( trans.app.model.Role.table.c.name==name ).first(): @@ -76,7 +77,14 @@ class Admin( BaseController ): for group in [ trans.app.model.Group.get( x ) for x in in_groups ]: gra = trans.app.model.GroupRoleAssociation( group, role ) gra.flush() - msg = "Role '%s' has been created with %d associated users and %d associated groups" % ( role.name, len( in_users ), len( in_groups ) ) + if create_group_for_role == 'yes': + # Create the group + group = trans.app.model.Group( name=name ) + group.flush() + msg = "Group '%s' has been created, and role '%s' has been created with %d associated users and %d associated groups" % \ + ( group.name, role.name, len( in_users ), len( in_groups ) ) + else: + msg = "Role '%s' has been created with %d associated users and %d associated groups" % ( role.name, len( in_users ), len( in_groups ) ) trans.response.send_redirect( web.url_for( controller='admin', action='roles', msg=util.sanitize_text( msg ), messagetype='done' ) ) trans.response.send_redirect( web.url_for( controller='admin', action='create_role', msg=util.sanitize_text( msg ), messagetype='error' ) ) out_users = [] @@ -201,23 +209,12 @@ class Admin( BaseController ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) - # Build a list of tuples which are roles followed by lists of groups and users - # [ ( role, [ group, group, group ], [ user, user ] ), ( role, [ group, group ], [ user ] ) ] - roles_groups_users = [] roles = trans.app.model.Role.query() \ .filter( trans.app.model.Role.table.c.deleted==True ) \ .order_by( trans.app.model.Role.table.c.name ) \ .all() - for role in roles: - groups = [] - for gra in role.groups: - groups.append( trans.app.model.Group.get( gra.group_id ) ) - users = [] - for ura in role.users: - users.append( trans.app.model.User.get( ura.user_id ) ) - roles_groups_users.append( ( role, groups, users ) ) return trans.fill_template( '/admin/dataset_security/deleted_roles.mako', - roles_groups_users=roles_groups_users, + roles=roles, msg=msg, messagetype=messagetype ) @web.expose @@ -398,23 +395,12 @@ class Admin( BaseController ): params = util.Params( kwd ) msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) - # Build a list of tuples which are groups followed by lists of members and roles - # [ ( group, [ member, member, member ], [ role, role ] ), ( group, [ member, member ], [ role ] ) ] - groups_members_roles = [] groups = trans.app.model.Group.query() \ .filter( trans.app.model.Group.table.c.deleted==True ) \ .order_by( trans.app.model.Group.table.c.name ) \ .all() - for group in groups: - members = [] - for uga in group.members: - members.append( trans.app.model.User.get( uga.user_id ) ) - roles = [] - for gra in group.roles: - roles.append( trans.app.model.Role.get( gra.role_id ) ) - groups_members_roles.append( ( group, members, roles ) ) return trans.fill_template( '/admin/dataset_security/deleted_groups.mako', - groups_members_roles=groups_members_roles, + groups=groups, msg=msg, messagetype=messagetype ) @web.expose @@ -627,8 +613,8 @@ class Admin( BaseController ): msg = util.restore_text( params.get( 'msg', '' ) ) messagetype = params.get( 'messagetype', 'done' ) users = trans.app.model.User.filter( and_( trans.app.model.User.table.c.deleted==True, trans.app.model.User.table.c.purged==False ) ) \ - .order_by( trans.app.model.User.table.c.email ) \ - .all() + .order_by( trans.app.model.User.table.c.email ) \ + .all() return trans.fill_template( '/admin/user/deleted_users.mako', users=users, msg=msg, messagetype=messagetype ) @web.expose @web.require_admin diff --git a/templates/admin/dataset_security/deleted_groups.mako b/templates/admin/dataset_security/deleted_groups.mako index 422c80073bd..391c33127e4 100644 --- a/templates/admin/dataset_security/deleted_groups.mako +++ b/templates/admin/dataset_security/deleted_groups.mako @@ -2,7 +2,7 @@ <%namespace file="/message.mako" import="render_msg" /> ## Render a row -<%def name="render_row( group, members, roles, ctr, anchored, curr_anchor )"> +<%def name="render_row( group, ctr, anchored, curr_anchor )"> %if ctr % 2 == 1: %else: @@ -17,18 +17,10 @@ - + ${len( group.members )} - + ${len( group.roles )} %if not anchored:
top
@@ -43,12 +35,12 @@ ${render_msg( msg, messagetype )} %endif -%if len( groups_members_roles ) == 0: +%if len( groups ) == 0: There are no deleted Galaxy groups %else: <% - render_quick_find = len( groups_members_roles ) > 50 + render_quick_find = len( groups ) > 50 ctr = 0 %> %if render_quick_find: @@ -69,34 +61,29 @@ %endif - + - %for ctr, group_tuple in enumerate( groups_members_roles ): - <% - group = group_tuple[0] - members = group_tuple[1] - roles = group_tuple[2] - %> + %for ctr, group in enumerate( groups ): %if render_quick_find and not group.name.upper().startswith( curr_anchor ): <% anchored = False %> %endif %if render_quick_find and group.name.upper().startswith( curr_anchor ): %if not anchored: - ${render_row( group, members, roles, ctr, anchored, curr_anchor )} + ${render_row( group, ctr, anchored, curr_anchor )} <% anchored = True %> %else: - ${render_row( group, members, roles, ctr, anchored, curr_anchor )} + ${render_row( group, ctr, anchored, curr_anchor )} %endif %elif render_quick_find: %for anchor in anchors[ anchor_loc: ]: %if group.name.upper().startswith( anchor ): %if not anchored: <% curr_anchor = anchor %> - ${render_row( group, members, roles, ctr, anchored, curr_anchor )} + ${render_row( group, ctr, anchored, curr_anchor )} <% anchored = True %> %else: - ${render_row( group, members, roles, ctr, anchored, curr_anchor )} + ${render_row( group, ctr, anchored, curr_anchor )} %endif <% anchor_loc = anchors.index( anchor ) @@ -105,7 +92,7 @@ %endif %endfor %else: - ${render_row( group, members, roles, ctr, True, '' )} + ${render_row( group, ctr, True, '' )} %endif %endfor
NameMembersUsers Roles
diff --git a/templates/admin/dataset_security/deleted_roles.mako b/templates/admin/dataset_security/deleted_roles.mako index 9975997d92e..e9a79c3bb9b 100644 --- a/templates/admin/dataset_security/deleted_roles.mako +++ b/templates/admin/dataset_security/deleted_roles.mako @@ -2,7 +2,7 @@ <%namespace file="/message.mako" import="render_msg" /> ## Render a row -<%def name="render_row( role, groups, users, ctr, anchored, curr_anchor )"> +<%def name="render_row( role, ctr, anchored, curr_anchor )"> %if ctr % 2 == 1: %else: @@ -16,19 +16,13 @@ Purge + ${role.description} + ${role.type} - + ${len( role.users )} - + ${len( role.groups )} %if not anchored:
top
@@ -43,12 +37,12 @@ ${render_msg( msg, messagetype )} %endif -%if len( roles_groups_users ) == 0: +%if len( roles ) == 0: There are no deleted Galaxy roles %else: <% - render_quick_find = len( roles_groups_users ) > 50 + render_quick_find = len( roles ) > 50 ctr = 0 %> %if render_quick_find: @@ -69,34 +63,31 @@ %endif - - + + + + - %for ctr, role_tuple in enumerate( roles_groups_users ): - <% - role = role_tuple[0] - groups = role_tuple[1] - users = role_tuple[2] - %> + %for ctr, role in enumerate( roles ): %if render_quick_find and not role.name.upper().startswith( curr_anchor ): <% anchored = False %> %endif %if render_quick_find and role.name.upper().startswith( curr_anchor ): %if not anchored: - ${render_row( role, groups, users, ctr, anchored, curr_anchor )} + ${render_row( role, ctr, anchored, curr_anchor )} <% anchored = True %> %else: - ${render_row( role, groups, users, ctr, anchored, curr_anchor )} + ${render_row( role, ctr, anchored, curr_anchor )} %endif %elif render_quick_find: %for anchor in anchors[ anchor_loc: ]: %if role.name.upper().startswith( anchor ): %if not anchored: <% curr_anchor = anchor %> - ${render_row( role, groups, users, ctr, anchored, curr_anchor )} + ${render_row( role, ctr, anchored, curr_anchor )} <% anchored = True %> %else: - ${render_row( role, groups, users, ctr, anchored, curr_anchor )} + ${render_row( role, ctr, anchored, curr_anchor )} %endif <% anchor_loc = anchors.index( anchor ) @@ -105,7 +96,7 @@ %endif %endfor %else: - ${render_row( role, groups, users, ctr, True, '' )} + ${render_row( role, ctr, True, '' )} %endif %endfor
NameAssociated GroupsAssociated UsersDescriptionTypeUsersGroups
diff --git a/templates/admin/dataset_security/group.mako b/templates/admin/dataset_security/group.mako index 354bf7ea6c9..dbaab7d0ada 100644 --- a/templates/admin/dataset_security/group.mako +++ b/templates/admin/dataset_security/group.mako @@ -53,24 +53,24 @@ $().ready(function() {
- Roles associated with '${group.name}'
+ ${render_select( "in_roles", in_roles )}
- Roles not associated with '${group.name}'
+ ${render_select( "out_roles", out_roles )}
- Users associated with '${group.name}'
+ ${render_select( "in_users", in_users )}
- Users not associated with '${group.name}'
+ ${render_select( "out_users", out_users )}
diff --git a/templates/admin/dataset_security/group_create.mako b/templates/admin/dataset_security/group_create.mako index 5ae5083cc47..69f5b274468 100644 --- a/templates/admin/dataset_security/group_create.mako +++ b/templates/admin/dataset_security/group_create.mako @@ -52,28 +52,29 @@ $().ready(function() {
- Name: + +
- Groups associated with new role
+ ${render_select( "in_roles", in_roles )}
- Groups not associated with new role
+ ${render_select( "out_roles", out_roles )}
- Users associated with new role
+ ${render_select( "in_users", in_users )}
- Users not associated with new role
+ ${render_select( "out_users", out_users )}
diff --git a/templates/admin/dataset_security/role.mako b/templates/admin/dataset_security/role.mako index 2b90190fc17..eda5a7f25a8 100644 --- a/templates/admin/dataset_security/role.mako +++ b/templates/admin/dataset_security/role.mako @@ -53,24 +53,24 @@ $().ready(function() {
- Users associated with '${role.name}'
+ ${render_select( "in_users", in_users )}
- Users not associated with '${role.name}'
+ ${render_select( "out_users", out_users )}
- Groups associated with '${role.name}'
+ ${render_select( "in_groups", in_groups )}
- Groups not associated with '${role.name}'
+ ${render_select( "out_groups", out_groups )}
diff --git a/templates/admin/dataset_security/role_create.mako b/templates/admin/dataset_security/role_create.mako index b987248bd5e..419ac019765 100644 --- a/templates/admin/dataset_security/role_create.mako +++ b/templates/admin/dataset_security/role_create.mako @@ -52,33 +52,40 @@ $().ready(function() {
- Name: - Description: + + +
+
+ +
- Groups associated with new role
+ ${render_select( "in_groups", in_groups )}
- Groups not associated with new role
+ ${render_select( "out_groups", out_groups )}
- Users associated with new role
+ ${render_select( "in_users", in_users )}
- Users not associated with new role
+ ${render_select( "out_users", out_users )}
+
+ Create a new group of the same name for this role +
diff --git a/templates/admin/dataset_security/user.mako b/templates/admin/dataset_security/user.mako index 5cc757ed1a0..af57707ecac 100644 --- a/templates/admin/dataset_security/user.mako +++ b/templates/admin/dataset_security/user.mako @@ -53,24 +53,24 @@ $().ready(function() {
- Roles associated with '${user.email}'
+ ${render_select( "in_roles", in_roles )}
- Roles not associated with '${user.email}'
+ ${render_select( "out_roles", out_roles )}
- Groups associated with '${user.email}'
+ ${render_select( "in_groups", in_groups )}
- Groups not associated with '${user.email}'
+ ${render_select( "out_groups", out_groups )}
diff --git a/templates/admin/user/create.mako b/templates/admin/user/create.mako index ef076e75096..1b438ed1edb 100644 --- a/templates/admin/user/create.mako +++ b/templates/admin/user/create.mako @@ -6,7 +6,7 @@ %endif
-
Create account
+
Create user account