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

Commit184bc2b

Browse files
committed
Add kind to notification_templates and query to retrieve templates by kind
Signed-off-by: Danny Kopping <danny@coder.com>
1 parenta4daa44 commit184bc2b

File tree

14 files changed

+179
-33
lines changed

14 files changed

+179
-33
lines changed

‎coderd/database/dbauthz/dbauthz.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,14 @@ func (q *querier) GetNotificationTemplateById(ctx context.Context, id uuid.UUID)
14911491
returnq.db.GetNotificationTemplateById(ctx,id)
14921492
}
14931493

1494+
func (q*querier)GetNotificationTemplatesByKind(ctx context.Context,kind database.NotificationTemplateKind) ([]database.NotificationTemplate,error) {
1495+
// TODO: restrict 'system' kind to admins only?
1496+
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceNotificationTemplate);err!=nil {
1497+
returnnil,err
1498+
}
1499+
returnq.db.GetNotificationTemplatesByKind(ctx,kind)
1500+
}
1501+
14941502
func (q*querier)GetNotificationsSettings(ctx context.Context) (string,error) {
14951503
// No authz checks
14961504
returnq.db.GetNotificationsSettings(ctx)
@@ -3035,8 +3043,8 @@ func (q *querier) UpdateMemberRoles(ctx context.Context, arg database.UpdateMemb
30353043
returnq.db.UpdateMemberRoles(ctx,arg)
30363044
}
30373045

3038-
// TODO: how to restrict this to admins?
30393046
func (q*querier)UpdateNotificationTemplateMethodById(ctx context.Context,arg database.UpdateNotificationTemplateMethodByIdParams) (database.NotificationTemplate,error) {
3047+
// TODO: how to restrict this to admins?
30403048
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceNotificationTemplate);err!=nil {
30413049
return database.NotificationTemplate{},err
30423050
}

‎coderd/database/dbmem/dbmem.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,8 +2818,12 @@ func (q *FakeQuerier) GetNotificationMessagesByStatus(_ context.Context, arg dat
28182818
returnout,nil
28192819
}
28202820

2821-
func (q*FakeQuerier)GetNotificationTemplateById(_ context.Context,id uuid.UUID) (database.NotificationTemplate,error) {
2822-
return database.NotificationTemplate{ID:id,Name:"fake"},nil
2821+
func (*FakeQuerier)GetNotificationTemplateById(_ context.Context,_ uuid.UUID) (database.NotificationTemplate,error) {
2822+
return database.NotificationTemplate{},ErrUnimplemented
2823+
}
2824+
2825+
func (q*FakeQuerier)GetNotificationTemplatesByKind(ctx context.Context,kind database.NotificationTemplateKind) ([]database.NotificationTemplate,error) {
2826+
returnnil,ErrUnimplemented
28232827
}
28242828

28252829
func (q*FakeQuerier)GetNotificationsSettings(_ context.Context) (string,error) {
@@ -7650,16 +7654,8 @@ func (q *FakeQuerier) UpdateMemberRoles(_ context.Context, arg database.UpdateMe
76507654
return database.OrganizationMember{},sql.ErrNoRows
76517655
}
76527656

7653-
func (q*FakeQuerier)UpdateNotificationTemplateMethodById(_ context.Context,arg database.UpdateNotificationTemplateMethodByIdParams) (database.NotificationTemplate,error) {
7654-
err:=validateDatabaseType(arg)
7655-
iferr!=nil {
7656-
return database.NotificationTemplate{},err
7657-
}
7658-
7659-
return database.NotificationTemplate{
7660-
ID:arg.ID,
7661-
Method:arg.Method,
7662-
},nil
7657+
func (*FakeQuerier)UpdateNotificationTemplateMethodById(_ context.Context,_ database.UpdateNotificationTemplateMethodByIdParams) (database.NotificationTemplate,error) {
7658+
return database.NotificationTemplate{},ErrUnimplemented
76637659
}
76647660

76657661
func (q*FakeQuerier)UpdateOAuth2ProviderAppByID(_ context.Context,arg database.UpdateOAuth2ProviderAppByIDParams) (database.OAuth2ProviderApp,error) {

‎coderd/database/dbmetrics/dbmetrics.go

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

‎coderd/database/dump.sql

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
DROPTABLE IF EXISTS notification_preferences;
2-
31
ALTERTABLE notification_templates
4-
DROP COLUMN IF EXISTS method;
2+
DROP COLUMN IF EXISTS method,
3+
DROP COLUMN IF EXISTS kind;
4+
5+
DROPTABLE IF EXISTS notification_preferences;
6+
DROPTYPE IF EXISTS notification_template_kind;
57

68
DROPTRIGGER IF EXISTS inhibit_enqueue_if_disabled_triggerON notification_messages;
79
DROPFUNCTION IF EXISTS inhibit_enqueue_if_disabled;

‎coderd/database/migrations/000231_notification_preferences.up.sqlrenamed to‎coderd/database/migrations/000232_notification_preferences.up.sql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ CREATE TABLE notification_preferences
1111
ALTERTABLE notification_preferences
1212
ADDCONSTRAINT unique_user_notification_template UNIQUE (user_id, notification_template_id);
1313

14-
-- Allow per-template notification method (enterprise only).
14+
-- Add a new type (to be expanded upon later) which specifies the kind of notification template.
15+
CREATETYPEnotification_template_kindAS ENUM (
16+
'system'
17+
);
18+
1519
ALTERTABLE notification_templates
16-
ADD COLUMN method notification_method;
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;
1724
COMMENT ON COLUMN notification_templates.method IS'NULL defers to the deployment-level method';
1825

1926
-- No equivalent in down migration because ENUM values cannot be deleted.
@@ -45,4 +52,4 @@ CREATE TRIGGER inhibit_enqueue_if_disabled_trigger
4552
EXECUTE FUNCTION inhibit_enqueue_if_disabled();
4653

4754
-- Allow modifications to notification templates to be audited.
48-
ALTERTYPE resource_type ADD VALUE IF NOT EXISTS'notification_template';
55+
ALTERTYPE resource_type ADD VALUE IF NOT EXISTS'notification_template';

‎coderd/database/models.go

Lines changed: 57 additions & 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: 1 addition & 0 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: 41 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/notifications.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,7 @@ RETURNING *;
167167
SELECT*
168168
FROM notification_templates
169169
WHERE id= @id::uuid;
170+
171+
-- name: GetNotificationTemplatesByKind :many
172+
SELECT*FROM notification_templates
173+
WHERE kind= @kind::notification_template_kind;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp