From 53df124973c15b90e070f9225fcbeccdb0e64e55 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 25 May 2018 18:57:30 +0100 Subject: [PATCH] Add edit and delete screenshot --- app/flatpages/help/ranks_permissions.md | 26 +++++++++++ app/models.py | 14 +++++- app/tasks/importtasks.py | 1 + app/templates/packages/screenshot_edit.html | 22 ++++++++++ app/templates/packages/view.html | 2 +- app/views/admin.py | 3 +- app/views/packages/__init__.py | 2 +- app/views/packages/screenshots.py | 48 ++++++++++++++++++++- migrations/versions/fa12fadbdb40_.py | 28 ++++++++++++ 9 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 app/templates/packages/screenshot_edit.html create mode 100644 migrations/versions/fa12fadbdb40_.py diff --git a/app/flatpages/help/ranks_permissions.md b/app/flatpages/help/ranks_permissions.md index 79dc7d21..61b70e36 100644 --- a/app/flatpages/help/ranks_permissions.md +++ b/app/flatpages/help/ranks_permissions.md @@ -74,6 +74,32 @@ title: Ranks and Permissions ✓ ✓ + + Add/Delete Screenshot + ✓ + + ✓ + + ✓ + ✓ + ✓ + ✓ + ✓ + ✓ + + + Approve Screenshot + + + ✓ + + ✓ + ✓ + ✓ + ✓ + ✓ + ✓ + Approve EditRequest diff --git a/app/models.py b/app/models.py index 9118f78c..e8b66fba 100644 --- a/app/models.py +++ b/app/models.py @@ -65,6 +65,8 @@ class Permission(enum.Enum): DELETE_PACKAGE = "DELETE_PACKAGE" CHANGE_AUTHOR = "CHANGE_AUTHOR" MAKE_RELEASE = "MAKE_RELEASE" + ADD_SCREENSHOTS = "ADD_SCREENSHOTS" + APPROVE_SCREENSHOT = "APPROVE_SCREENSHOT" APPROVE_RELEASE = "APPROVE_RELEASE" APPROVE_NEW = "APPROVE_NEW" CHANGE_RELEASE_URL = "CHANGE_RELEASE_URL" @@ -393,7 +395,7 @@ class Package(db.Model): isOwner = user == self.author # Members can edit their own packages, and editors can edit any packages - if perm == Permission.MAKE_RELEASE: + if perm == Permission.MAKE_RELEASE or perm == Permission.ADD_SCREENSHOTS: return isOwner or user.rank.atLeast(UserRank.EDITOR) if perm == Permission.EDIT_PACKAGE or perm == Permission.APPROVE_CHANGES: @@ -401,7 +403,7 @@ class Package(db.Model): # Editors can change authors, approve new packages, and approve releases elif perm == Permission.CHANGE_AUTHOR or perm == Permission.APPROVE_NEW \ - or perm == Permission.APPROVE_RELEASE: + or perm == Permission.APPROVE_RELEASE or perm == Permission.APPROVE_SCREENSHOT: return user.rank.atLeast(UserRank.EDITOR) # Moderators can delete packages @@ -452,6 +454,14 @@ class PackageScreenshot(db.Model): package_id = db.Column(db.Integer, db.ForeignKey("package.id")) title = db.Column(db.String(100), nullable=False) url = db.Column(db.String(100), nullable=False) + approved = db.Column(db.Boolean, nullable=False, default=False) + + + def getEditURL(self): + return url_for("edit_screenshot_page", + author=self.package.author.username, + name=self.package.name, + id=self.id) def getThumbnailURL(self): return self.url # TODO diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index a20bbee8..db992b3c 100644 --- a/app/tasks/importtasks.py +++ b/app/tasks/importtasks.py @@ -252,6 +252,7 @@ def importRepoScreenshot(id): urllib.request.urlretrieve(urlmaker.getScreenshotURL(), imagePath) ss = PackageScreenshot() + ss.approved = True ss.package = package ss.title = "screenshot.png" ss.url = "/uploads/" + filename diff --git a/app/templates/packages/screenshot_edit.html b/app/templates/packages/screenshot_edit.html new file mode 100644 index 00000000..7e0f9dc5 --- /dev/null +++ b/app/templates/packages/screenshot_edit.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} + +{% block title %} + Add a screenshot | {{ package.title }} +{% endblock %} + +{% block content %} + {% from "macros/forms.html" import render_field, render_submit_field %} +
+ {{ form.hidden_tag() }} + + {{ render_field(form.title) }} + {{ render_field(form.delete) }} + + {% if package.checkPerm(current_user, "APPROVE_SCREENSHOT") %} + {{ render_field(form.approved) }} + {% else %} +

Approved: {{ screenshot.approved }}

+ {% endif %} + {{ render_submit_field(form.submit) }} +
+{% endblock %} diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html index 8d329ef7..85a0b7d7 100644 --- a/app/templates/packages/view.html +++ b/app/templates/packages/view.html @@ -42,7 +42,7 @@