refactor the rest of the module to use new manager

This commit is contained in:
Martin Cech
2017-08-17 15:30:57 -04:00
parent e17ab411e3
commit cd09d1327a
+51 -57
View File
@@ -85,23 +85,22 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
@expose_api_anonymous
def show_version(self, trans, encoded_dataset_id, encoded_ldda_id, **kwd):
"""
show_version( self, trans, encoded_dataset_id, encoded_ldda_id, **kwd ):
* GET /api/libraries/datasets/{encoded_dataset_id}/versions/{encoded_ldda_id}
Displays information about specific version of the library_dataset (i.e. ldda).
Display a specific version of a library dataset (i.e. ldda).
:param encoded_dataset_id: the encoded id of the dataset to query
* GET /api/libraries/datasets/{encoded_dataset_id}/versions/{encoded_ldda_id}
:param encoded_dataset_id: the encoded id of the related library dataset
:type encoded_dataset_id: an encoded id string
:param encoded_ldda_id: the encoded id of the ldda to query
:type encoded_ldda_id: an encoded id string
:rtype: dictionary
:returns: dict of ldda's details
:rtype: dictionary
:raises: ObjectNotFound
"""
try:
library_dataset = self.get_library_dataset(trans, id=encoded_dataset_id, check_ownership=False, check_accessible=True)
except Exception:
raise exceptions.ObjectNotFound('Requested library_dataset was not found.')
library_dataset = self.ld_manager.get(trans, managers_base.decode_id(self.app, encoded_dataset_id))
try:
ldda = self.get_library_dataset_dataset_association(trans, id=encoded_ldda_id, check_ownership=False, check_accessible=False)
@@ -117,10 +116,9 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
@expose_api
def show_roles(self, trans, encoded_dataset_id, **kwd):
"""
show_roles( self, trans, id, **kwd ):
Display information about current or available roles for a given dataset permission.
* GET /api/libraries/datasets/{encoded_dataset_id}/permissions
Displays information about current or available roles
for a given dataset permission.
:param encoded_dataset_id: the encoded id of the dataset to query
:type encoded_dataset_id: an encoded id string
@@ -128,16 +126,14 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
:param scope: either 'current' or 'available'
:type scope: string
:returns: either dict of current roles for all permission types
or dict of available roles to choose from (is the same for any permission type)
:rtype: dictionary
:returns: either dict of current roles for all permission types or
dict of available roles to choose from (is the same for any permission type)
"""
:raises: InsufficientPermissionsException
"""
current_user_roles = trans.get_current_user_roles()
try:
library_dataset = self.get_library_dataset(trans, id=encoded_dataset_id, check_ownership=False, check_accessible=False)
except Exception as e:
raise exceptions.ObjectNotFound('Requested dataset was not found.' + str(e))
library_dataset = self.ld_manager.get(trans, managers_base.decode_id(self.app, encoded_dataset_id))
dataset = library_dataset.library_dataset_dataset_association.dataset
# User has to have manage permissions permission in order to see the roles.
@@ -202,8 +198,9 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
@expose_api
def update_permissions(self, trans, encoded_dataset_id, payload=None, **kwd):
"""
Set permissions of the given library dataset to the given role ids.
*POST /api/libraries/datasets/{encoded_dataset_id}/permissions
Set permissions of the given dataset to the given role ids.
:param encoded_dataset_id: the encoded id of the dataset to update permissions of
:type encoded_dataset_id: an encoded id string
@@ -218,6 +215,7 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
:param modify_ids[]: list of Role.id defining roles that should have modify permission on the library dataset item
:type modify_ids[]: string or list
:type: dictionary
:returns: dict of current roles for all available permission types
:rtype: dictionary
@@ -226,10 +224,7 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
"""
if payload:
kwd.update(payload)
try:
library_dataset = self.get_library_dataset(trans, id=encoded_dataset_id, check_ownership=False, check_accessible=False)
except Exception as e:
raise exceptions.ObjectNotFound('Requested dataset was not found.' + str(e))
library_dataset = self.ld_manager.get(trans, managers_base.decode_id(self.app, encoded_dataset_id))
dataset = library_dataset.library_dataset_dataset_association.dataset
current_user_roles = trans.get_current_user_roles()
can_manage = trans.app.security_agent.can_manage_dataset(current_user_roles, dataset) or trans.user_is_admin()
@@ -330,62 +325,59 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
@expose_api
def delete(self, trans, encoded_dataset_id, **kwd):
"""
delete( self, trans, encoded_dataset_id, **kwd ):
Mark the dataset deleted or undeleted.
* DELETE /api/libraries/datasets/{encoded_dataset_id}
Marks the dataset deleted or undeleted based on the value
of the undelete flag.
If the flag is not present it is considered False and the
item is marked deleted.
:param encoded_dataset_id: the encoded id of the dataset to change
:type encoded_dataset_id: an encoded id string
:param undelete: flag whether to undeleted instead of deleting
:type undelete: bool
:returns: dict containing information about the dataset
:rtype: dictionary
"""
undelete = util.string_as_bool(kwd.get('undelete', False))
try:
dataset = self.get_library_dataset(trans, id=encoded_dataset_id, check_ownership=False, check_accessible=False)
except Exception as e:
raise exceptions.ObjectNotFound('Requested dataset was not found.' + str(e))
library_dataset = self.ld_manager.get(trans, managers_base.decode_id(self.app, encoded_dataset_id))
current_user_roles = trans.get_current_user_roles()
allowed = trans.app.security_agent.can_modify_library_item(current_user_roles, dataset)
allowed = trans.app.security_agent.can_modify_library_item(current_user_roles, library_dataset)
if (not allowed) and (not trans.user_is_admin()):
raise exceptions.InsufficientPermissionsException('You do not have proper permissions to delete this dataset.')
if undelete:
dataset.deleted = False
library_dataset.deleted = False
else:
dataset.deleted = True
library_dataset.deleted = True
trans.sa_session.add(dataset)
trans.sa_session.add(library_dataset)
trans.sa_session.flush()
rval = trans.security.encode_all_ids(dataset.to_dict())
nice_size = util.nice_size(int(dataset.library_dataset_dataset_association.get_size()))
rval = trans.security.encode_all_ids(library_dataset.to_dict())
nice_size = util.nice_size(int(library_dataset.library_dataset_dataset_association.get_size()))
rval['file_size'] = nice_size
rval['update_time'] = dataset.update_time.strftime("%Y-%m-%d %I:%M %p")
rval['deleted'] = dataset.deleted
rval['update_time'] = library_dataset.update_time.strftime("%Y-%m-%d %I:%M %p")
rval['deleted'] = library_dataset.deleted
rval['folder_id'] = 'F' + rval['folder_id']
return rval
@expose_api
def load(self, trans, payload=None, **kwd):
"""
Load dataset(s) from the given source into the library.
* POST /api/libraries/datasets
Load dataset from the given source into the library.
Source can be:
user directory - root folder specified in galaxy.ini as "$user_library_import_dir"
example path: path/to/galaxy/$user_library_import_dir/user@example.com/{user can browse everything here}
the folder with the user login has to be created beforehand
(admin)import directory - root folder specified in galaxy ini as "$library_import_dir"
example path: path/to/galaxy/$library_import_dir/{admin can browse everything here}
(admin)any absolute or relative path - option allowed with "allow_library_path_paste" in galaxy.ini
:param payload: dictionary structure containing:
:param encoded_folder_id: the encoded id of the folder to import dataset(s) to
:type encoded_folder_id: an encoded id string
:param source: source the datasets should be loaded from
Source can be:
user directory - root folder specified in galaxy.ini as "$user_library_import_dir"
example path: path/to/galaxy/$user_library_import_dir/user@example.com/{user can browse everything here}
the folder with the user login has to be created beforehand
(admin)import directory - root folder specified in galaxy ini as "$library_import_dir"
example path: path/to/galaxy/$library_import_dir/{admin can browse everything here}
(admin)any absolute or relative path - option allowed with "allow_library_path_paste" in galaxy.ini
:type source: str
:param link_data: flag whether to link the dataset to data or copy it to Galaxy, defaults to copy
while linking is set to True all symlinks will be resolved _once_
@@ -400,8 +392,10 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
:param tag_using_filenames: flag whether to generate dataset tags from filenames
:type tag_using_filenames: bool
:type dictionary
:returns: dict containing information about the created upload job
:rtype: dictionary
:raises: RequestParameterMissingException, AdminRequiredException, ConfigDoesNotAllowException, RequestParameterInvalidException
InsufficientPermissionsException, ObjectNotFound
"""
@@ -508,10 +502,10 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
# TODO convert to expose_api
def download(self, trans, format, **kwd):
"""
download( self, trans, format, **kwd )
Download requested datasets (identified by encoded IDs) in requested format.
* GET /api/libraries/datasets/download/{format}
* POST /api/libraries/datasets/download/{format}
Downloads requested datasets (identified by encoded IDs) in requested format.
example: ``GET localhost:8080/api/libraries/datasets/download/tbz?ld_ids%255B%255D=a0d84b45643a2678&ld_ids%255B%255D=fe38c84dcd46c828``
@@ -524,8 +518,8 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
:param folder_ids[]: an array of encoded folder ids
:type folder_ids[]: an array
:rtype: file
:returns: either archive with the requested datasets packed inside or a single uncompressed dataset
:rtype: file
:raises: MessageException, ItemDeletionException, ItemAccessibilityException, HTTPBadRequest, OSError, IOError, ObjectNotFound
"""
@@ -634,7 +628,8 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
zpath = os.path.split(path)[-1] # comes as base_name/fname
outfname, zpathext = os.path.splitext(zpath)
if is_composite: # need to add all the components from the extra_files_path to the zip
if is_composite:
# need to add all the components from the extra_files_path to the zip
if zpathext == '':
zpath = '%s.html' % zpath # fake the real nature of the html file
try:
@@ -669,10 +664,9 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
log.exception("Requested dataset %s does not exist on the host.", fpath)
raise exceptions.ObjectNotFound("Requested dataset not found.")
except Exception as e:
log.exception("Unable to add %s to temporary library download archive %s", fname, outfname)
log.exception("Unable to add %s to temporary library download archive %s" % (fname, outfname))
raise exceptions.InternalServerError("Unable to add dataset to temporary library download archive . " + str(e))
else: # simple case
else:
try:
if format == 'zip':
archive.add(ldda.dataset.file_name, path)
@@ -735,8 +729,8 @@ class LibraryDatasetsController(BaseAPIController, UsesVisualizationMixin):
:type: list
"""
path_to_root = []
# We are almost in root
if folder.parent_id is None:
# We are almost in root
path_to_root.append(('F' + trans.security.encode_id(folder.id), folder.name))
else:
# We add the current folder and traverse up one folder.