-
Notifications
You must be signed in to change notification settings - Fork 876
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
c4755f4
5c3ac59
013a626
fd7ed60
c3f5e2a
73bc02e
de41561
dd51bd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,42 @@ | ||
ALTER TABLE notification_templates ADD COLUMN enabled_by_default boolean DEFAULT TRUE NOT NULL; | ||
|
||
-- 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'; | ||
|
||
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; | ||
|
||
-- Fails if the notification template is disabled by default and the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pinging @mafredri to review SQL changes |
||
-- user hasn't explicitly enabled it. | ||
IF (NOT EXISTS (SELECT 1 | ||
FROM notification_preferences | ||
WHERE disabled = FALSE | ||
AND user_id = NEW.user_id | ||
AND notification_template_id = NEW.notification_template_id)) | ||
AND (EXISTS (SELECT 1 | ||
FROM notification_templates | ||
WHERE id = NEW.notification_template_id | ||
AND enabled_by_default = FALSE)) THEN | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: could this not be an Perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can do! So make this an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Yes please, I think that'd be a more precise error message |
||
RAISE EXCEPTION 'cannot enqueue message: user has disabled this notification'; | ||
END IF; | ||
|
||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this might've been better suited in its own migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do! 👍