diff --git a/config/messages.json b/config/messages.json index 476702020d..5c34dbc48f 100644 --- a/config/messages.json +++ b/config/messages.json @@ -11438,6 +11438,24 @@ "file": "user_registry.go" } }, + "event:user.notification.create": { + "translations": { + "en": "create notification" + }, + "description": { + "package": "pkg/identityserver", + "file": "notification_registry.go" + } + }, + "event:user.notification.update_status": { + "translations": { + "en": "update notification status" + }, + "description": { + "package": "pkg/identityserver", + "file": "notification_registry.go" + } + }, "event:user.purge": { "translations": { "en": "purge user" diff --git a/pkg/identityserver/notification_registry.go b/pkg/identityserver/notification_registry.go index dfb80959ad..d67c57f768 100644 --- a/pkg/identityserver/notification_registry.go +++ b/pkg/identityserver/notification_registry.go @@ -21,6 +21,7 @@ import ( "go.thethings.network/lorawan-stack/v3/pkg/auth/rights" "go.thethings.network/lorawan-stack/v3/pkg/email" "go.thethings.network/lorawan-stack/v3/pkg/errors" + "go.thethings.network/lorawan-stack/v3/pkg/events" "go.thethings.network/lorawan-stack/v3/pkg/identityserver/store" "go.thethings.network/lorawan-stack/v3/pkg/log" "go.thethings.network/lorawan-stack/v3/pkg/ttnpb" @@ -28,6 +29,23 @@ import ( "google.golang.org/protobuf/types/known/emptypb" ) +var ( + evtNotificationCreate = events.Define( + "user.notification.create", "create notification", + events.WithVisibility(ttnpb.Right_RIGHT_USER_NOTIFICATIONS_READ), + events.WithDataType(&ttnpb.Notification{}), + events.WithAuthFromContext(), + events.WithClientInfoFromContext(), + ) + evtNotificationUpdateStatus = events.Define( + "user.notification.update_status", "update notification status", + events.WithVisibility(ttnpb.Right_RIGHT_USER_NOTIFICATIONS_READ), + events.WithDataType(&ttnpb.UpdateNotificationStatusRequest{}), + events.WithAuthFromContext(), + events.WithClientInfoFromContext(), + ) +) + func receiversContains(receivers []ttnpb.NotificationReceiver, search ttnpb.NotificationReceiver) bool { for _, receiver := range receivers { if receiver == search { @@ -259,6 +277,12 @@ func (is *IdentityServer) createNotification(ctx context.Context, req *ttnpb.Cre } } + evs := make([]events.Event, 0, len(receiverUserIDs)) + for _, ids := range receiverUserIDs { + evs = append(evs, evtNotificationCreate.NewWithIdentifiersAndData(ctx, ids, notification)) + } + events.Publish(evs...) + return &ttnpb.CreateNotificationResponse{ Id: notification.Id, }, nil @@ -341,6 +365,7 @@ func (is *IdentityServer) updateNotificationStatus(ctx context.Context, req *ttn if err != nil { return nil, err } + events.Publish(evtNotificationUpdateStatus.NewWithIdentifiersAndData(ctx, req.ReceiverIds, req)) return ttnpb.Empty, nil } diff --git a/pkg/webui/locales/ja.json b/pkg/webui/locales/ja.json index 35d83ffe15..c8b7048222 100644 --- a/pkg/webui/locales/ja.json +++ b/pkg/webui/locales/ja.json @@ -2766,6 +2766,8 @@ "event:user.api-key.update": "ユーザAPIキーを更新", "event:user.create": "ユーザ作成", "event:user.delete": "ユーザ削除", + "event:user.notification.create": "", + "event:user.notification.update_status": "", "event:user.purge": "ユーザ消去", "event:user.restore": "ユーザーの復元", "event:user.update": "ユーザ更新",