Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6fcdc7

Browse files
committed
Rollback enums
1 parent fa1d788 commit c6fcdc7

File tree

10 files changed

+96
-135
lines changed

10 files changed

+96
-135
lines changed

coderd/apidoc/docs.go

Lines changed: 1 addition & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 1 addition & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/inboxnotifications.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,32 @@ const (
2929
notificationFormatPlaintext = "plaintext"
3030
)
3131

32-
var fallbackIcons = map[uuid.UUID]codersdk.InboxNotificationFallbackIcon{
32+
var fallbackIcons = map[uuid.UUID]string{
3333
// workspace related notifications
34-
notifications.TemplateWorkspaceCreated: codersdk.FallbackIconWorkspace,
35-
notifications.TemplateWorkspaceManuallyUpdated: codersdk.FallbackIconWorkspace,
36-
notifications.TemplateWorkspaceDeleted: codersdk.FallbackIconWorkspace,
37-
notifications.TemplateWorkspaceAutobuildFailed: codersdk.FallbackIconWorkspace,
38-
notifications.TemplateWorkspaceDormant: codersdk.FallbackIconWorkspace,
39-
notifications.TemplateWorkspaceAutoUpdated: codersdk.FallbackIconWorkspace,
40-
notifications.TemplateWorkspaceMarkedForDeletion: codersdk.FallbackIconWorkspace,
41-
notifications.TemplateWorkspaceManualBuildFailed: codersdk.FallbackIconWorkspace,
42-
notifications.TemplateWorkspaceOutOfMemory: codersdk.FallbackIconWorkspace,
43-
notifications.TemplateWorkspaceOutOfDisk: codersdk.FallbackIconWorkspace,
34+
notifications.TemplateWorkspaceCreated: codersdk.InboxNotificationFallbackIconWorkspace,
35+
notifications.TemplateWorkspaceManuallyUpdated: codersdk.InboxNotificationFallbackIconWorkspace,
36+
notifications.TemplateWorkspaceDeleted: codersdk.InboxNotificationFallbackIconWorkspace,
37+
notifications.TemplateWorkspaceAutobuildFailed: codersdk.InboxNotificationFallbackIconWorkspace,
38+
notifications.TemplateWorkspaceDormant: codersdk.InboxNotificationFallbackIconWorkspace,
39+
notifications.TemplateWorkspaceAutoUpdated: codersdk.InboxNotificationFallbackIconWorkspace,
40+
notifications.TemplateWorkspaceMarkedForDeletion: codersdk.InboxNotificationFallbackIconWorkspace,
41+
notifications.TemplateWorkspaceManualBuildFailed: codersdk.InboxNotificationFallbackIconWorkspace,
42+
notifications.TemplateWorkspaceOutOfMemory: codersdk.InboxNotificationFallbackIconWorkspace,
43+
notifications.TemplateWorkspaceOutOfDisk: codersdk.InboxNotificationFallbackIconWorkspace,
4444

4545
// account related notifications
46-
notifications.TemplateUserAccountCreated: codersdk.FallbackIconAccount,
47-
notifications.TemplateUserAccountDeleted: codersdk.FallbackIconAccount,
48-
notifications.TemplateUserAccountSuspended: codersdk.FallbackIconAccount,
49-
notifications.TemplateUserAccountActivated: codersdk.FallbackIconAccount,
50-
notifications.TemplateYourAccountSuspended: codersdk.FallbackIconAccount,
51-
notifications.TemplateYourAccountActivated: codersdk.FallbackIconAccount,
52-
notifications.TemplateUserRequestedOneTimePasscode: codersdk.FallbackIconAccount,
46+
notifications.TemplateUserAccountCreated: codersdk.InboxNotificationFallbackIconAccount,
47+
notifications.TemplateUserAccountDeleted: codersdk.InboxNotificationFallbackIconAccount,
48+
notifications.TemplateUserAccountSuspended: codersdk.InboxNotificationFallbackIconAccount,
49+
notifications.TemplateUserAccountActivated: codersdk.InboxNotificationFallbackIconAccount,
50+
notifications.TemplateYourAccountSuspended: codersdk.InboxNotificationFallbackIconAccount,
51+
notifications.TemplateYourAccountActivated: codersdk.InboxNotificationFallbackIconAccount,
52+
notifications.TemplateUserRequestedOneTimePasscode: codersdk.InboxNotificationFallbackIconAccount,
5353

5454
// template related notifications
55-
notifications.TemplateTemplateDeleted: codersdk.FallbackIconTemplate,
56-
notifications.TemplateTemplateDeprecated: codersdk.FallbackIconTemplate,
57-
notifications.TemplateWorkspaceBuildsFailedReport: codersdk.FallbackIconTemplate,
55+
notifications.TemplateTemplateDeleted: codersdk.InboxNotificationFallbackIconTemplate,
56+
notifications.TemplateTemplateDeprecated: codersdk.InboxNotificationFallbackIconTemplate,
57+
notifications.TemplateWorkspaceBuildsFailedReport: codersdk.InboxNotificationFallbackIconTemplate,
5858
}
5959

6060
func ensureNotificationIcon(notif codersdk.InboxNotification) codersdk.InboxNotification {
@@ -64,7 +64,7 @@ func ensureNotificationIcon(notif codersdk.InboxNotification) codersdk.InboxNoti
6464

6565
fallbackIcon, ok := fallbackIcons[notif.TemplateID]
6666
if !ok {
67-
fallbackIcon = codersdk.FallbackIconOther
67+
fallbackIcon = codersdk.InboxNotificationFallbackIconOther
6868
}
6969

7070
notif.Icon = fallbackIcon
@@ -80,7 +80,7 @@ func convertInboxNotificationResponse(ctx context.Context, logger slog.Logger, n
8080
Targets: notif.Targets,
8181
Title: notif.Title,
8282
Content: notif.Content,
83-
Icon: codersdk.InboxNotificationFallbackIcon(notif.Icon),
83+
Icon: notif.Icon,
8484
Actions: func() []codersdk.InboxNotificationAction {
8585
var actionsList []codersdk.InboxNotificationAction
8686
err := json.Unmarshal([]byte(notif.Actions), &actionsList)

coderd/inboxnotifications_internal_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ func TestInboxNotifications_ensureNotificationIcon(t *testing.T) {
1616

1717
tests := []struct {
1818
name string
19-
icon codersdk.InboxNotificationFallbackIcon
19+
icon string
2020
templateID uuid.UUID
21-
expectedIcon codersdk.InboxNotificationFallbackIcon
21+
expectedIcon string
2222
}{
23-
{"WorkspaceCreated", "", notifications.TemplateWorkspaceCreated, codersdk.FallbackIconWorkspace},
24-
{"UserAccountCreated", "", notifications.TemplateUserAccountCreated, codersdk.FallbackIconAccount},
25-
{"TemplateDeleted", "", notifications.TemplateTemplateDeleted, codersdk.FallbackIconTemplate},
26-
{"TestNotification", "", notifications.TemplateTestNotification, codersdk.FallbackIconOther},
23+
{"WorkspaceCreated", "", notifications.TemplateWorkspaceCreated, codersdk.InboxNotificationFallbackIconWorkspace},
24+
{"UserAccountCreated", "", notifications.TemplateUserAccountCreated, codersdk.InboxNotificationFallbackIconAccount},
25+
{"TemplateDeleted", "", notifications.TemplateTemplateDeleted, codersdk.InboxNotificationFallbackIconTemplate},
26+
{"TestNotification", "", notifications.TemplateTestNotification, codersdk.InboxNotificationFallbackIconOther},
2727
{"TestExistingIcon", "https://cdn.coder.com/icon_notif.png", notifications.TemplateTemplateDeleted, "https://cdn.coder.com/icon_notif.png"},
28-
{"UnknownTemplate", "", uuid.New(), codersdk.FallbackIconOther},
28+
{"UnknownTemplate", "", uuid.New(), codersdk.InboxNotificationFallbackIconOther},
2929
}
3030

3131
for _, tt := range tests {

coderd/inboxnotifications_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func TestInboxNotification_Watch(t *testing.T) {
137137
require.Equal(t, memberClient.ID, notif.Notification.UserID)
138138

139139
// check for the fallback icon logic
140-
require.Equal(t, codersdk.FallbackIconWorkspace, notif.Notification.Icon)
140+
require.Equal(t, codersdk.InboxNotificationFallbackIconWorkspace, notif.Notification.Icon)
141141
})
142142

143143
t.Run("OK - change format", func(t *testing.T) {
@@ -557,11 +557,11 @@ func TestInboxNotifications_List(t *testing.T) {
557557
require.Len(t, notifs.Notifications, 10)
558558

559559
require.Equal(t, "https://dev.coder.com/icon.png", notifs.Notifications[0].Icon)
560-
require.Equal(t, codersdk.FallbackIconWorkspace, notifs.Notifications[9].Icon)
561-
require.Equal(t, codersdk.FallbackIconWorkspace, notifs.Notifications[8].Icon)
562-
require.Equal(t, codersdk.FallbackIconAccount, notifs.Notifications[7].Icon)
563-
require.Equal(t, codersdk.FallbackIconTemplate, notifs.Notifications[6].Icon)
564-
require.Equal(t, codersdk.FallbackIconOther, notifs.Notifications[4].Icon)
560+
require.Equal(t, codersdk.InboxNotificationFallbackIconWorkspace, notifs.Notifications[9].Icon)
561+
require.Equal(t, codersdk.InboxNotificationFallbackIconWorkspace, notifs.Notifications[8].Icon)
562+
require.Equal(t, codersdk.InboxNotificationFallbackIconAccount, notifs.Notifications[7].Icon)
563+
require.Equal(t, codersdk.InboxNotificationFallbackIconTemplate, notifs.Notifications[6].Icon)
564+
require.Equal(t, codersdk.InboxNotificationFallbackIconOther, notifs.Notifications[4].Icon)
565565
})
566566

567567
t.Run("OK with template filter", func(t *testing.T) {
@@ -607,7 +607,7 @@ func TestInboxNotifications_List(t *testing.T) {
607607
require.Len(t, notifs.Notifications, 5)
608608

609609
require.Equal(t, "Notification 8", notifs.Notifications[0].Title)
610-
require.Equal(t, codersdk.FallbackIconWorkspace, notifs.Notifications[0].Icon)
610+
require.Equal(t, codersdk.InboxNotificationFallbackIconWorkspace, notifs.Notifications[0].Icon)
611611
})
612612

613613
t.Run("OK with target filter", func(t *testing.T) {

codersdk/inboxnotification.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,24 @@ import (
1010
"github.com/google/uuid"
1111
)
1212

13-
type InboxNotificationFallbackIcon string
14-
1513
const (
16-
FallbackIconWorkspace InboxNotificationFallbackIcon = "DEFAULT_ICON_WORKSPACE"
17-
FallbackIconAccount InboxNotificationFallbackIcon = "DEFAULT_ICON_ACCOUNT"
18-
FallbackIconTemplate InboxNotificationFallbackIcon = "DEFAULT_ICON_TEMPLATE"
19-
FallbackIconOther InboxNotificationFallbackIcon = "DEFAULT_ICON_OTHER"
14+
InboxNotificationFallbackIconWorkspace = "DEFAULT_ICON_WORKSPACE"
15+
InboxNotificationFallbackIconAccount = "DEFAULT_ICON_ACCOUNT"
16+
InboxNotificationFallbackIconTemplate = "DEFAULT_ICON_TEMPLATE"
17+
InboxNotificationFallbackIconOther = "DEFAULT_ICON_OTHER"
2018
)
2119

2220
type InboxNotification struct {
23-
ID uuid.UUID `json:"id" format:"uuid"`
24-
UserID uuid.UUID `json:"user_id" format:"uuid"`
25-
TemplateID uuid.UUID `json:"template_id" format:"uuid"`
26-
Targets []uuid.UUID `json:"targets" format:"uuid"`
27-
Title string `json:"title"`
28-
Content string `json:"content"`
29-
Icon InboxNotificationFallbackIcon `json:"icon"`
30-
Actions []InboxNotificationAction `json:"actions"`
31-
ReadAt *time.Time `json:"read_at"`
32-
CreatedAt time.Time `json:"created_at" format:"date-time"`
21+
ID uuid.UUID `json:"id" format:"uuid"`
22+
UserID uuid.UUID `json:"user_id" format:"uuid"`
23+
TemplateID uuid.UUID `json:"template_id" format:"uuid"`
24+
Targets []uuid.UUID `json:"targets" format:"uuid"`
25+
Title string `json:"title"`
26+
Content string `json:"content"`
27+
Icon string `json:"icon"`
28+
Actions []InboxNotificationAction `json:"actions"`
29+
ReadAt *time.Time `json:"read_at"`
30+
CreatedAt time.Time `json:"created_at" format:"date-time"`
3331
}
3432

3533
type InboxNotificationAction struct {

docs/reference/api/notifications.md

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

docs/reference/api/schemas.md

Lines changed: 15 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/api/typesGenerated.ts

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

0 commit comments

Comments
 (0)