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

Commit203668d

Browse files
committed
chore: add kind 'custom' type to notification template kind enum
1 parent0d1144a commit203668d

File tree

10 files changed

+208
-18
lines changed

10 files changed

+208
-18
lines changed

‎coderd/apidoc/docs.go‎

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

‎coderd/coderd.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,7 @@ func New(options *Options) *API {
15781578
r.Put("/settings",api.putNotificationsSettings)
15791579
r.Route("/templates",func(r chi.Router) {
15801580
r.Get("/system",api.systemNotificationTemplates)
1581+
r.Get("/custom",api.customNotificationTemplates)
15811582
})
15821583
r.Get("/dispatch-methods",api.notificationDispatchMethods)
15831584
r.Post("/test",api.postTestNotification)

‎coderd/database/dbauthz/dbauthz.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,8 +2281,8 @@ func (q *querier) GetNotificationTemplateByID(ctx context.Context, id uuid.UUID)
22812281
}
22822282

22832283
func (q*querier)GetNotificationTemplatesByKind(ctx context.Context,kind database.NotificationTemplateKind) ([]database.NotificationTemplate,error) {
2284-
// Anyone can read the system notification templates.
2285-
ifkind==database.NotificationTemplateKindSystem {
2284+
// Anyone can read the'system' and 'custom' notification templates.
2285+
ifkind==database.NotificationTemplateKindSystem||kind==database.NotificationTemplateKindCustom{
22862286
returnq.db.GetNotificationTemplatesByKind(ctx,kind)
22872287
}
22882288

‎coderd/database/dump.sql‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
1+
-- Remove Custom Notification template
12
DELETEFROM notification_templatesWHERE id='39b1e189-c857-4b0c-877a-511144c18516';
23

4+
-- Recreate the old enum without 'custom'
5+
CREATETYPEold_notification_template_kindAS ENUM ('system');
6+
7+
-- Update notification_templates to use the old enum
8+
ALTERTABLE notification_templates
9+
ALTER COLUMN kind DROP DEFAULT,
10+
ALTER COLUMN kind TYPE old_notification_template_kind USING (kind::text::old_notification_template_kind),
11+
ALTER COLUMN kindSET DEFAULT'system'::old_notification_template_kind;
12+
13+
-- Drop the current enum and restore the original name
14+
DROPTYPE notification_template_kind;
15+
ALTERTYPE old_notification_template_kind RENAME TO notification_template_kind;

‎coderd/database/migrations/000367_add_custom_notifications.up.sql‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
-- Create new enum with 'custom' value
2+
CREATETYPEnew_notification_template_kindAS ENUM (
3+
'system',
4+
'custom'
5+
);
6+
7+
-- Update the notification_templates table to use new enum
8+
ALTERTABLE notification_templates
9+
ALTER COLUMN kind DROP DEFAULT,
10+
ALTER COLUMN kind TYPE new_notification_template_kind USING (kind::text::new_notification_template_kind),
11+
ALTER COLUMN kindSET DEFAULT'system'::new_notification_template_kind;
12+
13+
-- Drop old enum and rename new one
14+
DROPTYPE notification_template_kind;
15+
ALTERTYPE new_notification_template_kind RENAME TO notification_template_kind;
16+
17+
-- Insert new Custom Notification template with 'custom' kind
118
INSERT INTO notification_templates (
219
id,
320
name,
@@ -16,6 +33,6 @@ INSERT INTO notification_templates (
1633
'[]',
1734
'Custom Events',
1835
NULL,
19-
'system'::notification_template_kind,
36+
'custom'::notification_template_kind,
2037
true
2138
);

‎coderd/database/models.go‎

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

‎coderd/notifications.go‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package coderd
33
import (
44
"bytes"
55
"encoding/json"
6+
"fmt"
67
"net/http"
78
"strings"
89

@@ -125,20 +126,14 @@ func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request
125126
httpapi.Write(r.Context(),rw,http.StatusOK,settings)
126127
}
127128

128-
// @Summary Get system notification templates
129-
// @ID get-system-notification-templates
130-
// @Security CoderSessionToken
131-
// @Produce json
132-
// @Tags Notifications
133-
// @Success 200 {array} codersdk.NotificationTemplate
134-
// @Router /notifications/templates/system [get]
135-
func (api*API)systemNotificationTemplates(rw http.ResponseWriter,r*http.Request) {
129+
// notificationTemplatesByKind gets the notification templates by kind
130+
func (api*API)notificationTemplatesByKind(rw http.ResponseWriter,r*http.Request,kind database.NotificationTemplateKind) {
136131
ctx:=r.Context()
137132

138-
templates,err:=api.Database.GetNotificationTemplatesByKind(ctx,database.NotificationTemplateKindSystem)
133+
templates,err:=api.Database.GetNotificationTemplatesByKind(ctx,kind)
139134
iferr!=nil {
140135
httpapi.Write(r.Context(),rw,http.StatusInternalServerError, codersdk.Response{
141-
Message:"Failed to retrievesystem notifications templates.",
136+
Message:fmt.Sprintf("Failed to retrieve'%s' notifications templates.",kind),
142137
Detail:err.Error(),
143138
})
144139
return
@@ -148,6 +143,30 @@ func (api *API) systemNotificationTemplates(rw http.ResponseWriter, r *http.Requ
148143
httpapi.Write(r.Context(),rw,http.StatusOK,out)
149144
}
150145

146+
// @Summary Get system notification templates
147+
// @ID get-system-notification-templates
148+
// @Security CoderSessionToken
149+
// @Produce json
150+
// @Tags Notifications
151+
// @Success 200 {array} codersdk.NotificationTemplate
152+
// @Failure 500 {object} codersdk.Response "Failed to retrieve 'system' notifications template"
153+
// @Router /notifications/templates/system [get]
154+
func (api*API)systemNotificationTemplates(rw http.ResponseWriter,r*http.Request) {
155+
api.notificationTemplatesByKind(rw,r,database.NotificationTemplateKindSystem)
156+
}
157+
158+
// @Summary Get custom notification templates
159+
// @ID get-custom-notification-templates
160+
// @Security CoderSessionToken
161+
// @Produce json
162+
// @Tags Notifications
163+
// @Success 200 {array} codersdk.NotificationTemplate
164+
// @Failure 500 {object} codersdk.Response "Failed to retrieve 'custom' notifications template"
165+
// @Router /notifications/templates/custom [get]
166+
func (api*API)customNotificationTemplates(rw http.ResponseWriter,r*http.Request) {
167+
api.notificationTemplatesByKind(rw,r,database.NotificationTemplateKindCustom)
168+
}
169+
151170
// @Summary Get notification dispatch methods
152171
// @ID get-notification-dispatch-methods
153172
// @Security CoderSessionToken

‎docs/reference/api/notifications.md‎

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