about summary refs log tree commit diff
path: root/web/panettone
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-04-03T17·03-0400
committerglittershark <grfn@gws.fyi>2021-04-04T14·17+0000
commit37d573479ba56eebc5304f5209790ba7a4a3762b (patch)
tree08b2355a43f461090b062ba9d0c5a304a26672aa /web/panettone
parent9551b628d02323b01ecb80220342eea488f7200e (diff)
feat(panettone): Add a user settings table r/2425
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>
Diffstat (limited to 'web/panettone')
-rw-r--r--web/panettone/src/model.lisp31
-rw-r--r--web/panettone/src/packages.lisp3
2 files changed, 33 insertions, 1 deletions
diff --git a/web/panettone/src/model.lisp b/web/panettone/src/model.lisp
index 300ee19b6b10..d43478d45b3f 100644
--- a/web/panettone/src/model.lisp
+++ b/web/panettone/src/model.lisp
@@ -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 ()
diff --git a/web/panettone/src/packages.lisp b/web/panettone/src/packages.lisp
index 3b6edcdd14e3..3bdb553b7089 100644
--- a/web/panettone/src/packages.lisp
+++ b/web/panettone/src/packages.lisp
@@ -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