def build_initial_query(self, trans, **kwd): clause_list = [] tool_shed_repository_ids = util.listify( kwd.get('tool_shed_repository_ids', None)) if tool_shed_repository_ids: for tool_shed_repository_id in tool_shed_repository_ids: clause_list.append(self.model_class.table.c.id == trans. security.decode_id(tool_shed_repository_id)) if clause_list: return trans.install_model.context.query( self.model_class ) \ .filter( or_( *clause_list ) ) for tool_shed_repository in trans.install_model.context.query( self.model_class ) \ .filter( self.model_class.table.c.deleted == False ): if tool_shed_repository.status in [ trans.install_model.ToolShedRepository.installation_status. NEW, trans.install_model.ToolShedRepository. installation_status.CLONING, trans.install_model.ToolShedRepository.installation_status. SETTING_TOOL_VERSIONS, trans.install_model.ToolShedRepository.installation_status. INSTALLING_TOOL_DEPENDENCIES, trans.install_model.ToolShedRepository.installation_status. LOADING_PROPRIETARY_DATATYPES ]: clause_list.append( self.model_class.table.c.id == tool_shed_repository.id) if clause_list: return trans.install_model.context.query( self.model_class ) \ .filter( or_( *clause_list ) ) return trans.install_model.context.query( self.model_class ) \ .filter( self.model_class.table.c.status == trans.install_model.ToolShedRepository.installation_status.NEW )
def list( self, trans, deleted=False ): """ Return a list of libraries from the DB. :param deleted: if True, show only ``deleted`` libraries, if False show only ``non-deleted`` :type deleted: boolean (optional) :returns: query that will emit all accessible libraries :rtype: sqlalchemy query """ is_admin = trans.user_is_admin() query = trans.sa_session.query( trans.app.model.Library ) if is_admin: if deleted is None: # Flag is not specified, do not filter on it. pass elif deleted: query = query.filter( trans.app.model.Library.table.c.deleted == True ) else: query = query.filter( trans.app.model.Library.table.c.deleted == False ) else: # Nonadmins can't see deleted libraries current_user_role_ids = [ role.id for role in trans.get_current_user_roles() ] library_access_action = trans.app.security_agent.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 ) ) ) ) ] query = query.filter( or_( not_( trans.model.Library.table.c.id.in_( restricted_library_ids ) ), trans.model.Library.table.c.id.in_( accessible_restricted_library_ids ) ) ) return query
def apply_query_filter(self, trans, query, **kwd): current_user_role_ids = [ role.id for role in trans.get_current_user_roles() ] library_access_action = trans.app.security_agent.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 ) ) ) ] if not trans.user: # Filter to get only public libraries, a library whose id # is not in restricted_library_ids is a public library return query.filter( not_(trans.model.Library.table.c.id.in_( restricted_library_ids))) else: # Filter to get libraries accessible by the current user, get both # public libraries and restricted libraries accessible by the current user. return query.filter( or_( not_( trans.model.Library.table.c.id.in_( restricted_library_ids)), trans.model.Library.table.c.id.in_( accessible_restricted_library_ids)))
def index( self, trans, deleted='False', **kwd ): """ GET /api/libraries GET /api/libraries/deleted Displays a collection (list) of libraries. """ log.debug( "LibrariesController.index: enter" ) query = trans.sa_session.query( trans.app.model.Library ) deleted = util.string_as_bool( deleted ) if deleted: route = 'deleted_library' query = query.filter( trans.app.model.Library.table.c.deleted == True ) else: route = 'library' query = query.filter( trans.app.model.Library.table.c.deleted == False ) current_user_role_ids = [ role.id for role in trans.get_current_user_roles() ] library_access_action = trans.app.security_agent.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 ) ) ) ] query = query.filter( or_( not_( trans.model.Library.table.c.id.in_( restricted_library_ids ) ), trans.model.Library.table.c.id.in_( accessible_restricted_library_ids ) ) ) rval = [] for library in query: item = library.get_api_value() item['url'] = url_for( route, id=trans.security.encode_id( library.id ) ) item['id'] = trans.security.encode_id( item['id'] ) rval.append( item ) return rval
def apply_query_filter(self, trans, query, **kwd): current_user_role_ids = [role.id for role in trans.get_current_user_roles()] library_access_action = trans.app.security_agent.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), ) ) ] if not trans.user: # Filter to get only public libraries, a library whose id # is not in restricted_library_ids is a public library return query.filter(not_(trans.model.Library.table.c.id.in_(restricted_library_ids))) else: # Filter to get libraries accessible by the current user, get both # public libraries and restricted libraries accessible by the current user. return query.filter( or_( not_(trans.model.Library.table.c.id.in_(restricted_library_ids)), trans.model.Library.table.c.id.in_(accessible_restricted_library_ids), ) )
def index( self, trans, **kwd ): """ index( self, trans, **kwd ) * GET /api/libraries: Returns a list of summary data for all libraries. :param deleted: if True, show only ``deleted`` libraries, if False show only ``non-deleted`` :type deleted: boolean (optional) :returns: list of dictionaries containing library information :rtype: list .. seealso:: :attr:`galaxy.model.Library.dict_collection_visible_keys` """ is_admin = trans.user_is_admin() query = trans.sa_session.query( trans.app.model.Library ) deleted = kwd.get( 'deleted', 'missing' ) try: if not is_admin: # non-admins can't see deleted libraries deleted = False else: deleted = util.asbool( deleted ) if deleted: query = query.filter( trans.app.model.Library.table.c.deleted == True ) else: query = query.filter( trans.app.model.Library.table.c.deleted == False ) except ValueError: # given value wasn't true/false but the user is admin so we don't filter on this parameter at all pass if not is_admin: # non-admins can see only allowed and public libraries current_user_role_ids = [ role.id for role in trans.get_current_user_roles() ] library_access_action = trans.app.security_agent.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 ) ) ) ) ] query = query.filter( or_( not_( trans.model.Library.table.c.id.in_( restricted_library_ids ) ), trans.model.Library.table.c.id.in_( accessible_restricted_library_ids ) ) ) libraries = [] for library in query: item = library.to_dict( view='element', value_mapper={ 'id': trans.security.encode_id, 'root_folder_id': trans.security.encode_id } ) if trans.app.security_agent.library_is_public( library, contents=False ): item[ 'public' ] = True current_user_roles = trans.get_current_user_roles() if not trans.user_is_admin(): item['can_user_add'] = trans.app.security_agent.can_add_library_item( current_user_roles, library ) item['can_user_modify'] = trans.app.security_agent.can_modify_library_item( current_user_roles, library ) item['can_user_manage'] = trans.app.security_agent.can_manage_library_item( current_user_roles, library ) else: item['can_user_add'] = True item['can_user_modify'] = True item['can_user_manage'] = True libraries.append( item ) return libraries
def build_initial_query( self, trans, **kwd ): tool_dependency_ids = tool_dependency_util.get_tool_dependency_ids( as_string=False, **kwd ) if tool_dependency_ids: clause_list = [] for tool_dependency_id in tool_dependency_ids: clause_list.append( self.model_class.table.c.id == trans.security.decode_id( tool_dependency_id ) ) return trans.sa_session.query( self.model_class ) \ .filter( or_( *clause_list ) ) return trans.sa_session.query( self.model_class )
def filter(self, trans, user, query, column_filter): if column_filter == 'Unfinished': return query.filter( not_( or_( model.Job.table.c.state == model.Job.states.OK, model.Job.table.c.state == model.Job.states.ERROR, model.Job.table.c.state == model.Job.states.DELETED))) return query
def build_initial_query( self, trans, **kwd ): return trans.sa_session.query( model.Repository ) \ .filter( and_( model.Repository.table.c.deleted == False, model.Repository.table.c.deprecated == False, model.Repository.reviews == None ) ) \ .join( model.RepositoryMetadata.table ) \ .filter( and_( model.RepositoryMetadata.table.c.downloadable == True, or_( model.RepositoryMetadata.table.c.includes_tools == False, and_( model.RepositoryMetadata.table.c.includes_tools == True, model.RepositoryMetadata.table.c.tools_functionally_correct == True ) ) ) ) \ .join( model.User.table )
def build_initial_query(self, trans, **kwd): return trans.sa_session.query( model.Repository ) \ .filter( and_( model.Repository.table.c.deleted == False, model.Repository.table.c.deprecated == False, model.Repository.reviews == None ) ) \ .join( model.RepositoryMetadata.table ) \ .filter( and_( model.RepositoryMetadata.table.c.downloadable == True, or_( model.RepositoryMetadata.table.c.includes_tools == False, and_( model.RepositoryMetadata.table.c.includes_tools == True, model.RepositoryMetadata.table.c.tools_functionally_correct == True ) ) ) ) \ .join( model.User.table )
def build_initial_query(self, trans, **kwd): tool_dependency_ids = tool_dependency_util.get_tool_dependency_ids( as_string=False, **kwd) if tool_dependency_ids: clause_list = [] for tool_dependency_id in tool_dependency_ids: clause_list.append(self.model_class.table.c.id == trans. security.decode_id(tool_dependency_id)) return trans.install_model.context.query( self.model_class ) \ .filter( or_( *clause_list ) ) return trans.install_model.context.query(self.model_class)
def build_initial_query( self, trans, **kwd ): clause_list = [] tool_shed_repository_ids = util.listify( kwd.get( 'tool_shed_repository_ids', None ) ) if tool_shed_repository_ids: for tool_shed_repository_id in tool_shed_repository_ids: clause_list.append( self.model_class.table.c.id == trans.security.decode_id( tool_shed_repository_id ) ) if clause_list: return trans.sa_session.query( self.model_class ) \ .filter( or_( *clause_list ) ) for tool_shed_repository in trans.sa_session.query( self.model_class ) \ .filter( self.model_class.table.c.deleted == False ): if tool_shed_repository.status in [ trans.model.ToolShedRepository.installation_status.NEW, trans.model.ToolShedRepository.installation_status.CLONING, trans.model.ToolShedRepository.installation_status.SETTING_TOOL_VERSIONS, trans.model.ToolShedRepository.installation_status.INSTALLING_TOOL_DEPENDENCIES, trans.model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES ]: clause_list.append( self.model_class.table.c.id == tool_shed_repository.id ) if clause_list: return trans.sa_session.query( self.model_class ) \ .filter( or_( *clause_list ) ) return trans.sa_session.query( self.model_class ) \ .filter( self.model_class.table.c.status == trans.model.ToolShedRepository.installation_status.NEW )
def load_repository_and_suite_tuples( self ): # Load self.certified_level_one_repository_and_suite_tuples and self.certified_level_one_suite_tuples. for repository in self.sa_session.query( model.Repository ) \ .join( model.RepositoryMetadata.table ) \ .filter( or_( *self.certified_level_one_clause_list ) ) \ .join( model.User.table ): self.load_certified_level_one_repository_and_suite_tuple( repository ) # Load self.repository_and_suite_tuples and self.suite_tuples for repository in self.sa_session.query( model.Repository ) \ .filter( and_( model.Repository.table.c.deleted == False, model.Repository.table.c.deprecated == False ) ) \ .join( model.User.table ): self.load_repository_and_suite_tuple( repository )
def list(self, trans, deleted=False): """ Return a list of libraries from the DB. :param deleted: if True, show only ``deleted`` libraries, if False show only ``non-deleted`` :type deleted: boolean (optional) """ is_admin = trans.user_is_admin() query = trans.sa_session.query(trans.app.model.Library) if is_admin: if deleted is None: # Flag is not specified, do not filter on it. pass elif deleted: query = query.filter( trans.app.model.Library.table.c.deleted == True) else: query = query.filter( trans.app.model.Library.table.c.deleted == False) else: # Nonadmins can't see deleted libraries current_user_role_ids = [ role.id for role in trans.get_current_user_roles() ] library_access_action = trans.app.security_agent.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)))) ] query = query.filter( or_( not_( trans.model.Library.table.c.id.in_( restricted_library_ids)), trans.model.Library.table.c.id.in_( accessible_restricted_library_ids))) return query
def index( self, trans, deleted='False', **kwd ): """ index( self, trans, deleted='False', **kwd ) * GET /api/libraries: returns a list of summary data for libraries * GET /api/libraries/deleted: returns a list of summary data for deleted libraries :type deleted: boolean :param deleted: if True, show only deleted libraries, if False, non-deleted :rtype: list :returns: list of dictionaries containing library information .. seealso:: :attr:`galaxy.model.Library.dict_collection_visible_keys` """ # log.debug( "LibrariesController.index: enter" ) query = trans.sa_session.query( trans.app.model.Library ) deleted = util.string_as_bool( deleted ) if deleted: route = 'deleted_library' query = query.filter( trans.app.model.Library.table.c.deleted == True ) else: route = 'library' query = query.filter( trans.app.model.Library.table.c.deleted == False ) current_user_role_ids = [ role.id for role in trans.get_current_user_roles() ] library_access_action = trans.app.security_agent.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 ) ) ) ] query = query.filter( or_( not_( trans.model.Library.table.c.id.in_( restricted_library_ids ) ), trans.model.Library.table.c.id.in_( accessible_restricted_library_ids ) ) ) rval = [] for library in query: item = library.to_dict() item['url'] = url_for( route, id=trans.security.encode_id( library.id ) ) item['id'] = trans.security.encode_id( item['id'] ) rval.append( item ) return rval
def index(self, trans, deleted='False', **kwd): """ GET /api/libraries GET /api/libraries/deleted Displays a collection (list) of libraries. """ log.debug("LibrariesController.index: enter") query = trans.sa_session.query(trans.app.model.Library) deleted = util.string_as_bool(deleted) if deleted: route = 'deleted_library' query = query.filter( trans.app.model.Library.table.c.deleted == True) else: route = 'library' query = query.filter( trans.app.model.Library.table.c.deleted == False) current_user_role_ids = [ role.id for role in trans.get_current_user_roles() ] library_access_action = trans.app.security_agent.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 ) ) ) ] query = query.filter( or_( not_(trans.model.Library.table.c.id.in_( restricted_library_ids)), trans.model.Library.table.c.id.in_( accessible_restricted_library_ids))) rval = [] for library in query: item = library.get_api_value() item['url'] = url_for(route, id=trans.security.encode_id(library.id)) item['id'] = trans.security.encode_id(item['id']) rval.append(item) return rval
def index(self, trans, **kwd): """ index( self, trans, **kwd ) * GET /api/libraries: Returns a list of summary data for all libraries. :param deleted: if True, show only ``deleted`` libraries, if False show only ``non-deleted`` :type deleted: boolean (optional) :returns: list of dictionaries containing library information :rtype: list .. seealso:: :attr:`galaxy.model.Library.dict_collection_visible_keys` """ query = trans.sa_session.query(trans.app.model.Library) deleted = kwd.get('deleted', 'missing') try: if not trans.user_is_admin(): # non-admins can't see deleted libraries deleted = False else: deleted = util.asbool(deleted) if deleted: query = query.filter( trans.app.model.Library.table.c.deleted == True) else: query = query.filter( trans.app.model.Library.table.c.deleted == False) except ValueError: # given value wasn't true/false but the user is admin so we don't filter on this parameter at all pass current_user_role_ids = [ role.id for role in trans.get_current_user_roles() ] library_access_action = trans.app.security_agent.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)))) ] query = query.filter( or_( not_(trans.model.Library.table.c.id.in_( restricted_library_ids)), trans.model.Library.table.c.id.in_( accessible_restricted_library_ids))) libraries = [] for library in query: item = library.to_dict(view='element', value_mapper={ 'id': trans.security.encode_id, 'root_folder_id': trans.security.encode_id }) if trans.app.security_agent.library_is_public(library, contents=False): item['public'] = True current_user_roles = trans.get_current_user_roles() if not trans.user_is_admin(): item[ 'can_user_add'] = trans.app.security_agent.can_add_library_item( current_user_roles, library) item[ 'can_user_modify'] = trans.app.security_agent.can_modify_library_item( current_user_roles, library) item[ 'can_user_manage'] = trans.app.security_agent.can_manage_library_item( current_user_roles, library) else: item['can_user_add'] = True item['can_user_modify'] = True item['can_user_manage'] = True libraries.append(item) return libraries
def filter( self, trans, user, query, column_filter ): if column_filter == 'Unfinished': return query.filter( not_( or_( model.Job.table.c.state == model.Job.states.OK, model.Job.table.c.state == model.Job.states.ERROR, model.Job.table.c.state == model.Job.states.DELETED ) ) ) return query