details: http://www.bx.psu.edu/hg/galaxy/rev/dcdbb13b0c76
changeset: 2757:dcdbb13b0c76
user: rc
date: Wed Sep 23 17:16:13 2009 -0400
description:
Cleaned up new/edit request code.
2 file(s) affected in this change:
lib/galaxy/web/controllers/requests.py
lib/galaxy/web/controllers/requests_admin.py
diffs (211 lines):
diff -r fbd7d0a0f596 -r dcdbb13b0c76 lib/galaxy/web/controllers/requests.py
--- a/lib/galaxy/web/controllers/requests.py Wed Sep 23 17:01:04 2009 -0400
+++ b/lib/galaxy/web/controllers/requests.py Wed Sep 23 17:16:13 2009 -0400
@@ -462,31 +462,16 @@
helptext='(Optional)'))
# libraries selectbox
- all_libraries = trans.app.model.Library.filter( trans.app.model.Library.table.c.deleted == False ) \
- .order_by( trans.app.model.Library.name ).all()
- user, roles = trans.get_user_and_roles()
- actions_to_check = [ trans.app.security_agent.permitted_actions.LIBRARY_ADD ]
- # The libraries dictionary looks like: { library : '1,2' }, library : '3' }
- # Its keys are the libraries that should be displayed for the current user and whose values are a
- # string of comma-separated folder ids, of the associated folders the should NOT be displayed.
- # The folders that should not be displayed may not be a complete list, but it is ultimately passed
- # to the calling method to keep from re-checking the same folders when the library / folder
- # select lists are rendered.
- libraries = odict()
- for library in all_libraries:
- can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check )
- if can_show:
- libraries[ library ] = hidden_folder_ids
- libui = self.__library_ui(trans, libraries, **kwd)
+ libui = self.__library_ui(trans, request=None, **kwd)
widgets = widgets + libui
- widgets = widgets + request_type.request_form.get_widgets( user, **kwd )
+ widgets = widgets + request_type.request_form.get_widgets( trans.user, **kwd )
return trans.fill_template( '/requests/new_request.mako',
select_request_type=select_request_type,
request_type=request_type,
widgets=widgets,
msg=msg,
messagetype=messagetype)
- def __library_ui(self, trans, libraries, request=None, **kwd):
+ def __library_ui(self, trans, request=None, **kwd):
params = util.Params( kwd )
lib_id = params.get( 'library_id', 'none' )
# if editing a request
@@ -497,6 +482,16 @@
else:
# new request
selected_lib = None
+ # get all permitted libraries for this user
+ all_libraries = trans.app.model.Library.filter( trans.app.model.Library.table.c.deleted == False ) \
+ .order_by( trans.app.model.Library.name ).all()
+ user, roles = trans.get_user_and_roles()
+ actions_to_check = [ trans.app.security_agent.permitted_actions.LIBRARY_ADD ]
+ libraries = odict()
+ for library in all_libraries:
+ can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check )
+ if can_show:
+ libraries[ library ] = hidden_folder_ids
lib_id_list = ['new'] + [str(lib.id) for lib in libraries.keys()]
lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=lib_id_list )
# fill up the options in the Library selectfield
@@ -513,7 +508,7 @@
else:
lib_list.add_option(lib.name, lib.id)
lib_list.refresh_on_change_values.append(lib.id)
- # new library
+ # new library option
if lib_id == 'new':
lib_list.add_option('Create a new data library', 'new', selected=True)
else:
@@ -539,8 +534,6 @@
else:
folder_list.add_option('Select one', 'none')
# get all show-able folders for the selected library
- user, roles = trans.get_user_and_roles()
- actions_to_check = [ trans.app.security_agent.permitted_actions.LIBRARY_ADD ]
showable_folders = trans.app.security_agent.get_showable_folders( user, roles,
selected_lib,
actions_to_check,
@@ -724,25 +717,9 @@
widget=TextField('desc', 40, desc),
helptext='(Optional)'))
# libraries selectbox
- all_libraries = trans.app.model.Library.filter( trans.app.model.Library.table.c.deleted == False ) \
- .order_by( trans.app.model.Library.name ).all()
- user, roles = trans.get_user_and_roles()
- actions_to_check = [ trans.app.security_agent.permitted_actions.LIBRARY_ADD ]
- # The libraries dictionary looks like:
- # { library : '1,2' }, library : '3' }
- # Its keys are the libraries that should be displayed for the current user and whose values are a
- # string of comma-separated folder ids, of the associated folders the should NOT be displayed.
- # The folders that should not be displayed may not be a complete list, but it is ultimately passed
- # to the calling method to keep from re-checking the same folders when the library / folder
- # select lists are rendered.
- libraries = {}
- for library in all_libraries:
- can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check )
- if can_show:
- libraries[ library ] = hidden_folder_ids
- libui = self.__library_ui(trans, libraries, request, **kwd)
+ libui = self.__library_ui(trans, request, **kwd)
widgets = widgets + libui
- widgets = widgets + request.type.request_form.get_widgets( user, request.values.content, **kwd )
+ widgets = widgets + request.type.request_form.get_widgets( trans.user, request.values.content, **kwd )
return trans.fill_template( '/requests/edit_request.mako',
select_request_type=select_request_type,
request_type=request.type,
diff -r fbd7d0a0f596 -r dcdbb13b0c76 lib/galaxy/web/controllers/requests_admin.py
--- a/lib/galaxy/web/controllers/requests_admin.py Wed Sep 23 17:01:04 2009 -0400
+++ b/lib/galaxy/web/controllers/requests_admin.py Wed Sep 23 17:16:13 2009 -0400
@@ -720,9 +720,20 @@
"""
params = util.Params( kwd )
lib_id = params.get( 'library_id', 'none' )
+ # if editing a request
+ if request and lib_id == 'none':
+ if request.library:
+ lib_id = str(request.library.id)
+ selected_lib = request.library
+ else:
+ # new request
+ selected_lib = None
+ # if new request no user is selected initially, none of the libraries are
+ # listed in the selectfield
if not user:
libraries = {}
else:
+ # get all permitted libraries for this user
all_libraries = trans.app.model.Library.filter( trans.app.model.Library.table.c.deleted == False ) \
.order_by( trans.app.model.Library.name ).all()
roles = user.all_roles()
@@ -733,43 +744,38 @@
# The folders that should not be displayed may not be a complete list, but it is ultimately passed
# to the calling method to keep from re-checking the same folders when the library / folder
# select lists are rendered.
- #
- # TODO: RC, when you add the folders select list to your request form, take advantage of the hidden_folder_ids
- # so that you do not need to check those same folders yet again when populating the select list.
- #
libraries = {}
for library in all_libraries:
can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check )
if can_show:
libraries[ library ] = hidden_folder_ids
+ # create the selectfield
lib_id_list = ['new'] + [str(lib.id) for lib in libraries.keys()]
lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=lib_id_list )
- folders = []
- if request and lib_id == 'none':
- if request.library:
- lib_id = str(request.library.id)
+ # first option
if lib_id == 'none':
lib_list.add_option('Select one', 'none', selected=True)
else:
lib_list.add_option('Select one', 'none')
+ # all the libraries available to the selected user
for lib, hidden_folder_ids in libraries.items():
if str(lib.id) == lib_id:
lib_list.add_option(lib.name, lib.id, selected=True)
- folders.append( lib.root_folder )
- for f in lib.root_folder.folders:
- if str(f.id) not in hidden_folder_ids.split(','):
- folders.append( f )
+ selected_lib, selected_hidden_folder_ids = lib, hidden_folder_ids.split(',')
else:
lib_list.add_option(lib.name, lib.id)
lib_list.refresh_on_change_values.append(lib.id)
+ # new data library option
if lib_id == 'new':
lib_list.add_option('Create a new data library', 'new', selected=True)
else:
lib_list.add_option('Create a new data library', 'new')
+ # widget
lib_widget = dict(label='Data library',
widget=lib_list,
helptext='Data library where the resultant dataset will be stored.')
- if folders:
+ if selected_lib:
+ # when editing a request
if request:
if request.folder:
current_fid = request.folder.id
@@ -778,11 +784,22 @@
else:
current_fid = params.get( 'folder_id', 'none' )
folder_list = SelectField( 'folder_id')
- for f in folders:
- if str(f.id) == current_fid:
+ # first option
+ if lib_id == 'none':
+ folder_list.add_option('Select one', 'none', selected=True)
+ else:
+ folder_list.add_option('Select one', 'none')
+ # get all show-able folders for the selected library
+ showable_folders = trans.app.security_agent.get_showable_folders( user, roles,
+ selected_lib,
+ actions_to_check,
+ selected_hidden_folder_ids )
+ for f in showable_folders:
+ if str(f.id) == str(current_fid):
folder_list.add_option(f.name, f.id, selected=True)
else:
folder_list.add_option(f.name, f.id)
+ # folder widget
folder_widget = dict(label='Folder',
widget=folder_list,
helptext='Folder of the selected data library where the resultant dataset will be stored.')
@@ -793,7 +810,7 @@
helptext='Enter a name here to request a new data library')
return [lib_widget, new_lib]
else:
- if folders:
+ if selected_lib:
return [lib_widget, folder_widget]
else:
return [lib_widget]
details: http://www.bx.psu.edu/hg/galaxy/rev/c7446ed27839
changeset: 2754:c7446ed27839
user: Greg Von Kuster <greg(a)bx.psu.edu>
date: Wed Sep 23 11:08:36 2009 -0400
description:
Added new get_showable_folders() method to the security agent for use by the sample requests. The sample request UI is now a bit broken.
2 file(s) affected in this change:
lib/galaxy/security/__init__.py
lib/galaxy/web/controllers/requests.py
diffs (94 lines):
diff -r be3c27418de9 -r c7446ed27839 lib/galaxy/security/__init__.py
--- a/lib/galaxy/security/__init__.py Wed Sep 23 09:24:10 2009 -0400
+++ b/lib/galaxy/security/__init__.py Wed Sep 23 11:08:36 2009 -0400
@@ -425,7 +425,8 @@
comma-separated string of folder ids whose folders do NOT meet the criteria for showing. Along with
the string, True is returned if the current user has permission to perform any 1 of actions_to_check
on library_item. Otherwise, cycle through all sub-folders in library_item until one is found that meets
- this criteria, if it exists.
+ this criteria, if it exists. This method does not necessarily scan the entire library as it returns
+ when it finds the first library_item that allows user to perform any one action in actions_to_check.
"""
for action in actions_to_check:
if self.allow_library_item_action( user, roles, action, library_item ):
@@ -442,6 +443,22 @@
else:
hidden_folder_ids = '%d' % folder.id
return False, hidden_folder_ids
+ def get_showable_folders( self, user, roles, library_item, actions_to_check, showable_folders=[] ):
+ """
+ This method must be sent an instance of Library(), all the folders of which are scanned to determine if
+ user is allowed to perform any action in actions_to_check. A list of showable folders is generated.
+ This method scans the entire library.
+ """
+ if isinstance( library_item, self.model.Library ):
+ return self.get_showable_folders( user, roles, library_item.root_folder, actions_to_check, showable_folders=showable_folders )
+ if isinstance( library_item, self.model.LibraryFolder ):
+ for action in actions_to_check:
+ if self.allow_library_item_action( user, roles, action, library_item ):
+ showable_folders.append( library_item )
+ break
+ for folder in library_item.active_folders:
+ self.get_showable_folders( user, roles, folder, actions_to_check, showable_folders=showable_folders )
+ return showable_folders
def set_entity_user_associations( self, users=[], roles=[], groups=[], delete_existing_assocs=True ):
for user in users:
if delete_existing_assocs:
@@ -495,6 +512,8 @@
comma-separated string of folder ids whose folders do NOT meet the criteria for showing. Along
with the string, True is returned if the current user has permission to access folder. Otherwise,
cycle through all sub-folders in folder until one is found that meets this criteria, if it exists.
+ This method does not necessarily scan the entire library as it returns when it finds the first
+ folder that is accessible to user.
"""
action = self.permitted_actions.DATASET_ACCESS
lddas = self.sa_session.query( self.model.LibraryDatasetDatasetAssociation ) \
diff -r be3c27418de9 -r c7446ed27839 lib/galaxy/web/controllers/requests.py
--- a/lib/galaxy/web/controllers/requests.py Wed Sep 23 09:24:10 2009 -0400
+++ b/lib/galaxy/web/controllers/requests.py Wed Sep 23 11:08:36 2009 -0400
@@ -474,9 +474,9 @@
# select lists are rendered.
libraries = odict()
for library in all_libraries:
- can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check )
- if can_show:
- libraries[ library ] = hidden_folder_ids
+ showable_folders = trans.app.security_agent.get_showable_folders( user, roles, library, actions_to_check )
+ if showable_folders:
+ libraries[ library ] = showable_folders
libui = self.__library_ui(libraries, **kwd)
widgets = widgets + libui
widgets = widgets + request_type.request_form.get_widgets( user, **kwd )
@@ -491,7 +491,6 @@
lib_id = params.get( 'library_id', 'none' )
lib_id_list = ['new'] + [str(lib.id) for lib in libraries.keys()]
lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=lib_id_list )
- folders = []
if request and lib_id == 'none':
if request.library:
lib_id = str(request.library.id)
@@ -499,13 +498,9 @@
lib_list.add_option('Select one', 'none', selected=True)
else:
lib_list.add_option('Select one', 'none')
- for lib, hidden_folder_ids in libraries.items():
+ for lib, folders in libraries.items():
if str(lib.id) == lib_id:
lib_list.add_option(lib.name, lib.id, selected=True)
- folders.append( lib.root_folder )
- for f in lib.root_folder.folders:
- if str(f.id) not in hidden_folder_ids.split(','):
- folders.append( f )
else:
lib_list.add_option(lib.name, lib.id)
lib_list.refresh_on_change_values.append(lib.id)
@@ -516,7 +511,8 @@
lib_widget = dict(label='Data library',
widget=lib_list,
helptext='Data library where the resultant dataset will be stored.')
- if folders:
+ selected, value = lib_widget[ 'widget' ].get_selected()
+ if selected not in [ 'new', 'none' ]:
if request:
if request.folder:
current_fid = request.folder.id
details: http://www.bx.psu.edu/hg/galaxy/rev/69615210cf99
changeset: 2755:69615210cf99
user: rc
date: Wed Sep 23 13:25:22 2009 -0400
description:
Fixed a bug in the new/edit request code. Now user can select all permitted folders & subfolders of a selected library when creating or editing a request.
2 file(s) affected in this change:
lib/galaxy/security/__init__.py
lib/galaxy/web/controllers/requests.py
diffs (150 lines):
diff -r c7446ed27839 -r 69615210cf99 lib/galaxy/security/__init__.py
--- a/lib/galaxy/security/__init__.py Wed Sep 23 11:08:36 2009 -0400
+++ b/lib/galaxy/security/__init__.py Wed Sep 23 13:25:22 2009 -0400
@@ -443,19 +443,21 @@
else:
hidden_folder_ids = '%d' % folder.id
return False, hidden_folder_ids
- def get_showable_folders( self, user, roles, library_item, actions_to_check, showable_folders=[] ):
+ def get_showable_folders( self, user, roles, library_item, actions_to_check, hidden_folder_ids=[], showable_folders=[] ):
"""
This method must be sent an instance of Library(), all the folders of which are scanned to determine if
- user is allowed to perform any action in actions_to_check. A list of showable folders is generated.
- This method scans the entire library.
+ user is allowed to perform any action in actions_to_check. The param hidden_folder_ids, if passed, should
+ contain a list of folder IDs which was generated when the library was previously scanned
+ using the same actions_to_check. A list of showable folders is generated. This method scans the entire library.
"""
if isinstance( library_item, self.model.Library ):
- return self.get_showable_folders( user, roles, library_item.root_folder, actions_to_check, showable_folders=showable_folders )
+ return self.get_showable_folders( user, roles, library_item.root_folder, actions_to_check, showable_folders=[] )
if isinstance( library_item, self.model.LibraryFolder ):
- for action in actions_to_check:
- if self.allow_library_item_action( user, roles, action, library_item ):
- showable_folders.append( library_item )
- break
+ if library_item.id not in hidden_folder_ids:
+ for action in actions_to_check:
+ if self.allow_library_item_action( user, roles, action, library_item ):
+ showable_folders.append( library_item )
+ break
for folder in library_item.active_folders:
self.get_showable_folders( user, roles, folder, actions_to_check, showable_folders=showable_folders )
return showable_folders
diff -r c7446ed27839 -r 69615210cf99 lib/galaxy/web/controllers/requests.py
--- a/lib/galaxy/web/controllers/requests.py Wed Sep 23 11:08:36 2009 -0400
+++ b/lib/galaxy/web/controllers/requests.py Wed Sep 23 13:25:22 2009 -0400
@@ -474,45 +474,57 @@
# select lists are rendered.
libraries = odict()
for library in all_libraries:
- showable_folders = trans.app.security_agent.get_showable_folders( user, roles, library, actions_to_check )
- if showable_folders:
- libraries[ library ] = showable_folders
- libui = self.__library_ui(libraries, **kwd)
+ can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check )
+ if can_show:
+ libraries[ library ] = hidden_folder_ids
+ libui = self.__library_ui(trans, libraries, **kwd)
widgets = widgets + libui
widgets = widgets + request_type.request_form.get_widgets( user, **kwd )
return trans.fill_template( '/requests/new_request.mako',
select_request_type=select_request_type,
- request_type=request_type,
+ request_type=request_type,
widgets=widgets,
msg=msg,
messagetype=messagetype)
- def __library_ui(self, libraries, request=None, **kwd):
+ def __library_ui(self, trans, libraries, request=None, **kwd):
params = util.Params( kwd )
lib_id = params.get( 'library_id', 'none' )
- lib_id_list = ['new'] + [str(lib.id) for lib in libraries.keys()]
- lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=lib_id_list )
+ # if editing a request
if request and lib_id == 'none':
if request.library:
lib_id = str(request.library.id)
+ selected_lib = request.library
+ else:
+ # new request
+ selected_lib = None
+ lib_id_list = ['new'] + [str(lib.id) for lib in libraries.keys()]
+ lib_list = SelectField( 'library_id', refresh_on_change=True, refresh_on_change_values=lib_id_list )
+ # fill up the options in the Library selectfield
+ # first option
if lib_id == 'none':
lib_list.add_option('Select one', 'none', selected=True)
else:
lib_list.add_option('Select one', 'none')
- for lib, folders in libraries.items():
+ # all the libraries available to the user
+ for lib, hidden_folder_ids in libraries.items():
if str(lib.id) == lib_id:
lib_list.add_option(lib.name, lib.id, selected=True)
+ selected_lib, selected_hidden_folder_ids = lib, hidden_folder_ids.split(',')
else:
lib_list.add_option(lib.name, lib.id)
lib_list.refresh_on_change_values.append(lib.id)
+ # new library
if lib_id == 'new':
lib_list.add_option('Create a new data library', 'new', selected=True)
else:
lib_list.add_option('Create a new data library', 'new')
+ # data library widget
lib_widget = dict(label='Data library',
widget=lib_list,
helptext='Data library where the resultant dataset will be stored.')
- selected, value = lib_widget[ 'widget' ].get_selected()
- if selected not in [ 'new', 'none' ]:
+ # show the folder widget only if the user has selected a valid library above
+ if selected_lib:
+ # when editing a request
if request:
if request.folder:
current_fid = request.folder.id
@@ -521,11 +533,24 @@
else:
current_fid = params.get( 'folder_id', 'none' )
folder_list = SelectField( 'folder_id')
- for f in folders:
- if str(f.id) == current_fid:
+ # first option
+ if lib_id == 'none':
+ folder_list.add_option('Select one', 'none', selected=True)
+ else:
+ folder_list.add_option('Select one', 'none')
+ # get all show-able folders for the selected library
+ user, roles = trans.get_user_and_roles()
+ actions_to_check = [ trans.app.security_agent.permitted_actions.LIBRARY_ADD ]
+ showable_folders = trans.app.security_agent.get_showable_folders( user, roles,
+ selected_lib,
+ actions_to_check,
+ selected_hidden_folder_ids )
+ for f in showable_folders:
+ if str(f.id) == str(current_fid):
folder_list.add_option(f.name, f.id, selected=True)
else:
folder_list.add_option(f.name, f.id)
+ # folder widget
folder_widget = dict(label='Folder',
widget=folder_list,
helptext='Folder of the selected data library where the resultant dataset will be stored.')
@@ -536,7 +561,7 @@
helptext='Enter a name here to request a new data library')
return [lib_widget, new_lib]
else:
- if folders:
+ if selected_lib:
return [lib_widget, folder_widget]
else:
return [lib_widget]
@@ -715,7 +740,7 @@
can_show, hidden_folder_ids = trans.app.security_agent.show_library_item( user, roles, library, actions_to_check )
if can_show:
libraries[ library ] = hidden_folder_ids
- libui = self.__library_ui(libraries, request, **kwd)
+ libui = self.__library_ui(trans, libraries, request, **kwd)
widgets = widgets + libui
widgets = widgets + request.type.request_form.get_widgets( user, request.values.content, **kwd )
return trans.fill_template( '/requests/edit_request.mako',