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

Commitf881fc3

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

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
@@ -1484,6 +1484,13 @@ func (q *querier) GetNotificationMessagesByStatus(ctx context.Context, arg datab
14841484
returnq.db.GetNotificationMessagesByStatus(ctx,arg)
14851485
}
14861486

1487+
func (q*querier)GetNotificationTemplateById(ctx context.Context,id uuid.UUID) (database.NotificationTemplate,error) {
1488+
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceNotificationTemplate);err!=nil {
1489+
return database.NotificationTemplate{},err
1490+
}
1491+
returnq.db.GetNotificationTemplateById(ctx,id)
1492+
}
1493+
14871494
func (q*querier)GetNotificationsSettings(ctx context.Context) (string,error) {
14881495
// No authz checks
14891496
returnq.db.GetNotificationsSettings(ctx)
@@ -2095,6 +2102,13 @@ func (q *querier) GetUserLinksByUserID(ctx context.Context, userID uuid.UUID) ([
20952102
returnq.db.GetUserLinksByUserID(ctx,userID)
20962103
}
20972104

2105+
func (q*querier)GetUserNotificationPreferences(ctx context.Context,userID uuid.UUID) ([]database.NotificationPreference,error) {
2106+
iferr:=q.authorizeContext(ctx,policy.ActionReadPersonal,rbac.ResourceUserObject(userID));err!=nil {
2107+
returnnil,err
2108+
}
2109+
returnq.db.GetUserNotificationPreferences(ctx,userID)
2110+
}
2111+
20982112
func (q*querier)GetUserWorkspaceBuildParameters(ctx context.Context,params database.GetUserWorkspaceBuildParametersParams) ([]database.GetUserWorkspaceBuildParametersRow,error) {
20992113
u,err:=q.db.GetUserByID(ctx,params.OwnerID)
21002114
iferr!=nil {
@@ -3021,6 +3035,14 @@ func (q *querier) UpdateMemberRoles(ctx context.Context, arg database.UpdateMemb
30213035
returnq.db.UpdateMemberRoles(ctx,arg)
30223036
}
30233037

3038+
// TODO: how to restrict this to admins?
3039+
func (q*querier)UpdateNotificationTemplateMethod(ctx context.Context,arg database.UpdateNotificationTemplateMethodParams) (int64,error) {
3040+
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceNotificationTemplate);err!=nil {
3041+
return-1,err
3042+
}
3043+
returnq.db.UpdateNotificationTemplateMethod(ctx,arg)
3044+
}
3045+
30243046
func (q*querier)UpdateOAuth2ProviderAppByID(ctx context.Context,arg database.UpdateOAuth2ProviderAppByIDParams) (database.OAuth2ProviderApp,error) {
30253047
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceOauth2App);err!=nil {
30263048
return database.OAuth2ProviderApp{},err
@@ -3319,6 +3341,13 @@ func (q *querier) UpdateUserLoginType(ctx context.Context, arg database.UpdateUs
33193341
returnq.db.UpdateUserLoginType(ctx,arg)
33203342
}
33213343

3344+
func (q*querier)UpdateUserNotificationPreferences(ctx context.Context,arg database.UpdateUserNotificationPreferencesParams) (int64,error) {
3345+
iferr:=q.authorizeContext(ctx,policy.ActionUpdatePersonal,rbac.ResourceUserObject(arg.UserID));err!=nil {
3346+
return-1,err
3347+
}
3348+
returnq.db.UpdateUserNotificationPreferences(ctx,arg)
3349+
}
3350+
33223351
func (q*querier)UpdateUserProfile(ctx context.Context,arg database.UpdateUserProfileParams) (database.User,error) {
33233352
u,err:=q.db.GetUserByID(ctx,arg.ID)
33243353
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
@@ -2817,6 +2818,10 @@ func (q *FakeQuerier) GetNotificationMessagesByStatus(_ context.Context, arg dat
28172818
returnout,nil
28182819
}
28192820

2821+
func (q*FakeQuerier)GetNotificationTemplateById(_ context.Context,id uuid.UUID) (database.NotificationTemplate,error) {
2822+
return database.NotificationTemplate{ID:id,Name:"fake"},nil
2823+
}
2824+
28202825
func (q*FakeQuerier)GetNotificationsSettings(_ context.Context) (string,error) {
28212826
q.mutex.RLock()
28222827
deferq.mutex.RUnlock()
@@ -4962,6 +4967,22 @@ func (q *FakeQuerier) GetUserLinksByUserID(_ context.Context, userID uuid.UUID)
49624967
returnuls,nil
49634968
}
49644969

4970+
func (q*FakeQuerier)GetUserNotificationPreferences(_ context.Context,userID uuid.UUID) ([]database.NotificationPreference,error) {
4971+
q.mutex.RLock()
4972+
deferq.mutex.RUnlock()
4973+
4974+
out:=make([]database.NotificationPreference,0,len(q.notificationPreferences))
4975+
for_,np:=rangeq.notificationPreferences {
4976+
ifnp.UserID!=userID {
4977+
continue
4978+
}
4979+
4980+
out=append(out,np)
4981+
}
4982+
4983+
returnout,nil
4984+
}
4985+
49654986
func (q*FakeQuerier)GetUserWorkspaceBuildParameters(_ context.Context,params database.GetUserWorkspaceBuildParametersParams) ([]database.GetUserWorkspaceBuildParametersRow,error) {
49664987
q.mutex.RLock()
49674988
deferq.mutex.RUnlock()
@@ -7629,6 +7650,15 @@ func (q *FakeQuerier) UpdateMemberRoles(_ context.Context, arg database.UpdateMe
76297650
return database.OrganizationMember{},sql.ErrNoRows
76307651
}
76317652

7653+
func (q*FakeQuerier)UpdateNotificationTemplateMethod(ctx context.Context,arg database.UpdateNotificationTemplateMethodParams) (int64,error) {
7654+
err:=validateDatabaseType(arg)
7655+
iferr!=nil {
7656+
return0,err
7657+
}
7658+
7659+
return1,nil
7660+
}
7661+
76327662
func (q*FakeQuerier)UpdateOAuth2ProviderAppByID(_ context.Context,arg database.UpdateOAuth2ProviderAppByIDParams) (database.OAuth2ProviderApp,error) {
76337663
err:=validateDatabaseType(arg)
76347664
iferr!=nil {
@@ -8203,6 +8233,47 @@ func (q *FakeQuerier) UpdateUserLoginType(_ context.Context, arg database.Update
82038233
return database.User{},sql.ErrNoRows
82048234
}
82058235

8236+
func (q*FakeQuerier)UpdateUserNotificationPreferences(ctx context.Context,arg database.UpdateUserNotificationPreferencesParams) (int64,error) {
8237+
err:=validateDatabaseType(arg)
8238+
iferr!=nil {
8239+
return0,err
8240+
}
8241+
8242+
q.mutex.Lock()
8243+
deferq.mutex.Unlock()
8244+
8245+
varupsertedint64
8246+
fori,templateID:=rangearg.NotificationTemplateIds {
8247+
var (
8248+
found*database.NotificationPreference
8249+
disabled=arg.Disableds[i]
8250+
)
8251+
8252+
for_,np:=rangeq.notificationPreferences {
8253+
ifnp.UserID!=arg.UserID&&np.NotificationTemplateID!=templateID {
8254+
continue
8255+
}
8256+
8257+
found=&np
8258+
}
8259+
8260+
iffound!=nil {
8261+
found.Disabled=disabled
8262+
found.UpdatedAt=time.Now()
8263+
}else {
8264+
q.notificationPreferences=append(q.notificationPreferences, database.NotificationPreference{
8265+
Disabled:disabled,
8266+
UserID:arg.UserID,
8267+
NotificationTemplateID:templateID,
8268+
CreatedAt:time.Now(),
8269+
UpdatedAt:time.Now(),
8270+
})
8271+
}
8272+
}
8273+
8274+
returnupserted,nil
8275+
}
8276+
82068277
func (q*FakeQuerier)UpdateUserProfile(_ context.Context,arg database.UpdateUserProfileParams) (database.User,error) {
82078278
iferr:=validateDatabaseType(arg);err!=nil {
82088279
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