@@ -10,6 +10,7 @@ import (
1010 "github.com/coder/coder/v2/coderd/audit"
1111 "github.com/coder/coder/v2/coderd/database"
1212 "github.com/coder/coder/v2/coderd/httpapi"
13+ "github.com/coder/coder/v2/coderd/rbac"
1314 "github.com/coder/coder/v2/codersdk"
1415)
1516
@@ -71,9 +72,9 @@ func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request
7172 return
7273 }
7374
74- currentSettingsJSON , err := api .Database .GetNotificationsSettings (r . Context () )
75+ currentSettingsJSON , err := api .Database .GetNotificationsSettings (ctx )
7576 if err != nil {
76- httpapi .Write (r . Context () , rw , http .StatusInternalServerError , codersdk.Response {
77+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
7778 Message : "Failed to fetch current notifications settings." ,
7879 Detail : err .Error (),
7980 })
@@ -82,7 +83,7 @@ func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request
8283
8384 if bytes .Equal (settingsJSON , []byte (currentSettingsJSON )) {
8485 // See: https://www.rfc-editor.org/rfc/rfc7232#section-4.1
85- httpapi .Write (r . Context () , rw , http .StatusNotModified , nil )
86+ httpapi .Write (ctx , rw , http .StatusNotModified , nil )
8687 return
8788 }
8889
@@ -102,10 +103,15 @@ func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request
102103
103104 err = api .Database .UpsertNotificationsSettings (ctx , string (settingsJSON ))
104105 if err != nil {
105- httpapi .Write (r .Context (), rw , http .StatusInternalServerError , codersdk.Response {
106- Message : "Failed to update notifications settings." ,
107- Detail : err .Error (),
108- })
106+ if rbac .IsUnauthorizedError (err ) {
107+ httpapi .Forbidden (rw )
108+ } else {
109+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
110+ Message : "Failed to update notifications settings." ,
111+ Detail : err .Error (),
112+ })
113+ }
114+
109115 return
110116 }
111117
0 commit comments