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

Commite6e4702

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

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
@@ -3026,11 +3026,11 @@ func (q *querier) UpdateMemberRoles(ctx context.Context, arg database.UpdateMemb
30263026
}
30273027

30283028
// TODO: how to restrict this to admins?
3029-
func (q*querier)UpdateNotificationTemplateMethod(ctx context.Context,arg database.UpdateNotificationTemplateMethodParams) (int64,error) {
3029+
func (q*querier)UpdateNotificationTemplateMethodById(ctx context.Context,arg database.UpdateNotificationTemplateMethodByIdParams) (database.NotificationTemplate,error) {
30303030
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,rbac.ResourceNotificationTemplate);err!=nil {
3031-
return-1,err
3031+
returndatabase.NotificationTemplate{},err
30323032
}
3033-
returnq.db.UpdateNotificationTemplateMethod(ctx,arg)
3033+
returnq.db.UpdateNotificationTemplateMethodById(ctx,arg)
30343034
}
30353035

30363036
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
@@ -7541,13 +7541,16 @@ func (q *FakeQuerier) UpdateMemberRoles(_ context.Context, arg database.UpdateMe
75417541
return database.OrganizationMember{},sql.ErrNoRows
75427542
}
75437543

7544-
func (q*FakeQuerier)UpdateNotificationTemplateMethod(ctx context.Context,arg database.UpdateNotificationTemplateMethodParams) (int64,error) {
7544+
func (q*FakeQuerier)UpdateNotificationTemplateMethodById(_ context.Context,arg database.UpdateNotificationTemplateMethodByIdParams) (database.NotificationTemplate,error) {
75457545
err:=validateDatabaseType(arg)
75467546
iferr!=nil {
7547-
return0,err
7547+
returndatabase.NotificationTemplate{},err
75487548
}
75497549

7550-
return1,nil
7550+
return database.NotificationTemplate{
7551+
ID:arg.ID,
7552+
Method:arg.Method,
7553+
},nil
75517554
}
75527555

75537556
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