feat(panettone): Add a settings page

Add a user settings page, with a single checkbox that allows disabling
receiving all email notifications.

Change-Id: Ibef2a497cd59f93b695ff8b9cd36047e514e00c2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2806
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
Griffin Smith 2021-04-03 14:27:37 -04:00 committed by glittershark
parent 8d3ab61e7c
commit 3ec15ec9f9
4 changed files with 70 additions and 6 deletions

View file

@ -138,7 +138,13 @@
((:and input (:= type "submit") ((:and input (:= type "submit")
(:or :hover :active :focus)) (:or :hover :active :focus))
:box-shadow 0 0 0 0)))) :box-shadow 0 0 0 0))
(.form-group
:margin-top "1rem")
(label.checkbox
:cursor "pointer")))
(defparameter issue-styles (defparameter issue-styles
`((.issue-info `((.issue-info
@ -193,7 +199,12 @@
(nav (nav
:display "flex" :display "flex"
:color ,color/gray :color ,color/gray
:justify-content "space-between") :justify-content "space-between"
(.nav-group
:display "flex"
(>*
:margin-left "0.5rem")))
(footer (footer
:border-top "1px" "solid" ,color/gray :border-top "1px" "solid" ,color/gray

View file

@ -55,6 +55,24 @@ database connection."
(:select '* :from 'user-settings :where (:= 'user-dn dn)))) (:select '* :from 'user-settings :where (:= 'user-dn dn))))
(insert-dao (make-instance 'user-settings :user-dn dn)))) (insert-dao (make-instance 'user-settings :user-dn dn))))
(defun update-user-settings (settings &rest attrs)
"Update the fields of the settings for USER with the given ATTRS, which is a
plist of slot and value"
(check-type settings user-settings)
(when-let ((set-fields
(iter
(for slot in '(enable-email-notifications))
(for new-value = (getf attrs slot))
(appending
(progn
(setf (slot-value settings slot) new-value)
(list slot new-value))))))
(execute
(sql-compile
`(:update user-settings
:set ,@set-fields
:where (:= user-dn ,(user-dn settings)))))))
(define-constant +issue-statuses+ '(:open :closed) (define-constant +issue-statuses+ '(:open :closed)
:test #'equal) :test #'equal)

View file

@ -36,6 +36,7 @@
:user-settings :user-settings
:user-dn :enable-email-notifications-p :settings-for-user :user-dn :enable-email-notifications-p :settings-for-user
:update-user-settings :enable-email-notifications
:issue :issue-comment :issue-event :issue :issue-comment :issue-event
:id :subject :body :author-dn :issue-id :status :created-at :acting-user-dn :id :subject :body :author-dn :issue-id :status :created-at :acting-user-dn

View file

@ -75,10 +75,12 @@
(who:htm (:a :href "/" "All Issues"))) (who:htm (:a :href "/" "All Issues")))
(if *user* (if *user*
(who:htm (who:htm
(:div :class "nav-group"
(:a :href "/settings" "Settings")
(:form :class "form-link log-out" (:form :class "form-link log-out"
:method "post" :method "post"
:action "/logout" :action "/logout"
(:input :type "submit" :value "Log Out"))) (:input :type "submit" :value "Log Out"))))
(who:htm (who:htm
(:a :href (:a :href
(format nil (format nil
@ -169,6 +171,27 @@
(:input :type "submit" (:input :type "submit"
:value "Submit")))))) :value "Submit"))))))
(defun render/settings ()
(let ((settings (model:settings-for-user (dn *user*))))
(render ()
(:div
:class "settings-page"
(:header
(:h1 "Settings"))
(:form
:method :post :action "/settings"
(:div
(:label :class "checkbox"
(:input :type "checkbox"
:name "enable-email-notifications"
:id "enable-email-notifications"
:checked (model:enable-email-notifications-p
settings))
"Enable Email Notifications"))
(:div :class "form-group"
(:input :type "submit"
:value "Save Settings")))))))
(defun created-by-at (issue) (defun created-by-at (issue)
(check-type issue model:issue) (check-type issue model:issue)
(who:with-html-output (*standard-output*) (who:with-html-output (*standard-output*)
@ -438,6 +461,17 @@
(let ((issues (model:list-issues :status :open))) (let ((issues (model:list-issues :status :open)))
(render/index :issues issues))) (render/index :issues issues)))
(defroute settings ("/settings" :method :get :decorators (@auth)) ()
(render/settings))
(defroute save-settings ("/settings" :method :post :decorators (@auth))
(&post enable-email-notifications)
(let ((settings (model:settings-for-user (dn *user*))))
(model:update-user-settings
settings
'model:enable-email-notifications enable-email-notifications)
(render/settings)))
(defroute handle-closed-issues (defroute handle-closed-issues
("/issues/closed" :decorators (@auth-optional)) () ("/issues/closed" :decorators (@auth-optional)) ()
(let ((issues (model:list-issues :status :closed))) (let ((issues (model:list-issues :status :closed)))