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

Commita4daa44

Browse files
committed
Allow notification templates to be auditable
Signed-off-by: Danny Kopping <danny@coder.com>
1 parentf881fc3 commita4daa44

File tree

8 files changed

+42
-27
lines changed

8 files changed

+42
-27
lines changed

‎coderd/database/dbauthz/dbauthz.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,11 +3036,11 @@ func (q *querier) UpdateMemberRoles(ctx context.Context, arg database.UpdateMemb
30363036
}
30373037

30383038
// TODO: how to restrict this to admins?
3039-
func (q*querier)UpdateNotificationTemplateMethod(ctx context.Context,arg database.UpdateNotificationTemplateMethodParams) (int64,error) {
3039+
func (q*querier)UpdateNotificationTemplateMethodById(ctx context.Context,arg database.UpdateNotificationTemplateMethodByIdParams) (database.NotificationTemplate,error) {
30403040
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceNotificationTemplate);err!=nil {
3041-
return-1,err
3041+
returndatabase.NotificationTemplate{},err
30423042
}
3043-
returnq.db.UpdateNotificationTemplateMethod(ctx,arg)
3043+
returnq.db.UpdateNotificationTemplateMethodById(ctx,arg)
30443044
}
30453045

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

‎coderd/database/dbmem/dbmem.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7650,13 +7650,16 @@ func (q *FakeQuerier) UpdateMemberRoles(_ context.Context, arg database.UpdateMe
76507650
return database.OrganizationMember{},sql.ErrNoRows
76517651
}
76527652

7653-
func (q*FakeQuerier)UpdateNotificationTemplateMethod(ctx context.Context,arg database.UpdateNotificationTemplateMethodParams) (int64,error) {
7653+
func (q*FakeQuerier)UpdateNotificationTemplateMethodById(_ context.Context,arg database.UpdateNotificationTemplateMethodByIdParams) (database.NotificationTemplate,error) {
76547654
err:=validateDatabaseType(arg)
76557655
iferr!=nil {
7656-
return0,err
7656+
returndatabase.NotificationTemplate{},err
76577657
}
76587658

7659-
return1,nil
7659+
return database.NotificationTemplate{
7660+
ID:arg.ID,
7661+
Method:arg.Method,
7662+
},nil
76607663
}
76617664

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

‎coderd/database/dbmetrics/dbmetrics.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/migrations/000229_notification_preferences.up.sqlrenamed to‎coderd/database/migrations/000231_notification_preferences.up.sql

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ CREATE TABLE notification_preferences
77
updated_atTIMESTAMP WITH TIME ZONENOT NULL DEFAULTCURRENT_TIMESTAMP
88
);
99

10-
-- Ensure we cannot insert multiple entries for the same user/template combination
10+
-- Ensure we cannot insert multiple entries for the same user/template combination.
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+
-- Allow per-template notification method (enterprise only).
1515
ALTERTABLE notification_templates
1616
ADD COLUMN method notification_method;
1717
COMMENT ON COLUMN notification_templates.method IS'NULL defers to the deployment-level method';
1818

19-
-- No equivalent in down migration because ENUM values cannot be deleted
19+
-- No equivalent in down migration because ENUM values cannot be deleted.
2020
ALTERTYPE notification_message_status ADD VALUE IF NOT EXISTS'inhibited';
2121

22-
-- Function to prevent enqueuing notifications unnecessarily
22+
-- Function to prevent enqueuing notifications unnecessarily.
2323
CREATE OR REPLACEFUNCTIONinhibit_enqueue_if_disabled()
2424
RETURNS TRIGGERAS
2525
$$
2626
BEGIN
27-
-- Fail the insertion if the user has disabled this notification
27+
-- Fail the insertion if the user has disabled this notification.
2828
IF EXISTS (SELECT1
2929
FROM notification_preferences
3030
WHERE disabled= TRUE
@@ -37,9 +37,12 @@ BEGIN
3737
END;
3838
$$ LANGUAGE plpgsql;
3939

40-
-- Trigger to execute above function on insertion
40+
-- Trigger to execute above function on insertion.
4141
CREATETRIGGERinhibit_enqueue_if_disabled_trigger
4242
BEFORE INSERT
4343
ON notification_messages
4444
FOR EACH ROW
45-
EXECUTE FUNCTION inhibit_enqueue_if_disabled();
45+
EXECUTE FUNCTION inhibit_enqueue_if_disabled();
46+
47+
-- Allow modifications to notification templates to be audited.
48+
ALTERTYPE resource_type ADD VALUE IF NOT EXISTS'notification_template';

‎coderd/database/querier.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/queries.sql.go

Lines changed: 16 additions & 8 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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ ON CONFLICT (user_id, notification_template_id) DO UPDATE
157157
SET disabled=EXCLUDED.disabled,
158158
updated_at=CURRENT_TIMESTAMP;
159159

160-
-- name:UpdateNotificationTemplateMethod :execrows
160+
-- name:UpdateNotificationTemplateMethodById :one
161161
UPDATE notification_templates
162162
SET method=sqlc.narg('method')::notification_method
163-
WHERE id= @id::uuid;
163+
WHERE id= @id::uuid
164+
RETURNING*;
164165

165166
-- name: GetNotificationTemplateById :one
166167
SELECT*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp