1 | from galaxy.web.base.controller import * |
---|
2 | from galaxy.web.framework.helpers import time_ago, iff, grids |
---|
3 | from galaxy.model.orm import * |
---|
4 | from galaxy.datatypes import sniff |
---|
5 | from galaxy import model, util |
---|
6 | from galaxy.util.odict import odict |
---|
7 | |
---|
8 | log = logging.getLogger( __name__ ) |
---|
9 | |
---|
10 | class LibraryListGrid( grids.Grid ): |
---|
11 | class NameColumn( grids.TextColumn ): |
---|
12 | def get_value( self, trans, grid, library ): |
---|
13 | return library.name |
---|
14 | class DescriptionColumn( grids.TextColumn ): |
---|
15 | def get_value( self, trans, grid, library ): |
---|
16 | if library.description: |
---|
17 | return library.description |
---|
18 | return '' |
---|
19 | # Grid definition |
---|
20 | title = "Data Libraries" |
---|
21 | model_class = model.Library |
---|
22 | template='/library/grid.mako' |
---|
23 | default_sort_key = "name" |
---|
24 | columns = [ |
---|
25 | NameColumn( "Name", |
---|
26 | key="name", |
---|
27 | model_class=model.Library, |
---|
28 | link=( lambda library: dict( operation="browse", id=library.id ) ), |
---|
29 | attach_popup=False, |
---|
30 | filterable="advanced" ), |
---|
31 | DescriptionColumn( "Description", |
---|
32 | key="description", |
---|
33 | model_class=model.Library, |
---|
34 | attach_popup=False, |
---|
35 | filterable="advanced" ), |
---|
36 | ] |
---|
37 | columns.append( grids.MulticolFilterColumn( "Search", |
---|
38 | cols_to_filter=[ columns[0], columns[1] ], |
---|
39 | key="free-text-search", |
---|
40 | visible=False, |
---|
41 | filterable="standard" ) ) |
---|
42 | standard_filters = [] |
---|
43 | default_filter = dict( name="All", description="All", deleted="False", purged="False" ) |
---|
44 | num_rows_per_page = 50 |
---|
45 | preserve_state = False |
---|
46 | use_paging = True |
---|
47 | def build_initial_query( self, trans, **kwargs ): |
---|
48 | return trans.sa_session.query( self.model_class ).filter( self.model_class.table.c.deleted == False ) |
---|
49 | def apply_query_filter( self, trans, query, **kwd ): |
---|
50 | current_user_role_ids = [ role.id for role in trans.get_current_user_roles() ] |
---|
51 | library_access_action = trans.app.security_agent.permitted_actions.LIBRARY_ACCESS.action |
---|
52 | restricted_library_ids = [ lp.library_id for lp in trans.sa_session.query( trans.model.LibraryPermissions ) \ |
---|
53 | .filter( trans.model.LibraryPermissions.table.c.action == library_access_action ) \ |
---|
54 | .distinct() ] |
---|
55 | accessible_restricted_library_ids = [ lp.library_id for lp in trans.sa_session.query( trans.model.LibraryPermissions ) \ |
---|
56 | .filter( and_( trans.model.LibraryPermissions.table.c.action == library_access_action, |
---|
57 | trans.model.LibraryPermissions.table.c.role_id.in_( current_user_role_ids ) ) ) ] |
---|
58 | if not trans.user: |
---|
59 | # Filter to get only public libraries, a library whose id |
---|
60 | # is not in restricted_library_ids is a public library |
---|
61 | return query.filter( not_( trans.model.Library.table.c.id.in_( restricted_library_ids ) ) ) |
---|
62 | else: |
---|
63 | # Filter to get libraries accessible by the current user, get both |
---|
64 | # public libraries and restricted libraries accessible by the current user. |
---|
65 | return query.filter( or_( not_( trans.model.Library.table.c.id.in_( restricted_library_ids ) ), |
---|
66 | trans.model.Library.table.c.id.in_( accessible_restricted_library_ids ) ) ) |
---|
67 | class Library( BaseController ): |
---|
68 | |
---|
69 | library_list_grid = LibraryListGrid() |
---|
70 | |
---|
71 | @web.expose |
---|
72 | def index( self, trans, **kwd ): |
---|
73 | params = util.Params( kwd ) |
---|
74 | message = util.restore_text( params.get( 'message', '' ) ) |
---|
75 | status = params.get( 'status', 'done' ) |
---|
76 | return trans.fill_template( "/library/index.mako", |
---|
77 | default_action=params.get( 'default_action', None ), |
---|
78 | message=message, |
---|
79 | status=status ) |
---|
80 | @web.expose |
---|
81 | def browse_libraries( self, trans, **kwd ): |
---|
82 | if 'operation' in kwd: |
---|
83 | operation = kwd['operation'].lower() |
---|
84 | if operation == "browse": |
---|
85 | return trans.response.send_redirect( web.url_for( controller='library_common', |
---|
86 | action='browse_library', |
---|
87 | cntrller='library', |
---|
88 | **kwd ) ) |
---|
89 | # Render the list view |
---|
90 | return self.library_list_grid( trans, **kwd ) |
---|