Skip to content

Commit 71dc2cd

Browse files
authored
adding GUI access to users for software (#3019)
1 parent 947903e commit 71dc2cd

File tree

7 files changed

+94
-17
lines changed

7 files changed

+94
-17
lines changed

qiita_db/software.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,40 @@ def merging_scheme(self):
705705
'outputs': outputs,
706706
'ignore_parent_command': ipc}
707707

708+
@property
709+
def resource_allocation(self):
710+
"""The resource allocation defined in the database for this command
711+
712+
Returns
713+
-------
714+
str
715+
"""
716+
717+
with qdb.sql_connection.TRN:
718+
sql = """SELECT allocation FROM
719+
qiita.processing_job_resource_allocation
720+
WHERE name = %s and
721+
job_type = 'RESOURCE_PARAMS_COMMAND'"""
722+
qdb.sql_connection.TRN.add(sql, [self.name])
723+
724+
result = qdb.sql_connection.TRN.execute_fetchflatten()
725+
726+
# if no matches for both type and name were found, query the
727+
# 'default' value for the type
728+
729+
if not result:
730+
sql = """SELECT allocation FROM
731+
qiita.processing_job_resource_allocation WHERE
732+
name = %s and job_type = 'RESOURCE_PARAMS_COMMAND'"""
733+
qdb.sql_connection.TRN.add(sql, ['default'])
734+
735+
result = qdb.sql_connection.TRN.execute_fetchflatten()
736+
if not result:
737+
raise ValueError("Could not match '%s' to a resource "
738+
"allocation!" % self.name)
739+
740+
return result[0]
741+
708742

