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

Commit46a6d51

Browse files
committed
Merge branch 'dk/notification-prefs/db-audit' of github.com:coder/coder into dk/notification-prefs/db-audit
2 parents8061685 +95960ca commit46a6d51

File tree

89 files changed

+1188
-692
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1188
-692
lines changed

‎.github/workflows/dogfood.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ on:
1010
-"flake.lock"
1111
-"flake.nix"
1212
pull_request:
13+
branches-ignore:
14+
-"dependabot/**"
1315
paths:
1416
-"dogfood/**"
1517
-".github/workflows/dogfood.yaml"

‎coderd/database/dbauthz/dbauthz.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,11 +1474,11 @@ 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) {
1477+
func (q*querier)GetNotificationTemplateByID(ctx context.Context,id uuid.UUID) (database.NotificationTemplate,error) {
14781478
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceNotificationTemplate);err!=nil {
14791479
return database.NotificationTemplate{},err
14801480
}
1481-
returnq.db.GetNotificationTemplateById(ctx,id)
1481+
returnq.db.GetNotificationTemplateByID(ctx,id)
14821482
}
14831483

14841484
func (q*querier)GetNotificationTemplatesByKind(ctx context.Context,kind database.NotificationTemplateKind) ([]database.NotificationTemplate,error) {
@@ -3033,12 +3033,12 @@ func (q *querier) UpdateMemberRoles(ctx context.Context, arg database.UpdateMemb
30333033
returnq.db.UpdateMemberRoles(ctx,arg)
30343034
}
30353035

3036-
func (q*querier)UpdateNotificationTemplateMethodById(ctx context.Context,arg database.UpdateNotificationTemplateMethodByIdParams) (database.NotificationTemplate,error) {
3036+
func (q*querier)UpdateNotificationTemplateMethodByID(ctx context.Context,arg database.UpdateNotificationTemplateMethodByIDParams) (database.NotificationTemplate,error) {
30373037
// TODO: how to restrict this to admins?
30383038
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceNotificationTemplate);err!=nil {
30393039
return database.NotificationTemplate{},err
30403040
}
3041-
returnq.db.UpdateNotificationTemplateMethodById(ctx,arg)
3041+
returnq.db.UpdateNotificationTemplateMethodByID(ctx,arg)
30423042
}
30433043

30443044
func (q*querier)UpdateOAuth2ProviderAppByID(ctx context.Context,arg database.UpdateOAuth2ProviderAppByIDParams) (database.OAuth2ProviderApp,error) {

‎coderd/database/dbauthz/dbauthz_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,7 +2597,7 @@ func (s *MethodTestSuite) TestNotifications() {
25972597
}))
25982598

