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

Method deleteUserWebpushSubscription

coderd/webpush.go:123–171  ·  view source on GitHub ↗

@Summary Delete user webpush subscription @ID delete-user-webpush-subscription @Security CoderSessionToken @Accept json @Tags Notifications @Param request body codersdk.DeleteWebpushSubscription true "Webpush subscription" @Param user path string true "User ID, name, or me" @Router /api/v2/users/{us

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

Source from the content-addressed store, hash-verified

121// @Success 204
122// @x-apidocgen {"skip": true}
123func (api *API) deleteUserWebpushSubscription(rw http.ResponseWriter, r *http.Request) {
124 ctx := r.Context()
125 user := httpmw.UserParam(r)
126
127 var req codersdk.DeleteWebpushSubscription
128 if !httpapi.Read(ctx, rw, r, &req) {
129 return
130 }
131
132 // Return NotFound if the subscription does not exist.
133 existing, err := api.Database.GetWebpushSubscriptionsByUserID(ctx, user.ID)
134 if err != nil {
135 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
136 Message: "Failed to get webpush subscriptions.",
137 Detail: err.Error(),
138 })
139 return
140 }
141 if idx := slices.IndexFunc(existing, func(s database.WebpushSubscription) bool {
142 return s.Endpoint == req.Endpoint
143 }); idx == -1 {
144 httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
145 Message: "Webpush subscription not found.",
146 })
147 return
148 }
149
150 if err := api.Database.DeleteWebpushSubscriptionByUserIDAndEndpoint(ctx, database.DeleteWebpushSubscriptionByUserIDAndEndpointParams{
151 UserID: user.ID,
152 Endpoint: req.Endpoint,
153 }); err != nil {
154 if errors.Is(err, sql.ErrNoRows) {
155 httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
156 Message: "Webpush subscription not found.",
157 })
158 return
159 }
160 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
161 Message: "Failed to delete push notification subscription.",
162 Detail: err.Error(),
163 })
164 return
165 }
166 if invalidator, ok := api.WebpushDispatcher.(webpush.SubscriptionCacheInvalidator); ok {
167 invalidator.InvalidateUser(user.ID)
168 }
169
170 rw.WriteHeader(http.StatusNoContent)
171}
172
173// @Summary Send a test push notification
174// @ID send-a-test-push-notification

Callers

nothing calls this directly

Calls 10

UserParamFunction · 0.92
ReadFunction · 0.92
WriteFunction · 0.92
ContextMethod · 0.65
InvalidateUserMethod · 0.65
ErrorMethod · 0.45
IsMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected