Add support for post-approval threads

This commit is contained in:
rubenwardy 2018-07-28 15:19:30 +01:00
parent df8d05f09d
commit 909a2b4ce9
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
4 changed files with 12 additions and 5 deletions

View File

@ -77,6 +77,7 @@ class Permission(enum.Enum):
CHANGE_EMAIL = "CHANGE_EMAIL"
EDIT_EDITREQUEST = "EDIT_EDITREQUEST"
SEE_THREAD = "SEE_THREAD"
CREATE_THREAD = "CREATE_THREAD"
# Only return true if the permission is valid for *all* contexts
# See Package.checkPerm for package-specific contexts
@ -480,7 +481,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 or perm == Permission.ADD_SCREENSHOTS:
if perm == Permission.MAKE_RELEASE or perm == Permission.ADD_SCREENSHOTS or perm == Permission.CREATE_THREAD:
return isOwner or user.rank.atLeast(UserRank.EDITOR)
if perm == Permission.EDIT_PACKAGE or perm == Permission.APPROVE_CHANGES:

View File

@ -28,7 +28,7 @@
{% macro render_threadlist(threads) -%}
<ul>
{% for t in threads %}
<li><a href="{{ url_for('thread_page', id=t.id) }}">{{ t.title }}</a> by {{ t.author.display_name }}</li>
<li>{% if t.private %}&#x1f512; {% endif %}<a href="{{ url_for('thread_page', id=t.id) }}">{{ t.title }}</a> by {{ t.author.display_name }}</li>
{% else %}
<li><i>No threads found</i></li>
{% endfor %}

View File

@ -171,6 +171,9 @@
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
<li><a href="{{ package.getCreateReleaseURL() }}">Create Release</a></li>
{% endif %}
{% if package.approved and package.checkPerm(current_user, "CREATE_THREAD") %}
<li><a href="{{ url_for('new_thread_page', pid=package.id) }}">Open Thread</a></li>
{% endif %}
{% if package.checkPerm(current_user, "DELETE_PACKAGE") %}
<li><a href="{{ package.getDeleteURL() }}">Delete</a></li>
{% endif %}
@ -319,6 +322,10 @@
{% if threads %}
<h3>Threads</h3>
{% if package.approved and package.checkPerm(current_user, "CREATE_THREAD") %}
<p><a href="{{ url_for('new_thread_page', pid=package.id) }}">Open Thread</a></p>
{% endif %}
{% from "macros/threads.html" import render_threadlist %}
{{ render_threadlist(threads) }}
{% endif %}

View File

@ -92,7 +92,7 @@ def new_thread_page():
flash("Unable to find that package!", "error")
# Don't allow making threads on approved packages for now
if package is None or package.approved:
if package is None:
abort(403)
def_is_private = request.args.get("private") or False
@ -102,8 +102,7 @@ def new_thread_page():
is_review_thread = package is not None and not package.approved
# Check that user can make the thread
if is_review_thread and not (package.author == current_user or \
package.checkPerm(current_user, Permission.APPROVE_NEW)):
if not package.checkPerm(current_user, Permission.CREATE_THREAD):
flash("Unable to create thread!", "error")
return redirect(url_for("home_page"))