Skip to content

feat: add notification preferences business logic & APIs #14117

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

Conversation

dannykopping
Copy link
Contributor

@dannykopping dannykopping commented Aug 2, 2024

Part of coder/internal#19

Users should be empowered to control which notifications they do not wish to receive.

Added two new routes:

  • GET /users/{users}/notifications/preferences
    • Retrieves notification preferences for a given user
  • PUT /users/{users}/notifications/preferences
    • Updates notification preferences for a given user

When a user has disabled a notification template in their preferences, we need to ensure that:

  1. Messages currently in the queue which use that (now disabled) notification template are inhibited from sending
  2. Any new messages which are enqueued after the preference is set will fail when being inserted into the database, and the enqueuer will return a notifications.ErrCannotEnqueueDisabledNotification error

The database logic was implemented in #14100, see the inhibit_enqueue_if_disabled trigger.

Copy link
Contributor Author

dannykopping commented Aug 2, 2024

Copy link

alwaysmeticulous bot commented Aug 2, 2024

Meticulous was unable to execute a test run for this PR because the most recent commit is associated with multiple PRs. To execute a test run, please try pushing up a new commit that is only associated with this PR.

Last updated for commit 11eacb8. This comment will update as new commits are pushed.

@dannykopping dannykopping force-pushed the dk/notification-prefs/admin-template-method branch 2 times, most recently from 4a0e0f2 to 8041cc7 Compare August 2, 2024 14:40
@dannykopping dannykopping force-pushed the dk/notification-prefs/user-prefs branch from 6e027ef to 01e7b50 Compare August 2, 2024 14:40
@dannykopping dannykopping changed the title Test database business logic feat: add notification preferences business logic & APIs Aug 2, 2024
@dannykopping dannykopping force-pushed the dk/notification-prefs/admin-template-method branch from 30f3525 to 62f6dec Compare August 5, 2024 08:08
@dannykopping dannykopping force-pushed the dk/notification-prefs/user-prefs branch from 01e7b50 to 0aef037 Compare August 5, 2024 08:09
@dannykopping dannykopping force-pushed the dk/notification-prefs/admin-template-method branch from 88b9796 to ce7f0c3 Compare August 5, 2024 09:29
@dannykopping dannykopping force-pushed the dk/notification-prefs/user-prefs branch 2 times, most recently from fe8aa2d to 3516354 Compare August 5, 2024 09:34
@dannykopping dannykopping force-pushed the dk/notification-prefs/admin-template-method branch from 0386dab to 8bec5b1 Compare August 5, 2024 09:35
@dannykopping dannykopping marked this pull request as ready for review August 5, 2024 09:54
@dannykopping dannykopping force-pushed the dk/notification-prefs/admin-template-method branch from 8bec5b1 to f2926a3 Compare August 5, 2024 11:45
@dannykopping dannykopping force-pushed the dk/notification-prefs/user-prefs branch from 3516354 to 2dd0b09 Compare August 5, 2024 11:49
@dannykopping dannykopping force-pushed the dk/notification-prefs/admin-template-method branch 2 times, most recently from b3679fe to d627fef Compare August 5, 2024 11:54
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
Test fix

Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping force-pushed the dk/notification-prefs/user-prefs branch from 2dd0b09 to 7bb1ee0 Compare August 5, 2024 11:55
input := database.UpdateUserNotificationPreferencesParams{
UserID: user.ID,
NotificationTemplateIds: make([]uuid.UUID, 0, len(prefs.TemplateDisabledMap)),
Disableds: make([]bool, 0, len(prefs.TemplateDisabledMap)),
Copy link
Member

Choose a reason for hiding this comment

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

Suggest setting Enabled in the external API instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I vacillated on this quite a bit.
I think this is more correct though because the feature is to disable notifications, and this happens to line up with the database design as well.

@dannykopping dannykopping merged commit 33e9bc9 into dk/notification-prefs/admin-template-method Aug 5, 2024
31 checks passed
@dannykopping dannykopping deleted the dk/notification-prefs/user-prefs branch August 5, 2024 13:16
@github-actions github-actions bot locked and limited conversation to collaborators Aug 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants