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

Commit7bb1ee0

Browse files
committed
Self-review
Signed-off-by: Danny Kopping <danny@coder.com>
1 parentaa9f5a0 commit7bb1ee0

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

‎coderd/database/modelmethods.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,6 @@ func (a GetOAuth2ProviderAppsByUserIDRow) RBACObject() rbac.Object {
290290
returna.OAuth2ProviderApp.RBACObject()
291291
}
292292

293-
func (nNotificationPreference)RBACObject() rbac.Object {
294-
returnrbac.ResourceNotificationPreference.WithOwner(n.UserID.String())
295-
}
296-
297293
typeWorkspaceAgentConnectionStatusstruct {
298294
StatusWorkspaceAgentStatus`json:"status"`
299295
FirstConnectedAt*time.Time`json:"first_connected_at"`

‎coderd/notifications.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,17 @@ func (api *API) userNotificationPreferences(rw http.ResponseWriter, r *http.Requ
161161

162162
prefs,err:=api.Database.GetUserNotificationPreferences(ctx,user.ID)
163163
iferr!=nil {
164-
logger.Error(ctx,"failed to retrieve")
164+
logger.Error(ctx,"failed to retrieve preferences",slog.Error(err))
165165

166-
httpapi.Write(r.Context(),rw,http.StatusInternalServerError, codersdk.Response{
166+
httpapi.Write(ctx,rw,http.StatusInternalServerError, codersdk.Response{
167167
Message:"Failed to retrieve user notification preferences.",
168168
Detail:err.Error(),
169169
})
170170
return
171171
}
172172

173173
out:=convertNotificationPreferences(prefs)
174-
httpapi.Write(r.Context(),rw,http.StatusOK,out)
174+
httpapi.Write(ctx,rw,http.StatusOK,out)
175175
}
176176

177177
// @Summary Update user notification preferences
@@ -191,11 +191,13 @@ func (api *API) putUserNotificationPreferences(rw http.ResponseWriter, r *http.R
191191
logger=api.Logger.Named("notifications.preferences").With(slog.F("user_id",user.ID))
192192
)
193193

194+
// Parse request.
194195
varprefs codersdk.UpdateUserNotificationPreferences
195196
if!httpapi.Read(ctx,rw,r,&prefs) {
196197
return
197198
}
198199

200+
// Build query params.
199201
input:= database.UpdateUserNotificationPreferencesParams{
200202
UserID:user.ID,
201203
NotificationTemplateIds:make([]uuid.UUID,0,len(prefs.TemplateDisabledMap)),
@@ -204,9 +206,9 @@ func (api *API) putUserNotificationPreferences(rw http.ResponseWriter, r *http.R
204206
fortmplID,disabled:=rangeprefs.TemplateDisabledMap {
205207
id,err:=uuid.Parse(tmplID)
206208
iferr!=nil {
207-
logger.Warn(ctx,"failed to parse notification template UUID",slog.F("input",tmplID))
209+
logger.Warn(ctx,"failed to parse notification template UUID",slog.F("input",tmplID),slog.Error(err))
208210

209-
httpapi.Write(r.Context(),rw,http.StatusBadRequest, codersdk.Response{
211+
httpapi.Write(ctx,rw,http.StatusBadRequest, codersdk.Response{
210212
Message:"Unable to parse notification template UUID.",
211213
Detail:err.Error(),
212214
})
@@ -217,32 +219,34 @@ func (api *API) putUserNotificationPreferences(rw http.ResponseWriter, r *http.R
217219
input.Disableds=append(input.Disableds,disabled)
218220
}
219221

222+
// Update preferences with params.
220223
updated,err:=api.Database.UpdateUserNotificationPreferences(ctx,input)
221224
iferr!=nil {
222225
logger.Error(ctx,"failed to update preferences",slog.Error(err))
223226

224-
httpapi.Write(r.Context(),rw,http.StatusInternalServerError, codersdk.Response{
227+
httpapi.Write(ctx,rw,http.StatusInternalServerError, codersdk.Response{
225228
Message:"Failed to update user notifications preferences.",
226229
Detail:err.Error(),
227230
})
228231
return
229232
}
230233

234+
// Preferences updated, now fetch all preferences belonging to this user.
231235
logger.Info(ctx,"updated preferences",slog.F("count",updated))
232236

233237
userPrefs,err:=api.Database.GetUserNotificationPreferences(ctx,user.ID)
234238
iferr!=nil {
235239
logger.Error(ctx,"failed to retrieve preferences",slog.Error(err))
236240

237-
httpapi.Write(r.Context(),rw,http.StatusInternalServerError, codersdk.Response{
241+
httpapi.Write(ctx,rw,http.StatusInternalServerError, codersdk.Response{
238242
Message:"Failed to retrieve user notifications preferences.",
239243
Detail:err.Error(),
240244
})
241245
return
242246
}
243247

244248
out:=convertNotificationPreferences(userPrefs)
245-
httpapi.Write(r.Context(),rw,http.StatusOK,out)
249+
httpapi.Write(ctx,rw,http.StatusOK,out)
246250
}
247251

248252
funcconvertNotificationTemplates(in []database.NotificationTemplate) (out []codersdk.NotificationTemplate) {

‎codersdk/notifications.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (c *Client) GetSystemNotificationTemplates(ctx context.Context) ([]Notifica
112112
returntemplates,nil
113113
}
114114

115-
// GetUserNotificationPreferencesTODO
115+
// GetUserNotificationPreferencesretrieves notification preferences for a given user.
116116
func (c*Client)GetUserNotificationPreferences(ctx context.Context,userID uuid.UUID) ([]NotificationPreference,error) {
117117
res,err:=c.Request(ctx,http.MethodGet,fmt.Sprintf("/api/v2/users/%s/notifications/preferences",userID.String()),nil)
118118
iferr!=nil {
@@ -137,7 +137,7 @@ func (c *Client) GetUserNotificationPreferences(ctx context.Context, userID uuid
137137
returnprefs,nil
138138
}
139139

140-
// UpdateUserNotificationPreferencesTODO
140+
// UpdateUserNotificationPreferencesupdates notification preferences for a given user.
141141
func (c*Client)UpdateUserNotificationPreferences(ctx context.Context,userID uuid.UUID,reqUpdateUserNotificationPreferences) ([]NotificationPreference,error) {
142142
res,err:=c.Request(ctx,http.MethodPut,fmt.Sprintf("/api/v2/users/%s/notifications/preferences",userID.String()),req)
143143
iferr!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp