diff options
| author | rubenwardy <rw@rubenwardy.com> | 2019-11-15 23:51:42 +0000 |
|---|---|---|
| committer | rubenwardy <rw@rubenwardy.com> | 2019-11-15 23:51:42 +0000 |
| commit | 64f131ae27a7332245b5a4eb8e1e4879d7d99578 (patch) | |
| tree | a0b4101ca9c2132a072f1586c0df693583c91cf7 /app/views/admin | |
| parent | 015abe5a2507ad02273bc89953016c386aae4457 (diff) | |
| download | cheatdb-64f131ae27a7332245b5a4eb8e1e4879d7d99578.tar.xz | |
Refactor endpoints to use blueprints instead
Diffstat (limited to 'app/views/admin')
| -rw-r--r-- | app/views/admin/__init__.py | 18 | ||||
| -rw-r--r-- | app/views/admin/admin.py | 128 | ||||
| -rw-r--r-- | app/views/admin/licenseseditor.py | 62 | ||||
| -rw-r--r-- | app/views/admin/tagseditor.py | 57 | ||||
| -rw-r--r-- | app/views/admin/todo.py | 101 | ||||
| -rw-r--r-- | app/views/admin/versioneditor.py | 60 |
6 files changed, 0 insertions, 426 deletions
diff --git a/app/views/admin/__init__.py b/app/views/admin/__init__.py deleted file mode 100644 index 2e467da..0000000 --- a/app/views/admin/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -# Content DB -# Copyright (C) 2018 rubenwardy -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - - -from . import admin, licenseseditor, tagseditor, versioneditor, todo diff --git a/app/views/admin/admin.py b/app/views/admin/admin.py deleted file mode 100644 index b359700..0000000 --- a/app/views/admin/admin.py +++ /dev/null @@ -1,128 +0,0 @@ -# Content DB -# Copyright (C) 2018 rubenwardy -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - - -from flask import * -from flask_user import * -import flask_menu as menu -from app import app -from app.models import * -from celery import uuid -from app.tasks.importtasks import importRepoScreenshot, importAllDependencies, makeVCSRelease -from app.tasks.forumtasks import importTopicList, checkAllForumAccounts -from flask_wtf import FlaskForm -from wtforms import * -from app.utils import loginUser, rank_required, triggerNotif -import datetime - -@app.route("/admin/", methods=["GET", "POST"]) -@rank_required(UserRank.ADMIN) -def admin_page(): - if request.method == "POST": - action = request.form["action"] - if action == "delstuckreleases": - PackageRelease.query.filter(PackageRelease.task_id != None).delete() - db.session.commit() - return redirect(url_for("admin_page")) - elif action == "importmodlist": - task = importTopicList.delay() - return redirect(url_for("check_task", id=task.id, r=url_for("todo_topics_page"))) - elif action == "checkusers": - task = checkAllForumAccounts.delay() - return redirect(url_for("check_task", id=task.id, r=url_for("admin_page"))) - elif action == "importscreenshots": - packages = Package.query \ - .filter_by(soft_deleted=False) \ - .outerjoin(PackageScreenshot, Package.id==PackageScreenshot.package_id) \ - .filter(PackageScreenshot.id==None) \ - .all() - for package in packages: - importRepoScreenshot.delay(package.id) - - return redirect(url_for("admin_page")) - elif action == "restore": - package = Package.query.get(request.form["package"]) - if package is None: - flash("Unknown package", "error") - else: - package.soft_deleted = False - db.session.commit() - return redirect(url_for("admin_page")) - elif action == "importdepends": - task = importAllDependencies.delay() - return redirect(url_for("check_task", id=task.id, r=url_for("admin_page"))) - elif action == "modprovides": - packages = Package.query.filter_by(type=PackageType.MOD).all() - mpackage_cache = {} - for p in packages: - if len(p.provides) == 0: - p.provides.append(MetaPackage.GetOrCreate(p.name, mpackage_cache)) - - db.session.commit() - return redirect(url_for("admin_page")) - elif action == "recalcscores": - for p in Package.query.all(): - p.recalcScore() - - db.session.commit() - return redirect(url_for("admin_page")) - elif action == "vcsrelease": - for package in Package.query.filter(Package.repo.isnot(None)).all(): - if package.releases.count() != 0: - continue - - rel = PackageRelease() - rel.package = package - rel.title = datetime.date.today().isoformat() - rel.url = "" - rel.task_id = uuid() - rel.approved = True - db.session.add(rel) - db.session.commit() - - makeVCSRelease.apply_async((rel.id, "master"), task_id=rel.task_id) - - msg = "{}: Release {} created".format(package.title, rel.title) - triggerNotif(package.author, current_user, msg, rel.getEditURL()) - db.session.commit() - - else: - flash("Unknown action: " + action, "error") - - deleted_packages = Package.query.filter_by(soft_deleted=True).all() - return render_template("admin/list.html", deleted_packages=deleted_packages) - -class SwitchUserForm(FlaskForm): - username = StringField("Username") - submit = SubmitField("Switch") - - -@app.route("/admin/switchuser/", methods=["GET", "POST"]) -@rank_required(UserRank.ADMIN) -def switch_user_page(): - form = SwitchUserForm(formdata=request.form) - if request.method == "POST" and form.validate(): - user = User.query.filter_by(username=form["username"].data).first() - if user is None: - flash("Unable to find user", "error") - elif loginUser(user): - return redirect(url_for("user_profile_page", username=current_user.username)) - else: - flash("Unable to login as user", "error") - - - # Process GET or invalid POST - return render_template("admin/switch_user_page.html", form=form) diff --git a/app/views/admin/licenseseditor.py b/app/views/admin/licenseseditor.py deleted file mode 100644 index 343f4ee..0000000 --- a/app/views/admin/licenseseditor.py +++ /dev/null @@ -1,62 +0,0 @@ -# Content DB -# Copyright (C) 2018 rubenwardy -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - - -from flask import * -from flask_user import * -from app import app -from app.models import * -from flask_wtf import FlaskForm -from wtforms import * -from wtforms.validators import * -from app.utils import rank_required - -@app.route("/licenses/") -@rank_required(UserRank.MODERATOR) -def license_list_page(): - return render_template("admin/licenses/list.html", licenses=License.query.order_by(db.asc(License.name)).all()) - -class LicenseForm(FlaskForm): - name = StringField("Name", [InputRequired(), Length(3,100)]) - is_foss = BooleanField("Is FOSS") - submit = SubmitField("Save") - -@app.route("/licenses/new/", methods=["GET", "POST"]) -@app.route("/licenses/<name>/edit/", methods=["GET", "POST"]) -@rank_required(UserRank.MODERATOR) -def createedit_license_page(name=None): - license = None - if name is not None: - license = License.query.filter_by(name=name).first() - if license is None: - abort(404) - - form = LicenseForm(formdata=request.form, obj=license) - if request.method == "GET" and license is None: - form.is_foss.data = True - elif request.method == "POST" and form.validate(): - if license is None: - license = License(form.name.data) - db.session.add(license) - flash("Created license " + form.name.data, "success") - else: - flash("Updated license " + form.name.data, "success") - - form.populate_obj(license) - db.session.commit() - return redirect(url_for("license_list_page")) - - return render_template("admin/licenses/edit.html", license=license, form=form) diff --git a/app/views/admin/tagseditor.py b/app/views/admin/tagseditor.py deleted file mode 100644 index 7d88f28..0000000 --- a/app/views/admin/tagseditor.py +++ /dev/null @@ -1,57 +0,0 @@ -# Content DB -# Copyright (C) 2018 rubenwardy -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - - -from flask import * -from flask_user import * -from app import app -from app.models import * -from flask_wtf import FlaskForm -from wtforms import * -from wtforms.validators import * -from app.utils import rank_required - -@app.route("/tags/") -@rank_required(UserRank.MODERATOR) -def tag_list_page(): - return render_template("admin/tags/list.html", tags=Tag.query.order_by(db.asc(Tag.title)).all()) - -class TagForm(FlaskForm): - title = StringField("Title", [InputRequired(), Length(3,100)]) - name = StringField("Name", [Optional(), Length(1, 20), Regexp("^[a-z0-9_]", 0, "Lower case letters (a-z), digits (0-9), and underscores (_) only")]) - submit = SubmitField("Save") - -@app.route("/tags/new/", methods=["GET", "POST"]) -@app.route("/tags/<name>/edit/", methods=["GET", "POST"]) -@rank_required(UserRank.MODERATOR) -def createedit_tag_page(name=None): - tag = None - if name is not None: - tag = Tag.query.filter_by(name=name).first() - if tag is None: - abort(404) - - form = TagForm(formdata=request.form, obj=tag) - if request.method == "POST" and form.validate(): - if tag is None: - tag = Tag(form.title.data) - db.session.add(tag) - else: - form.populate_obj(tag) - db.session.commit() - return redirect(url_for("createedit_tag_page", name=tag.name)) - - return render_template("admin/tags/edit.html", tag=tag, form=form) diff --git a/app/views/admin/todo.py b/app/views/admin/todo.py deleted file mode 100644 index 9909eff..0000000 --- a/app/views/admin/todo.py +++ /dev/null @@ -1,101 +0,0 @@ -# Content DB -# Copyright (C) 2018 rubenwardy -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - - -from flask import * -from flask_user import * -import flask_menu as menu -from app import app -from app.models import * -from app.querybuilder import QueryBuilder - -@app.route("/todo/", methods=["GET", "POST"]) -@login_required -def todo_page(): - canApproveNew = Permission.APPROVE_NEW.check(current_user) - canApproveRel = Permission.APPROVE_RELEASE.check(current_user) - canApproveScn = Permission.APPROVE_SCREENSHOT.check(current_user) - - packages = None - if canApproveNew: - packages = Package.query.filter_by(approved=False, soft_deleted=False).order_by(db.desc(Package.created_at)).all() - - releases = None - if canApproveRel: - releases = PackageRelease.query.filter_by(approved=False).all() - - screenshots = None - if canApproveScn: - screenshots = PackageScreenshot.query.filter_by(approved=False).all() - - if not canApproveNew and not canApproveRel and not canApproveScn: - abort(403) - - if request.method == "POST": - if request.form["action"] == "screenshots_approve_all": - if not canApproveScn: - abort(403) - - PackageScreenshot.query.update({ "approved": True }) - db.session.commit() - return redirect(url_for("todo_page")) - else: - abort(400) - - topic_query = ForumTopic.query \ - .filter_by(discarded=False) - - total_topics = topic_query.count() - topics_to_add = topic_query \ - .filter(~ db.exists().where(Package.forums==ForumTopic.topic_id)) \ - .count() - - return render_template("todo/list.html", title="Reports and Work Queue", - packages=packages, releases=releases, screenshots=screenshots, - canApproveNew=canApproveNew, canApproveRel=canApproveRel, canApproveScn=canApproveScn, - topics_to_add=topics_to_add, total_topics=total_topics) - - -@app.route("/todo/topics/") -@login_required -def todo_topics_page(): - qb = QueryBuilder(request.args) - qb.setSortIfNone("date") - query = qb.buildTopicQuery() - - tmp_q = ForumTopic.query - if not qb.show_discarded: - tmp_q = tmp_q.filter_by(discarded=False) - total = tmp_q.count() - topic_count = query.count() - - page = int(request.args.get("page") or 1) - num = int(request.args.get("n") or 100) - if num > 100 and not current_user.rank.atLeast(UserRank.EDITOR): - num = 100 - - query = query.paginate(page, num, True) - next_url = url_for("todo_topics_page", page=query.next_num, query=qb.search, \ - show_discarded=qb.show_discarded, n=num, sort=qb.order_by) \ - if query.has_next else None - prev_url = url_for("todo_topics_page", page=query.prev_num, query=qb.search, \ - show_discarded=qb.show_discarded, n=num, sort=qb.order_by) \ - if query.has_prev else None - - return render_template("todo/topics.html", topics=query.items, total=total, \ - topic_count=topic_count, query=qb.search, show_discarded=qb.show_discarded, \ - next_url=next_url, prev_url=prev_url, page=page, page_max=query.pages, \ - n=num, sort_by=qb.order_by) diff --git a/app/views/admin/versioneditor.py b/app/views/admin/versioneditor.py deleted file mode 100644 index 6bcf93a..0000000 --- a/app/views/admin/versioneditor.py +++ /dev/null @@ -1,60 +0,0 @@ -# Content DB -# Copyright (C) 2018 rubenwardy -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - - -from flask import * -from flask_user import * -from app import app -from app.models import * -from flask_wtf import FlaskForm -from wtforms import * -from wtforms.validators import * -from app.utils import rank_required - -@app.route("/versions/") -@rank_required(UserRank.MODERATOR) -def version_list_page(): - return render_template("admin/versions/list.html", versions=MinetestRelease.query.order_by(db.asc(MinetestRelease.id)).all()) - -class VersionForm(FlaskForm): - name = StringField("Name", [InputRequired(), Length(3,100)]) - protocol = IntegerField("Protocol") - submit = SubmitField("Save") - -@app.route("/versions/new/", methods=["GET", "POST"]) -@app.route("/versions/<name>/edit/", methods=["GET", "POST"]) -@rank_required(UserRank.MODERATOR) -def createedit_version_page(name=None): - version = None - if name is not None: - version = MinetestRelease.query.filter_by(name=name).first() - if version is None: - abort(404) - - form = VersionForm(formdata=request.form, obj=version) - if request.method == "POST" and form.validate(): - if version is None: - version = MinetestRelease(form.name.data) - db.session.add(version) - flash("Created version " + form.name.data, "success") - else: - flash("Updated version " + form.name.data, "success") - - form.populate_obj(version) - db.session.commit() - return redirect(url_for("version_list_page")) - - return render_template("admin/versions/edit.html", version=version, form=form) |
