Skip to content

Changing how artifact visibility works #2098

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

Merged
merged 3 commits into from
Apr 4, 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
30 changes: 17 additions & 13 deletions qiita_db/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,11 @@ def create(cls, filepaths, artifact_type, name=None, prep_template=None,

Notes
-----
The visibility of the artifact is set by default to `sandbox`
The timestamp of the artifact is set by default to `datetime.now()`
The value of `submitted_to_vamps` is set by default to `False`
The visibility of the artifact is set by default to `sandbox` if
prep_template is passed but if parents is passed we will inherit the
Copy link
Contributor

Choose a reason for hiding this comment

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

is passed but -> is passed and if?

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 I also understand this as well.

most closed visibility.
Copy link
Contributor

Choose a reason for hiding this comment

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

most closed -> closest?

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand now, what you mean here.

The timestamp of the artifact is set by default to `datetime.now()`.
The value of `submitted_to_vamps` is set by default to `False`.
"""
# We need at least one file
if not filepaths:
Expand Down Expand Up @@ -617,19 +619,21 @@ def visibility(self, value):
only applies when the new visibility is more open than before.
"""
with qdb.sql_connection.TRN:
# In order to correctly propagate the visibility we need to find
# the root of this artifact and then propagate to all the artifacts
sql = "SELECT * FROM qiita.find_artifact_roots(%s)"
qdb.sql_connection.TRN.add(sql, [self.id])
root_id = qdb.sql_connection.TRN.execute_fetchlast()
root = qdb.artifact.Artifact(root_id)
# these are the ids of all the children from the root
ids = [a.id for a in root.descendants.nodes()]

sql = """UPDATE qiita.artifact
SET visibility_id = %s
WHERE artifact_id = %s"""
qdb.sql_connection.TRN.add(
sql, [qdb.util.convert_to_id(value, "visibility"), self.id])
WHERE artifact_id IN %s"""
vis_id = qdb.util.convert_to_id(value, "visibility")
qdb.sql_connection.TRN.add(sql, [vis_id, tuple(ids)])
qdb.sql_connection.TRN.execute()
# In order to correctly propagate the visibility upstream, we need
# to go one step at a time. By setting up the visibility of our
# parents first, we accomplish that, since they will propagate
# the changes to its parents
for p in self.parents:
visibilites = [[d.visibility] for d in p.descendants.nodes()]
p.visibility = qdb.util.infer_status(visibilites)

@property
def artifact_type(self):
Expand Down
5 changes: 5 additions & 0 deletions qiita_db/support_files/patches/53.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Apr 1, 2017
-- setting visibility of all artifacts to be the most open of the full
-- processing tree

SELECT 42;
19 changes: 19 additions & 0 deletions qiita_db/support_files/patches/python_patches/53.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from qiita_db.study import Study

studies = Study.get_by_status('private').union(
Study.get_by_status('public')).union(Study.get_by_status('sandbox'))
raw_data = [pt.artifact for s in studies for pt in s.prep_templates()]

for rd in raw_data:
# getting the most open visibility of all the children in the pipeline
children = rd.descendants.nodes()
vis = [a.visibility for a in children]
vis.append(rd.visibility)

new_vis = 'sandbox'
if 'public' in vis:
new_vis = 'public'
elif 'private' in vis:
Copy link
Contributor

Choose a reason for hiding this comment

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

are there situations where an artifact was bumped to private but where the user expects all other artifacts to remain sandboxed?

Copy link
Member Author

Choose a reason for hiding this comment

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

in praxis no ... at least based on what we have seen so far ...

new_vis = 'private'

rd.visibility = new_vis
17 changes: 8 additions & 9 deletions qiita_db/test/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,8 @@ def test_visibility_setter(self):
# /- 2 (private) -|- 5 (private)
# 1 (private) -| \- 6 (private)
# \- 3 (private)
# By changing the visibility of 4 to public, the visibility of 1 and
# 2 also changes to public
# By changing the visibility of 4 to public, the visibility of all
# should change
a1 = qdb.artifact.Artifact(1)
a2 = qdb.artifact.Artifact(2)
a3 = qdb.artifact.Artifact(3)
Expand All @@ -979,17 +979,16 @@ def test_visibility_setter(self):

self.assertEqual(a1.visibility, "public")
self.assertEqual(a2.visibility, "public")
self.assertEqual(a3.visibility, "private")
self.assertEqual(a3.visibility, "public")
self.assertEqual(a4.visibility, "public")
self.assertEqual(a5.visibility, "private")
self.assertEqual(a6.visibility, "private")
self.assertEqual(a5.visibility, "public")
self.assertEqual(a6.visibility, "public")

# However, if we change it back to private,
# it should remain public
# Same if we go back
a4.visibility = 'private'

self.assertEqual(a1.visibility, "public")
self.assertEqual(a2.visibility, "public")
self.assertEqual(a1.visibility, "private")
self.assertEqual(a2.visibility, "private")
self.assertEqual(a3.visibility, "private")
self.assertEqual(a4.visibility, "private")
self.assertEqual(a5.visibility, "private")
Expand Down
188 changes: 109 additions & 79 deletions qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,89 +968,119 @@ def test_generate_study_list(self):

qdb.artifact.Artifact(4).visibility = 'public'
exp_info[0]['status'] = 'public'
exp_info[0]['proc_data_info'] = [{
'data_type': '18S',
'algorithm': 'QIIME (Pick closed-reference OTUs)',
'pid': 4,
'processed_date': '2012-10-02 17:30:00',
'params': {
'similarity': 0.97,
'reference_name': 'Greengenes',
'sortmerna_e_value': 1,
'sortmerna_max_pos': 10000,
'threads': 1,
'sortmerna_coverage': 0.97,
'reference_version': '13_8'},
'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
'1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
'1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
'1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
'1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}]
exp_info[0]['proc_data_info'] = [
{'data_type': '18S',
'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 4,
'processed_date': '2012-10-02 17:30:00',
'params': {'similarity': 0.97, 'reference_name': 'Greengenes',
'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000,
'threads': 1, u'sortmerna_coverage': 0.97,
'reference_version': '13_8'},
'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
'1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
'1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
'1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
'1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']},
{'data_type': '18S',
'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 5,
'processed_date': '2012-10-02 17:30:00',
'params': {'similarity': 0.97, 'reference_name': 'Greengenes',
'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000,
'threads': 1, 'sortmerna_coverage': 0.97,
'reference_version': '13_8'},
'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
'1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
'1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
'1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
'1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']},
{'data_type': '16S',
'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 6,
'processed_date': '2012-10-02 17:30:00',
'params': {'similarity': 0.97, 'reference_name': 'Silva',
'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000,
'threads': 1, 'sortmerna_coverage': 0.97,
'reference_version': 'test'},
'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
'1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
'1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
'1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
'1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}]
obs_info = qdb.util.generate_study_list([1, 2, 3, 4], True,
public_only=True)
self.assertEqual(obs_info, exp_info)

exp_info[0]['proc_data_info'].extend(
[{
'data_type': '18S',
'algorithm': 'QIIME (Pick closed-reference OTUs)',
'pid': 5,
'processed_date': '2012-10-02 17:30:00',
'params': {
'similarity': 0.97,
'reference_name': 'Greengenes',
'sortmerna_e_value': 1,
'sortmerna_max_pos': 10000,
'threads': 1,
'sortmerna_coverage': 0.97,
'reference_version': '13_8'},
'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
'1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
'1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
'1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
'1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}, {
'data_type': '16S',
'algorithm': 'QIIME (Pick closed-reference OTUs)',
'pid': 6,
'processed_date': '2012-10-02 17:30:00',
'params': {
'similarity': 0.97,
'reference_name': 'Silva',
'sortmerna_e_value': 1,
'sortmerna_max_pos': 10000,
'threads': 1,
'sortmerna_coverage': 0.97,
'reference_version': 'test'},
'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
'1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
'1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
'1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
'1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}, {
'processed_date': '2012-10-02 17:30:00',
'pid': 7,
'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
'1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
'1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
'1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
'1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192'],
'data_type': '16S'}])

exp_info[0]['proc_data_info'] = [
{'data_type': '18S',
'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 4,
'processed_date': '2012-10-02 17:30:00',
'params': {'similarity': 0.97, 'reference_name': 'Greengenes',
'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000,
'threads': 1, 'sortmerna_coverage': 0.97,
'reference_version': '13_8'},
'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
'1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
'1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
'1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
'1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']},
{'data_type': '18S',
'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 5,
'processed_date': '2012-10-02 17:30:00',
'params': {'similarity': 0.97, 'reference_name': 'Greengenes',
'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000,
'threads': 1, 'sortmerna_coverage': 0.97,
'reference_version': '13_8'},
'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
'1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
'1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
'1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
'1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']},
{'data_type': '16S',
'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 6,
'processed_date': '2012-10-02 17:30:00',
'params': {'similarity': 0.97, 'reference_name': 'Silva',
'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000,
'threads': 1, 'sortmerna_coverage': 0.97,
'reference_version': 'test'},
'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
'1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
'1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
'1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
'1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']},
{'processed_date': '2012-10-02 17:30:00', 'pid': 7,
'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
'1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
'1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
'1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
'1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
'1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
'1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
'1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
'1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192'],
'data_type': '16S'}]
obs_info = qdb.util.generate_study_list([1, 2, 3, 4], True)
self.assertEqual(obs_info, exp_info)

Expand Down
21 changes: 9 additions & 12 deletions qiita_pet/handlers/api_proxy/tests/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def test_artifact_summary_get_request(self):
'files': exp_files,
'errored_jobs': [],
'editable': True,
'visibility': 'private',
'visibility': 'sandbox',
'job': None,
'message': '',
'name': 'Demultiplexed 1',
Expand All @@ -316,17 +316,14 @@ def test_artifact_summary_get_request(self):
'min_per_read_length_fraction': 0.75,
'barcode_type': u'golay_12'},
'summary': None,
'buttons': ('<button onclick="if (confirm(\'Are you sure you '
'want to make public artifact id: 2?\')) { '
'set_artifact_visibility(\'public\', 2) }" '
'class="btn btn-primary btn-sm">Make public'
'</button> <button onclick="if (confirm(\'Are you '
'sure you want to revert to sandbox artifact id: '
'2?\')) { set_artifact_visibility(\'sandbox\', 2) '
'}" class="btn btn-primary btn-sm">Revert to '
'sandbox</button> <a class="btn btn-primary '
'btn-sm" href="/vamps/2"><span class="glyphicon '
'glyphicon-export"></span> Submit to VAMPS</a>'),
'buttons': (
'<button onclick="if (confirm(\'Are you sure you want to '
'request approval for artifact id: 2?\')) { '
'set_artifact_visibility(\'awaiting_approval\', 2) }" '
'class="btn btn-primary btn-sm">Request approval</button> '
'<a class="btn btn-primary btn-sm" href="/vamps/2"><span '
'class="glyphicon glyphicon-export"></span> Submit to '
'VAMPS</a>'),
'study_id': 1,
'prep_id': 1}
self.assertEqual(obs, exp)
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/handlers/api_proxy/tests/test_prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def test_prep_template_graph_get_req(self):
obs = prep_template_graph_get_req(1, 'demo@microbio.me')
self.assertEqual(obs['message'], '')
self.assertEqual(obs['status'], 'success')
self.assertEqual(8, len(obs['node_labels']))
self.assertEqual(11, len(obs['node_labels']))
self.assertIn(('artifact', 1, 'Raw data 1 - FASTQ'),
obs['node_labels'])
self.assertIn(('artifact', 2, 'Demultiplexed 1 - Demultiplexed'),
Expand Down