- Notifications
You must be signed in to change notification settings - Fork928
fix: allow all users to read system notification templates#14181
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Signed-off-by: Danny Kopping <danny@coder.com>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1489,13 +1489,13 @@ func (q *querier) GetNotificationTemplateByID(ctx context.Context, id uuid.UUID) | ||
} | ||
func (q *querier) GetNotificationTemplatesByKind(ctx context.Context, kind database.NotificationTemplateKind) ([]database.NotificationTemplate, error) { | ||
// Anyone can read the system notification templates. | ||
if kind == database.NotificationTemplateKindSystem { | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return q.db.GetNotificationTemplatesByKind(ctx, kind) | ||
} | ||
// TODO(dannyk): handle template ownership when we support user-default notification templates. | ||
panic("developer error: implement authorization of non-system notification templates") | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
func (q *querier) GetNotificationsSettings(ctx context.Context) (string, error) { | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -24,13 +24,15 @@ import ( | ||
"github.com/coder/serpent" | ||
"github.com/coder/coder/v2/coderd/coderdtest" | ||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/database/dbgen" | ||
"github.com/coder/coder/v2/coderd/database/dbtestutil" | ||
"github.com/coder/coder/v2/coderd/notifications" | ||
"github.com/coder/coder/v2/coderd/notifications/dispatch" | ||
"github.com/coder/coder/v2/coderd/notifications/render" | ||
"github.com/coder/coder/v2/coderd/notifications/types" | ||
"github.com/coder/coder/v2/coderd/rbac" | ||
"github.com/coder/coder/v2/coderd/util/syncmap" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/testutil" | ||
@@ -893,6 +895,43 @@ func TestCustomNotificationMethod(t *testing.T) { | ||
}, testutil.WaitLong, testutil.IntervalFast) | ||
} | ||
func TestNotificationsTemplates(t *testing.T) { | ||
t.Parallel() | ||
// SETUP | ||
if !dbtestutil.WillUsePostgres() { | ||
// Notification system templates are only served from the database and not dbmem at this time. | ||
t.Skip("This test requires postgres; it relies on business-logic only implemented in the database") | ||
} | ||
ctx := testutil.Context(t, testutil.WaitLong) | ||
api := coderdtest.New(t, createOpts(t)) | ||
// GIVEN: the first user (owner) and a regular member | ||
firstUser := coderdtest.CreateFirstUser(t, api) | ||
memberClient, _ := coderdtest.CreateAnotherUser(t, api, firstUser.OrganizationID, rbac.RoleMember()) | ||
// WHEN: requesting system notification templates as owner should work | ||
templates, err := api.GetSystemNotificationTemplates(ctx) | ||
require.NoError(t, err) | ||
require.True(t, len(templates) > 1) | ||
// WHEN: requesting system notification templates as member should work3 | ||
dannykopping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
templates, err = memberClient.GetSystemNotificationTemplates(ctx) | ||
require.NoError(t, err) | ||
require.True(t, len(templates) > 1) | ||
} | ||
func createOpts(t *testing.T) *coderdtest.Options { | ||
t.Helper() | ||
dt := coderdtest.DeploymentValues(t) | ||
dt.Experiments = []string{string(codersdk.ExperimentNotifications)} | ||
return &coderdtest.Options{ | ||
DeploymentValues: dt, | ||
} | ||
} | ||
type fakeHandler struct { | ||
mu sync.RWMutex | ||
succeeded, failed []string | ||
Uh oh!
There was an error while loading.Please reload this page.