From 37d573479ba56eebc5304f5209790ba7a4a3762b Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 3 Apr 2021 13:03:44 -0400 Subject: 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 Reviewed-by: tazjin --- web/panettone/src/model.lisp | 31 ++++++++++++++++++++++++++++++- web/panettone/src/packages.lisp | 3 +++ 2 files changed, 33 insertions(+), 1 deletion(-) 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 -- cgit 1.4.1