diff --git a/qiita_db/artifact.py b/qiita_db/artifact.py index 49e932d3d..2b59d3095 100644 --- a/qiita_db/artifact.py +++ b/qiita_db/artifact.py @@ -334,6 +334,15 @@ def create(cls, filepaths, artifact_type, name=None, prep_template=None, qdb.sql_connection.TRN.add(sql, sql_args, many=True) instance = cls(a_id) + # inheriting visibility + visibilities = {a.visibility for a in instance.parents} + # set based on the "lowest" visibility + if 'sandbox' in visibilities: + instance.visibility = 'sandbox' + elif 'private' in visibilities: + instance.visibility = 'private' + else: + instance.visibility = 'public' else: dtype_id = qdb.util.convert_to_id(prep_template.data_type(), "data_type") diff --git a/qiita_db/support_files/patches/47.sql b/qiita_db/support_files/patches/47.sql new file mode 100644 index 000000000..077bb6690 --- /dev/null +++ b/qiita_db/support_files/patches/47.sql @@ -0,0 +1,5 @@ +-- Jan 15, 2017 +-- Inherit the status of the study to all it's artifacts. +-- This code is much easier using python so check that patch + +SELECT 1; diff --git a/qiita_db/support_files/patches/python_patches/47.py b/qiita_db/support_files/patches/python_patches/47.py new file mode 100644 index 000000000..a325a7a2e --- /dev/null +++ b/qiita_db/support_files/patches/python_patches/47.py @@ -0,0 +1,30 @@ +from qiita_db.study import Study + + +class ForRecursion(object): + """for some strange reason, my guess is how we are executing the patches + recursion doesn't work directly so decided to use a class to make it + work""" + + @classmethod + def change_status(cls, artifact, status): + for a in artifact.children: + try: + a.visibility = status + except: + # print so we know which changes failed and we can deal by hand + print "failed aid: %d, status %s" % (artifact.id, status) + return + cls.change_status(a, status) + + +studies = Study.get_by_status('private').union( + Study.get_by_status('public')).union(Study.get_by_status('sandbox')) +# just getting the base artifacts, no parents +artifacts = {a for s in studies for a in s.artifacts() if not a.parents} + +# inheriting status +fr = ForRecursion +for a in artifacts: + status = a.visibility + fr.change_status(a, status) diff --git a/qiita_db/test/test_artifact.py b/qiita_db/test/test_artifact.py index cc0432da9..142cbf59e 100644 --- a/qiita_db/test/test_artifact.py +++ b/qiita_db/test/test_artifact.py @@ -668,7 +668,7 @@ def test_create_processed(self): self.assertEqual(obs.name, 'noname') self.assertTrue(before < obs.timestamp < datetime.now()) self.assertEqual(obs.processing_parameters, exp_params) - self.assertEqual(obs.visibility, 'sandbox') + self.assertEqual(obs.visibility, 'private') self.assertEqual(obs.artifact_type, "Demultiplexed") self.assertEqual(obs.data_type, qdb.artifact.Artifact(1).data_type) self.assertTrue(obs.can_be_submitted_to_ebi) @@ -700,7 +700,7 @@ def test_create_copy_files(self): self.assertEqual(obs.name, 'noname') self.assertTrue(before < obs.timestamp < datetime.now()) self.assertEqual(obs.processing_parameters, exp_params) - self.assertEqual(obs.visibility, 'sandbox') + self.assertEqual(obs.visibility, 'private') self.assertEqual(obs.artifact_type, "Demultiplexed") self.assertEqual(obs.data_type, qdb.artifact.Artifact(1).data_type) self.assertTrue(obs.can_be_submitted_to_ebi) @@ -732,7 +732,7 @@ def test_create_biom(self): self.assertEqual(obs.name, 'noname') self.assertTrue(before < obs.timestamp < datetime.now()) self.assertEqual(obs.processing_parameters, exp_params) - self.assertEqual(obs.visibility, 'sandbox') + self.assertEqual(obs.visibility, 'private') self.assertEqual(obs.artifact_type, 'BIOM') self.assertEqual(obs.data_type, qdb.artifact.Artifact(2).data_type) self.assertFalse(obs.can_be_submitted_to_ebi) diff --git a/qiita_db/test/test_util.py b/qiita_db/test/test_util.py index 419e02d6a..d2529e788 100644 --- a/qiita_db/test/test_util.py +++ b/qiita_db/test/test_util.py @@ -98,8 +98,8 @@ def test_convert_to_id_bad_value(self): def test_get_artifact_types(self): obs = qdb.util.get_artifact_types() - exp = {'SFF': 1, 'FASTA_Sanger': 2, 'FASTQ': 3, 'FASTA': 4, - 'per_sample_FASTQ': 5, 'Demultiplexed': 6, 'BIOM': 7} + exp = {'Demultiplexed': 6, 'FASTA_Sanger': 2, 'FASTQ': 3, 'BIOM': 7, + 'per_sample_FASTQ': 5, 'SFF': 1, 'FASTA': 4} self.assertEqual(obs, exp) obs = qdb.util.get_artifact_types(key_by_id=True)