Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
23 changes: 17 additions & 6 deletions qiita_db/software.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,24 @@ class Software(qdb.base.QiitaObject):
_table = "software"

@classmethod
def iter_active(cls):
"""Iterates over all active software"""
def iter(cls, active=True):
"""Iterates over all active software

Parameters
----------
active : bool, optional
If True will only return active software

Returns
-------
list of qiita_db.software.Software
The software objects
"""
sql = """SELECT software_id
FROM qiita.software {0}
ORDER BY software_id""".format(
'WHERE active = True' if active else '')
with qdb.sql_connection.TRN:
sql = """SELECT software_id
FROM qiita.software
WHERE active = True
ORDER BY software_id"""
qdb.sql_connection.TRN.add(sql)
for s_id in qdb.sql_connection.TRN.execute_fetchflatten():
yield cls(s_id)
Expand Down
41 changes: 27 additions & 14 deletions qiita_db/test/test_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,31 +397,44 @@ def test_activate(self):


@qiita_test_checker()
class SoftwareTests(TestCase):
def setUp(self):
self._clean_up_files = []
class SoftwareTestsIter(TestCase):
# different class to assure integrity of database

def tearDown(self):
for f in self._clean_up_files:
if exists(f):
remove(f)
def test_iter(self):
s1 = qdb.software.Software(1)
s2 = qdb.software.Software(2)
s3 = qdb.software.Software(3)
s4 = qdb.software.Software(4)

def test_iter_active(self):
qdb.software.Software.deactivate_all()
obs = list(qdb.software.Software.iter_active())
obs = list(qdb.software.Software.iter())
self.assertEqual(obs, [])
obs = list(qdb.software.Software.iter(False))
self.assertEqual(obs, [s1, s2, s3, s4])

s2 = qdb.software.Software(2)
s2.activate()
obs = list(qdb.software.Software.iter_active())
obs = list(qdb.software.Software.iter())
self.assertEqual(obs, [s2])
obs = list(qdb.software.Software.iter(False))
self.assertEqual(obs, [s1, s2, s3, s4])

s1 = qdb.software.Software(1)
s3 = qdb.software.Software(3)
s1.activate()
s3.activate()
obs = list(qdb.software.Software.iter_active())
obs = list(qdb.software.Software.iter())
self.assertEqual(obs, [s1, s2, s3])
obs = list(qdb.software.Software.iter(False))
self.assertEqual(obs, [s1, s2, s3, s4])


@qiita_test_checker()
class SoftwareTests(TestCase):
def setUp(self):
self._clean_up_files = []

def tearDown(self):
for f in self._clean_up_files:
if exists(f):
remove(f)

def test_from_name_and_version(self):
obs = qdb.software.Software.from_name_and_version('QIIME', '1.9.1')
Expand Down
4 changes: 2 additions & 2 deletions qiita_pet/handlers/logger_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
class LogEntryViewerHandler(BaseHandler):
def check_access(self):
if self.current_user.level not in {'admin', 'dev'}:
raise HTTPError(405, reason="User %s doesn't have sufficient "
raise HTTPError(403, reason="User %s doesn't have sufficient "
"privileges to view error page" %
self.current_user)
self.current_user.email)

@authenticated
@execute_as_transaction
Expand Down
31 changes: 31 additions & 0 deletions qiita_pet/handlers/software.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -----------------------------------------------------------------------------
# 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 __future__ import division

from tornado.gen import coroutine
from tornado.web import HTTPError

from qiita_core.util import execute_as_transaction
from qiita_db.software import Software
from .base_handlers import BaseHandler


class SoftwareHandler(BaseHandler):
def check_access(self):
if self.current_user.level not in {'admin', 'dev'}:
raise HTTPError(403, reason="User %s doesn't have sufficient "
"privileges to view error page" %
self.current_user.email)

