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,
Ted
diff -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 pdb
from sqlalchemy import desc, and_
from galaxy import model, web
from galaxy.web import error, url_for
@@ -8,9 +9,6 @@
from galaxy.util.odict import odict
from galaxy.util.json import from_json_string
from 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_session
operation = kwargs['operation'].lower()
ids = util.listify( kwargs['id'] )
@@ -765,14 +789,12 @@
# Render the list view
return 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 view
return 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/