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

Skip to content

feat: allow admins to modify notification template delivery method #14116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Self-review
Signed-off-by: Danny Kopping <[email protected]>
  • Loading branch information
dannykopping committed Aug 5, 2024
commit c2f024ee1c91b460083e13f3d73f1491dd036fbb
5 changes: 4 additions & 1 deletion coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions coderd/httpmw/notificationtemplateparam.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type notificationTemplateParamContextKey struct{}
func NotificationTemplateParam(r *http.Request) database.NotificationTemplate {
template, ok := r.Context().Value(notificationTemplateParamContextKey{}).(database.NotificationTemplate)
if !ok {
panic("developer error: notification template param middleware not provided")
panic("developer error: notification template middleware not used")
}
return template
}
Expand All @@ -29,7 +29,7 @@ func ExtractNotificationTemplateParam(db database.Store) func(http.Handler) http
if !parsed {
return
}
nt, err := db.GetNotificationTemplateById(r.Context(), notifTemplateID)
nt, err := db.GetNotificationTemplateByID(r.Context(), notifTemplateID)
if httpapi.Is404Error(err) {
httpapi.ResourceNotFound(rw)
return
Expand Down
7 changes: 4 additions & 3 deletions docs/api/enterprise.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions enterprise/coderd/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (
)

// @Summary Update notification template dispatch method
// @ID post-notification-template-method
// @ID put-notification-template-method
// @Security CoderSessionToken
// @Produce json
// @Tags Enterprise
// @Success 200
// @Success 304
// @Router /notifications/templates/{notification_template}/method [put]
func (api *API) updateNotificationTemplateMethod(rw http.ResponseWriter, r *http.Request) {
// TODO: authorization (restrict to admin/template admin?)
var (
ctx = r.Context()
template = httpmw.NotificationTemplateParam(r)
Expand Down Expand Up @@ -74,7 +74,7 @@ func (api *API) updateNotificationTemplateMethod(rw http.ResponseWriter, r *http

err := api.Database.InTx(func(tx database.Store) error {
var err error
template, err = api.Database.UpdateNotificationTemplateMethodById(r.Context(), database.UpdateNotificationTemplateMethodByIdParams{
template, err = api.Database.UpdateNotificationTemplateMethodByID(r.Context(), database.UpdateNotificationTemplateMethodByIDParams{
ID: template.ID,
Method: nm,
})
Expand Down
15 changes: 3 additions & 12 deletions enterprise/coderd/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import (

"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbmem"
"github.com/coder/coder/v2/coderd/database/dbtestutil"
"github.com/coder/coder/v2/coderd/database/pubsub"
"github.com/coder/coder/v2/coderd/notifications"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
Expand All @@ -24,21 +22,14 @@ import (
func createOpts(t *testing.T, usePostgres bool) *coderdenttest.Options {
t.Helper()

var (
db database.Store
ps pubsub.Pubsub
)

if usePostgres {
if !dbtestutil.WillUsePostgres() {
t.Skip("This test requires postgres; it relies on read from and writing to the notification_templates table")
}

db, ps = dbtestutil.NewDB(t)
} else {
db, ps = dbmem.New(), pubsub.NewInMemory()
}

db, ps := dbtestutil.NewDB(t)

dt := coderdtest.DeploymentValues(t)
dt.Experiments = []string{string(codersdk.ExperimentNotifications)}
return &coderdenttest.Options{
Expand Down Expand Up @@ -83,7 +74,7 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
t.Run("Insufficient permissions", func(t *testing.T) {
t.Parallel()

ctx := testutil.Context(t, testutil.WaitShort)
ctx := testutil.Context(t, testutil.WaitSuperLong)

// Given: the first user which has an "owner" role, and another user which does not.
api, firstUser := coderdenttest.New(t, createOpts(t, false))
Expand Down