Skip to content

Commit ef22b35

Browse files
committed
make webpush endpoints 404 if experiment not enabled
1 parent 57d84a9 commit ef22b35

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

cli/server.go

+2
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
790790
options.WebpushDispatcher = webpusher
791791
} else {
792792
options.WebpushDispatcher = &webpush.NoopWebpusher{
793+
// Users will likely not see this message as the endpoints return 404
794+
// if not enabled. Just in case...
793795
Msg: "Web Push notifications are an experimental feature and are disabled by default. Enable the 'web-push' experiment to use this feature.",
794796
}
795797
}

coderd/notifications.go

+14
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ func (api *API) putUserNotificationPreferences(rw http.ResponseWriter, r *http.R
337337
func (api *API) postUserWebpushSubscription(rw http.ResponseWriter, r *http.Request) {
338338
ctx := r.Context()
339339
user := httpmw.UserParam(r)
340+
if !api.Experiments.Enabled(codersdk.ExperimentWebPush) {
341+
httpapi.ResourceNotFound(rw)
342+
return
343+
}
340344

341345
var req codersdk.WebpushSubscription
342346
if !httpapi.Read(ctx, rw, r, &req) {
@@ -382,6 +386,11 @@ func (api *API) deleteUserWebpushSubscription(rw http.ResponseWriter, r *http.Re
382386
ctx := r.Context()
383387
user := httpmw.UserParam(r)
384388

389+
if !api.Experiments.Enabled(codersdk.ExperimentWebPush) {
390+
httpapi.ResourceNotFound(rw)
391+
return
392+
}
393+
385394
var req codersdk.DeleteWebpushSubscription
386395
if !httpapi.Read(ctx, rw, r, &req) {
387396
return
@@ -414,6 +423,11 @@ func (api *API) postUserPushNotificationTest(rw http.ResponseWriter, r *http.Req
414423
ctx := r.Context()
415424
user := httpmw.UserParam(r)
416425

426+
if !api.Experiments.Enabled(codersdk.ExperimentWebPush) {
427+
httpapi.ResourceNotFound(rw)
428+
return
429+
}
430+
417431
if err := api.WebpushDispatcher.Dispatch(ctx, user.ID, codersdk.WebpushMessage{
418432
Title: "It's working!",
419433
Body: "You've subscribed to push notifications.",

coderd/notifications_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,11 @@ func TestWebpushSubscribeUnsubscribe(t *testing.T) {
390390

391391
ctx := testutil.Context(t, testutil.WaitShort)
392392

393-
client := coderdtest.New(t, nil)
393+
dv := coderdtest.DeploymentValues(t)
394+
dv.Experiments = []string{string(codersdk.ExperimentWebPush)}
395+
client := coderdtest.New(t, &coderdtest.Options{
396+
DeploymentValues: dv,
397+
})
394398
owner := coderdtest.CreateFirstUser(t, client)
395399
memberClient, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
396400

0 commit comments

Comments
 (0)