Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit cbe1c1f526442a9daed8708d8efc7678d81ff604 Author: Adam Samalik asamalik@redhat.com Date: Wed Apr 30 12:44:29 2014 +0200
admin/playground page
frontend/coprs_frontend/coprs/forms.py | 8 ++ frontend/coprs_frontend/coprs/logic/coprs_logic.py | 9 +++ .../coprs/templates/admin/_admin_forms.html | 31 +++++++++ .../coprs/templates/admin/layout.html | 3 + .../coprs/templates/admin/playground.html | 16 +++++ .../coprs/views/admin_ns/admin_general.py | 69 ++++++++++++++++++++ 6 files changed, 136 insertions(+), 0 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/forms.py b/frontend/coprs_frontend/coprs/forms.py index 691610a..ba5a2a4 100644 --- a/frontend/coprs_frontend/coprs/forms.py +++ b/frontend/coprs_frontend/coprs/forms.py @@ -302,3 +302,11 @@ class CoprModifyForm(wtf.Form):
class ModifyChrootForm(wtf.Form): buildroot_pkgs = wtforms.TextField('Additional packages to be always present in minimal buildroot') + +class AdminPlaygroundForm(wtf.Form): + playground = wtforms.BooleanField("Playground") + + +class AdminPlaygroundSearchForm(wtf.Form): + project = wtforms.TextField("Project") + diff --git a/frontend/coprs_frontend/coprs/logic/coprs_logic.py b/frontend/coprs_frontend/coprs/logic/coprs_logic.py index 73d20c9..1bc8be4 100644 --- a/frontend/coprs_frontend/coprs/logic/coprs_logic.py +++ b/frontend/coprs_frontend/coprs/logic/coprs_logic.py @@ -103,6 +103,15 @@ class CoprsLogic(object): return cls.get_all().filter(models.Copr.playground == True)
@classmethod + def set_playground(cls, user, copr): + if user.admin: + db.session.add(copr) + pass + else: + raise exceptions.InsufficientRightsException( + "User is not a system admin") + + @classmethod def get_multiple_fulltext(cls, user, search_string): query = (models.Copr.query.join(models.User) .filter(models.Copr.deleted == False) diff --git a/frontend/coprs_frontend/coprs/templates/admin/_admin_forms.html b/frontend/coprs_frontend/coprs/templates/admin/_admin_forms.html new file mode 100644 index 0000000..6e48b6b --- /dev/null +++ b/frontend/coprs_frontend/coprs/templates/admin/_admin_forms.html @@ -0,0 +1,31 @@ +{% from "_helpers.html" import render_field %} + +{% macro admin_playground_form(form, copr) %} + <form action="{{ url_for('admin_ns.playground_set', username=copr.owner.name, coprname=copr.name) }}" method="post"> + {{ form.csrf_token }} + <table class="status-table"> + <tbody> + <tr> + <th>Project</th> + <th>Playground</th> + <th></th> + </tr> + <tr> + <th>{{copr.owner.name}}/{{copr.name}}</th> + <th>{{ form.playground }}</th> + <th><input type="submit" value="Set"></th> + </tr> + </tbody> + </table> + </form> +{% endmacro %} + +{% macro admin_playground_search(form) %} + <form action="{{ url_for('admin_ns.playground') }}" method="post"> + <dl> + {{ form.csrf_token }} + Playground flag: {{ form.project }} + <dt><input type="submit" value="Set"></dt> + </dl> + </form> +{% endmacro %} diff --git a/frontend/coprs_frontend/coprs/templates/admin/layout.html b/frontend/coprs_frontend/coprs/templates/admin/layout.html index c8d48c9..23fcd57 100644 --- a/frontend/coprs_frontend/coprs/templates/admin/layout.html +++ b/frontend/coprs_frontend/coprs/templates/admin/layout.html @@ -8,6 +8,9 @@ <li class="{% block legal_flag_selected %}unselected{% endblock %}"> <a href="{{ url_for('admin_ns.legal_flag') }}">Legal Flags</a> </li> + <li class="{% block playground_selected %}unselected{% endblock %}"> + <a href="{{ url_for('admin_ns.playground') }}">Playground</a> + </li> </ul> </div> {% block admin_body %}{% endblock %} diff --git a/frontend/coprs_frontend/coprs/templates/admin/playground.html b/frontend/coprs_frontend/coprs/templates/admin/playground.html new file mode 100644 index 0000000..7b1b761 --- /dev/null +++ b/frontend/coprs_frontend/coprs/templates/admin/playground.html @@ -0,0 +1,16 @@ +{% extends "admin/layout.html" %} +{% from "admin/_admin_forms.html" import admin_playground_form %} +{% from "admin/_admin_forms.html" import admin_playground_search %} + +{% block playground_selected %}selected{% endblock %} + +{% block admin_body %} +{% if form_search: %} +{{ admin_playground_search(form_search) }} +{% endif %} + +{% if form_set and copr:%} +{{ admin_playground_form(form_set, copr) }} +{% endif %} + +{% endblock %} diff --git a/frontend/coprs_frontend/coprs/views/admin_ns/admin_general.py b/frontend/coprs_frontend/coprs/views/admin_ns/admin_general.py index 1f91370..e3fbeb4 100644 --- a/frontend/coprs_frontend/coprs/views/admin_ns/admin_general.py +++ b/frontend/coprs_frontend/coprs/views/admin_ns/admin_general.py @@ -1,14 +1,19 @@ import time +import re
import flask
from coprs import db from coprs import helpers from coprs import models +from coprs import forms + +from coprs.logic import coprs_logic
from coprs.views.admin_ns import admin_ns from coprs.views.misc import login_required
+from coprs.exceptions import InsufficientRightsException
@admin_ns.route("/") @login_required(role=helpers.RoleEnum("admin")) @@ -42,3 +47,67 @@ def legal_flag_resolve(flag_id): db.session.commit() flask.flash("Legal flag resolved") return flask.redirect(flask.url_for("admin_ns.legal_flag")) + + +@admin_ns.route("/playground/", methods=["POST", "GET"]) +@login_required(role=helpers.RoleEnum("admin")) +def playground(): + form = forms.AdminPlaygroundSearchForm() + + if form.validate_on_submit() and form.project.data: + m = re.match(r"(.+)/(.+)", form.project.data) + if not m: + flask.flash("Please search as username/projectname") + else: + username = m.group(1) + coprname = m.group(2) + + copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() + + if copr: + return flask.redirect(flask.url_for("admin_ns.playground_project", + username=username, + coprname=coprname)) + else: + flask.flash("This project does not exist") + + return flask.render_template("admin/playground.html", form_search = form) + + +@admin_ns.route("/playground/<username>/<coprname>/") +@login_required(role=helpers.RoleEnum("admin")) +def playground_project(username, coprname): + copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() + if not copr: + flask.flash("Project {0} does not exist".format(copr)) + return flask.render_template("admin/playground.html") + + form = forms.AdminPlaygroundForm() + form.playground.data = copr.playground + return flask.render_template("admin/playground.html", + form_set = form, + copr = copr) + + +@admin_ns.route("/playground/<username>/<coprname>/set/", methods=["POST"]) +@login_required(role=helpers.RoleEnum("admin")) +def playground_set(username, coprname): + copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() + if copr: + form = forms.AdminPlaygroundForm() + + if form.validate_on_submit(): + try: + copr.playground = form.playground.data + coprs_logic.CoprsLogic.set_playground(flask.g.user, copr) + except InsufficientRightsException as e: + flask.flash(str(e)) + db.session.rollback() + else: + flask.flash("Playground flag has been updated") + db.session.commit() + + return flask.redirect(flask.url_for("admin_ns.playground_project", + username=username, + coprname=coprname)) +
copr-commits@lists.fedorahosted.org