8000 Review feedback · coder/coder@0f29293 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f29293

Browse files
committed
Review feedback
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent ba5f7c6 commit 0f29293

File tree

18 files changed

+420
-167
lines changed

18 files changed

+420
-167
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/open-policy-agent/opa/topdown"
1818

1919
"cdr.dev/slog"
20+
2021
"github.com/coder/coder/v2/coderd/rbac/policy"
2122
"github.com/coder/coder/v2/coderd/rbac/rolestore"
2223

@@ -1471,6 +1472,13 @@ func (q *querier) GetLogoURL(ctx context.Context) (string, error) {
14711472
return q.db.GetLogoURL(ctx)
14721473
}
14731474

1475+
func (q *querier) GetNotificationMessagesByStatus(ctx context.Context, arg database.GetNotificationMessagesByStatusParams) ([]database.NotificationMessage, error) {
1476+
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
1477+
return nil, err
1478+
}
1479+
return q.db.GetNotificationMessagesByStatus(ctx, arg)
1480+
}
1481+
14741482
func (q *querier) GetOAuth2ProviderAppByID(ctx context.Context, id uuid.UUID) (database.OAuth2ProviderApp, error) {
14751483
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceOauth2App); err != nil {
14761484
return database.OAuth2ProviderApp{}, err

coderd/database/dbmem/dbmem.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -944,10 +944,10 @@ func (q *FakeQuerier) AcquireNotificationMessages(_ context.Context, arg databas
944944
}
945945

946946
// Mimic mutation in database query.
947-
nm.UpdatedAt = sql.NullTime{Time: time.Now(), Valid: true}
947+
nm.UpdatedAt = sql.NullTime{Time: dbtime.Now(), Valid: true}
948948
nm.Status = database.NotificationMessageStatusLeased
949949
nm.StatusReason = sql.NullString{String: fmt.Sprintf("Enqueued by notifier %d", arg.NotifierID), Valid: true}
950-
nm.LeasedUntil = sql.NullTime{Time: time.Now().Add(time.Second * time.Duration(arg.LeaseSeconds)), Valid: true}
950+
nm.LeasedUntil = sql.NullTime{Time: dbtime.Now().Add(time.Second * time.Duration(arg.LeaseSeconds)), Valid: true}
951951

952952
out = append(out, database.AcquireNotificationMessagesRow{
953953
ID: nm.ID,
@@ -1836,7 +1836,7 @@ func (q *FakeQuerier) EnqueueNotificationMessage(_ context.Context, arg database
18361836
Targets: arg.Targets,
18371837
CreatedBy: arg.CreatedBy,
18381838
// Default fields.
1839-
CreatedAt: time.Now(),
1839+
CreatedAt: dbtime.Now(),
18401840
Status: database.NotificationMessageStatusPending,
18411841
}
18421842

@@ -2740,6 +2740,26 @@ func (q *FakeQuerier) GetLogoURL(_ context.Context) (string, error) {
27402740
return q.logoURL, nil
27412741
}
27422742

2743+
func (q *FakeQuerier< D966 /span>) GetNotificationMessagesByStatus(_ context.Context, arg database.GetNotificationMessagesByStatusParams) ([]database.NotificationMessage, error) {
2744+
err := validateDatabaseType(arg)
2745+
if err != nil {
2746+
return nil, err
2747+
}
2748+
2749+
var out []database.NotificationMessage
2750+
for _, m := range q.notificationMessages {
2751+
if len(out) > int(arg.Limit) {
2752+
return out, nil
2753+
}
2754+
2755+
if m.Status == arg.Status {
2756+
out = append(out, m)
2757+
}
2758+
}
2759+
2760+
return out, nil
2761+
}
2762+
27432763
func (q *FakeQuerier) GetOAuth2ProviderAppByID(_ context.Context, id uuid.UUID) (database.OAuth2ProviderApp, error) {
27442764
q.mutex.Lock()
27452765
defer q.mutex.Unlock()

coderd/database/dbmetrics/dbmetrics.go

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

coderd/database/dbmock/dbmock.go

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

coderd/database/migrations/000221_notifications.up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ CREATE INDEX idx_notification_messages_status ON notification_messages (status);
5252
-- TODO: autogenerate constants which reference the UUIDs
5353
INSERT INTO notification_templates (id, name, title_template, body_template, "group", actions)
5454
VALUES ('f517da0b-cdc9-410f-ab89-a86107c420ed', 'Workspace Deleted', E'Workspace "{{.Labels.name}}" deleted',
55-
E'Hi {{.UserName}}\n\nYour workspace **{{.Labels.name}}** was deleted.\nThe specified reason was "**{{.Labels.reason}}**".',
55+
E'Hi {{.UserName}}\n\nYour workspace **{{.Labels.name}}** was deleted.\nThe specified reason was "**{{.Labels.reason}}{{ if .Labels.initiatedBy }} ({{ .Labels.initiatedBy }}){{end}}**".',
5656
'Workspace Events', '[
5757
{
5858
"label": "View workspaces",

coderd/database/querier.go

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

coderd/database/queries.sql.go

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

coderd/database/queries/notifications.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,6 @@ WHERE id IN
125125
FROM notification_messages AS nested
126126
WHERE nested.updated_at < NOW() - INTERVAL '7 days');
127127

128+
-- name: GetNotificationMessagesByStatus :many
129+
SELECT * FROM notification_messages WHERE status = @status LIMIT sqlc.arg('limit')::int;
130+

coderd/notifications/dispatch/smtp.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020

2121
"cdr.dev/slog"
2222

23-
"github.com/coder/coder/v2/coderd/database"
2423
"github.com/coder/coder/v2/coderd/notifications/render"
2524
"github.com/coder/coder/v2/coderd/notifications/types"
2625
markdown "github.com/coder/coder/v2/coderd/render"
@@ -53,10 +52,6 @@ func NewSMTPHandler(cfg codersdk.NotificationsEmailConfig, log slog.Logger) *SMT
5352
return &SMTPHandler{cfg: cfg, log: log}
5453
}
5554

56-
func (*SMTPHandler) NotificationMethod() database.NotificationMethod {
57-
return database.NotificationMethodSmtp
58-
}
59-
6055
func (s *SMTPHandler) Dispatcher(payload types.MessagePayload, titleTmpl, bodyTmpl string) (DeliveryFunc, error) {
6156
// First render the subject & body into their own discrete strings.
6257
subject, err := markdown.PlaintextFromMarkdown(titleTmpl)

coderd/notifications/dispatch/webhook.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"cdr.dev/slog"
1515

16-
"github.com/coder/coder/v2/coderd/database"
1716
"github.com/coder/coder/v2/coderd/notifications/types"
1817
markdown "github.com/coder/coder/v2/coderd/render"
1918
"github.com/coder/coder/v2/codersdk"
@@ -40,11 +39,6 @@ func NewWebhookHandler(cfg codersdk.NotificationsWebhookConfig, log slog.Logger)
4039
return &WebhookHandler{cfg: cfg, log: log, cl: &http.Client{}}
4140
}
4241

43-
func (*WebhookHandler) NotificationMethod() database.NotificationMethod {
44-
// TODO: don't use database types
45-
return database.NotificationMethodWebhook
46-
}
47-
4842
func (w *WebhookHandler) Dispatcher(payload types.MessagePayload, titleTmpl, bodyTmpl string) (DeliveryFunc, error) {
4943
if w.cfg.Endpoint.String() == "" {
5044
return nil, xerrors.New("webhook endpoint not defined")

0 commit comments

Comments
 (0)
0