Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 27 additions & 1 deletion qiita_pet/handlers/study_handlers/description_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from qiita_db.metadata_template.util import (load_template_to_dataframe,
looks_like_qiime_mapping_file)
from qiita_db.metadata_template.constants import SAMPLE_TEMPLATE_COLUMNS
from qiita_db.util import convert_to_id, get_mountpoint
from qiita_db.util import convert_to_id, get_mountpoint, infer_status
from qiita_db.exceptions import (QiitaDBUnknownIDError, QiitaDBColumnError,
QiitaDBExecutionError, QiitaDBDuplicateError,
QiitaDBDuplicateHeaderError, QiitaDBError)
Expand Down Expand Up @@ -84,6 +84,28 @@ def _to_int(value):
return res


def _propagate_visibility(artifact):
"""Propagates the visibility of artifact to all its ancestors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"of artifact" -> "of an artifact"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


Parameters
----------
artifact : qiita_db.artifact.Artifact
The artifact to propagate the visibility for

Notes
-----
This is emulating the previous functionality, in which the status of the
processed data was propagated to the preprocessed/raw data that was used
to generate such processed data. In the current interface, only the status
of the BIOM artifacts (processed data) can be changed, so this works as
expected.
"""
for a in artifact.ancestors.nodes():
visibilities = [[c.visibility] for c in a.descendants.nodes()
if c.artifact_type == 'BIOM']
a.visibility = infer_status(visibilities)


class StudyDescriptionHandler(BaseHandler):
@execute_as_transaction
def _get_study_and_check_access(self, study_id):
Expand Down Expand Up @@ -469,6 +491,7 @@ def make_public(self, study, user, callback):
pd_id = int(self.get_argument('pd_id'))
pd = Artifact(pd_id)
pd.visibility = 'public'
_propagate_visibility(pd)
msg = "Processed data set to public"
msg_level = "success"
callback((msg, msg_level, "processed_data_tab", pd_id, None))
Expand All @@ -491,6 +514,7 @@ def approve_study(self, study, user, callback):
pd_id = int(self.get_argument('pd_id'))
pd = Artifact(pd_id)
pd.visibility = 'private'
_propagate_visibility(pd)
msg = "Processed data approved"
msg_level = "success"
else:
Expand All @@ -516,6 +540,7 @@ def request_approval(self, study, user, callback):
pd_id = int(self.get_argument('pd_id'))
pd = Artifact(pd_id)
pd.visibility = 'awaiting_approval'
_propagate_visibility(pd)
msg = "Processed data sent to admin for approval"
msg_level = "success"
callback((msg, msg_level, "processed_data_tab", pd_id, None))
Expand All @@ -537,6 +562,7 @@ def make_sandbox(self, study, user, callback):
pd_id = int(self.get_argument('pd_id'))
pd = Artifact(pd_id)
pd.visibility = 'sandbox'
_propagate_visibility(pd)
msg = "Processed data reverted to sandbox"
msg_level = "success"
callback((msg, msg_level, "processed_data_tab", pd_id, None))
Expand Down
24 changes: 24 additions & 0 deletions qiita_pet/test/test_study_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

from qiita_pet.test.tornado_test_base import TestHandlerBase
from qiita_core.exceptions import IncompetentQiitaDeveloperError
from qiita_db.artifact import Artifact
from qiita_db.study import StudyPerson, Study
from qiita_db.util import get_count, check_count
from qiita_db.user import User
from qiita_pet.handlers.study_handlers.listing_handlers import (
_get_shared_links_for_study, _build_study_info, _build_single_study_info,
_build_single_proc_data_info)
from qiita_pet.handlers.study_handlers.description_handlers import (
_propagate_visibility)


class TestHelpers(TestHandlerBase):
Expand Down Expand Up @@ -156,6 +159,27 @@ def test_build_study_info_new_study(self):
'proc_data_info': []})
self.assertEqual(obs, self.exp)

def test_propagate_visibility(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test for those that are not BIOM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

a = Artifact(4)
a.visibility = 'public'
_propagate_visibility(a)
self.assertEqual(Artifact(1).visibility, 'public')
self.assertEqual(Artifact(2).visibility, 'public')
self.assertEqual(Artifact(4).visibility, 'public')

a.visibility = 'private'
_propagate_visibility(a)
self.assertEqual(Artifact(1).visibility, 'private')
self.assertEqual(Artifact(2).visibility, 'private')
self.assertEqual(Artifact(4).visibility, 'private')

a = Artifact(2)
a.visibility = 'public'
_propagate_visibility(a)
self.assertEqual(Artifact(1).visibility, 'private')
self.assertEqual(Artifact(2).visibility, 'private')
self.assertEqual(Artifact(4).visibility, 'private')


class TestStudyEditorForm(TestHandlerBase):
# TODO: add proper test for this once figure out how. Issue 567
Expand Down