-
Couldn't load subscription status.
- Fork 79
Propagate artifact visibility #1578
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -84,6 +84,28 @@ def _to_int(value): | |
| return res | ||
|
|
||
|
|
||
| def _propagate_visibility(artifact): | ||
| """Propagates the visibility of artifact to all its ancestors | ||
|
|
||
| Parameters | ||
| ---------- | ||
| artifact : qiita_db.artifact.Artifact | ||
| The artifact to propagate the visibility for | ||
|
|
||
| Notes | ||
| ----- | ||
| This is emulating the previous functionlity, in which the status of the | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. functionality There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| 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): | ||
|
|
@@ -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)) | ||
|
|
@@ -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: | ||
|
|
@@ -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)) | ||
|
|
@@ -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)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
|
@@ -156,6 +159,20 @@ def test_build_study_info_new_study(self): | |
| 'proc_data_info': []}) | ||
| self.assertEqual(obs, self.exp) | ||
|
|
||
| def test_propagate_visibility(self): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a test for those that are not BIOM? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
|
|
||
|
|
||
| class TestStudyEditorForm(TestHandlerBase): | ||
| # TODO: add proper test for this once figure out how. Issue 567 | ||
|
|
||
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done