From 943a4c92149b366d24a7485f0ff547fbbedc5d44 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Thu, 23 Jul 2020 18:50:13 -0400 Subject: feat(web/panettone): Disallow issues with an empty subject Disallow creating issues with an empty subject, and render a nice(ish) alert box indicating the error. Change-Id: I2857923dc0eb7702c85cd1974a73270ca27720fc Reviewed-on: https://cl.tvl.fyi/c/depot/+/1404 Reviewed-by: kanepyork Tested-by: BuildkiteCI --- web/panettone/src/css.lisp | 5 +++++ web/panettone/src/panettone.lisp | 30 ++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'web/panettone/src') diff --git a/web/panettone/src/css.lisp b/web/panettone/src/css.lisp index 9829c33d2e8e..8cf8509a71ef 100644 --- a/web/panettone/src/css.lisp +++ b/web/panettone/src/css.lisp @@ -146,6 +146,11 @@ ,@(button '.new-issue) + (.alert + :padding "0.5rem" + :margin-bottom "1rem" + :background-color ,color/failure) + (.login-form :width "300px" :margin "0 auto") diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp index b8e5d350795e..5c8afc2ca7e9 100644 --- a/web/panettone/src/panettone.lisp +++ b/web/panettone/src/panettone.lisp @@ -185,6 +185,13 @@ updated issue" (:div :class "content" ,@body)))) +(defun render/alert (message) + "Render an alert box for MESSAGE, if non-null" + (check-type message (or null string)) + (who:with-html-output (*standard-output*) + (when message + (who:htm (:div :class "alert" (who:esc message)))))) + (defun render/login (&optional message) (render (:div @@ -193,8 +200,7 @@ updated issue" (:h1 "Login")) (:main :class "login-form" - (when message - (who:htm (:div :class "alert" (who:esc message)))) + (render/alert message) (:form :method :post :action "/login" (:div @@ -276,11 +282,12 @@ updated issue" (:a :href "/" "View open isues")) (render/issue-list :issues issues)))) -(defun render/new-issue () +(defun render/new-issue (&optional message) (render (:header (:h1 "New Issue")) (:main + (render/alert message) (:form :method "post" :action "/issues" :class "issue-form" @@ -400,13 +407,16 @@ updated issue" (defroute handle-create-issue ("/issues" :method :post :decorators (@auth)) (&post subject body) - (cl-prevalence:execute-transaction - (create-issue *p-system* - 'subject subject - 'body body - 'author-dn (dn *user*))) - (cl-prevalence:snapshot *p-system*) - (hunchentoot:redirect "/")) + (if (string= subject "") + (render/new-issue "Subject is required") + (progn + (cl-prevalence:execute-transaction + (create-issue *p-system* + 'subject subject + 'body body + 'author-dn (dn *user*))) + (cl-prevalence:snapshot *p-system*) + (hunchentoot:redirect "/")))) (defroute show-issue ("/issues/:id" :decorators (@auth)) (&path (id 'integer)) -- cgit 1.4.1