diff --git a/qiita_pet/handlers/analysis_handlers/__init__.py b/qiita_pet/handlers/analysis_handlers/__init__.py index 0c130e6b4..868abfa1b 100644 --- a/qiita_pet/handlers/analysis_handlers/__init__.py +++ b/qiita_pet/handlers/analysis_handlers/__init__.py @@ -11,8 +11,10 @@ AnalysisGraphHandler, AnalysisJobsHandler) from .listing_handlers import (ListAnalysesHandler, AnalysisSummaryAJAX, SelectedSamplesHandler) +from .sharing_handlers import ShareAnalysisAJAX __all__ = ['CreateAnalysisHandler', 'AnalysisDescriptionHandler', 'AnalysisGraphHandler', 'AnalysisJobsHandler', 'ListAnalysesHandler', 'AnalysisSummaryAJAX', - 'SelectedSamplesHandler', 'check_analysis_access'] + 'SelectedSamplesHandler', 'check_analysis_access', + 'ShareAnalysisAJAX'] diff --git a/qiita_pet/handlers/analysis_handlers/sharing_handlers.py b/qiita_pet/handlers/analysis_handlers/sharing_handlers.py new file mode 100644 index 000000000..b06335083 --- /dev/null +++ b/qiita_pet/handlers/analysis_handlers/sharing_handlers.py @@ -0,0 +1,68 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) 2014--, The Qiita Development Team. +# +# Distributed under the terms of the BSD 3-clause License. +# +# The full license is in the file LICENSE, distributed with this software. +# ----------------------------------------------------------------------------- + +from json import dumps + +from tornado.web import authenticated, HTTPError +from tornado.gen import coroutine, Task + +from qiita_core.qiita_settings import qiita_config +from qiita_core.util import execute_as_transaction +from qiita_pet.handlers.base_handlers import BaseHandler +from qiita_pet.handlers.util import get_shared_links +from qiita_db.user import User +from qiita_db.analysis import Analysis +from qiita_db.util import add_message + + +class ShareAnalysisAJAX(BaseHandler): + @execute_as_transaction + def _get_shared_for_study(self, analysis, callback): + shared_links = get_shared_links(analysis) + users = [u.email for u in analysis.shared_with] + callback((users, shared_links)) + + @execute_as_transaction + def _share(self, analysis, user, callback): + user = User(user) + add_message('Analysis \'%s\' ' + 'has been shared with you.' % + (qiita_config.portal_dir, analysis.id, analysis.name), + [user]) + callback(analysis.share(user)) + + @execute_as_transaction + def _unshare(self, analysis, user, callback): + user = User(user) + add_message('Analysis \'%s\' has been unshared with you.' % + analysis.name, [user]) + callback(analysis.unshare(user)) + + @authenticated + @coroutine + @execute_as_transaction + def get(self): + analysis_id = int(self.get_argument('id')) + analysis = Analysis(analysis_id) + if self.current_user != analysis.owner and \ + self.current_user not in analysis.shared_with: + raise HTTPError(403, 'User %s does not have permissions to share ' + 'analysis %s' % ( + self.current_user.id, analysis.id)) + + selected = self.get_argument('selected', None) + deselected = self.get_argument('deselected', None) + + if selected is not None: + yield Task(self._share, analysis, selected) + if deselected is not None: + yield Task(self._unshare, analysis, deselected) + + users, links = yield Task(self._get_shared_for_study, analysis) + + self.write(dumps({'users': users, 'links': links})) diff --git a/qiita_pet/handlers/analysis_handlers/tests/test_sharing_handlers.py b/qiita_pet/handlers/analysis_handlers/tests/test_sharing_handlers.py new file mode 100644 index 000000000..551385358 --- /dev/null +++ b/qiita_pet/handlers/analysis_handlers/tests/test_sharing_handlers.py @@ -0,0 +1,59 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) 2014--, The Qiita Development Team. +# +# Distributed under the terms of the BSD 3-clause License. +# +# The full license is in the file LICENSE, distributed with this software. +# ----------------------------------------------------------------------------- + +from unittest import main +from json import loads + +from qiita_db.analysis import Analysis +from qiita_db.user import User +from qiita_pet.test.tornado_test_base import TestHandlerBase + + +class TestShareStudyAjax(TestHandlerBase): + + def test_get(self): + a = Analysis(1) + u = User('shared@foo.bar') + self.assertEqual(a.shared_with, [u]) + + # deselecting + args = {'deselected': u.id, 'id': a.id} + response = self.get('/analysis/sharing/', args) + self.assertEqual(response.code, 200) + exp = {'users': [], 'links': ''} + self.assertEqual(loads(response.body), exp) + self.assertEqual(a.shared_with, []) + + # Make sure unshared message added to the system + self.assertEqual("Analysis 'SomeAnalysis' has been unshared with you.", + u.messages()[0][1]) + + # selecting + args = {'selected': u.id, 'id': a.id} + response = self.get('/analysis/sharing/', args) + self.assertEqual(response.code, 200) + exp = { + 'users': ['shared@foo.bar'], + 'links': + ('Shared')} + self.assertEqual(loads(response.body), exp) + self.assertEqual(a.shared_with, [u]) + + # Make sure shared message added to the system + self.assertEqual('Analysis \'SomeAnalys' + 'is\' has been shared with you.', + u.messages()[0][1]) + + def test_get_no_access(self): + args = {'selected': 'demo@microbio.me', 'id': 2} + response = self.get('/analysis/sharing/', args) + self.assertEqual(response.code, 403) + + +if __name__ == '__main__': + main() diff --git a/qiita_pet/static/js/qiita.js b/qiita_pet/static/js/qiita.js index 77ff78d11..24b900562 100644 --- a/qiita_pet/static/js/qiita.js +++ b/qiita_pet/static/js/qiita.js @@ -147,6 +147,7 @@ function draw_processing_graph(nodes, edges, target, artifactFunc, jobFunc) { edges: edges }; var options = { + clickToUse: true, nodes: { shape: 'dot', font: { @@ -172,7 +173,7 @@ function draw_processing_graph(nodes, edges, target, artifactFunc, jobFunc) { zoomView: true, selectConnectedEdges: true, navigationButtons: true, - keyboard: true + keyboard: false }, groups: { jobs: { diff --git a/qiita_pet/static/js/sharing.js b/qiita_pet/static/js/sharing.js index 455768375..cdd6347d4 100644 --- a/qiita_pet/static/js/sharing.js +++ b/qiita_pet/static/js/sharing.js @@ -26,7 +26,6 @@ function init_sharing(portal) { function modify_sharing(id) { var shared_list; - $('#shares-select').attr('data-current-id', id); $.get($('#shares-select').attr('data-share-url'), {id: id}) .done(function(data) { var users_links = JSON.parse(data); @@ -51,4 +50,4 @@ function update_share(params) { links = users_links.links; $("#shared_html_"+share_id).html(links); }); -} \ No newline at end of file +} diff --git a/qiita_pet/templates/analysis_description.html b/qiita_pet/templates/analysis_description.html index 0c991eec5..5a81b5d5f 100644 --- a/qiita_pet/templates/analysis_description.html +++ b/qiita_pet/templates/analysis_description.html @@ -1,7 +1,10 @@ {% extends sitebase.html %} {% block head %} - + + @@ -233,8 +240,12 @@
-

{{analysis_name}} - ID {{analysis_id}}

+

+ {{analysis_name}} - ID {{analysis_id}} + +

{{analysis_description}}

+ Shared with:
@@ -245,7 +256,11 @@

- +
+
+
+ +

@@ -258,4 +273,30 @@

+ + + + {% end %} diff --git a/qiita_pet/templates/artifact_ajax/artifact_summary.html b/qiita_pet/templates/artifact_ajax/artifact_summary.html index 32ee96484..de1ac57b4 100644 --- a/qiita_pet/templates/artifact_ajax/artifact_summary.html +++ b/qiita_pet/templates/artifact_ajax/artifact_summary.html @@ -127,31 +127,44 @@

{% if processing_jobs %} - Jobs using this set of files:
- {% end %} - {% for j_id, c_name, j_status, j_step, j_error in processing_jobs %} - Job {{j_id}} ({{c_name}}). Status: {{j_status}}. - {% if j_step %} - Step: {{j_step}} - {% end %} - {% if j_error %} - Error message: {{j_error}} - {% end %} -
+
+ +
+ {% for j_id, c_name, j_status, j_step, j_error in processing_jobs %} + Job {{j_id}} ({{c_name}}). Status: {{j_status}}. + {% if j_step %} + Step: {{j_step}} + {% end %} + {% if j_error %} + Error message: {{j_error}} + {% end %} +
+ {% end %} +
+
{% end %}
{% if summary is not None %} +
+
Open summary in a new window +
{% elif job is not None %} Job {{ job[0] }}: {{ job[1] }} {{ job[2] }} {% else %} Currently, no summary exists.

