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 <rikingcoding@gmail.com>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2020-07-23 18:50:13 -04:00 committed by glittershark
parent 280ec4a46c
commit 943a4c9214
2 changed files with 25 additions and 10 deletions

View file

@ -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")

View file

@ -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))