Ted, have you considered if you can do what you need with the 'allowed' method of GridOperation? It let's you define a callable condition that determines if that operation is allowed on a given item. It does not have access to trans but it would be reasonable to add that.
--
James Taylor, Assistant Professor, Biology/CS, Emory UniversityOn Mon, Jan 7, 2013 at 2:55 AM, Ted Goldstein <ted@soe.ucsc.edu> wrote:HI Greg,I thought of this. But there is potential bug in it which has security implications. Though it is a low probability event, I have seen this sort of leakage happen in other environments where user data was stuck into globally shared objects. The grid object is shared by all requests. You are storing user specific data in the GridOperation. So if there is an unfortunate context switch in the middle of the setting the ids int the grid operation but before they are used, the user specific data of one user will be visible to the other user. Of course the solution is to make sure the grid is not shared (e.g. it is instantiated or deep-copied) in the function or at least in the request thread that uses it.Thanks, I will do this with on a deepcopy of the Grid to ensure that it doesn't et shared between threads. You might want to chsnge the code in repository.pyBest regards,TedOn Jan 6, 2013, at 4:12 PM, Greg Von Kuster wrote:Hi Ted,If I understand what your trying to do, I believe I've implemented grid operations similar to what your attempting in several places in the Galaxy tool shed, so checking the various grid classes and associated methods in /lib/galaxy/webapps/community/controllers will give you some examples.The trick is that you need to define the grid operations outside of the grid class itself, but in the method that calls the grid (but just before the call to display it) so the request parameters will include the selected page ids.For an example of what I'm talking about, see the following method on about line #740 in my ~/lib/galaxy/webapps/community/controllers/repository.py code file.Here is the relevant snippet of code.def browse_valid_repositories( self, trans, **kwd ):...irrelevant code not displayed...repository_id = Nonefor k, v in kwd.items():changset_revision_str = 'changeset_revision_'if k.startswith( changset_revision_str ):repository_id = trans.security.encode_id( int( k.lstrip( changset_revision_str ) ) )repository = suc.get_repository_in_tool_shed( trans, repository_id )if repository.tip( trans.app ) != v:return trans.response.send_redirect( web.url_for( controller='repository',action='preview_tools_in_changeset',repository_id=trans.security.encode_id( repository.id ),changeset_revision=v ) )url_args = dict( action='browse_valid_repositories',operation='preview_tools_in_changeset',repository_id=repository_id )self.valid_repository_grid.operations = [ grids.GridOperation( "Preview and install",url_args=url_args,allow_multiple=False,async_compatible=False ) ]return self.valid_repository_grid( trans, **kwd )Sorry if I misunderstood your dilemma and this does not help you.Greg Von KusterOn Jan 6, 2013, at 4:52 PM, Ted Goldstein wrote:Hi,___________________________________________________________Based on a suggestion by James Taylor, I am working on extending the security model so that pages can use the same RBAC permission system used in libraries. In fact, many of my pages have assets (images, etc) which are stored in a library. So this is a natural model. Therefore I want to make a connection between Pages and Libraries. that is visible to the user and extends the security model of page access. The owner of the page essentially grants anyone with access to a library access to the page as well. This part is going well. It is few lines of code in the page access security code.The implementation is to that I created a many-to-many relationship table LibraryPageAssociation, that "Connects" Page objects to Library Objects. Grid objects provide a convenient interface to selecting multiple of each. In fact, I just extend the regular PageListGrid instantiated by the /page/list action to select the pages by adding a new GridOperation labeled "Select Libraries" which then brings up new Grid LibrarySelectGrid (similar to the one visualization.py, but simpler) it has one GridOperation labeled "Connect Pages to Libraries" (allows_multi=True).Here is the problem: I can pass the page ids (enoded) into the mako page that carries the LibrarySelectGrid. But I don't see a way to parametriize "Connect Pages to Libraries" GridOperation to pass anything out of the page except the Grid Sttate itself. Do I have to extend GridOperation or am I missing something? I have tried a number of things with url_args and global_operation lambda. But these execute at controller instantiation time -- much too early. I need the page_ids that the user selects in the PageListGrid.See the ???? in the bold region below.Thanks,Teddiff -r 13098c7dc32a lib/galaxy/webapps/galaxy/controllers/page.py--- a/lib/galaxy/webapps/galaxy/controllers/page.py Sat Jan 05 17:40:49 2013 -0800+++ b/lib/galaxy/webapps/galaxy/controllers/page.py Sun Jan 06 13:47:05 2013 -0800@@ -1,3 +1,4 @@+import pdbfrom sqlalchemy import desc, and_from galaxy import model, webfrom galaxy.web import error, url_for@@ -8,9 +9,6 @@from galaxy.util.odict import odictfrom galaxy.util.json import from_json_stringfrom galaxy.web.base.controller import *-"""-from galaxy.webapps.galaxy.controllers.library import LibraryListGrid;-"""def format_bool( b ):@@ -54,6 +52,7 @@grids.GridOperation( "Edit content", allow_multiple=False, url_args=dict( action='edit_content') ),grids.GridOperation( "Edit attributes", allow_multiple=False, url_args=dict( action='edit') ),grids.GridOperation( "Share or Publish", allow_multiple=False, condition=( lambda item: not item.deleted ), async_compatible=False ),+ grids.GridOperation( "Select Library", allow_multiple=True, condition=( lambda item: not item.deleted ), async_compatible=False ),grids.GridOperation( "Delete", confirm="Are you sure you want to delete this page?" ),]def apply_query_filter( self, trans, query, **kwargs ):@@ -198,24 +197,37 @@key="free-text-search", visible=False, filterable="standard" ))-"""-class PageLibrariesSelectionGrid( LibraryListGrid ):- ""- Grid enables user to select multiple Libraries, which are then connected to the page.- ""- title = "Select Librariies"- template='/tracks/history_select_grid.mako'+class LibrarySelectionGrid( ItemSelectionGrid ):+ """ Grid for selecting library. """+ # Grid definition.+ title = "Select Libraries "model_class = model.Library- datasets_action = 'list_library_datasets'- datasets_param = "f-library"columns = [- NameColumn( "Library Name", key="name", filterable="standard" )+ grids.TextColumn( "Library Name", key="name", filterable="standard" ),+ grids.TextColumn( "Description", key="description", filterable="advanced" ),+ grids.TextColumn( "Synopsis", key="synopsis", filterable="advanced" )]- num_rows_per_page = 10- use_async = True- use_paging = True-"""-+ operations = [+ grids.GridOperation( "Connect to Library", allow_multiple=True,+ url_args=???????????,+ async_compatible=False ),+ ]++ def apply_query_filter( self, trans, query, **kwargs ):+ """Return all data libraries that the received user can access"""+ user = trans.user+ current_user_role_ids = [ role.id for role in user.all_roles() ]+ library_access_action = trans.app.model.Library.permitted_actions.LIBRARY_ACCESS.action+ restricted_library_ids = [ lp.library_id for lp in trans.sa_session.query( trans.model.LibraryPermissions ) \+ .filter( trans.model.LibraryPermissions.table.c.action == library_access_action ) \+ .distinct() ]+ accessible_restricted_library_ids = [ lp.library_id for lp in trans.sa_session.query( trans.model.LibraryPermissions ) \+ .filter( and_( trans.model.LibraryPermissions.table.c.action == library_access_action,+ trans.model.LibraryPermissions.table.c.role_id.in_( current_user_role_ids ) ) ) ]+ # Filter to get libraries accessible by the current user. Get both+ # public libraries and restricted libraries accessible by the current user.+ return query.filter( and_( trans.model.Library.table.c.deleted == False, ( or_( not_( trans.model.Library.table.c.id.in_( restricted_library_ids ) ), trans.model.Library.table.c.id.in_( accessible_restricted_library_ids ) ) ) ) ) .order_by( trans.app.model.Library.name )+@ -309,16 +321,28 @@_datasets_selection_grid = HistoryDatasetAssociationSelectionGrid()_page_selection_grid = PageSelectionGrid()_visualization_selection_grid = VisualizationSelectionGrid()- """- _libraries_selection_grid = LibrariesSelectionGrid()- """+ _libraries_selection_grid = LibrarySelectionGrid()@web.expose@web.require_login()def list( self, trans, *args, **kwargs ):""" List user's pages. """# Handle operation- if 'operation' in kwargs and 'id' in kwargs:+++ # library connect step 1+ if 'operation' in kwargs and kwargs['operation'] == 'select library':+ ids = util.listify( kwargs['id'] )+ session = trans.sa_session+ pages = [session.query( model.Page ).get( trans.security.decode_id( id ) ) for id in ids]+ return trans.fill_template( "page/library_datasets_select_grid.mako", pages=pages, grid=self._libraries_selection_grid, **kwargs)++ # library connect step 2+ elif 'operation' in kwargs and kwargs['operation'] == 'connect to library':+ # TBD+ pdb.set_trace()++ elif 'operation' in kwargs and 'id' in kwargs:session = trans.sa_sessionoperation = kwargs['operation'].lower()ids = util.listify( kwargs['id'] )@@ -765,14 +789,12 @@# Render the list viewreturn self._workflow_selection_grid( trans, **kwargs )- """@web.expose@web.require_login("select libraries from all accessible libraries")def list_libraries_for_selection( self, trans, **kwargs ):" Returns HTML that enables a user to select one or more libraries. "# Render the list viewreturn self._libraries_selection_grid( trans, **kwargs )- """@web.expose@web.require_login("select a visualization from saved visualizations")
Please keep all replies on the list by using "reply all"
in your mail client. To manage your subscriptions to this
and other Galaxy lists, please use the interface at:
http://lists.bx.psu.edu/
___________________________________________________________
Please keep all replies on the list by using "reply all"
in your mail client. To manage your subscriptions to this
and other Galaxy lists, please use the interface at:
http://lists.bx.psu.edu/