[2] | 1 | from galaxy.web.base.controller import * |
---|
| 2 | from galaxy import model |
---|
| 3 | from galaxy.model.orm import * |
---|
| 4 | from galaxy.web.framework.helpers import time_ago, iff, grids |
---|
| 5 | import logging |
---|
| 6 | log = logging.getLogger( __name__ ) |
---|
| 7 | |
---|
| 8 | class UserListGrid( grids.Grid ): |
---|
| 9 | class EmailColumn( grids.TextColumn ): |
---|
| 10 | def get_value( self, trans, grid, user ): |
---|
| 11 | return user.email |
---|
| 12 | class UserNameColumn( grids.TextColumn ): |
---|
| 13 | def get_value( self, trans, grid, user ): |
---|
| 14 | if user.username: |
---|
| 15 | return user.username |
---|
| 16 | return 'not set' |
---|
| 17 | class StatusColumn( grids.GridColumn ): |
---|
| 18 | def get_value( self, trans, grid, user ): |
---|
| 19 | if user.purged: |
---|
| 20 | return "purged" |
---|
| 21 | elif user.deleted: |
---|
| 22 | return "deleted" |
---|
| 23 | return "" |
---|
| 24 | class GroupsColumn( grids.GridColumn ): |
---|
| 25 | def get_value( self, trans, grid, user ): |
---|
| 26 | if user.groups: |
---|
| 27 | return len( user.groups ) |
---|
| 28 | return 0 |
---|
| 29 | class RolesColumn( grids.GridColumn ): |
---|
| 30 | def get_value( self, trans, grid, user ): |
---|
| 31 | if user.roles: |
---|
| 32 | return len( user.roles ) |
---|
| 33 | return 0 |
---|
| 34 | class ExternalColumn( grids.GridColumn ): |
---|
| 35 | def get_value( self, trans, grid, user ): |
---|
| 36 | if user.external: |
---|
| 37 | return 'yes' |
---|
| 38 | return 'no' |
---|
| 39 | class LastLoginColumn( grids.GridColumn ): |
---|
| 40 | def get_value( self, trans, grid, user ): |
---|
| 41 | if user.galaxy_sessions: |
---|
| 42 | return self.format( user.galaxy_sessions[ 0 ].update_time ) |
---|
| 43 | return 'never' |
---|
| 44 | |
---|
| 45 | # Grid definition |
---|
| 46 | webapp = "galaxy" |
---|
| 47 | title = "Users" |
---|
| 48 | model_class = model.User |
---|
| 49 | template='/admin/user/grid.mako' |
---|
| 50 | default_sort_key = "email" |
---|
| 51 | columns = [ |
---|
| 52 | EmailColumn( "Email", |
---|
| 53 | key="email", |
---|
| 54 | model_class=model.User, |
---|
| 55 | link=( lambda item: dict( operation="information", id=item.id, webapp="galaxy" ) ), |
---|
| 56 | attach_popup=True, |
---|
| 57 | filterable="advanced" ), |
---|
| 58 | UserNameColumn( "User Name", |
---|
| 59 | key="username", |
---|
| 60 | model_class=model.User, |
---|
| 61 | attach_popup=False, |
---|
| 62 | filterable="advanced" ), |
---|
| 63 | GroupsColumn( "Groups", attach_popup=False ), |
---|
| 64 | RolesColumn( "Roles", attach_popup=False ), |
---|
| 65 | ExternalColumn( "External", attach_popup=False ), |
---|
| 66 | LastLoginColumn( "Last Login", format=time_ago ), |
---|
| 67 | StatusColumn( "Status", attach_popup=False ), |
---|
| 68 | # Columns that are valid for filtering but are not visible. |
---|
| 69 | grids.DeletedColumn( "Deleted", key="deleted", visible=False, filterable="advanced" ) |
---|
| 70 | ] |
---|
| 71 | columns.append( grids.MulticolFilterColumn( "Search", |
---|
| 72 | cols_to_filter=[ columns[0], columns[1] ], |
---|
| 73 | key="free-text-search", |
---|
| 74 | visible=False, |
---|
| 75 | filterable="standard" ) ) |
---|
| 76 | global_actions = [ |
---|
| 77 | grids.GridAction( "Create new user", dict( controller='admin', action='users', operation='create', webapp="galaxy" ) ) |
---|
| 78 | ] |
---|
| 79 | operations = [ |
---|
| 80 | grids.GridOperation( "Manage Roles and Groups", |
---|
| 81 | condition=( lambda item: not item.deleted ), |
---|
| 82 | allow_multiple=False, |
---|
| 83 | url_args=dict( webapp="galaxy", action="manage_roles_and_groups_for_user" ) ), |
---|
| 84 | grids.GridOperation( "Reset Password", |
---|
| 85 | condition=( lambda item: not item.deleted ), |
---|
| 86 | allow_multiple=True, |
---|
| 87 | allow_popup=False, |
---|
| 88 | url_args=dict( webapp="galaxy", action="reset_user_password" ) ) |
---|
| 89 | ] |
---|
| 90 | #TODO: enhance to account for trans.app.config.allow_user_deletion here so that we can eliminate these operations if |
---|
| 91 | # the setting is False |
---|
| 92 | #operations.append( grids.GridOperation( "Delete", condition=( lambda item: not item.deleted ), allow_multiple=True ) ) |
---|
| 93 | #operations.append( grids.GridOperation( "Undelete", condition=( lambda item: item.deleted and not item.purged ), allow_multiple=True ) ) |
---|
| 94 | #operations.append( grids.GridOperation( "Purge", condition=( lambda item: item.deleted and not item.purged ), allow_multiple=True ) ) |
---|
| 95 | standard_filters = [ |
---|
| 96 | grids.GridColumnFilter( "Active", args=dict( deleted=False ) ), |
---|
| 97 | grids.GridColumnFilter( "Deleted", args=dict( deleted=True, purged=False ) ), |
---|
| 98 | grids.GridColumnFilter( "Purged", args=dict( purged=True ) ), |
---|
| 99 | grids.GridColumnFilter( "All", args=dict( deleted='All' ) ) |
---|
| 100 | ] |
---|
| 101 | num_rows_per_page = 50 |
---|
| 102 | preserve_state = False |
---|
| 103 | use_paging = True |
---|
| 104 | def get_current_item( self, trans, **kwargs ): |
---|
| 105 | return trans.user |
---|
| 106 | |
---|
| 107 | class RoleListGrid( grids.Grid ): |
---|
| 108 | class NameColumn( grids.TextColumn ): |
---|
| 109 | def get_value( self, trans, grid, role ): |
---|
| 110 | return role.name |
---|
| 111 | class DescriptionColumn( grids.TextColumn ): |
---|
| 112 | def get_value( self, trans, grid, role ): |
---|
| 113 | if role.description: |
---|
| 114 | return role.description |
---|
| 115 | return '' |
---|
| 116 | class TypeColumn( grids.TextColumn ): |
---|
| 117 | def get_value( self, trans, grid, role ): |
---|
| 118 | return role.type |
---|
| 119 | class StatusColumn( grids.GridColumn ): |
---|
| 120 | def get_value( self, trans, grid, role ): |
---|
| 121 | if role.deleted: |
---|
| 122 | return "deleted" |
---|
| 123 | return "" |
---|
| 124 | class GroupsColumn( grids.GridColumn ): |
---|
| 125 | def get_value( self, trans, grid, role ): |
---|
| 126 | if role.groups: |
---|
| 127 | return len( role.groups ) |
---|
| 128 | return 0 |
---|
| 129 | class UsersColumn( grids.GridColumn ): |
---|
| 130 | def get_value( self, trans, grid, role ): |
---|
| 131 | if role.users: |
---|
| 132 | return len( role.users ) |
---|
| 133 | return 0 |
---|
| 134 | |
---|
| 135 | # Grid definition |
---|
| 136 | webapp = "galaxy" |
---|
| 137 | title = "Roles" |
---|
| 138 | model_class = model.Role |
---|
| 139 | template='/admin/dataset_security/role/grid.mako' |
---|
| 140 | default_sort_key = "name" |
---|
| 141 | columns = [ |
---|
| 142 | NameColumn( "Name", |
---|
| 143 | key="name", |
---|
| 144 | link=( lambda item: dict( operation="Manage users and groups", id=item.id, webapp="galaxy" ) ), |
---|
| 145 | model_class=model.Role, |
---|
| 146 | attach_popup=True, |
---|
| 147 | filterable="advanced" ), |
---|
| 148 | DescriptionColumn( "Description", |
---|
| 149 | key='description', |
---|
| 150 | model_class=model.Role, |
---|
| 151 | attach_popup=False, |
---|
| 152 | filterable="advanced" ), |
---|
| 153 | TypeColumn( "Type", |
---|
| 154 | key='type', |
---|
| 155 | model_class=model.Role, |
---|
| 156 | attach_popup=False, |
---|
| 157 | filterable="advanced" ), |
---|
| 158 | GroupsColumn( "Groups", attach_popup=False ), |
---|
| 159 | UsersColumn( "Users", attach_popup=False ), |
---|
| 160 | StatusColumn( "Status", attach_popup=False ), |
---|
| 161 | # Columns that are valid for filtering but are not visible. |
---|
| 162 | grids.DeletedColumn( "Deleted", key="deleted", visible=False, filterable="advanced" ) |
---|
| 163 | ] |
---|
| 164 | columns.append( grids.MulticolFilterColumn( "Search", |
---|
| 165 | cols_to_filter=[ columns[0], columns[1], columns[2] ], |
---|
| 166 | key="free-text-search", |
---|
| 167 | visible=False, |
---|
| 168 | filterable="standard" ) ) |
---|
| 169 | global_actions = [ |
---|
| 170 | grids.GridAction( "Add new role", dict( controller='admin', action='roles', operation='create' ) ) |
---|
| 171 | ] |
---|
| 172 | operations = [ grids.GridOperation( "Rename", |
---|
| 173 | condition=( lambda item: not item.deleted ), |
---|
| 174 | allow_multiple=False, |
---|
| 175 | url_args=dict( webapp="galaxy", action="rename_role" ) ), |
---|
| 176 | grids.GridOperation( "Delete", |
---|
| 177 | condition=( lambda item: not item.deleted ), |
---|
| 178 | allow_multiple=True, |
---|
| 179 | url_args=dict( webapp="galaxy", action="mark_role_deleted" ) ), |
---|
| 180 | grids.GridOperation( "Undelete", |
---|
| 181 | condition=( lambda item: item.deleted ), |
---|
| 182 | allow_multiple=True, |
---|
| 183 | url_args=dict( webapp="galaxy", action="undelete_role" ) ), |
---|
| 184 | grids.GridOperation( "Purge", |
---|
| 185 | condition=( lambda item: item.deleted ), |
---|
| 186 | allow_multiple=True, |
---|
| 187 | url_args=dict( webapp="galaxy", action="purge_role" ) ) ] |
---|
| 188 | standard_filters = [ |
---|
| 189 | grids.GridColumnFilter( "Active", args=dict( deleted=False ) ), |
---|
| 190 | grids.GridColumnFilter( "Deleted", args=dict( deleted=True ) ), |
---|
| 191 | grids.GridColumnFilter( "All", args=dict( deleted='All' ) ) |
---|
| 192 | ] |
---|
| 193 | num_rows_per_page = 50 |
---|
| 194 | preserve_state = False |
---|
| 195 | use_paging = True |
---|
| 196 | def apply_query_filter( self, trans, query, **kwargs ): |
---|
| 197 | return query.filter( model.Role.type != model.Role.types.PRIVATE ) |
---|
| 198 | |
---|
| 199 | class GroupListGrid( grids.Grid ): |
---|
| 200 | class NameColumn( grids.TextColumn ): |
---|
| 201 | def get_value( self, trans, grid, group ): |
---|
| 202 | return group.name |
---|
| 203 | class StatusColumn( grids.GridColumn ): |
---|
| 204 | def get_value( self, trans, grid, group ): |
---|
| 205 | if group.deleted: |
---|
| 206 | return "deleted" |
---|
| 207 | return "" |
---|
| 208 | class RolesColumn( grids.GridColumn ): |
---|
| 209 | def get_value( self, trans, grid, group ): |
---|
| 210 | if group.roles: |
---|
| 211 | return len( group.roles ) |
---|
| 212 | return 0 |
---|
| 213 | class UsersColumn( grids.GridColumn ): |
---|
| 214 | def get_value( self, trans, grid, group ): |
---|
| 215 | if group.members: |
---|
| 216 | return len( group.members ) |
---|
| 217 | return 0 |
---|
| 218 | |
---|
| 219 | # Grid definition |
---|
| 220 | webapp = "galaxy" |
---|
| 221 | title = "Groups" |
---|
| 222 | model_class = model.Group |
---|
| 223 | template='/admin/dataset_security/group/grid.mako' |
---|
| 224 | default_sort_key = "name" |
---|
| 225 | columns = [ |
---|
| 226 | NameColumn( "Name", |
---|
| 227 | key="name", |
---|
| 228 | link=( lambda item: dict( operation="Manage users and roles", id=item.id, webapp="galaxy" ) ), |
---|
| 229 | model_class=model.Group, |
---|
| 230 | attach_popup=True, |
---|
| 231 | filterable="advanced" ), |
---|
| 232 | UsersColumn( "Users", attach_popup=False ), |
---|
| 233 | RolesColumn( "Roles", attach_popup=False ), |
---|
| 234 | StatusColumn( "Status", attach_popup=False ), |
---|
| 235 | # Columns that are valid for filtering but are not visible. |
---|
| 236 | grids.DeletedColumn( "Deleted", key="deleted", visible=False, filterable="advanced" ) |
---|
| 237 | ] |
---|
| 238 | columns.append( grids.MulticolFilterColumn( "Search", |
---|
| 239 | cols_to_filter=[ columns[0], columns[1], columns[2] ], |
---|
| 240 | key="free-text-search", |
---|
| 241 | visible=False, |
---|
| 242 | filterable="standard" ) ) |
---|
| 243 | global_actions = [ |
---|
| 244 | grids.GridAction( "Add new group", dict( controller='admin', action='groups', operation='create', webapp="galaxy" ) ) |
---|
| 245 | ] |
---|
| 246 | operations = [ grids.GridOperation( "Rename", |
---|
| 247 | condition=( lambda item: not item.deleted ), |
---|
| 248 | allow_multiple=False, |
---|
| 249 | url_args=dict( webapp="galaxy", action="rename_group" ) ), |
---|
| 250 | grids.GridOperation( "Delete", |
---|
| 251 | condition=( lambda item: not item.deleted ), |
---|
| 252 | allow_multiple=True, |
---|
| 253 | url_args=dict( webapp="galaxy", action="mark_group_deleted" ) ), |
---|
| 254 | grids.GridOperation( "Undelete", |
---|
| 255 | condition=( lambda item: item.deleted ), |
---|
| 256 | allow_multiple=True, |
---|
| 257 | url_args=dict( webapp="galaxy", action="undelete_group" ) ), |
---|
| 258 | grids.GridOperation( "Purge", |
---|
| 259 | condition=( lambda item: item.deleted ), |
---|
| 260 | allow_multiple=True, |
---|
| 261 | url_args=dict( webapp="galaxy", action="purge_group" ) ) ] |
---|
| 262 | standard_filters = [ |
---|
| 263 | grids.GridColumnFilter( "Active", args=dict( deleted=False ) ), |
---|
| 264 | grids.GridColumnFilter( "Deleted", args=dict( deleted=True ) ), |
---|
| 265 | grids.GridColumnFilter( "All", args=dict( deleted='All' ) ) |
---|
| 266 | ] |
---|
| 267 | num_rows_per_page = 50 |
---|
| 268 | preserve_state = False |
---|
| 269 | use_paging = True |
---|
| 270 | |
---|
| 271 | class AdminGalaxy( BaseController, Admin ): |
---|
| 272 | |
---|
| 273 | user_list_grid = UserListGrid() |
---|
| 274 | role_list_grid = RoleListGrid() |
---|
| 275 | group_list_grid = GroupListGrid() |
---|