mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-13 00:44:55 +08:00
Conflicts: eggs.ini lib/galaxy/__init__.py lib/galaxy/datatypes/binary.py lib/galaxy/datatypes/converters/bgzip.py lib/galaxy/datatypes/converters/gff_to_interval_index_converter.py lib/galaxy/datatypes/converters/interval_to_bed_converter.py lib/galaxy/datatypes/converters/interval_to_bedstrict_converter.py lib/galaxy/datatypes/converters/interval_to_coverage.py lib/galaxy/datatypes/converters/interval_to_fli.py lib/galaxy/datatypes/converters/interval_to_tabix_converter.py lib/galaxy/datatypes/converters/maf_to_fasta_converter.py lib/galaxy/datatypes/converters/maf_to_interval_converter.py lib/galaxy/datatypes/converters/pbed_ldreduced_converter.py lib/galaxy/datatypes/converters/vcf_to_interval_index_converter.py lib/galaxy/datatypes/converters/vcf_to_vcf_bgzip.py lib/galaxy/datatypes/converters/wiggle_to_simple_converter.py lib/galaxy/datatypes/coverage.py lib/galaxy/eggs/__init__.py lib/galaxy/eggs/dist.py lib/galaxy/eggs/scramble.py lib/galaxy/exceptions/__init__.py lib/galaxy/jobs/runners/pbs.py lib/galaxy/jobs/transfer_manager.py lib/galaxy/model/__init__.py lib/galaxy/model/migrate/check.py lib/galaxy/model/orm/__init__.py lib/galaxy/model/tool_shed_install/migrate/check.py lib/galaxy/web/framework/__init__.py lib/galaxy/web/framework/helpers/__init__.py lib/galaxy/web/framework/middleware/sentry.py lib/galaxy/web/framework/openid_manager.py lib/galaxy/web/framework/webapp.py lib/galaxy/webapps/galaxy/controllers/cloudlaunch.py lib/galaxy/webapps/galaxy/controllers/dataset.py lib/galaxy/webapps/galaxy/controllers/library_common.py lib/galaxy/webapps/reports/controllers/workflows.py lib/galaxy/webapps/tool_shed/controllers/repository.py lib/galaxy/webapps/tool_shed/search/repo_search.py lib/galaxy/webapps/tool_shed/search/tool_search.py lib/galaxy_ext/metadata/set_metadata.py lib/pulsar/client/config_util.py lib/tool_shed/galaxy_install/install_manager.py lib/tool_shed/galaxy_install/migrate/check.py lib/tool_shed/grids/admin_grids.py lib/tool_shed/grids/repository_grids.py lib/tool_shed/repository_types/repository_suite_definition.py lib/tool_shed/repository_types/tool_dependency_definition.py lib/tool_shed/scripts/bootstrap_tool_shed/bootstrap_util.py lib/tool_shed/scripts/bootstrap_tool_shed/create_user_with_api_key.py lib/tool_shed/scripts/check_repositories_for_functional_tests.py lib/tool_shed/scripts/check_s3_for_empty_tool_dependency_installation_paths.py lib/tool_shed/scripts/check_tool_dependency_definition_repositories.py lib/tool_shed/scripts/show_tool_dependency_installation_dir_contents.py lib/tool_shed/util/basic_util.py lib/tool_shed/util/encoding_util.py lib/tool_shed/util/hg_util.py scripts/check_eggs.py scripts/dist-scramble.py scripts/fetch_eggs.py scripts/make_egg_packager.py scripts/scramble.py scripts/scramble/lib/scramble_lib.py scripts/scramble/scripts/DRMAA_python-macosx.py scripts/scramble/scripts/DRMAA_python-solaris.py scripts/scramble/scripts/DRMAA_python.py scripts/scramble/scripts/MySQL_python-solaris.py scripts/scramble/scripts/MySQL_python.py scripts/scramble/scripts/PyRods.py scripts/scramble/scripts/bx_python-solaris.py scripts/scramble/scripts/generic.py scripts/scramble/scripts/pbs_python.py scripts/scramble/scripts/psycopg2-linux.py scripts/scramble/scripts/psycopg2-macosx.py scripts/scramble/scripts/psycopg2-solaris.py scripts/scramble/scripts/psycopg2.py scripts/scramble/scripts/pysam-solaris.py scripts/scramble/scripts/pysqlite.py scripts/test_dist_egg.py
124 lines
4.5 KiB
Python
124 lines
4.5 KiB
Python
"""
|
|
Manager and Serializer for TS groups.
|
|
"""
|
|
import logging
|
|
|
|
from sqlalchemy import false, true
|
|
from sqlalchemy.orm.exc import MultipleResultsFound
|
|
from sqlalchemy.orm.exc import NoResultFound
|
|
|
|
from galaxy.exceptions import Conflict
|
|
from galaxy.exceptions import InconsistentDatabase
|
|
from galaxy.exceptions import InternalServerError
|
|
from galaxy.exceptions import ItemAccessibilityException
|
|
from galaxy.exceptions import ObjectNotFound
|
|
from galaxy.exceptions import RequestParameterInvalidException
|
|
|
|
log = logging.getLogger( __name__ )
|
|
|
|
|
|
# =============================================================================
|
|
class GroupManager( object ):
|
|
"""
|
|
Interface/service object for interacting with TS groups.
|
|
"""
|
|
|
|
def __init__( self, *args, **kwargs ):
|
|
super( GroupManager, self ).__init__( *args, **kwargs )
|
|
|
|
def get( self, trans, decoded_group_id=None, name=None ):
|
|
"""
|
|
Get the group from the DB based on its ID or name.
|
|
|
|
:param decoded_group_id: decoded group id
|
|
:type decoded_group_id: int
|
|
|
|
:returns: the requested group
|
|
:rtype: Group
|
|
"""
|
|
if decoded_group_id is None and name is None:
|
|
raise RequestParameterInvalidException( 'You must supply either ID or a name of the group.' )
|
|
|
|
name_query = trans.sa_session.query( trans.app.model.Group ).filter( trans.app.model.Group.table.c.name == name )
|
|
id_query = trans.sa_session.query( trans.app.model.Group ).filter( trans.app.model.Group.table.c.id == decoded_group_id )
|
|
|
|
try:
|
|
group = id_query.one() if decoded_group_id else name_query.one()
|
|
except MultipleResultsFound:
|
|
raise InconsistentDatabase( 'Multiple groups found with the same identifier.' )
|
|
except NoResultFound:
|
|
raise ObjectNotFound( 'No group found with the identifier provided.' )
|
|
except Exception:
|
|
raise InternalServerError( 'Error loading from the database.' )
|
|
return group
|
|
|
|
def create( self, trans, name, description=''):
|
|
"""
|
|
Create a new group.
|
|
"""
|
|
if not trans.user_is_admin:
|
|
raise ItemAccessibilityException( 'Only administrators can create groups.' )
|
|
else:
|
|
if self.get( trans, name=name ):
|
|
raise Conflict( 'Group with the given name already exists. Name: ' + str( name ) )
|
|
# TODO add description field to the model
|
|
group = trans.app.model.Group( name=name )
|
|
trans.sa_session.add( group )
|
|
trans.sa_session.flush()
|
|
return group
|
|
|
|
def update( self, trans, group, name=None, description=None ):
|
|
"""
|
|
Update the given group
|
|
"""
|
|
changed = False
|
|
if not trans.user_is_admin():
|
|
raise ItemAccessibilityException( 'Only administrators can update groups.' )
|
|
if group.deleted:
|
|
raise RequestParameterInvalidException( 'You cannot modify a deleted group. Undelete it first.' )
|
|
if name is not None:
|
|
group.name = name
|
|
changed = True
|
|
if description is not None:
|
|
group.description = description
|
|
changed = True
|
|
if changed:
|
|
trans.sa_session.add( group )
|
|
trans.sa_session.flush()
|
|
return group
|
|
|
|
def delete( self, trans, group, undelete=False ):
|
|
"""
|
|
Mark given group deleted/undeleted based on the flag.
|
|
"""
|
|
if not trans.user_is_admin():
|
|
raise ItemAccessibilityException( 'Only administrators can delete and undelete groups.' )
|
|
if undelete:
|
|
group.deleted = False
|
|
else:
|
|
group.deleted = True
|
|
trans.sa_session.add( group )
|
|
trans.sa_session.flush()
|
|
return group
|
|
|
|
def list( self, trans, deleted=False ):
|
|
"""
|
|
Return a list of groups from the DB.
|
|
|
|
:returns: query that will emit all groups
|
|
:rtype: sqlalchemy query
|
|
"""
|
|
is_admin = trans.user_is_admin()
|
|
query = trans.sa_session.query( trans.app.model.Group )
|
|
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.Group.table.c.deleted == true() )
|
|
else:
|
|
query = query.filter( trans.app.model.Group.table.c.deleted == false() )
|
|
else:
|
|
query = query.filter( trans.app.model.Group.table.c.deleted == false() )
|
|
return query
|