709743
class Software(qdb.base.QiitaObject):
710744
r"""A software package available in the system

qiita_db/test/test_software.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,30 @@ def test_iter(self):
463463
obs = list(qdb.software.Software.iter(False))
464464
self.assertEqual(obs, [s1, s2, s3, s4])
465465

466+
# test command resouce allocations here to be able to delete
467+
# allocations so we can tests errors.
468+
469+
# Command 2 is Split libraries and has defined resources
470+
self.assertEqual(
471+
qdb.software.Command(2).resource_allocation,
472+
'-q qiita -l nodes=1:ppn=1 -l mem=60gb -l walltime=25:00:00')
473+
474+
# Command 9 is Summarize Taxa and has no defined resources so it goes
475+
# to defaults
476+
self.assertEqual(
477+
qdb.software.Command(9).resource_allocation,
478+
'-q qiita -l nodes=1:ppn=5 -l pmem=8gb -l walltime=168:00:00')
479+
480+
# delete allocations to test errors
481+
with qdb.sql_connection.TRN:
482+
qdb.sql_connection.TRN.add(
483+
"DELETE FROM qiita.processing_job_resource_allocation")
484+
qdb.sql_connection.TRN.execute()
485+
486+
with self.assertRaisesRegex(ValueError, "Could not match 'Split "
487+
"libraries' to a resource allocation!"):
488+
qdb.software.Command(2).resource_allocation
489+
466490

467491
@qiita_test_checker()
468492
class SoftwareTests(TestCase):

qiita_pet/handlers/software.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@
66
# The full license is in the file LICENSE, distributed with this software.
77
# -----------------------------------------------------------------------------
88
from tornado.gen import coroutine
9-
from tornado.web import HTTPError
109

1110
from qiita_core.util import execute_as_transaction
1211
from qiita_db.software import Software
1312
from .base_handlers import BaseHandler
1413

1514

1615
class SoftwareHandler(BaseHandler):
17-
def check_access(self):
18-
if self.current_user.level not in {'admin', 'dev'}:
19-
raise HTTPError(403, reason="User %s doesn't have sufficient "
20-
"privileges to view error page" %
21-
self.current_user.email)
22-
2316
@coroutine
2417
@execute_as_transaction
2518
def get(self):
26-
self.check_access()
27-
software = Software.iter(False)
19+
# active True will only show active software
20+
active = True
21+
user = self.current_user
22+
if user is not None and user.level in {'admin', 'dev'}:
23+
active = False
24+
25+
software = Software.iter(active=active)
2826
self.render("software.html", software=software)

qiita_pet/templates/sitebase.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@
370370
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Admin<b class="caret"></b></a>
371371
<ul class="dropdown-menu">
372372
{% if qiita_config.portal == "QIITA" %}
373-
<li><a href="{% raw qiita_config.portal_dir %}/admin/software/">Available Software</a></li>
374373
<li><a href="{% raw qiita_config.portal_dir %}/admin/error/">View Errors</a></li>
375374
<li><a href="{% raw qiita_config.portal_dir %}/admin/approval/">View Studies awaiting approval</a></li>
376375
<li><a href="{% raw qiita_config.portal_dir %}/admin/portals/studies/">Edit study portal connections</a></li>
@@ -483,6 +482,9 @@
483482
<li>
484483
<a href="{% raw qiita_config.portal_dir %}/stats/">Stats</a>
485484
</li>
485+
<li>
486+
<a href="{% raw qiita_config.portal_dir %}/software/">Available Software</a>
487+
</li>
486488
<li>
487489
<a href="http://github.com/biocore/qiita">GitHub</a>
488490
</li>

qiita_pet/templates/software.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313

1414
{% block content %}
1515
{% if software %}
16-
<h3>Available plugins</h3>
16+
<h3>Available Software</h3>
17+
18+
<h5>
19+
<a href="https://qiita.ucsd.edu/static/doc/html/processingdata/processing-recommendations.html">Here</a> you will find our current processing recommendations.
20+
</h5>
21+
1722
<table class="table-bordered" width="50%">
1823
<thead>
1924
<tr>
20-
<th>Software</th>
25+
<th>Plugin</th>
2126
<th>Commands</th>
2227
</tr>
2328
</thead>
@@ -38,6 +43,12 @@ <h3>Available plugins</h3>
3843
</td>
3944
<td>
4045
<table class="display table-bordered table-hover" width="100%">
46+
<thead>
47+
<tr>
48+
<th>Command Name</th>
49+
<th>Resource Allocation</th>
50+
</tr>
51+
</thead>
4152
<tbody>
4253
{% for c in s.commands %}
4354
<tr>
@@ -49,6 +60,7 @@ <h3>Available plugins</h3>
4960
{% end %}
5061
ID {{c.id}}: {{c.name}}
5162
</td>
63+
<td>{{c.resource_allocation}}</td>
5264
</tr>
5365
{% end %}
5466
</tbody>

qiita_pet/test/test_software.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@
1717

1818
class TestSoftware(TestHandlerBase):
1919
def test_get(self):
20-
response = self.get('/admin/software/')
21-
self.assertEqual(response.code, 403)
20+
response = self.get('/software/')
21+
self.assertEqual(response.code, 200)
22+
body = response.body.decode('ascii')
23+
self.assertNotEqual(body, "")
24+
# checking that this software is not displayed
25+
self.assertNotIn('Target Gene', body)
2226

2327
BaseHandler.get_current_user = Mock(return_value=User("[email protected]"))
24-
response = self.get('/admin/software/')
28+
response = self.get('/software/')
2529
self.assertEqual(response.code, 200)
26-
self.assertNotEqual(response.body, "")
30+
body = response.body.decode('ascii')
31+
self.assertNotEqual(body, "")
32+
# checking that this software is displayed
33+
self.assertIn('Target Gene', body)
2734

2835

2936
if __name__ == "__main__":

qiita_pet/webserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ def __init__(self):
126126
(r"/admin/error/", LogEntryViewerHandler),
127127
(r"/admin/approval/", StudyApprovalList),
128128
(r"/admin/artifact/", ArtifactAdminAJAX),
129-
(r"/admin/software/", SoftwareHandler),
130129
(r"/ebi_submission/(.*)", EBISubmitHandler),
131130
# Study handlers
132131
(r"/study/create/", StudyEditHandler),
@@ -177,6 +176,7 @@ def __init__(self):
177176
(r"/upload/", UploadFileHandler),
178177
(r"/check_study/", CreateStudyAJAX),
179178
(r"/stats/", StatsHandler),
179+
(r"/software/", SoftwareHandler),
180180
(r"/download/(.*)", DownloadHandler),
181181
(r"/download_study_bioms/(.*)", DownloadStudyBIOMSHandler),
182182
(r"/download_raw_data/(.*)", DownloadRawData),

0 commit comments

Comments
 (0)