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

Skip to content

Commit 905958c

Browse files
committed
Only use pg when necessary
Signed-off-by: Danny Kopping <[email protected]>
1 parent 44a700b commit 905958c

File tree

5 files changed

+36
-38
lines changed

5 files changed

+36
-38
lines changed

coderd/apidoc/docs.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/notifications.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"github.com/coder/coder/v2/coderd/audit"
1111
"github.com/coder/coder/v2/coderd/database"
1212
"github.com/coder/coder/v2/coderd/httpapi"
13-
"github.com/coder/coder/v2/coderd/rbac"
14-
"github.com/coder/coder/v2/coderd/rbac/policy"
1513
"github.com/coder/coder/v2/codersdk"
1614
)
1715

@@ -59,13 +57,6 @@ func (api *API) notificationsSettings(rw http.ResponseWriter, r *http.Request) {
5957
func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request) {
6058
ctx := r.Context()
6159

62-
if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceDeploymentConfig) {
63-
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
64-
Message: "Insufficient permissions to update notifications settings.",
65-
})
66-
return
67-
}
68-
6960
var settings codersdk.NotificationsSettings
7061
if !httpapi.Read(ctx, rw, r, &settings) {
7162
return
@@ -121,8 +112,8 @@ func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request
121112
httpapi.Write(r.Context(), rw, http.StatusOK, settings)
122113
}
123114

124-
// @Summary Get notification templates pertaining to system events
125-
// @ID system-notification-templates
115+
// @Summary Get system notification templates
116+
// @ID get-system-notification-templates
126117
// @Security CoderSessionToken
127118
// @Produce json
128119
// @Tags Notifications

docs/api/notifications.md

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/coderd/notifications_test.go

+28-21
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,55 @@ import (
1212

1313
"github.com/coder/coder/v2/coderd/coderdtest"
1414
"github.com/coder/coder/v2/coderd/database"
15+
"github.com/coder/coder/v2/coderd/database/dbmem"
1516
"github.com/coder/coder/v2/coderd/database/dbtestutil"
17+
"github.com/coder/coder/v2/coderd/database/pubsub"
1618
"github.com/coder/coder/v2/coderd/notifications"
1719
"github.com/coder/coder/v2/codersdk"
1820
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
1921
"github.com/coder/coder/v2/testutil"
2022
)
2123

22-
func createOpts(t *testing.T) *coderdenttest.Options {
24+
func createOpts(t *testing.T, usePostgres bool) *coderdenttest.Options {
2325
t.Helper()
2426

25-
db, ps := dbtestutil.NewDB(t)
27+
var (
28+
db database.Store
29+
ps pubsub.Pubsub
30+
)
31+
32+
if usePostgres {
33+
if !dbtestutil.WillUsePostgres() {
34+
t.Skip("This test requires postgres; it relies on read from and writing to the notification_templates table")
35+
}
36+
37+
db, ps = dbtestutil.NewDB(t)
38+
} else {
39+
db, ps = dbmem.New(), pubsub.NewInMemory()
40+
}
2641

2742
dt := coderdtest.DeploymentValues(t)
2843
dt.Experiments = []string{string(codersdk.ExperimentNotifications)}
2944
return &coderdenttest.Options{
3045
Options: &coderdtest.Options{
31-
DeploymentValues: dt,
32-
33-
IncludeProvisionerDaemon: true,
34-
Database: db,
35-
Pubsub: ps,
46+
DeploymentValues: dt,
47+
Database: db,
48+
Pubsub: ps,
3649
},
3750
}
3851
}
3952

4053
func TestUpdateNotificationTemplateMethod(t *testing.T) {
4154
t.Parallel()
4255

43-
if !dbtestutil.WillUsePostgres() {
44-
t.Skip("This test requires postgres; it relies on read from and writing to the notification_templates table")
45-
}
46-
4756
t.Run("Happy path", func(t *testing.T) {
4857
t.Parallel()
4958

5059
ctx := testutil.Context(t, testutil.WaitSuperLong)
51-
52-
api, _ := coderdenttest.New(t, createOpts(t))
60+
api, _ := coderdenttest.New(t, createOpts(t, true))
5361

5462
var (
55-
method = string(database.NotificationMethodSmtp)
63+
method = string(database.NotificationMethodSmtp)
5664
templateID = notifications.TemplateWorkspaceDeleted
5765
)
5866

@@ -75,10 +83,10 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
7583
t.Run("Insufficient permissions", func(t *testing.T) {
7684
t.Parallel()
7785

78-
ctx := testutil.Context(t, testutil.WaitSuperLong)
86+
ctx := testutil.Context(t, testutil.WaitShort)
7987

8088
// Given: the first user which has an "owner" role, and another user which does not.
81-
api, firstUser := coderdenttest.New(t, createOpts(t))
89+
api, firstUser := coderdenttest.New(t, createOpts(t, false))
8290
anotherClient, _ := coderdtest.CreateAnotherUser(t, api, firstUser.OrganizationID)
8391

8492
// When: calling the API as an unprivileged user.
@@ -98,7 +106,7 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
98106
ctx := testutil.Context(t, testutil.WaitSuperLong)
99107

100108
// Given: the first user which has an "owner" role
101-
api, _ := coderdenttest.New(t, createOpts(t))
109+
api, _ := coderdenttest.New(t, createOpts(t, true))
102110

103111
// When: calling the API with an invalid method.
104112
const method = "nope"
@@ -119,11 +127,10 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
119127
t.Parallel()
120128

121129
ctx := testutil.Context(t, testutil.WaitSuperLong)
122-
123-
api, _ := coderdenttest.New(t, createOpts(t))
130+
api, _ := coderdenttest.New(t, createOpts(t, true))
124131

125132
var (
126-
method = string(database.NotificationMethodSmtp)
133+
method = string(database.NotificationMethodSmtp)
127134
templateID = notifications.TemplateWorkspaceDeleted
128135
)
129136

@@ -170,4 +177,4 @@ func getTemplateById(t *testing.T, ctx context.Context, api *codersdk.Client, id
170177
}
171178

172179
return template, nil
173-
}
180+
}

0 commit comments

Comments
 (0)