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

Method postUserPushNotificationTest

coderd/webpush.go:181–203  ·  view source on GitHub ↗

@Summary Send a test push notification @ID send-a-test-push-notification @Security CoderSessionToken @Tags Notifications @Param user path string true "User ID, name, or me" @Success 204 @Router /api/v2/users/{user}/webpush/test [post] @x-apidocgen {"skip": true}

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

179// @Router /api/v2/users/{user}/webpush/test [post]
180// @x-apidocgen {"skip": true}
181func (api *API) postUserPushNotificationTest(rw http.ResponseWriter, r *http.Request) {
182 ctx := r.Context()
183 user := httpmw.UserParam(r)
184
185 // We need to authorize the user to send a push notification to themselves.
186 if !api.Authorize(r, policy.ActionCreate, rbac.ResourceNotificationMessage.WithOwner(user.ID.String())) {
187 httpapi.Forbidden(rw)
188 return
189 }
190
191 if err := api.WebpushDispatcher.Dispatch(ctx, user.ID, codersdk.WebpushMessage{
192 Title: "It's working!",
193 Body: "You've subscribed to push notifications.",
194 }); err != nil {
195 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
196 Message: "Failed to send test notification",
197 Detail: err.Error(),
198 })
199 return
200 }
201
202 rw.WriteHeader(http.StatusNoContent)
203}

Callers

nothing calls this directly

Calls 10

AuthorizeMethod · 0.95
UserParamFunction · 0.92
ForbiddenFunction · 0.92
WriteFunction · 0.92
WithOwnerMethod · 0.80
ContextMethod · 0.65
DispatchMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected