@@ -10,6 +10,7 @@ import (
10
10
"github.com/coder/coder/v2/coderd/audit"
11
11
"github.com/coder/coder/v2/coderd/database"
12
12
"github.com/coder/coder/v2/coderd/httpapi"
13
+ "github.com/coder/coder/v2/coderd/rbac"
13
14
"github.com/coder/coder/v2/codersdk"
14
15
)
15
16
@@ -71,9 +72,9 @@ func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request
71
72
return
72
73
}
73
74
74
- currentSettingsJSON , err := api .Database .GetNotificationsSettings (r . Context () )
75
+ currentSettingsJSON , err := api .Database .GetNotificationsSettings (ctx )
75
76
if err != nil {
76
- httpapi .Write (r . Context () , rw , http .StatusInternalServerError , codersdk.Response {
77
+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
77
78
Message : "Failed to fetch current notifications settings." ,
78
79
Detail : err .Error (),
79
80
})
@@ -82,7 +83,7 @@ func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request
82
83
83
84
if bytes .Equal (settingsJSON , []byte (currentSettingsJSON )) {
84
85
// 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 )
86
87
return
87
88
}
88
89
@@ -102,10 +103,15 @@ func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request
102
103
103
104
err = api .Database .UpsertNotificationsSettings (ctx , string (settingsJSON ))
104
105
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
+
109
115
return
110
116
}
111
117
0 commit comments