Skip to content
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

Introduce Notifications CRUD Service #38327

Merged
merged 1 commit into from
Mar 1, 2024
Merged

Conversation

rudream
Copy link
Contributor

@rudream rudream commented Feb 16, 2024

Purpose

Part of #37704

This PR introduces the backend CRUD service for creating, updating, deleting and listing Notifications-related resources.

Note: The logic for fetching notifications for a user will be in a separate PR as that implementation is more complex.

@rudream rudream added no-changelog Indicates that a PR does not require a changelog entry backport/branch/v15 labels Feb 16, 2024
@rudream rudream force-pushed the yassine/notifications/service branch 6 times, most recently from 3eb723a to 61fb59b Compare February 20, 2024 20:17
@rudream rudream marked this pull request as ready for review February 20, 2024 20:18
@rudream rudream requested review from zmb3 and rosstimothy February 20, 2024 20:18
lib/services/local/notifications.go Outdated Show resolved Hide resolved
lib/services/local/notifications.go Outdated Show resolved Hide resolved
lib/services/local/notifications.go Outdated Show resolved Hide resolved
lib/services/notifications.go Show resolved Hide resolved
lib/services/notifications.go Outdated Show resolved Hide resolved
lib/services/notifications.go Outdated Show resolved Hide resolved
lib/services/notifications.go Show resolved Hide resolved
lib/services/notifications.go Outdated Show resolved Hide resolved
lib/services/local/notifications.go Outdated Show resolved Hide resolved
lib/services/local/notifications.go Outdated Show resolved Hide resolved
lib/services/local/notifications.go Outdated Show resolved Hide resolved
lib/services/local/notifications.go Outdated Show resolved Hide resolved
Comment on lines +81 to +86
if !cfg.PreserveResourceID {
notification = proto.Clone(notification).(*notificationsv1.Notification)
//nolint:staticcheck // SA1019. Deprecated, but still needed.
notification.Metadata.Id = 0
notification.Metadata.Revision = ""
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably improve maybeResetProtoResourceID to use types.SetRevision and add an equivalent types.SetResource so that it could be used. Not something you need to do here but a good example of where we fell slightly short in making these helpers support legacy and new resources.

lib/services/local/notifications.go Show resolved Hide resolved
lib/services/local/notifications.go Outdated Show resolved Hide resolved
lib/services/local/notifications.go Show resolved Hide resolved
lib/services/local/notifications.go Show resolved Hide resolved

// DeleteGlobalNotification deletes a global notification.
func (s *NotificationsService) DeleteGlobalNotification(ctx context.Context, notificationId string) error {
err := s.globalNotificationService.DeleteResource(ctx, notificationId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to clean up any associated resources for the notification as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, we would want to delete the notification states for this notification, but I don't think there is a performant way to do it here. We would need to list all notification states for all users, filter them for ones that are for this notification, and then loop through them and delete each one. I think this might be better if this was done during a periodic cleanup, what do you think?

@rudream rudream requested a review from rosstimothy February 23, 2024 01:24
lib/services/local/notifications.go Outdated Show resolved Hide resolved
lib/services/local/generic/generic_wrapper.go Outdated Show resolved Hide resolved
lib/services/local/notifications.go Outdated Show resolved Hide resolved
@rudream rudream requested a review from rosstimothy February 26, 2024 20:19
@rudream rudream force-pushed the yassine/notifications/service branch from 23819f9 to 62e7db7 Compare February 27, 2024 22:01
lib/services/local/notifications.go Outdated Show resolved Hide resolved
lib/services/local/generic/generic_wrapper.go Show resolved Hide resolved
lib/services/local/notifications.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

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

Overall looks pretty good, just a few small things I hadn't noticed before.

lib/services/notifications.go Show resolved Hide resolved
lib/services/notifications.go Outdated Show resolved Hide resolved
web/packages/teleport/pkg/sumdb/sum.golang.org/latest Outdated Show resolved Hide resolved
lib/services/local/notifications.go Outdated Show resolved Hide resolved
@rudream rudream force-pushed the yassine/notifications/service branch from 1718af6 to ca536aa Compare February 29, 2024 19:09
@rudream rudream requested a review from rosstimothy February 29, 2024 19:17
Copy link
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

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

Nice work @rudream!!

@rudream rudream force-pushed the yassine/notifications/service branch from 229f064 to 2595958 Compare March 1, 2024 16:23
@rudream rudream enabled auto-merge March 1, 2024 16:26
@rudream rudream force-pushed the yassine/notifications/service branch from 2595958 to fdf95dc Compare March 1, 2024 16:55
@rudream rudream added this pull request to the merge queue Mar 1, 2024
Merged via the queue into master with commit e5246f9 Mar 1, 2024
37 checks passed
@rudream rudream deleted the yassine/notifications/service branch March 1, 2024 19:05
@public-teleport-github-review-bot

@rudream See the table below for backport results.

Branch Result
branch/v15 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v15 no-changelog Indicates that a PR does not require a changelog entry size/lg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants