Skip to content

Commit 2a1129a

Browse files
josenavasantgonza
authored andcommitted
Arbitrary summary HTML (#2138)
* fix #1505 * improving some GUI stuff * improving some GUI stuff - missing lines * addressing all comments * ready for review * fix #1987 * initial commit * requested changes * fix filter job list * Fixing server cert (#2051) * fix get_studies * flake8 * fix #503 * fix #2010 * fix #1913 * fix errors * addressing @josenavas comment * flake8 * fix #1010 * fix #1066 (#2058) * addressing @josenavas comments * fix #1961 * fix #1837 * Automatic jobs & new stats (#2057) * fix #814, fix #1636 * fixing error in test-env * fixing stats.html call * adding img * addressing @josenavas comments * rm for loops * addresssing @ElDeveloper comments * generalizing this functionality * fix #1816 * fix #1959 * addressing @josenavas comments * addressing @josenavas comments * fixing error * fixed? * addressing @josenavas comments * addressing @wasade comments * fix flake8 * generate biom and metadata release (#2066) * initial commit * adding portal * addressing @josenavas comments * pid -> qiita_artifact_id * addressing @josenavas comments * addressing @ElDeveloper comments * rm 50.sql * database changes to fix 969 * adding delete * addressing @josenavas comments * addressing @ElDeveloper comments * duh! * fix generate_biom_and_metadata_release (#2072) * fix generate_biom_and_metadata_release * addressing @ElDeveloper comment * Removing qiita ware code that will not be used anymore * Organizing the handlers and new analysis description page * fixing timestamp * rm formats * st -> pt * Connecting the analysis creation and making interface responsive * Addressing @antgonza's comments * Initial artifact GUI refactor * Removing unused code * moving to ISO 8601 - wow :'( * fix errors * addressing @wasade comments * Adding can_edit call to the analysis * Fixing artifact rest API since not all artifacts have study * Adding can_be_publicized call to analysis * Adding QiitaHTTPError to handle errors gracefully * Adding safe_execution contextmanager * Fixing typo * Adding qiita test checker * Adapting some artifact handlers * Abstracting the graph reloading and adding some documentation * Fixing typo * Fixing changing artifact visibility * Fixing delete * Fixing artifact deletion * Adding default parameters to the commands * Fixing processing page * Fixing variable name * fixing private/public studies * Changing bdiv metrics to single choice * sanbox-to-sandbox * flake8 * Fixing patch * fixing other issues * adding share documentation * psycopg2 <= 2.7 * psycopg2 < 2.7 * Various small fixes to be able to run tests on the plugins * Adding private module * Fixing processing job completion * Fixing patch 52 * Fixing call * Fixing complete * small fixes * Adding processing handlers * Fixing url and bug on processing job workflow * Adding the private script runner * Adding is_analysis column to the command * Adding retrieval of commands excluding analysis commands * Addressing bug on retrieving information from redis * Enabling the command register endpoint to provide if the command is analysis only * Addressing @antgonza's comments * Addressing @wasade's comments * Supporting multiple choice * Adding documentation * Modifying handler to pass allow_change_optionals * returning optional parameters * Addressing bug found by @antgonza * Enabling changing the default parameters * Adding correct class * Allowing user to change default parameters * Fixing bug with commands listing * Enabling arbitrary htmls in the summary * Addressing @wasade's comments * Addressing @antgonza's comment
1 parent 3051113 commit 2a1129a

File tree

5 files changed

+71
-12
lines changed

5 files changed

+71
-12
lines changed

qiita_pet/handlers/artifact_handlers/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
# The full license is in the file LICENSE, distributed with this software.
77
# -----------------------------------------------------------------------------
88

9-
from .base_handlers import ArtifactSummaryAJAX, ArtifactAJAX
9+
from .base_handlers import (ArtifactSummaryAJAX, ArtifactAJAX,
10+
ArtifactSummaryHandler)
1011
from .process_handlers import ProcessArtifactHandler
1112

12-
__all__ = ['ArtifactSummaryAJAX', 'ArtifactAJAX', 'ProcessArtifactHandler']
13+
__all__ = ['ArtifactSummaryAJAX', 'ArtifactAJAX', 'ArtifactSummaryHandler',
14+
'ProcessArtifactHandler']

qiita_pet/handlers/artifact_handlers/base_handlers.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
# The full license is in the file LICENSE, distributed with this software.
77
# -----------------------------------------------------------------------------
88

9-
from os.path import basename
9+
from os.path import basename, relpath
1010
from json import dumps
1111

12-
from tornado.web import authenticated
12+
from tornado.web import authenticated, StaticFileHandler
1313
from moi import r_client
1414

1515
from qiita_core.qiita_settings import qiita_config
@@ -108,8 +108,12 @@ def artifact_summary_get_request(user, artifact_id):
108108

109109
# Check if the HTML summary exists
110110
if summary:
111-
with open(summary[1]) as f:
112-
summary = f.read()
111+
# Magic number 1: If the artifact has a summary, the call
112+
# artifact.html_summary_fp returns a tuple with 2 elements. The first
113+
# element is the filepath id, while the second one is the actual
114+
# actual filepath. We are only interested on the actual filepath,
115+
# hence the 1 value.
116+
summary = relpath(summary[1], qiita_config.base_data_dir)
113117
else:
114118
# Check if the summary is being generated
115119
command = Command.get_html_generator(artifact.artifact_type)
@@ -394,3 +398,24 @@ def patch(self, artifact_id):
394398
req_path, req_value, req_from)
395399

396400
self.finish()
401+
402+
403+
class ArtifactSummaryHandler(StaticFileHandler, BaseHandler):
404+
def validate_absolute_path(self, root, absolute_path):
405+
"""Overrides StaticFileHandler's method to include authentication"""
406+
user = self.current_user
407+
408+
# Magic number 1, the path structure for the summaries is
409+
# root/ARTIFACTDIR/artifact_id/FILE. We are interested in the
410+
# artifact_id. root is removed by relpath, so the second element of the
411+
# list is the artifact id
412+
artifact_id = relpath(absolute_path, root).split('/')[1]
413+
414+
# This call will check if the user has access to the artifact or not,
415+
# taking into account admin privileges. If not it will raise a 403
416+
# which will be handled correctly by tornado
417+
check_artifact_access(user, Artifact(artifact_id))
418+
419+
# If we reach this point the user has access to the file - return it
420+
return super(ArtifactSummaryHandler, self).validate_absolute_path(
421+
root, absolute_path)

qiita_pet/handlers/artifact_handlers/tests/test_base_handlers.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
from unittest import TestCase, main
1010
from tempfile import mkstemp
1111
from os import close, remove
12-
from os.path import basename, exists
12+
from os.path import basename, exists, relpath
1313

1414
from tornado.web import HTTPError
1515

1616
from qiita_core.util import qiita_test_checker
17+
from qiita_db.util import get_db_files_base_dir
1718
from qiita_db.user import User
1819
from qiita_db.artifact import Artifact
1920
from qiita_db.processing_job import ProcessingJob
@@ -134,6 +135,8 @@ def test_artifact_summary_get_request(self):
134135
exp_files.append(
135136
(a.html_summary_fp[0],
136137
'%s (html summary)' % basename(a.html_summary_fp[1])))
138+
exp_summary_path = relpath(
139+
a.html_summary_fp[1], get_db_files_base_dir())
137140
obs = artifact_summary_get_request(user, 1)
138141
exp = {'name': 'Raw data 1',
139142
'artifact_id': 1,
@@ -150,7 +153,7 @@ def test_artifact_summary_get_request(self):
150153
'sandbox</button>'),
151154
'processing_parameters': {},
152155
'files': exp_files,
153-
'summary': '<b>HTML TEST - not important</b>\n',
156+
'summary': exp_summary_path,
154157
'job': None,
155158
'processing_jobs': exp_p_jobs,
156159
'errored_jobs': []}
@@ -171,7 +174,7 @@ def test_artifact_summary_get_request(self):
171174
'buttons': '',
172175
'processing_parameters': {},
173176
'files': [],
174-
'summary': '<b>HTML TEST - not important</b>\n',
177+
'summary': exp_summary_path,
175178
'job': None,
176179
'processing_jobs': exp_p_jobs,
177180
'errored_jobs': []}
@@ -228,7 +231,7 @@ def test_artifact_summary_get_request(self):
228231
'editable': True,
229232
'buttons': '',
230233
'processing_parameters': {},
231-
'files': [(22, 'biom_table.biom (biom)')],
234+
'files': [(27, 'biom_table.biom (biom)')],
232235
'summary': None,
233236
'job': None,
234237
'processing_jobs': [],
@@ -309,6 +312,16 @@ def test_artifact_patch_request(self):
309312

310313

311314
class TestBaseHandlers(TestHandlerBase):
315+
def setUp(self):
316+
super(TestBaseHandlers, self).setUp()
317+
self._files_to_remove = []
318+
319+
def tearDown(self):
320+
super(TestBaseHandlers, self).tearDown()
321+
for fp in self._files_to_remove:
322+
if exists(fp):
323+
remove(fp)
324+
312325
def test_get_artifact_summary_ajax_handler(self):
313326
response = self.get('/artifact/1/summary/')
314327
self.assertEqual(response.code, 200)
@@ -322,6 +335,22 @@ def test_patch_artifact_ajax_handler(self):
322335
self.assertEqual(a.name, 'NEW_NAME')
323336
a.name = 'Raw data 1'
324337

338+
def test_get_artifact_summary_handler(self):
339+
a = Artifact(1)
340+
# Add a summary to the artifact
341+
fd, fp = mkstemp(suffix=".html")
342+
close(fd)
343+
with open(fp, 'w') as f:
344+
f.write('<b>HTML TEST - not important</b>\n')
345+
a = Artifact(1)
346+
a.html_summary_fp = fp
347+
self._files_to_remove.extend([fp, a.html_summary_fp[1]])
348+
349+
summary = relpath(a.html_summary_fp[1], get_db_files_base_dir())
350+
response = self.get('/artifact/html_summary/%s' % summary)
351+
self.assertEqual(response.code, 200)
352+
self.assertEqual(response.body, '<b>HTML TEST - not important</b>\n')
353+
325354

326355
if __name__ == '__main__':
327356
main()

qiita_pet/templates/artifact_ajax/artifact_summary.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ <h4>
144144
<div class='row'>
145145
<div class='col-md-12' id='artifact-summary-content'>
146146
{% if summary is not None %}
147-
{% raw summary %}
147+
<iframe width="100%" height="900" src="/artifact/html_summary/{{summary}}" frameBorder=0></iframe>
148148
{% elif job is not None %}
149149
Job <b>{{ job[0] }}</b>: <i>{{ job[1] }}</i> {{ job[2] }}
150150
{% else %}

qiita_pet/webserver.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
PrepTemplateSummaryAJAX,
3535
WorkflowHandler, WorkflowRunHandler, JobAJAX, AutocompleteHandler)
3636
from qiita_pet.handlers.artifact_handlers import (
37-
ArtifactSummaryAJAX, ArtifactAJAX, ProcessArtifactHandler)
37+
ArtifactSummaryAJAX, ArtifactAJAX, ArtifactSummaryHandler,
38+
ProcessArtifactHandler)
3839
from qiita_pet.handlers.websocket_handlers import (
3940
MessageHandler, SelectedSocketHandler, SelectSamplesHandler)
4041
from qiita_pet.handlers.logger_handlers import LogEntryViewerHandler
@@ -129,6 +130,8 @@ def __init__(self):
129130
# Artifact handlers
130131
(r"/artifact/graph/", ArtifactGraphAJAX),
131132
(r"/artifact/(.*)/summary/", ArtifactSummaryAJAX),
133+
(r"/artifact/html_summary/(.*)", ArtifactSummaryHandler,
134+
{"path": qiita_config.base_data_dir}),
132135
(r"/artifact/(.*)/process/", ProcessArtifactHandler),
133136
(r"/artifact/(.*)/", ArtifactAJAX),
134137
(r"/prep_template/", PrepTemplateHandler),

0 commit comments

Comments
 (0)