@Summary Send a test notification @ID send-a-test-notification @Security CoderSessionToken @Tags Notifications @Success 200 @Router /api/v2/notifications/test [post]
(rw http.ResponseWriter, r *http.Request)
| 197 | // @Success 200 |
| 198 | // @Router /api/v2/notifications/test [post] |
| 199 | func (api *API) postTestNotification(rw http.ResponseWriter, r *http.Request) { |
| 200 | var ( |
| 201 | ctx = r.Context() |
| 202 | key = httpmw.APIKey(r) |
| 203 | ) |
| 204 | |
| 205 | if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceDeploymentConfig) { |
| 206 | httpapi.Forbidden(rw) |
| 207 | return |
| 208 | } |
| 209 | |
| 210 | if _, err := api.NotificationsEnqueuer.EnqueueWithData( |
| 211 | //nolint:gocritic // We need to be notifier to send the notification. |
| 212 | dbauthz.AsNotifier(ctx), |
| 213 | key.UserID, |
| 214 | notifications.TemplateTestNotification, |
| 215 | map[string]string{}, |
| 216 | map[string]any{ |
| 217 | // NOTE(DanielleMaywood): |
| 218 | // When notifications are enqueued, they are checked to be |
| 219 | // unique within a single day. This means that if we attempt |
| 220 | // to send two test notifications to the same user on |
| 221 | // the same day, the enqueuer will prevent us from sending |
| 222 | // a second one. We are injecting a timestamp to make the |
| 223 | // notifications appear different enough to circumvent this |
| 224 | // deduplication logic. |
| 225 | "timestamp": api.Clock.Now(), |
| 226 | }, |
| 227 | "send-test-notification", |
| 228 | ); err != nil { |
| 229 | api.Logger.Error(ctx, "send notification", slog.Error(err)) |
| 230 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 231 | Message: "Failed to send test notification", |
| 232 | Detail: err.Error(), |
| 233 | }) |
| 234 | return |
| 235 | } |
| 236 | |
| 237 | rw.WriteHeader(http.StatusNoContent) |
| 238 | } |
| 239 | |
| 240 | // @Summary Get user notification preferences |
| 241 | // @ID get-user-notification-preferences |
nothing calls this directly
no test coverage detected