feat(panettone): Add a user settings table

Add a new user-settings table and dao class, with a flag that allows an
individual user to disable receiving email notifications

Change-Id: I537bfca74490941934c0adc7328bcd6ed5c9c0b9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2803
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 13:03:44 -04:00 committed by glittershark
parent 9551b628d0
commit 37d573479b
2 changed files with 33 additions and 1 deletions

View file

@ -14,6 +14,34 @@
;;; Schema
;;;
(defclass user-settings ()
((user-dn :col-type string :initarg :user-dn :accessor user-dn)
(enable-email-notifications
:col-type boolean
:initarg :enable-email-notifications
:accessor enable-email-notifications-p
:initform t
:col-default t))
(:metaclass dao-class)
(:keys user-dn)
(:table-name user_settings)
(:documentation
"Panettone settings for an individual user DN"))
(deftable (user-settings "user_settings")
(!dao-def))
(defun settings-for-user (dn)
"Retrieve the settings for the user with the given DN, creating a new row in
the database if not yet present"
(or
(car
(query-dao
'user-settings
(:select '* :from 'user-settings :where (:= 'user-dn dn))))
(insert-dao (make-instance 'user-settings :user-dn dn))))
(define-constant +issue-statuses+ '(:open :closed)
:test #'equal)
@ -134,7 +162,8 @@ its new value will be formatted using ~A into NEW-VALUE"))
(define-constant +all-tables+
'(issue
issue-comment
issue-event)
issue-event
user-settings)
:test #'equal)
(defun ddl/create-tables ()

View file

@ -34,6 +34,9 @@
(:export
:connect-postgres :ddl/init
:user-settings
:user-dn :enable-email-notifications-p :settings-for-user
:issue :issue-comment :issue-event
:id :subject :body :author-dn :issue-id :status :created-at :acting-user-dn
:field :previous-value :new-value