]> git.ipfire.org Git - ipfire.org.git/commitdiff
dbl: Create UI to add comments
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 3 Mar 2026 14:22:11 +0000 (14:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 3 Mar 2026 14:22:11 +0000 (14:22 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/dbl.py
src/templates/dbl/reports/show.html
src/web/__init__.py
src/web/dbl.py

index 8c94d630883cf82c125ee1cc9d0b365ecfac6992..6252123a76f188947201ad06dae879e50dc951aa 100644 (file)
@@ -414,6 +414,27 @@ class Report(Model):
 
                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):
index 1b3d049ae50be1284f19c929ac01fc3dfb9d8a3f..ef69c9010ffc6e471a57c0948c16d72a6458cbf3 100644 (file)
 
                                                {# 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">
index e1d39f7fc9d934bf55aff82f88b2397276574996..e55ffb2f665d6567867fb29cbf0ee0bebd4f177a 100644 (file)
@@ -229,6 +229,8 @@ class Application(tornado.web.Application):
                        (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
index 99d60797e250fcbc72f4178bc5951f5f8f36750d..b79558e2bed22bde7fdb11d9122caf57b5ba543d 100644 (file)
@@ -145,6 +145,27 @@ class ReportHandler(base.AnalyticsMixin, BaseHandler):
                        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