Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 2aab1bfaaa82ade6a7fcbaf621dab209371eae90
Author: Bohuslav Kabrda <bkabrda(a)redhat.com>
Date: Fri Mar 29 14:14:52 2013 +0100
Enable raising legal flag on a copr. Fixes #46 - now make it show up in admin
interface.
---------------------------------------------------------------
coprs_frontend/coprs/forms.py | 2 ++
coprs_frontend/coprs/helpers.py | 2 +-
coprs_frontend/coprs/static/copr.css | 10 ++++++++++
.../coprs/templates/coprs/_coprs_forms.html | 14 ++++++++++++++
.../coprs/templates/coprs/detail/overview.html | 6 ++++++
.../coprs/views/coprs_ns/coprs_general.py | 19 ++++++++++++++++---
.../tests/test_logic/test_coprs_logic.py | 10 +++++++++-
7 files changed, 58 insertions(+), 5 deletions(-)
diff --git a/coprs_frontend/coprs/forms.py b/coprs_frontend/coprs/forms.py
index 7c7cf35..6b533cd 100644
--- a/coprs_frontend/coprs/forms.py
+++ b/coprs_frontend/coprs/forms.py
@@ -138,6 +138,8 @@ class BuildForm(wtf.Form):
validators = [wtf.NumberRange(min =
constants.MIN_BUILD_TIMEOUT, max = constants.MAX_BUILD_TIMEOUT)],
default = constants.DEFAULT_BUILD_TIMEOUT)
+class CoprLegalForm(wtf.Form):
+ comment = wtf.TextAreaField('Comment')
class PermissionsApplierFormFactory(object):
@staticmethod
diff --git a/coprs_frontend/coprs/helpers.py b/coprs_frontend/coprs/helpers.py
index fdc87af..cad7324 100644
--- a/coprs_frontend/coprs/helpers.py
+++ b/coprs_frontend/coprs/helpers.py
@@ -37,7 +37,7 @@ class PermissionEnum(object):
class ActionTypeEnum(object):
__metaclass__ = EnumType
- vals = {'delete': 0, 'rename': 1}
+ vals = {'delete': 0, 'rename': 1, 'legal-flag': 2}
class BackendResultEnum(object):
__metaclass__ = EnumType
diff --git a/coprs_frontend/coprs/static/copr.css b/coprs_frontend/coprs/static/copr.css
index a2349a7..243b676 100644
--- a/coprs_frontend/coprs/static/copr.css
+++ b/coprs_frontend/coprs/static/copr.css
@@ -311,3 +311,13 @@ table.releases th.rightmost {
table.releases tr.release-end {
border-bottom: 3px solid #f2f2f2;
}
+
+form.legal-flag, form.legal-flag input {
+ color: #888888;
+ margin-top: 5px;
+}
+
+hr {
+ margin-top: 25px;
+ margin-bottom: 25px;
+}
diff --git a/coprs_frontend/coprs/templates/coprs/_coprs_forms.html
b/coprs_frontend/coprs/templates/coprs/_coprs_forms.html
index a0f55e3..e8856e1 100644
--- a/coprs_frontend/coprs/templates/coprs/_coprs_forms.html
+++ b/coprs_frontend/coprs/templates/coprs/_coprs_forms.html
@@ -75,4 +75,18 @@
<dd><input type="submit" value="Save"></dd>
</form>
{% endif %}
+ {% endmacro %}
+
+{% macro copr_legal_form(form, copr) %}
+<form class="legal-flag" method="post" action={{
url_for('coprs_ns.copr_legal_flag', username=copr.owner.name, coprname=copr.name)
}}>
+ If you think that this copr may be violating our policies, you can mark it for legal
review.
+ You can add an optional comment describing what you think is wrong here.
+
+ <dl>
+ {{ render_field(form.comment, rows=5, cols=50) }}
+ <dt>
+ <input type="submit" value="Raise Legal Flag">
+ </dt>
+ </dl>
+ </form>
{% endmacro %}
diff --git a/coprs_frontend/coprs/templates/coprs/detail/overview.html
b/coprs_frontend/coprs/templates/coprs/detail/overview.html
index 6152ddf..b0bf4e2 100644
--- a/coprs_frontend/coprs/templates/coprs/detail/overview.html
+++ b/coprs_frontend/coprs/templates/coprs/detail/overview.html
@@ -1,4 +1,7 @@
{% extends "coprs/detail.html" %}
+
+{% from "coprs/_coprs_forms.html" import copr_legal_form with context %}
+
{% block overview_selected %}selected{% endblock %}
{% block detail_body %}
@@ -46,4 +49,7 @@
{% endfor %}
</ul>
{% endif %}
+
+ <hr>
+ {{ copr_legal_form(form, copr) }}
{% endblock %}
diff --git a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
index cce699a..8c63eee 100644
--- a/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
+++ b/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
@@ -104,13 +104,15 @@ def copr_new():
@coprs_ns.route('/detail/<username>/<coprname>/')
def copr_detail(username, coprname):
query = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname,
with_mock_chroots=True)
+ form = forms.CoprLegalForm()
try:
copr = query.one()
except sqlalchemy.orm.exc.NoResultFound:
return page_not_found('Copr with name {0} does not
exist.'.format(coprname))
return flask.render_template('coprs/detail/overview.html',
- copr=copr)
+ copr=copr,
+ form=form)
@coprs_ns.route('/detail/<username>/<coprname>/permissions/')
def copr_permissions(username, coprname):
@@ -256,7 +258,18 @@ def copr_delete(username, coprname):
else:
return flask.render_template('coprs/detail/delete.html', form=form,
copr=copr)
-@coprs_ns.route('/detail/<username>/<coprname>/legal_flag/')
+@coprs_ns.route('/detail/<username>/<coprname>/legal_flag/',
methods=['POST'])
@login_required
def copr_legal_flag(username, coprname):
- pass
+ form = forms.CoprLegalForm()
+ copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first()
+
+ action = models.Action(action_type=helpers.ActionTypeEnum('legal-flag'),
+ object_type='copr',
+ object_id=copr.id,
+ message=form.comment.data,
+ created_on=int(time.time()))
+ db.session.add(action)
+ db.session.commit()
+ flask.flash('Admin was noticed about your report and will investigate the copr
shortly.')
+ return flask.redirect(flask.url_for('coprs_ns.copr_detail',
username=username, coprname=coprname))
diff --git a/coprs_frontend/tests/test_logic/test_coprs_logic.py
b/coprs_frontend/tests/test_logic/test_coprs_logic.py
index c3f365b..2f6d7d8 100644
--- a/coprs_frontend/tests/test_logic/test_coprs_logic.py
+++ b/coprs_frontend/tests/test_logic/test_coprs_logic.py
@@ -1,7 +1,7 @@
import pytest
from coprs.exceptions import ActionInProgressException
-from coprs.helpers import BackendResultEnum
+from coprs.helpers import ActionTypeEnum, BackendResultEnum
from coprs.logic.coprs_logic import CoprsLogic
from tests.coprs_test_case import CoprsTestCase
@@ -12,3 +12,11 @@ class TestCoprsLogic(CoprsTestCase):
with pytest.raises(ActionInProgressException):
CoprsLogic.update(self.u1, self.c1)
self.db.session.rollback()
+
+ def test_legal_flag_doesnt_block_copr_functionality(self, f_users, f_coprs, f_db):
+ self.db.session.add(self.models.Action(object_type='copr',
+ object_id=self.c1.id,
+
action_type=ActionTypeEnum('legal-flag')))
+ self.db.session.commit()
+ # test will fail if this raises exception
+ CoprsLogic.raise_if_unfinished_blocking_action(None, self.c1, 'ha,
failed')