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

fix #1987 #2047

Merged
merged 1 commit into from
Jan 17, 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
9 changes: 9 additions & 0 deletions qiita_db/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions qiita_db/support_files/patches/47.sql
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 30 additions & 0 deletions qiita_db/support_files/patches/python_patches/47.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from qiita_db.study import Study


class ForRecursion(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are facing the same issue that I was facing when doing the analysis refactor. Try changing this:

https://github.com/biocore/qiita/pull/2040/files#diff-694f6ed1529987bc3435746a74426405R408

then the functions should work

"""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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Failed "aid?" Not sure I would understand what that was saying if I got this message.

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)
6 changes: 3 additions & 3 deletions qiita_db/test/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down