@coroutine
@execute_as_transaction
def get(self):
self.check_access()
software = Software.iter(False)
self.render("software.html", software=software)
1 change: 1 addition & 0 deletions qiita_pet/templates/sitebase.html
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Admin<b class="caret"></b></a>
<ul class="dropdown-menu">
{% if qiita_config.portal == "QIITA" %}
<li><a href="{% raw qiita_config.portal_dir %}/admin/software/">Available Software</a></li>
<li><a href="{% raw qiita_config.portal_dir %}/admin/error/">View Errors</a></li>
<li><a href="{% raw qiita_config.portal_dir %}/admin/approval/">View Studies awaiting approval</a></li>
<li><a href="{% raw qiita_config.portal_dir %}/admin/portals/studies/">Edit study portal connections</a></li>
Expand Down
63 changes: 63 additions & 0 deletions qiita_pet/templates/software.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% extends sitebase.html %}
{% block head %}
{% from future.utils import viewitems %}
{% from qiita_core.qiita_settings import qiita_config %}

<script type="text/javascript">
$(document).ready(function() {
$('#error-table').dataTable({"order": [[1, "asc"]]});
$("#waiting").hide();
} );
</script>

{% end %}

{% block content %}
{% if software %}
<h3>Available plugins</h3>
<table class="table-bordered" width="50%">
<thead>
<tr>
<th>Software</th>
<th>Commands</th>
</tr>
</thead>
<tbody>
{% for s in software %}
<tr>
<td>
{% if s.active %}
<span class="glyphicon glyphicon-thumbs-up" style="color:green"></span>
{% else %}
<span class="glyphicon glyphicon-thumbs-down" style="color:red"></span>
{% end %}
{{s.name}}, {{s.version}}
</td>
<td>
<table class="display table-bordered table-hover" width="100%">
<tbody>
{% for c in s.commands %}
<tr>
<td>
{% if c.active %}
<span class="glyphicon glyphicon-thumbs-up" style="color:green"></span>
{% else %}
<span class="glyphicon glyphicon-thumbs-down" style="color:red"></span>
{% end %}
{{c.name}}
</td>
</tr>
{% end %}
</tbody>
</table>
</td>
</tr>
{% end %}
</tbody>
</table>
{% else %}
<div id="jumbotron" class="jumbotron">
<h1><span class="glyphicon glyphicon-thumbs-down"></span> There are no plugins in this system. </h1>
</div>
{% end %}
{% end %}
30 changes: 30 additions & 0 deletions qiita_pet/test/test_software.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -----------------------------------------------------------------------------
# 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 qiita_pet.test.tornado_test_base import TestHandlerBase

from mock import Mock

from qiita_db.user import User
from qiita_pet.handlers.base_handlers import BaseHandler


class TestSoftware(TestHandlerBase):
def test_get(self):
response = self.get('/admin/software/')
self.assertEqual(response.code, 405)

BaseHandler.get_current_user = Mock(return_value=User("admin@foo.bar"))
response = self.get('/admin/software/')
self.assertEqual(response.code, 200)
self.assertNotEqual(response.body, "")


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions qiita_pet/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from qiita_pet.handlers.prep_template import (
PrepTemplateHandler, PrepTemplateGraphHandler, PrepTemplateJobHandler)
from qiita_pet.handlers.ontology import OntologyHandler
from qiita_pet.handlers.software import SoftwareHandler
from qiita_db.handlers.processing_job import (
JobHandler, HeartbeatHandler, ActiveStepHandler, CompleteHandler,
ProcessingJobAPItestHandler)
Expand Down Expand Up @@ -122,6 +123,7 @@ def __init__(self):
(r"/admin/error/", LogEntryViewerHandler),
(r"/admin/approval/", StudyApprovalList),
(r"/admin/artifact/", ArtifactAdminAJAX),
(r"/admin/software/", SoftwareHandler),
(r"/ebi_submission/(.*)", EBISubmitHandler),
# Study handlers
(r"/study/create/", StudyEditHandler),
Expand Down
2 changes: 1 addition & 1 deletion scripts/qiita
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def start(port, master):

if master:
def callback_function():
active_software = list(qdb.software.Software.iter_active())
active_software = list(qdb.software.Software.iter())
sdefinition = [s for s in active_software
if s.type == 'artifact definition']
stransformation = [s for s in active_software
Expand Down