diff options
author | Griffin Smith <grfn@gws.fyi> | 2020-07-23T22·50-0400 |
---|---|---|
committer | glittershark <grfn@gws.fyi> | 2020-07-24T01·01+0000 |
commit | 943a4c92149b366d24a7485f0ff547fbbedc5d44 (patch) | |
tree | d158ad9f4dce748a5655511d709428b268dfe2e9 /web/panettone/src | |
parent | 280ec4a46c01e26f9316a029d9099e05ee882a94 (diff) |
feat(web/panettone): Disallow issues with an empty subject r/1448
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 <rikingcoding@gmail.com> Tested-by: BuildkiteCI
Diffstat (limited to 'web/panettone/src')
-rw-r--r-- | web/panettone/src/css.lisp | 5 | ||||
-rw-r--r-- | web/panettone/src/panettone.lisp | 30 |
2 files changed, 25 insertions, 10 deletions
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)) |