return [ReportComment(self._backend, **data) for data in response]
+ async def comment(self, comment, user):
+ """
+ Submits a new comment
+ """
+ # We cannot comment on a closed report
+ if self.is_closed():
+ raise RuntimeError("Cannot comment on closed report")
+
+ # Compose the body
+ body = {
+ "comment" : comment,
+ }
+
+ # Send the request
+ response = await self._backend.dbl._fetch(
+ "/reports/%s/comments" % self.id, method="POST", body=body, as_user=user,
+ )
+
+ # Return the new comment
+ return ReportComment(self._backend, **response)
+
class ReportComment(Model):
def __str__(self):
{# Actions #}
{% if not report.is_closed() %}
+ <div class="block">
+ <form method="POST" action="/dbl/reports/{{ report.id }}/comment">
+ {% raw xsrf_form_html() %}
+
+ <div class="field">
+ <div class="control">
+ <textarea type="text" class="textarea" name="comment"
+ rows="5" placeholder="{{ _("Write a comment...") }}"
+ ></textarea>
+ </div>
+ </div>
+
+ <button class="button">
+ {{ _("Comment") }}
+ </button>
+ </form>
+ </div>
+
{% if current_user and current_user.is_dbl_moderator() %}
<div class="block">
<form method="POST" action="/dbl/reports/{{ report.id }}/close">
(r"/dbl/report", dbl.SubmitReportHandler),
(r"/dbl/reports/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})", dbl.ReportHandler),
(r"/dbl/reports/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/close", dbl.ReportCloseHandler),
+ (r"/dbl/reports/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/comment",
+ dbl.ReportCommentHandler),
(r"/dbl/search", dbl.SearchHandler),
# Single-Sign-On for Discourse
list=list, reporter=reporter, status=status)
+class ReportCommentHandler(base.AnalyticsMixin, BaseHandler):
+ @tornado.web.authenticated
+ async def post(self, id):
+ # Fetch the report
+ report = await self.backend.dbl.get_report(id)
+ if not report:
+ raise tornado.web.HTTPError(404, "Could not find report '%s'" % id)
+
+ # Nobody can comment on closed reports
+ if report.is_closed():
+ raise tornado.web.HTTPError(400, "Cannot comment on closed reports")
+
+ # Comment on the report
+ await report.comment(
+ comment = self.get_argument("comment"),
+ user = self.current_user,
+ )
+
+ # Send back to the report
+ self.redirect("/dbl/reports/%s" % report.id)
+
class ReportCloseHandler(base.AnalyticsMixin, BaseHandler):
def prepare(self):
# Require DBL moderators