[hg] galaxy 2754: Added new get_showable_folders() method to the...
details: http://www.bx.psu.edu/hg/galaxy/rev/c7446ed27839 changeset: 2754:c7446ed27839 user: Greg Von Kuster <greg@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
participants (1)
-
Nate Coraor