Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve docs and access checks in datalibs manager/api #4560

Merged
merged 2 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions lib/galaxy/managers/library_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from galaxy import util

from galaxy.exceptions import InternalServerError
from galaxy.exceptions import ItemAccessibilityException
from galaxy.exceptions import InsufficientPermissionsException
from galaxy.exceptions import ObjectNotFound
from galaxy.exceptions import RequestParameterInvalidException
Expand Down Expand Up @@ -43,26 +42,25 @@ def get(self, trans, decoded_library_dataset_id, check_accessible=True):
def update(self, trans, ld, payload):
"""
Update the given library dataset - the latest linked ldda.
Updating older lddas (versions) is not supported.

:param ld: library dataset to change
:type ld: LibraryDataset
:param check_ownership: flag whether to check that user owns the item
:type check_ownership: bool
:param check_accessible: flag whether to check that user can access item
:type check_accessible: bool
Updating older lddas (versions) is not allowed.

:param ld: library dataset to change
:type ld: LibraryDataset
:param payload: dictionary structure containing::
:param name: new ld's name, must be longer than 0
:type name: str
:param misc_info: new ld's misc info
:type misc_info: str
:param file_ext: new ld's extension, must exist in the Galaxy registry
:type file_ext: str
:param genome_build: new ld's genome build
:type genome_build: str
:type payload: dict

:returns: the changed library dataset
:rtype: galaxy.model.LibraryDataset

:raises: ItemAccessibilityException, InsufficientPermissionsException
"""
current_user_roles = trans.get_current_user_roles()
self.check_modifiable(trans, ld)
if ld.deleted is True:
raise ItemAccessibilityException("You cannot update a deleted library dataset. Undelete it first.")
if not (trans.user_is_admin or trans.app.security_agent.can_modify_library_item(current_user_roles, ld)):
raise InsufficientPermissionsException('You do not have proper permission to modify this library dataset.')
# we are going to operate on the actual latest ldda
ldda = ld.library_dataset_dataset_association
payload = self._validate_and_parse_update_payload(payload)
Expand Down Expand Up @@ -169,13 +167,12 @@ def check_modifiable(self, trans, ld):

:raises: ObjectNotFound
"""
if trans.user_is_admin():
# all operations are available to an admin
if ld.deleted:
raise ObjectNotFound('Library dataset with the id provided is deleted.')
elif trans.user_is_admin():
return ld
if not trans.app.security_agent.can_modify_library_item(trans.get_current_user_roles(), ld):
raise InsufficientPermissionsException('You do not have proper permission to modify this library dataset.')
elif ld.deleted:
raise ObjectNotFound('Library dataset with the id provided is deleted.')
else:
return ld

Expand Down
14 changes: 12 additions & 2 deletions lib/galaxy/webapps/galaxy/api/library_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,18 @@ def update(self, trans, encoded_dataset_id, payload=None, **kwd):

* PATCH /api/libraries/datasets/{encoded_dataset_id}

:param encoded_dataset_id: the encoded id of the library dataset to update
:type encoded_dataset_id: an encoded id string
:param encoded_dataset_id: the encoded id of the library dataset to update
:type encoded_dataset_id: an encoded id string
:param payload: dictionary structure containing::
:param name: new ld's name, must be longer than 0
:type name: str
:param misc_info: new ld's misc info
:type misc_info: str
:param file_ext: new ld's extension, must exist in the Galaxy registry
:type file_ext: str
:param genome_build: new ld's genome build
:type genome_build: str
:type payload: dict

:returns: detailed library dataset information
:rtype: dictionary
Expand Down