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

Commit5b39130

Browse files
committed
Merge branch 'dk/notification-prefs/db' into dk/notification-prefs/audit
2 parentsec9db0e +65e8546 commit5b39130

25 files changed

+963
-222
lines changed

‎coderd/apidoc/docs.go

Lines changed: 4 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: 4 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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,21 @@ 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+
1484+
func (q*querier)GetNotificationTemplatesByKind(ctx context.Context,kind database.NotificationTemplateKind) ([]database.NotificationTemplate,error) {
1485+
// TODO: restrict 'system' kind to admins only?
1486+
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceNotificationTemplate);err!=nil {
1487+
returnnil,err
1488+
}
1489+
returnq.db.GetNotificationTemplatesByKind(ctx,kind)
1490+
}
1491+
14771492
func (q*querier)GetNotificationsSettings(ctx context.Context) (string,error) {
14781493
// No authz checks
14791494
returnq.db.GetNotificationsSettings(ctx)
@@ -2085,6 +2100,13 @@ func (q *querier) GetUserLinksByUserID(ctx context.Context, userID uuid.UUID) ([
20852100
returnq.db.GetUserLinksByUserID(ctx,userID)
20862101
}
20872102

2103+
func (q*querier)GetUserNotificationPreferences(ctx context.Context,userID uuid.UUID) ([]database.NotificationPreference,error) {
2104+
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceNotificationPreference.WithOwner(userID.String()));err!=nil {
2105+
returnnil,err
2106+
}
2107+
returnq.db.GetUserNotificationPreferences(ctx,userID)
2108+
}
2109+
20882110
func (q*querier)GetUserWorkspaceBuildParameters(ctx context.Context,params database.GetUserWorkspaceBuildParametersParams) ([]database.GetUserWorkspaceBuildParametersRow,error) {
20892111
u,err:=q.db.GetUserByID(ctx,params.OwnerID)
20902112
iferr!=nil {
@@ -3011,6 +3033,14 @@ func (q *querier) UpdateMemberRoles(ctx context.Context, arg database.UpdateMemb
30113033
returnq.db.UpdateMemberRoles(ctx,arg)
30123034
}
30133035

3036+
func (q*querier)UpdateNotificationTemplateMethodById(ctx context.Context,arg database.UpdateNotificationTemplateMethodByIdParams) (database.NotificationTemplate,error) {
3037+
// TODO: how to restrict this to admins?
3038+
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceNotificationTemplate);err!=nil {
3039+
return database.NotificationTemplate{},err
3040+
}
3041+
returnq.db.UpdateNotificationTemplateMethodById(ctx,arg)
3042+
}
3043+
30143044
func (q*querier)UpdateOAuth2ProviderAppByID(ctx context.Context,arg database.UpdateOAuth2ProviderAppByIDParams) (database.OAuth2ProviderApp,error) {
30153045
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceOauth2App);err!=nil {
30163046
return database.OAuth2ProviderApp{},err
@@ -3309,6 +3339,13 @@ func (q *querier) UpdateUserLoginType(ctx context.Context, arg database.UpdateUs
33093339
returnq.db.UpdateUserLoginType(ctx,arg)
33103340
}
33113341

3342+
func (q*querier)UpdateUserNotificationPreferences(ctx context.Context,arg database.UpdateUserNotificationPreferencesParams) (int64,error) {
3343+
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceNotificationPreference.WithOwner(arg.UserID.String()));err!=nil {
3344+
return-1,err
3345+
}
3346+
returnq.db.UpdateUserNotificationPreferences(ctx,arg)
3347+
}
3348+
33123349
func (q*querier)UpdateUserProfile(ctx context.Context,arg database.UpdateUserProfileParams) (database.User,error) {
33133350
u,err:=q.db.GetUserByID(ctx,arg.ID)
33143351
iferr!=nil {

‎coderd/database/dbmem/dbmem.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func New() database.Store {
6565
files:make([]database.File,0),
6666
gitSSHKey:make([]database.GitSSHKey,0),
6767
notificationMessages:make([]database.NotificationMessage,0),
68+
notificationPreferences:make([]database.NotificationPreference,0),
6869
parameterSchemas:make([]database.ParameterSchema,0),
6970
provisionerDaemons:make([]database.ProvisionerDaemon,0),
7071
workspaceAgents:make([]database.WorkspaceAgent,0),
@@ -160,6 +161,7 @@ type data struct {
160161
jfrogXRayScans []database.JfrogXrayScan
161162
licenses []database.License
162163
notificationMessages []database.NotificationMessage
164+
notificationPreferences []database.NotificationPreference
163165
oauth2ProviderApps []database.OAuth2ProviderApp
164166
oauth2ProviderAppSecrets []database.OAuth2ProviderAppSecret
165167
oauth2ProviderAppCodes []database.OAuth2ProviderAppCode
@@ -2708,6 +2710,14 @@ func (q *FakeQuerier) GetNotificationMessagesByStatus(_ context.Context, arg dat
27082710
returnout,nil
27092711
}
27102712

2713+
func (*FakeQuerier)GetNotificationTemplateById(_ context.Context,_ uuid.UUID) (database.NotificationTemplate,error) {
2714+
return database.NotificationTemplate{},ErrUnimplemented
2715+
}
2716+
2717+
func (q*FakeQuerier)GetNotificationTemplatesByKind(ctx context.Context,kind database.NotificationTemplateKind) ([]database.NotificationTemplate,error) {
2718+
returnnil,ErrUnimplemented
2719+
}
2720+
27112721
func (q*FakeQuerier)GetNotificationsSettings(_ context.Context) (string,error) {
27122722
q.mutex.RLock()
27132723
deferq.mutex.RUnlock()
@@ -4853,6 +4863,22 @@ func (q *FakeQuerier) GetUserLinksByUserID(_ context.Context, userID uuid.UUID)
48534863
returnuls,nil
48544864
}
48554865

4866+
func (q*FakeQuerier)GetUserNotificationPreferences(_ context.Context,userID uuid.UUID) ([]database.NotificationPreference,error) {
4867+
q.mutex.RLock()
4868+
deferq.mutex.RUnlock()
4869+
4870+
out:=make([]database.NotificationPreference,0,len(q.notificationPreferences))
4871+
for_,np:=rangeq.notificationPreferences {
4872+
ifnp.UserID!=userID {
4873+
continue
4874+
}
4875+
4876+
out=append(out,np)
4877+
}
4878+
4879+
returnout,nil
4880+
}
4881+
48564882
func (q*FakeQuerier)GetUserWorkspaceBuildParameters(_ context.Context,params database.GetUserWorkspaceBuildParametersParams) ([]database.GetUserWorkspaceBuildParametersRow,error) {
48574883
q.mutex.RLock()
48584884
deferq.mutex.RUnlock()
@@ -7520,6 +7546,10 @@ func (q *FakeQuerier) UpdateMemberRoles(_ context.Context, arg database.UpdateMe
75207546
return database.OrganizationMember{},sql.ErrNoRows
75217547
}
75227548

7549+
func (*FakeQuerier)UpdateNotificationTemplateMethodById(_ context.Context,_ database.UpdateNotificationTemplateMethodByIdParams) (database.NotificationTemplate,error) {
7550+
return database.NotificationTemplate{},ErrUnimplemented
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,57 @@ func (q *FakeQuerier) UpdateUserLoginType(_ context.Context, arg database.Update
80948124
return database.User{},sql.ErrNoRows
80958125
}
80968126

8127+
func (q*FakeQuerier)UpdateUserNotificationPreferences(_ context.Context,arg database.UpdateUserNotificationPreferencesParams) (int64,error) {
8128+
err:=validateDatabaseType(arg)
8129+
iferr!=nil {
8130+
return-1,err
8131+
}
8132+
8133+
q.mutex.Lock()
8134+
deferq.mutex.Unlock()
8135+
8136+
varupsertedint64
8137+
fori:=rangearg.NotificationTemplateIds {
8138+
var (
8139+
foundbool
8140+
templateID=arg.NotificationTemplateIds[i]
8141+
disabled=arg.Disableds[i]
8142+
)
8143+
8144+
forj,np:=rangeq.notificationPreferences {
8145+
ifnp.UserID!=arg.UserID {
8146+
continue
8147+
}
8148+
8149+
ifnp.NotificationTemplateID!=templateID {
8150+
continue
8151+
}
8152+
8153+
np.Disabled=disabled
8154+
np.UpdatedAt=time.Now()
8155+
q.notificationPreferences[j]=np
8156+
8157+
upserted++
8158+
found=true
8159+
break
8160+
}
8161+
8162+
if!found {
8163+
np:= database.NotificationPreference{
8164+
Disabled:disabled,
8165+
UserID:arg.UserID,
8166+
NotificationTemplateID:templateID,
8167+
CreatedAt:time.Now(),
8168+
UpdatedAt:time.Now(),
8169+
}
8170+
q.notificationPreferences=append(q.notificationPreferences,np)
8171+
upserted++
8172+
}
8173+
}
8174+
8175+
returnupserted,nil
8176+
}
8177+
80978178
func (q*FakeQuerier)UpdateUserProfile(_ context.Context,arg database.UpdateUserProfileParams) (database.User,error) {
80988179
iferr:=validateDatabaseType(arg);err!=nil {
80998180
return database.User{},err

‎coderd/database/dbmetrics/dbmetrics.go

Lines changed: 35 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: 75 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