MCPcopy Index your code
hub / github.com/coder/coder / postTestNotification

Method postTestNotification

coderd/notifications.go:199–238  ·  view source on GitHub ↗

@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)

Source from the content-addressed store, hash-verified

197// @Success 200
198// @Router /api/v2/notifications/test [post]
199func (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

Callers

nothing calls this directly

Calls 9

AuthorizeMethod · 0.95
APIKeyFunction · 0.92
ForbiddenFunction · 0.92
AsNotifierFunction · 0.92
WriteFunction · 0.92
ContextMethod · 0.65
EnqueueWithDataMethod · 0.65
ErrorMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected