mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-23 06:22:24 +01:00
Add package release editing and approving
This commit is contained in:
parent
32ac60256c
commit
5cc49f2828
@ -33,6 +33,7 @@ class Permission(enum.Enum):
|
|||||||
MAKE_RELEASE = "MAKE_RELEASE"
|
MAKE_RELEASE = "MAKE_RELEASE"
|
||||||
APPROVE_RELEASE = "APPROVE_RELEASE"
|
APPROVE_RELEASE = "APPROVE_RELEASE"
|
||||||
APPROVE_NEW = "APPROVE_NEW"
|
APPROVE_NEW = "APPROVE_NEW"
|
||||||
|
CHANGE_RELEASE_URL = "CHANGE_RELEASE_URL"
|
||||||
|
|
||||||
|
|
||||||
class User(db.Model, UserMixin):
|
class User(db.Model, UserMixin):
|
||||||
@ -150,7 +151,7 @@ class Package(db.Model):
|
|||||||
return user.rank.atLeast(UserRank.EDITOR)
|
return user.rank.atLeast(UserRank.EDITOR)
|
||||||
|
|
||||||
# Moderators can delete packages
|
# Moderators can delete packages
|
||||||
elif perm == Permission.DELETE_PACKAGE:
|
elif perm == Permission.DELETE_PACKAGE or perm == Permission.CHANGE_RELEASE_URL:
|
||||||
return user.rank.atLeast(UserRank.MODERATOR)
|
return user.rank.atLeast(UserRank.MODERATOR)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -165,6 +166,14 @@ class PackageRelease(db.Model):
|
|||||||
url = db.Column(db.String(100), nullable=False)
|
url = db.Column(db.String(100), nullable=False)
|
||||||
approved = db.Column(db.Boolean, nullable=False, default=False)
|
approved = db.Column(db.Boolean, nullable=False, default=False)
|
||||||
|
|
||||||
|
|
||||||
|
def getEditURL(self):
|
||||||
|
return url_for("edit_release_page",
|
||||||
|
type=self.package.type.toName(),
|
||||||
|
author=self.package.author.username,
|
||||||
|
name=self.package.name,
|
||||||
|
id=self.id)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.releaseDate = datetime.now()
|
self.releaseDate = datetime.now()
|
||||||
|
|
||||||
|
@ -58,9 +58,14 @@
|
|||||||
created {{ rel.releaseDate }}.
|
created {{ rel.releaseDate }}.
|
||||||
{% if not rel.approved %}
|
{% if not rel.approved %}
|
||||||
Waiting for approval.
|
Waiting for approval.
|
||||||
{% if package.checkPerm(current_user, "APPROVE_RELEASE") %}
|
|
||||||
<a href="">Approve</a>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if package.checkPerm(current_user, "MAKE_RELEASE") or package.checkPerm(current_user, "APPROVE_RELEASE") %}
|
||||||
|
<a href="{{ rel.getEditURL() }}">Edit
|
||||||
|
{% if not rel.approved and package.checkPerm(current_user, "APPROVE_RELEASE") %}
|
||||||
|
/ Approve
|
||||||
|
{% endif %}
|
||||||
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if not rel.approved %}</i>{% endif %}
|
{% if not rel.approved %}</i>{% endif %}
|
||||||
|
27
app/templates/package_release_edit.html
Normal file
27
app/templates/package_release_edit.html
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Create a release | {{ package.title }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% from "macros/forms.html" import render_field, render_submit_field %}
|
||||||
|
<form method="POST" action="">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
|
||||||
|
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
|
||||||
|
{{ render_field(form.title) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if package.checkPerm(current_user, "CHANGE_RELEASE_URL") %}
|
||||||
|
{{ render_field(form.url) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if package.checkPerm(current_user, "APPROVE_RELEASE") %}
|
||||||
|
{{ render_field(form.approved) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{{ render_submit_field(form.submit) }}
|
||||||
|
<input type="submit" value="Go">
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
@ -87,7 +87,7 @@ def edit_package_page(type, author, name):
|
|||||||
return render_template('package_edit.html', package=package, form=form)
|
return render_template('package_edit.html', package=package, form=form)
|
||||||
|
|
||||||
|
|
||||||
class PackageReleaseForm(FlaskForm):
|
class CreatePackageReleaseForm(FlaskForm):
|
||||||
name = StringField("Name")
|
name = StringField("Name")
|
||||||
title = StringField("Title")
|
title = StringField("Title")
|
||||||
uploadOpt = RadioField ("File", choices=[("vcs", "From VCS Commit or Branch"), ("upload", "File Upload")])
|
uploadOpt = RadioField ("File", choices=[("vcs", "From VCS Commit or Branch"), ("upload", "File Upload")])
|
||||||
@ -95,6 +95,13 @@ class PackageReleaseForm(FlaskForm):
|
|||||||
fileUpload = FileField("File Upload")
|
fileUpload = FileField("File Upload")
|
||||||
submit = SubmitField('Save')
|
submit = SubmitField('Save')
|
||||||
|
|
||||||
|
class EditPackageReleaseForm(FlaskForm):
|
||||||
|
name = StringField("Name")
|
||||||
|
title = StringField("Title")
|
||||||
|
url = StringField("URL")
|
||||||
|
approved = BooleanField("Is Approved")
|
||||||
|
submit = SubmitField('Save')
|
||||||
|
|
||||||
@app.route("/<type>s/<author>/<name>/releases/new/", methods=['GET', 'POST'])
|
@app.route("/<type>s/<author>/<name>/releases/new/", methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def create_release_page(type, author, name):
|
def create_release_page(type, author, name):
|
||||||
@ -103,7 +110,7 @@ def create_release_page(type, author, name):
|
|||||||
return redirect(package.getDetailsURL())
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
# Initial form class from post data and default data
|
# Initial form class from post data and default data
|
||||||
form = PackageReleaseForm(formdata=request.form)
|
form = CreatePackageReleaseForm(formdata=request.form)
|
||||||
if request.method == "POST" and form.validate():
|
if request.method == "POST" and form.validate():
|
||||||
if form["uploadOpt"].data == "vcs":
|
if form["uploadOpt"].data == "vcs":
|
||||||
rel = PackageRelease()
|
rel = PackageRelease()
|
||||||
@ -117,3 +124,43 @@ def create_release_page(type, author, name):
|
|||||||
raise Exception("Unimplemented option = file upload")
|
raise Exception("Unimplemented option = file upload")
|
||||||
|
|
||||||
return render_template('package_release_new.html', package=package, form=form)
|
return render_template('package_release_new.html', package=package, form=form)
|
||||||
|
|
||||||
|
@app.route("/<type>s/<author>/<name>/releases/<id>/", methods=['GET', 'POST'])
|
||||||
|
@login_required
|
||||||
|
def edit_release_page(type, author, name, id):
|
||||||
|
user = User.query.filter_by(username=author).first()
|
||||||
|
if user is None:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
release = PackageRelease.query.filter_by(id=id).first()
|
||||||
|
if release is None:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
package = release.package
|
||||||
|
if package.name != name or package.type != PackageType[type.upper()]:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
canEdit = package.checkPerm(current_user, Permission.MAKE_RELEASE)
|
||||||
|
canApprove = package.checkPerm(current_user, Permission.APPROVE_RELEASE)
|
||||||
|
if not (canEdit or canApprove):
|
||||||
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
|
# Initial form class from post data and default data
|
||||||
|
form = EditPackageReleaseForm(formdata=request.form, obj=release)
|
||||||
|
if request.method == "POST" and form.validate():
|
||||||
|
wasApproved = release.approved
|
||||||
|
if canEdit:
|
||||||
|
release.title = form["title"].data
|
||||||
|
|
||||||
|
if package.checkPerm(current_user, Permission.CHANGE_RELEASE_URL):
|
||||||
|
release.url = form["url"].data
|
||||||
|
|
||||||
|
if canApprove:
|
||||||
|
release.approved = form["approved"].data
|
||||||
|
else:
|
||||||
|
release.approved = wasApproved
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
|
return render_template('package_release_edit.html', package=package, form=form)
|
||||||
|
Loading…
Reference in New Issue
Block a user