- Notifications
You must be signed in to change notification settings - Fork927
feat: allow notification templates to be disabled by default#16093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
c4755f4
5c3ac59
013a626
fd7ed60
c3f5e2a
73bc02e
de41561
dd51bd7
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
ALTER TABLE notification_templates DROP COLUMN enabled_by_default; | ||
CREATE OR REPLACE FUNCTION inhibit_enqueue_if_disabled() | ||
RETURNS TRIGGER AS | ||
$$ | ||
BEGIN | ||
-- Fail the insertion if the user has disabled this notification. | ||
IF EXISTS (SELECT 1 | ||
FROM notification_preferences | ||
WHERE disabled = TRUE | ||
AND user_id = NEW.user_id | ||
AND notification_template_id = NEW.notification_template_id) THEN | ||
RAISE EXCEPTION 'cannot enqueue message: user has disabled this notification'; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
ALTER TABLE notification_templates ADD COLUMN enabled_by_default boolean DEFAULT TRUE NOT NULL; | ||
CREATE OR REPLACE FUNCTION inhibit_enqueue_if_disabled() | ||
RETURNS TRIGGER AS | ||
$$ | ||
BEGIN | ||
-- Fail the insertion if one of the following: | ||
-- * the user has disabled this notification. | ||
-- * the notification template is disabled by default and hasn't | ||
-- been explicitly enabled by the user. | ||
IF EXISTS ( | ||
SELECT 1 FROM notification_templates | ||
LEFT JOIN notification_preferences | ||
ON notification_preferences.notification_template_id = notification_templates.id | ||
AND notification_preferences.user_id = NEW.user_id | ||
WHERE notification_templates.id = NEW.notification_template_id AND ( | ||
-- Case 1: The user has explicitly disabled this template | ||
notification_preferences.disabled = TRUE | ||
OR | ||
-- Case 2: The template is disabled by default AND the user hasn't enabled it | ||
(notification_templates.enabled_by_default = FALSE AND notification_preferences.notification_template_id IS NULL) | ||
) | ||
) THEN | ||
RAISE EXCEPTION 'cannot enqueue message: notification is not enabled'; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- Enable 'workspace created' notification by default | ||
UPDATE notification_templates | ||
SET enabled_by_default = TRUE | ||
WHERE id = '281fdf73-c6d6-4cbb-8ff5-888baf8a2fff'; | ||
-- Enable 'workspace manually updated' notification by default | ||
UPDATE notification_templates | ||
SET enabled_by_default = TRUE | ||
WHERE id = 'd089fe7b-d5c5-4c0c-aaf5-689859f7d392'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- Disable 'workspace created' notification by default | ||
UPDATE notification_templates | ||
SET enabled_by_default = FALSE | ||
WHERE id = '281fdf73-c6d6-4cbb-8ff5-888baf8a2fff'; | ||
-- Disable 'workspace manually updated' notification by default | ||
UPDATE notification_templates | ||
SET enabled_by_default = FALSE | ||
WHERE id = 'd089fe7b-d5c5-4c0c-aaf5-689859f7d392'; |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.