25992599
// Notification templates
2600-
s.Run("GetNotificationTemplateById",s.Subtest(func(db database.Store,check*expects) {
2600+
s.Run("GetNotificationTemplateByID",s.Subtest(func(db database.Store,check*expects) {
26012601
user:=dbgen.User(s.T(),db, database.User{})
26022602
check.Args(user.ID).Asserts(rbac.ResourceNotificationTemplate,policy.ActionRead).
26032603
Errors(dbmem.ErrUnimplemented)
@@ -2607,8 +2607,8 @@ func (s *MethodTestSuite) TestNotifications() {
26072607
Asserts(rbac.ResourceNotificationTemplate,policy.ActionRead).
26082608
Errors(dbmem.ErrUnimplemented)
26092609
}))
2610-
s.Run("UpdateNotificationTemplateMethodById",s.Subtest(func(db database.Store,check*expects) {
2611-
check.Args(database.UpdateNotificationTemplateMethodByIdParams{
2610+
s.Run("UpdateNotificationTemplateMethodByID",s.Subtest(func(db database.Store,check*expects) {
2611+
check.Args(database.UpdateNotificationTemplateMethodByIDParams{
26122612
Method: database.NullNotificationMethod{NotificationMethod:database.NotificationMethodWebhook,Valid:true},
26132613
ID:notifications.TemplateWorkspaceDormant,
26142614
}).Asserts(rbac.ResourceNotificationTemplate,policy.ActionUpdate).

‎coderd/database/dbmem/dbmem.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,11 +2710,11 @@ func (q *FakeQuerier) GetNotificationMessagesByStatus(_ context.Context, arg dat
27102710
returnout,nil
27112711
}
27122712

2713-
func (*FakeQuerier)GetNotificationTemplateById(_ context.Context,_ uuid.UUID) (database.NotificationTemplate,error) {
2713+
func (*FakeQuerier)GetNotificationTemplateByID(_ context.Context,_ uuid.UUID) (database.NotificationTemplate,error) {
27142714
return database.NotificationTemplate{},ErrUnimplemented
27152715
}
27162716

2717-
func (q*FakeQuerier)GetNotificationTemplatesByKind(ctx context.Context,kind database.NotificationTemplateKind) ([]database.NotificationTemplate,error) {
2717+
func (*FakeQuerier)GetNotificationTemplatesByKind(_ context.Context,_ database.NotificationTemplateKind) ([]database.NotificationTemplate,error) {
27182718
returnnil,ErrUnimplemented
27192719
}
27202720

@@ -7546,7 +7546,7 @@ func (q *FakeQuerier) UpdateMemberRoles(_ context.Context, arg database.UpdateMe
75467546
return database.OrganizationMember{},sql.ErrNoRows
75477547
}
75487548

7549-
func (*FakeQuerier)UpdateNotificationTemplateMethodById(_ context.Context,_ database.UpdateNotificationTemplateMethodByIdParams) (database.NotificationTemplate,error) {
7549+
func (*FakeQuerier)UpdateNotificationTemplateMethodByID(_ context.Context,_ database.UpdateNotificationTemplateMethodByIDParams) (database.NotificationTemplate,error) {
75507550
return database.NotificationTemplate{},ErrUnimplemented
75517551
}
75527552

‎coderd/database/dbmetrics/dbmetrics.go

Lines changed: 6 additions & 6 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: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dump.sql

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

‎coderd/database/migrations/000234_notification_preferences.up.sql

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
11
CREATETABLEnotification_preferences
22
(
3-
user_id uuidREFERENCES usersON DELETE CASCADENOT NULL,
4-
notification_template_id uuidREFERENCES notification_templatesON DELETE CASCADENOT NULL,
5-
disabled boolNOT NULL DEFAULT FALSE,
6-
created_atTIMESTAMP WITH TIME ZONENOT NULL DEFAULTCURRENT_TIMESTAMP,
7-
updated_atTIMESTAMP WITH TIME ZONENOT NULL DEFAULTCURRENT_TIMESTAMP
3+
user_id uuidREFERENCES usersON DELETE CASCADENOT NULL,
4+
notification_template_id uuidREFERENCES notification_templatesON DELETE CASCADENOT NULL,
5+
disabled boolNOT NULL DEFAULT FALSE,
6+
created_atTIMESTAMP WITH TIME ZONENOT NULL DEFAULTCURRENT_TIMESTAMP,
7+
updated_atTIMESTAMP WITH TIME ZONENOT NULL DEFAULTCURRENT_TIMESTAMP,
8+
PRIMARY KEY (user_id, notification_template_id)
89
);
910

1011
-- Ensure we cannot insert multiple entries for the same user/template combination.
1112
ALTERTABLE notification_preferences
12-
ADDCONSTRAINT unique_user_notification_template UNIQUE (user_id, notification_template_id);
13+
ADDCONSTRAINT unique_user_notification_template UNIQUE (user_id, notification_template_id);
1314

1415
-- Add a new type (to be expanded upon later) which specifies the kind of notification template.
1516
CREATETYPEnotification_template_kindAS ENUM (
16-
'system'
17-
);
17+
'system'
18+
);
1819

1920
ALTERTABLE notification_templates
20-
-- Allow per-template notification method (enterprise only).
21-
ADD COLUMN method notification_method,
22-
-- Update all existing notification templates to be system templates.
23-
ADD COLUMN kind notification_template_kind DEFAULT'system'::notification_template_kindNOT NULL;
21+
-- Allow per-template notification method (enterprise only).
22+
ADD COLUMN method notification_method,
23+
-- Update all existing notification templates to be system templates.
24+
ADD COLUMN kind notification_template_kind DEFAULT'system'::notification_template_kindNOT NULL;
2425
COMMENT ON COLUMN notification_templates.method IS'NULL defers to the deployment-level method';
2526

2627
-- No equivalent in down migration because ENUM values cannot be deleted.
2728
ALTERTYPE notification_message_status ADD VALUE IF NOT EXISTS'inhibited';
2829

2930
-- Function to prevent enqueuing notifications unnecessarily.
3031
CREATE OR REPLACEFUNCTIONinhibit_enqueue_if_disabled()
31-
RETURNS TRIGGERAS
32+
RETURNS TRIGGERAS
3233
$$
3334
BEGIN
34-
-- Fail the insertion if the user has disabled this notification.
35-
IF EXISTS (SELECT1
36-
FROM notification_preferences
37-
WHERE disabled= TRUE
38-
AND user_id=NEW.user_id
39-
AND notification_template_id=NEW.notification_template_id) THEN
40-
RAISE EXCEPTION'cannot enqueue message: user has disabled this notification';
41-
END IF;
42-
43-
RETURN NEW;
35+
-- Fail the insertion if the user has disabled this notification.
36+
IF EXISTS (SELECT1
37+
FROM notification_preferences
38+
WHERE disabled= TRUE
39+
AND user_id=NEW.user_id
40+
AND notification_template_id=NEW.notification_template_id) THEN
41+
RAISE EXCEPTION'cannot enqueue message: user has disabled this notification';
42+
END IF;
43+
44+
RETURN NEW;
4445
END;
4546
$$ LANGUAGE plpgsql;
4647

4748
-- Trigger to execute above function on insertion.
4849
CREATETRIGGERinhibit_enqueue_if_disabled
49-
BEFORE INSERT
50-
ON notification_messages
51-
FOR EACH ROW
50+
BEFORE INSERT
51+
ON notification_messages
52+
FOR EACH ROW
5253
EXECUTE FUNCTION inhibit_enqueue_if_disabled();
5354

5455
-- Allow modifications to notification templates to be audited.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
INSERT INTO users(id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, deleted)
2+
VALUES ('fc1511ef-4fcf-4a3b-98a1-8df64160e35a','githubuser@coder.com','githubuser','\x',
3+
'2022-11-02 13:05:21.445455+02','2022-11-02 13:05:21.445455+02','active','{}', false)ON CONFLICT DO NOTHING;
4+
5+
INSERT INTO notification_templates (id, name, title_template, body_template,"group")
6+
VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11','A','title','body','Group 1')ON CONFLICT DO NOTHING;
7+
8+
INSERT INTO notification_preferences (user_id, notification_template_id, disabled, created_at, updated_at)
9+
VALUES ('a0061a8e-7db7-4585-838c-3116a003dd21','a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', FALSE,'2024-07-15 10:30:00+00','2024-07-15 10:30:00+00');

‎coderd/database/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier.go

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

‎coderd/database/queries.sql.go

Lines changed: 8 additions & 8 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