Add ability to delete reviews
This commit is contained in:
parent
71f9fe469a
commit
436a4cce2b
@ -100,4 +100,32 @@ def review(package):
|
||||
|
||||
return redirect(package.getDetailsURL())
|
||||
|
||||
return render_template("packages/review_create_edit.html", form=form, package=package)
|
||||
return render_template("packages/review_create_edit.html", \
|
||||
form=form, package=package, review=review)
|
||||
|
||||
|
||||
@bp.route("/packages/<author>/<name>/review/delete/", methods=["POST"])
|
||||
@login_required
|
||||
@is_package_page
|
||||
def delete_review(package):
|
||||
review = PackageReview.query.filter_by(package=package, author=current_user).first()
|
||||
if review is None or review.package != package:
|
||||
abort(404)
|
||||
|
||||
thread = review.thread
|
||||
|
||||
reply = ThreadReply()
|
||||
reply.thread = thread
|
||||
reply.author = current_user
|
||||
reply.comment = "_converted review into a thread_"
|
||||
db.session.add(reply)
|
||||
|
||||
thread.review = None
|
||||
|
||||
notif_msg = "Deleted review '{}' on package {}, comments were kept as a thread".format(thread.title, package.title)
|
||||
addNotification(package.maintainers, current_user, notif_msg, url_for("threads.view", id=thread.id))
|
||||
|
||||
db.session.delete(review)
|
||||
db.session.commit()
|
||||
|
||||
return redirect(thread.getViewURL())
|
||||
|
@ -1080,14 +1080,14 @@ class Thread(db.Model):
|
||||
watchers = db.relationship("User", secondary=watchers, lazy="subquery", \
|
||||
backref=db.backref("watching", lazy=True))
|
||||
|
||||
def getViewURL(self):
|
||||
return url_for("threads.view", id=self.id)
|
||||
|
||||
def getSubscribeURL(self):
|
||||
return url_for("threads.subscribe",
|
||||
id=self.id)
|
||||
return url_for("threads.subscribe", id=self.id)
|
||||
|
||||
def getUnsubscribeURL(self):
|
||||
return url_for("threads.unsubscribe",
|
||||
id=self.id)
|
||||
return url_for("threads.unsubscribe", id=self.id)
|
||||
|
||||
def checkPerm(self, user, perm):
|
||||
if not user.is_authenticated:
|
||||
@ -1135,10 +1135,12 @@ class PackageReview(db.Model):
|
||||
return 1 if self.recommends else -1
|
||||
|
||||
def getEditURL(self):
|
||||
return url_for("packages.edit_review",
|
||||
return self.package.getReviewURL()
|
||||
|
||||
def getDeleteURL(self):
|
||||
return url_for("packages.delete_review",
|
||||
author=self.package.author.username,
|
||||
name=self.package.name,
|
||||
id=self.id)
|
||||
name=self.package.name)
|
||||
|
||||
|
||||
|
||||
|
@ -41,8 +41,16 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
{% if review %}
|
||||
<form method="POST" action="{{ review.getDeleteURL() }}" class="alert alert-secondary my-5">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||
<input class="btn btn-sm btn-danger float-right" type="submit" value="{{ _('Delete') }}">
|
||||
<b>{{ _("Delete review.") }}</b>
|
||||
{{ _("This will convert the review into a thread, keeping the comments but removing its effect on the package's rating.") }}
|
||||
<div style="clear:both;"></div>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user