@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)
| 179 | // @Router /api/v2/users/{user}/webpush/test [post] |
| 180 | // @x-apidocgen {"skip": true} |
| 181 | func (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 | } |