Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Conversation

DanielleMaywood
Copy link
Contributor

Change as part of#16071

It has been decided that we want to be able to have some notification templates be disabledby default#16071 (comment).

This adds a new column (enabled_by_default) tonotification_templates that defaults toTRUE. It also modifies theinhibit_enqueue_if_disabled function to reject notifications for templates that haveenabled_by_default = FALSE with the user not explicitly enabling it.

@DanielleMaywoodDanielleMaywood marked this pull request as ready for reviewJanuary 13, 2025 11:35
Copy link
Contributor

@dannykoppingdannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM modulo a couple nits
Could you please deploy this to the preview env? I'd like to play around with the frontend.

Comment on lines 3 to 11
-- 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';
Copy link
Contributor

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.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can do! 👍

Comment on lines 33 to 36
AND (EXISTS (SELECT 1
FROM notification_templates
WHERE id = NEW.notification_template_id
AND enabled_by_default = FALSE)) THEN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nit: could this not be anOR on the other branch?
If we're gonna keep this separate branch I'd rather we raised a more specific error since this one is no longer accurate.

Perhapsnotification is not enabled covers both.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can do!

So make this anOR to the other branch and rename the error message tonotification is not enabled?

Copy link
Contributor

Choose a reason for hiding this comment

The 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

@github-actionsGitHub Actions
Copy link

github-actionsbot commentedJan 13, 2025
edited
Loading


✔️ PR 16093 Updated successfully.
🚀 Access the credentialshere.

cc:@DanielleMaywood

github-actions[bot] reacted with rocket emoji

RAISE EXCEPTION 'cannot enqueue message: user has disabled this notification';
END IF;

-- Fails if the notification template is disabled by default and the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

pinging@mafredri to review SQL changes

Comment on lines 7 to 26
-- 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_preferences
WHERE disabled = TRUE
AND user_id = NEW.user_id
AND notification_template_id = NEW.notification_template_id)
OR (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
RAISE EXCEPTION 'cannot enqueue message: notification is not enabled';
END IF;
Copy link
Member

@mafredrimafredriJan 13, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

How about simplifying this with a join instead?

Suggested change
-- 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 (SELECT1
FROM notification_preferences
WHERE disabled= TRUE
AND user_id=NEW.user_id
AND notification_template_id=NEW.notification_template_id)
OR (NOT EXISTS (SELECT1
FROM notification_preferences
WHERE disabled= FALSE
AND user_id=NEW.user_id
AND notification_template_id=NEW.notification_template_id))
AND (EXISTS (SELECT1
FROM notification_templates
WHERE id=NEW.notification_template_id
AND enabled_by_default= FALSE) ) THEN
RAISE EXCEPTION'cannot enqueue message: notification is not enabled';
END IF;
IF EXISTS (
SELECT1
FROM notification_templates nt
LEFT JOIN notification_preferences np
ONnp.notification_template_id=nt.id
ANDnp.user_id=NEW.user_id
WHEREnt.id=NEW.notification_template_id
AND (
-- Case 1: The user explicitly disabled this template
np.disabled= TRUE
OR
-- Case 2: Template is disabled by default
-- AND user never explicitly enabled it
(np.notification_template_id ISNULLANDnt.enabled_by_default= FALSE)
)
)
THEN
RAISE EXCEPTION'cannot enqueue message: notification is not enabled';
END IF;

I feel this is a bit more readable and concise. What do you think? (PS. Feel free to double check the logic, I actually used ChatGPT to rewrite it.)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think I agree with you, this definitely feels easier (at least for me) to read

@DanielleMaywoodDanielleMaywood merged commit009069c intomainJan 13, 2025
34 of 36 checks passed
@DanielleMaywoodDanielleMaywood deleted the dm-allow-notification-templates-to-be-disabled-by-default branchJanuary 13, 2025 15:01
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJan 13, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri left review comments

@dannykoppingdannykoppingdannykopping approved these changes

@mtojekmtojekmtojek approved these changes

Assignees

@DanielleMaywoodDanielleMaywood

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@DanielleMaywood@mafredri@dannykopping@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp