mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 22:12:24 +01:00
Add EditRequest approval and rejection
This commit is contained in:
parent
a5042a986a
commit
bb9d589fb5
@ -251,6 +251,7 @@ class EditRequest(db.Model):
|
|||||||
title = db.Column(db.String(100), nullable=False)
|
title = db.Column(db.String(100), nullable=False)
|
||||||
desc = db.Column(db.String(1000), nullable=True)
|
desc = db.Column(db.String(1000), nullable=True)
|
||||||
|
|
||||||
|
status = db.Column(db.Integer, nullable=False, default=0)
|
||||||
|
|
||||||
changes = db.relationship("EditRequestChange", backref="request",
|
changes = db.relationship("EditRequestChange", backref="request",
|
||||||
lazy="dynamic")
|
lazy="dynamic")
|
||||||
@ -262,6 +263,20 @@ class EditRequest(db.Model):
|
|||||||
name=self.package.name,
|
name=self.package.name,
|
||||||
id=self.id)
|
id=self.id)
|
||||||
|
|
||||||
|
def getApproveURL(self):
|
||||||
|
return url_for("approve_editrequest_page",
|
||||||
|
ptype=self.package.type.toName(),
|
||||||
|
author=self.package.author.username,
|
||||||
|
name=self.package.name,
|
||||||
|
id=self.id)
|
||||||
|
|
||||||
|
def getRejectURL(self):
|
||||||
|
return url_for("reject_editrequest_page",
|
||||||
|
ptype=self.package.type.toName(),
|
||||||
|
author=self.package.author.username,
|
||||||
|
name=self.package.name,
|
||||||
|
id=self.id)
|
||||||
|
|
||||||
def applyAll(self, package):
|
def applyAll(self, package):
|
||||||
for change in self.changes:
|
for change in self.changes:
|
||||||
change.apply(package)
|
change.apply(package)
|
||||||
@ -275,12 +290,11 @@ class EditRequestChange(db.Model):
|
|||||||
key = db.Column(db.Enum(PackagePropertyKey), nullable=False)
|
key = db.Column(db.Enum(PackagePropertyKey), nullable=False)
|
||||||
|
|
||||||
# TODO: make diff instead
|
# TODO: make diff instead
|
||||||
oldValue = db.Column(db.Text, nullable=False)
|
oldValue = db.Column(db.Text, nullable=True)
|
||||||
newValue = db.Column(db.Text, nullable=False)
|
newValue = db.Column(db.Text, nullable=True)
|
||||||
|
|
||||||
def apply(self, package):
|
def apply(self, package):
|
||||||
prop = PackagePropertyKey[self.key]
|
setattr(package, self.key.name, self.newValue)
|
||||||
|
|
||||||
|
|
||||||
# Setup Flask-User
|
# Setup Flask-User
|
||||||
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model
|
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model
|
||||||
|
@ -147,6 +147,11 @@ a:hover {
|
|||||||
border: 1px solid #c96;
|
border: 1px solid #c96;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.alert-success {
|
||||||
|
background: #161;
|
||||||
|
border: 1px solid #393;
|
||||||
|
}
|
||||||
|
|
||||||
/* Nav */
|
/* Nav */
|
||||||
|
|
||||||
nav, main, #alerts {
|
nav, main, #alerts {
|
||||||
|
@ -16,6 +16,21 @@
|
|||||||
<i>No description given</i>
|
<i>No description given</i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
|
{% if request.status == 1 %}
|
||||||
|
<div class="box box_grey alert alert-success">
|
||||||
|
This edit request was merged.
|
||||||
|
</div>
|
||||||
|
{% elif request.status == 2 %}
|
||||||
|
<div class="box box_grey alert alert-error">
|
||||||
|
This edit request was rejected.
|
||||||
|
</div>
|
||||||
|
{% elif package.checkPerm(current_user, "APPROVE_CHANGES") %}
|
||||||
|
<div class="box box_grey">
|
||||||
|
To resolve this request, either
|
||||||
|
<a href="{{ request.getApproveURL() }}">Approve and Apply</a> or
|
||||||
|
<a href="{{ request.getRejectURL() }}">Reject</a> it.
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -87,11 +87,11 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{% if current_user.is_authenticated or package.requests %}
|
{% if current_user.is_authenticated or requests %}
|
||||||
<h3>Edit Requests</h3>
|
<h3>Edit Requests</h3>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{% for r in package.requests %}
|
{% for r in requests %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ r.getURL() }}">{{ r.title }}</a>
|
<a href="{{ r.getURL() }}">{{ r.title }}</a>
|
||||||
by
|
by
|
||||||
|
@ -107,7 +107,8 @@ def package_page(type, author, name):
|
|||||||
return jsonify(package.getAsDictionary(request.url_root))
|
return jsonify(package.getAsDictionary(request.url_root))
|
||||||
else:
|
else:
|
||||||
releases = getReleases(package)
|
releases = getReleases(package)
|
||||||
return render_template("packages/view.html", package=package, releases=releases)
|
requests = [r for r in package.requests if r.status == 0]
|
||||||
|
return render_template("packages/view.html", package=package, releases=releases, requests=requests)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/<type>s/<author>/<name>/download/")
|
@app.route("/<type>s/<author>/<name>/download/")
|
||||||
@ -216,30 +217,27 @@ def create_editrequest_page(ptype, author, name):
|
|||||||
wasChangeMade = False
|
wasChangeMade = False
|
||||||
for e in PackagePropertyKey:
|
for e in PackagePropertyKey:
|
||||||
newValue = getattr(editedPackage, e.name)
|
newValue = getattr(editedPackage, e.name)
|
||||||
|
|
||||||
oldValue = getattr(package, e.name)
|
oldValue = getattr(package, e.name)
|
||||||
if newValue == "":
|
|
||||||
newValue = None
|
|
||||||
|
|
||||||
newValueComp = newValue
|
newValueComp = newValue
|
||||||
oldValueComp = oldValue
|
oldValueComp = oldValue
|
||||||
if type(newValue) is str:
|
if type(newValue) is str:
|
||||||
newValue = newValue.replace("\r\n", "\n")
|
newValue = newValue.replace("\r\n", "\n")
|
||||||
newValueComp = newValue.strip()
|
newValueComp = newValue.strip()
|
||||||
oldValueComp = oldValue.strip()
|
oldValueComp = "" if oldValue is None else oldValue.strip()
|
||||||
|
|
||||||
if newValueComp != oldValueComp:
|
if newValueComp != oldValueComp:
|
||||||
change = EditRequestChange()
|
change = EditRequestChange()
|
||||||
change.request = erequest
|
change.request = erequest
|
||||||
change.key = e
|
change.key = e
|
||||||
change.oldValue = oldValue
|
change.oldValue = str(oldValue)
|
||||||
change.newValue = newValue
|
change.newValue = str(newValue)
|
||||||
db.session.add(change)
|
db.session.add(change)
|
||||||
wasChangeMade = True
|
wasChangeMade = True
|
||||||
|
|
||||||
if wasChangeMade:
|
if wasChangeMade:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(package.getDetailsURL())
|
return redirect(erequest.getURL())
|
||||||
else:
|
else:
|
||||||
flash("No changes detected", "warning")
|
flash("No changes detected", "warning")
|
||||||
|
|
||||||
@ -257,6 +255,48 @@ def view_editrequest_page(ptype, author, name, id):
|
|||||||
return render_template("packages/editrequest_view.html", package=package, request=erequest)
|
return render_template("packages/editrequest_view.html", package=package, request=erequest)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/<ptype>s/<author>/<name>/requests/<id>/approve/")
|
||||||
|
def approve_editrequest_page(ptype, author, name, id):
|
||||||
|
package = getPageByInfo(ptype, author, name)
|
||||||
|
if not package.checkPerm(current_user, Permission.APPROVE_CHANGES):
|
||||||
|
flash("You don't have permission to do that.", "error")
|
||||||
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
|
erequest = EditRequest.query.filter_by(id=id).first()
|
||||||
|
if erequest is None:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
if erequest.status != 0:
|
||||||
|
flash("Edit request has already been resolved", "error")
|
||||||
|
|
||||||
|
else:
|
||||||
|
erequest.status = 1
|
||||||
|
erequest.applyAll(package)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
|
@app.route("/<ptype>s/<author>/<name>/requests/<id>/reject/")
|
||||||
|
def reject_editrequest_page(ptype, author, name, id):
|
||||||
|
package = getPageByInfo(ptype, author, name)
|
||||||
|
if not package.checkPerm(current_user, Permission.APPROVE_CHANGES):
|
||||||
|
flash("You don't have permission to do that.", "error")
|
||||||
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
|
erequest = EditRequest.query.filter_by(id=id).first()
|
||||||
|
if erequest is None:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
if erequest.status != 0:
|
||||||
|
flash("Edit request has already been resolved", "error")
|
||||||
|
|
||||||
|
else:
|
||||||
|
erequest.status = 2
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return redirect(package.getDetailsURL())
|
||||||
|
|
||||||
|
|
||||||
class CreatePackageReleaseForm(FlaskForm):
|
class CreatePackageReleaseForm(FlaskForm):
|
||||||
name = StringField("Name")
|
name = StringField("Name")
|
||||||
title = StringField("Title")
|
title = StringField("Title")
|
||||||
|
Loading…
Reference in New Issue
Block a user