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

Commitd88ab8b

Browse files
committed
Add preferences queries
Signed-off-by: Danny Kopping <danny@coder.com>
1 parenta7b400b commitd88ab8b

File tree

17 files changed

+445
-67
lines changed

17 files changed

+445
-67
lines changed

‎coderd/apidoc/docs.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbauthz/dbauthz.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,13 @@ func (q *querier) GetNotificationMessagesByStatus(ctx context.Context, arg datab
14741474
returnq.db.GetNotificationMessagesByStatus(ctx,arg)
14751475
}
14761476

1477+
func (q*querier)GetNotificationTemplateById(ctx context.Context,id uuid.UUID) (database.NotificationTemplate,error) {
1478+
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceNotificationTemplate);err!=nil {
1479+
return database.NotificationTemplate{},err
1480+
}
1481+
returnq.db.GetNotificationTemplateById(ctx,id)
1482+
}
1483+
14771484
func (q*querier)GetNotificationsSettings(ctx context.Context) (string,error) {
14781485
// No authz checks
14791486
returnq.db.GetNotificationsSettings(ctx)
@@ -2085,6 +2092,13 @@ func (q *querier) GetUserLinksByUserID(ctx context.Context, userID uuid.UUID) ([
20852092
returnq.db.GetUserLinksByUserID(ctx,userID)
20862093
}
20872094

2095+
func (q*querier)GetUserNotificationPreferences(ctx context.Context,userID uuid.UUID) ([]database.NotificationPreference,error) {
2096+
iferr:=q.authorizeContext(ctx,policy.ActionReadPersonal,rbac.ResourceUserObject(userID));err!=nil {
2097+
returnnil,err
2098+
}
2099+
returnq.db.GetUserNotificationPreferences(ctx,userID)
2100+
}
2101+
20882102
func (q*querier)GetUserWorkspaceBuildParameters(ctx context.Context,params database.GetUserWorkspaceBuildParametersParams) ([]database.GetUserWorkspaceBuildParametersRow,error) {
20892103
u,err:=q.db.GetUserByID(ctx,params.OwnerID)
20902104
iferr!=nil {
@@ -3011,6 +3025,14 @@ func (q *querier) UpdateMemberRoles(ctx context.Context, arg database.UpdateMemb
30113025
returnq.db.UpdateMemberRoles(ctx,arg)
30123026
}
30133027

3028+
// TODO: how to restrict this to admins?
3029+
func (q*querier)UpdateNotificationTemplateMethod(ctx context.Context,arg database.UpdateNotificationTemplateMethodParams) (int64,error) {
3030+
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceNotificationTemplate);err!=nil {
3031+
return-1,err
3032+
}
3033+
returnq.db.UpdateNotificationTemplateMethod(ctx,arg)
3034+
}
3035+
30143036
func (q*querier)UpdateOAuth2ProviderAppByID(ctx context.Context,arg database.UpdateOAuth2ProviderAppByIDParams) (database.OAuth2ProviderApp,error) {
30153037
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceOauth2App);err!=nil {
30163038
return database.OAuth2ProviderApp{},err
@@ -3309,6 +3331,13 @@ func (q *querier) UpdateUserLoginType(ctx context.Context, arg database.UpdateUs
33093331
returnq.db.UpdateUserLoginType(ctx,arg)
33103332
}
33113333

3334+
func (q*querier)UpdateUserNotificationPreferences(ctx context.Context,arg database.UpdateUserNotificationPreferencesParams) (int64,error) {
3335+
iferr:=q.authorizeContext(ctx,policy.ActionUpdatePersonal,rbac.ResourceUserObject(arg.UserID));err!=nil {
3336+
return-1,err
3337+
}
3338+
returnq.db.UpdateUserNotificationPreferences(ctx,arg)
3339+
}
3340+
33123341
func (q*querier)UpdateUserProfile(ctx context.Context,arg database.UpdateUserProfileParams) (database.User,error) {
33133342
u,err:=q.db.GetUserByID(ctx,arg.ID)
33143343
iferr!=nil {

‎coderd/database/dbmem/dbmem.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ type data struct {
160160
jfrogXRayScans []database.JfrogXrayScan
161161
licenses []database.License
162162
notificationMessages []database.NotificationMessage
163+
notificationPreferences []database.NotificationPreference
163164
oauth2ProviderApps []database.OAuth2ProviderApp
164165
oauth2ProviderAppSecrets []database.OAuth2ProviderAppSecret
165166
oauth2ProviderAppCodes []database.OAuth2ProviderAppCode
@@ -2708,6 +2709,10 @@ func (q *FakeQuerier) GetNotificationMessagesByStatus(_ context.Context, arg dat
27082709
returnout,nil
27092710
}
27102711

2712+
func (q*FakeQuerier)GetNotificationTemplateById(_ context.Context,id uuid.UUID) (database.NotificationTemplate,error) {
2713+
return database.NotificationTemplate{ID:id,Name:"fake"},nil
2714+
}
2715+
27112716
func (q*FakeQuerier)GetNotificationsSettings(_ context.Context) (string,error) {
27122717
q.mutex.RLock()
27132718
deferq.mutex.RUnlock()
@@ -4853,6 +4858,22 @@ func (q *FakeQuerier) GetUserLinksByUserID(_ context.Context, userID uuid.UUID)
48534858
returnuls,nil
48544859
}
48554860

4861+
func (q*FakeQuerier)GetUserNotificationPreferences(_ context.Context,userID uuid.UUID) ([]database.NotificationPreference,error) {
4862+
q.mutex.RLock()
4863+
deferq.mutex.RUnlock()
4864+
4865+
out:=make([]database.NotificationPreference,0,len(q.notificationPreferences))
4866+
for_,np:=rangeq.notificationPreferences {
4867+
ifnp.UserID!=userID {
4868+
continue
4869+
}
4870+
4871+
out=append(out,np)
4872+
}
4873+
4874+
returnout,nil
4875+
}
4876+
48564877
func (q*FakeQuerier)GetUserWorkspaceBuildParameters(_ context.Context,params database.GetUserWorkspaceBuildParametersParams) ([]database.GetUserWorkspaceBuildParametersRow,error) {
48574878
q.mutex.RLock()
48584879
deferq.mutex.RUnlock()
@@ -7520,6 +7541,15 @@ func (q *FakeQuerier) UpdateMemberRoles(_ context.Context, arg database.UpdateMe
75207541
return database.OrganizationMember{},sql.ErrNoRows
75217542
}
75227543

7544+
func (q*FakeQuerier)UpdateNotificationTemplateMethod(ctx context.Context,arg database.UpdateNotificationTemplateMethodParams) (int64,error) {
7545+
err:=validateDatabaseType(arg)
7546+
iferr!=nil {
7547+
return0,err
7548+
}
7549+
7550+
return1,nil
7551+
}
7552+
75237553
func (q*FakeQuerier)UpdateOAuth2ProviderAppByID(_ context.Context,arg database.UpdateOAuth2ProviderAppByIDParams) (database.OAuth2ProviderApp,error) {
75247554
err:=validateDatabaseType(arg)
75257555
iferr!=nil {
@@ -8094,6 +8124,47 @@ func (q *FakeQuerier) UpdateUserLoginType(_ context.Context, arg database.Update
80948124
return database.User{},sql.ErrNoRows
80958125
}
80968126

8127+
func (q*FakeQuerier)UpdateUserNotificationPreferences(ctx context.Context,arg database.UpdateUserNotificationPreferencesParams) (int64,error) {
8128+
err:=validateDatabaseType(arg)
8129+
iferr!=nil {
8130+
return0,err
8131+
}
8132+
8133+
q.mutex.Lock()
8134+
deferq.mutex.Unlock()
8135+
8136+
varupsertedint64
8137+
fori,templateID:=rangearg.NotificationTemplateIds {
8138+
var (
8139+
found*database.NotificationPreference
8140+
disabled=arg.Disableds[i]
8141+
)
8142+
8143+
for_,np:=rangeq.notificationPreferences {
8144+
ifnp.UserID!=arg.UserID&&np.NotificationTemplateID!=templateID {
8145+
continue
8146+
}
8147+
8148+
found=&np
8149+
}
8150+
8151+
iffound!=nil {
8152+
found.Disabled=disabled
8153+
found.UpdatedAt=time.Now()
8154+
}else {
8155+
q.notificationPreferences=append(q.notificationPreferences, database.NotificationPreference{
8156+
Disabled:disabled,
8157+
UserID:arg.UserID,
8158+
NotificationTemplateID:templateID,
8159+
CreatedAt:time.Now(),
8160+
UpdatedAt:time.Now(),
8161+
})
8162+
}
8163+
}
8164+
8165+
returnupserted,nil
8166+
}
8167+
80978168
func (q*FakeQuerier)UpdateUserProfile(_ context.Context,arg database.UpdateUserProfileParams) (database.User,error) {
80988169
iferr:=validateDatabaseType(arg);err!=nil {
80998170
return database.User{},err

‎coderd/database/dbmetrics/dbmetrics.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbmock/dbmock.go

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/foreign_key_constraint.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp