Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitef4f795

Browse files
committed
make webpush endpoints 404 if experiment not enabled
1 parent26a075b commitef4f795

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

‎cli/server.go‎

Lines changed: 2 additions & 0 deletions
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‎

Lines changed: 14 additions & 0 deletions
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
varreq 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
varreq 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
iferr:=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‎

Lines changed: 5 additions & 1 deletion
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)

[8]ページ先頭

©2009-2025 Movatter.jp