diff --git a/app/models.py b/app/models.py
index c97bdd90..02ae8876 100644
--- a/app/models.py
+++ b/app/models.py
@@ -251,6 +251,7 @@ class EditRequest(db.Model):
title = db.Column(db.String(100), nullable=False)
desc = db.Column(db.String(1000), nullable=True)
+ status = db.Column(db.Integer, nullable=False, default=0)
changes = db.relationship("EditRequestChange", backref="request",
lazy="dynamic")
@@ -262,6 +263,20 @@ class EditRequest(db.Model):
name=self.package.name,
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):
for change in self.changes:
change.apply(package)
@@ -275,12 +290,11 @@ class EditRequestChange(db.Model):
key = db.Column(db.Enum(PackagePropertyKey), nullable=False)
# TODO: make diff instead
- oldValue = db.Column(db.Text, nullable=False)
- newValue = db.Column(db.Text, nullable=False)
+ oldValue = db.Column(db.Text, nullable=True)
+ newValue = db.Column(db.Text, nullable=True)
def apply(self, package):
- prop = PackagePropertyKey[self.key]
-
+ setattr(package, self.key.name, self.newValue)
# Setup Flask-User
db_adapter = SQLAlchemyAdapter(db, User) # Register the User model
diff --git a/app/static/style.css b/app/static/style.css
index 551cc740..57d51993 100644
--- a/app/static/style.css
+++ b/app/static/style.css
@@ -147,6 +147,11 @@ a:hover {
border: 1px solid #c96;
}
+.alert-success {
+ background: #161;
+ border: 1px solid #393;
+}
+
/* Nav */
nav, main, #alerts {
diff --git a/app/templates/packages/editrequest_view.html b/app/templates/packages/editrequest_view.html
index b7abbbe2..22b60ae2 100644
--- a/app/templates/packages/editrequest_view.html
+++ b/app/templates/packages/editrequest_view.html
@@ -16,6 +16,21 @@
No description given
{% endif %}
+ {% if request.status == 1 %}
+
+ This edit request was merged.
+
+ {% elif request.status == 2 %}
+
+ This edit request was rejected.
+
+ {% elif package.checkPerm(current_user, "APPROVE_CHANGES") %}
+
+ {% endif %}
diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html
index 9ed7defd..2ed3a321 100644
--- a/app/templates/packages/view.html
+++ b/app/templates/packages/view.html
@@ -87,11 +87,11 @@
{% endfor %}
- {% if current_user.is_authenticated or package.requests %}
+ {% if current_user.is_authenticated or requests %}
Edit Requests
- {% for r in package.requests %}
+ {% for r in requests %}
-
{{ r.title }}
by
diff --git a/app/views/packages.py b/app/views/packages.py
index 62616065..6cace90c 100644
--- a/app/views/packages.py
+++ b/app/views/packages.py
@@ -107,7 +107,8 @@ def package_page(type, author, name):
return jsonify(package.getAsDictionary(request.url_root))
else:
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("/s///download/")
@@ -216,30 +217,27 @@ def create_editrequest_page(ptype, author, name):
wasChangeMade = False
for e in PackagePropertyKey:
newValue = getattr(editedPackage, e.name)
-
oldValue = getattr(package, e.name)
- if newValue == "":
- newValue = None
newValueComp = newValue
oldValueComp = oldValue
if type(newValue) is str:
newValue = newValue.replace("\r\n", "\n")
newValueComp = newValue.strip()
- oldValueComp = oldValue.strip()
+ oldValueComp = "" if oldValue is None else oldValue.strip()
if newValueComp != oldValueComp:
change = EditRequestChange()
change.request = erequest
change.key = e
- change.oldValue = oldValue
- change.newValue = newValue
+ change.oldValue = str(oldValue)
+ change.newValue = str(newValue)
db.session.add(change)
wasChangeMade = True
if wasChangeMade:
db.session.commit()
- return redirect(package.getDetailsURL())
+ return redirect(erequest.getURL())
else:
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)
+@app.route("/s///requests//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("/s///requests//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):
name = StringField("Name")
title = StringField("Title")