- {% for j_id, j_error in errored_jobs %} - Job {{ j_id }}: {% raw j_error.replace('\n', '
') %}

+ {% if errored_jobs %} +
+ +
+ {% for j_id, j_error in errored_jobs %} + Job {{ j_id }}: {% raw j_error.replace('\n', '
') %}

+ {% end %} +
{% end %} {% end %}
diff --git a/qiita_pet/templates/artifact_ajax/processing_artifact.html b/qiita_pet/templates/artifact_ajax/processing_artifact.html index e970b0a70..26aa6359c 100644 --- a/qiita_pet/templates/artifact_ajax/processing_artifact.html +++ b/qiita_pet/templates/artifact_ajax/processing_artifact.html @@ -338,7 +338,7 @@ } $("
").appendTo("#cmd-opts-div").attr('id', 'opt-vals-div').attr('name', 'opt-vals-div'); - sel.change(function(event){ + sel.change(function(){ var v = $("#params-sel").val(); $("#opt-vals-div").empty(); if (v !== "") { @@ -356,6 +356,14 @@ $("#add-cmd-btn-div").hide(); } }); + + sel.show(function(){ + // select first option if only 2 options ("Choose parameter set", "unique value") + if ($("#params-sel option").length == 2) { + $("#params-sel")[0].selectedIndex = 1; + $("#params-sel").trigger("change"); + } + }); }); } @@ -422,6 +430,7 @@ var data = {nodes: nodes, edges: edges}; var options = { + clickToUse: true, nodes: { shape: 'dot', font: { @@ -447,7 +456,7 @@ zoomView: true, selectConnectedEdges: false, navigationButtons: true, - keyboard: true + keyboard: false }, groups: { jobs: { diff --git a/qiita_pet/templates/list_analyses.html b/qiita_pet/templates/list_analyses.html index af408ee59..9fb69dee8 100644 --- a/qiita_pet/templates/list_analyses.html +++ b/qiita_pet/templates/list_analyses.html @@ -2,9 +2,14 @@ {% block head %} @@ -18,43 +23,43 @@

Create an analysis {% if analyses %} - - - - - - - - - - - {% for analysis in analyses %} - {% set _id = analysis.id %} +
Analysis NameAnalysis DescriptionTimestampMapping FileBiom Filestgz FilesDelete?
+ - - - - - - - + + + + + - {% end %} + + {% for analysis in analyses %} + {% set _id = analysis.id %} + + + + + + + + {% end %} + +
- {{analysis.name}} - - {{analysis.description}} - - {{ analysis.timestamp.strftime("%m/%d/%y %H:%M:%S")}} - - {% raw mappings[_id] %} - - {% raw bioms[_id] %} - - {% raw tgzs[_id] %} - - - ArtifactsAnalysis NameTimestampMapping FileDelete?
+ {{len(analysis.artifacts)}} + + {{analysis.name}} + {% if analysis.description %} + ({{analysis.description}}) + {% end %} + + {{ analysis.timestamp.strftime("%m/%d/%y %H:%M:%S")}} + + {% raw mappings[_id] %} + + +
+ {% end %} {% end %} diff --git a/qiita_pet/templates/sitebase.html b/qiita_pet/templates/sitebase.html index 31409d7f8..12a3ccb57 100644 --- a/qiita_pet/templates/sitebase.html +++ b/qiita_pet/templates/sitebase.html @@ -54,6 +54,14 @@