Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit58428aa

Browse files
authored
fix: allow all users to read system notification templates (#14181)
1 parent70a694e commit58428aa

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

‎coderd/database/dbauthz/dbauthz.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,13 +1489,13 @@ func (q *querier) GetNotificationTemplateByID(ctx context.Context, id uuid.UUID)
14891489
}
14901490

14911491
func (q*querier)GetNotificationTemplatesByKind(ctx context.Context,kind database.NotificationTemplateKind) ([]database.NotificationTemplate,error) {
1492-
// TODO: restrict 'system' kind to admins only?
1493-
// All notification templates share the same rbac.Object, so there is no need
1494-
// to authorize them individually. If this passes, all notification templates can be read.
1495-
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceNotificationTemplate);err!=nil {
1496-
returnnil,err
1492+
// Anyone can read the system notification templates.
1493+
ifkind==database.NotificationTemplateKindSystem {
1494+
returnq.db.GetNotificationTemplatesByKind(ctx,kind)
14971495
}
1498-
returnq.db.GetNotificationTemplatesByKind(ctx,kind)
1496+
1497+
// TODO(dannyk): handle template ownership when we support user-default notification templates.
1498+
returnnil,sql.ErrNoRows
14991499
}
15001500

15011501
func (q*querier)GetNotificationsSettings(ctx context.Context) (string,error) {

‎coderd/database/dbauthz/dbauthz_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2610,8 +2610,10 @@ func (s *MethodTestSuite) TestNotifications() {
26102610
}))
26112611
s.Run("GetNotificationTemplatesByKind",s.Subtest(func(db database.Store,check*expects) {
26122612
check.Args(database.NotificationTemplateKindSystem).
2613-
Asserts(rbac.ResourceNotificationTemplate,policy.ActionRead).
2613+
Asserts().
26142614
Errors(dbmem.ErrUnimplemented)
2615+
2616+
// TODO(dannyk): add support for other database.NotificationTemplateKind types once implemented.
26152617
}))
26162618
s.Run("UpdateNotificationTemplateMethodByID",s.Subtest(func(db database.Store,check*expects) {
26172619
check.Args(database.UpdateNotificationTemplateMethodByIDParams{

‎coderd/notifications/notifications_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ import (
2424

2525
"github.com/coder/serpent"
2626

27+
"github.com/coder/coder/v2/coderd/coderdtest"
2728
"github.com/coder/coder/v2/coderd/database"
2829
"github.com/coder/coder/v2/coderd/database/dbgen"
2930
"github.com/coder/coder/v2/coderd/database/dbtestutil"
3031
"github.com/coder/coder/v2/coderd/notifications"
3132
"github.com/coder/coder/v2/coderd/notifications/dispatch"
3233
"github.com/coder/coder/v2/coderd/notifications/render"
3334
"github.com/coder/coder/v2/coderd/notifications/types"
35+
"github.com/coder/coder/v2/coderd/rbac"
3436
"github.com/coder/coder/v2/coderd/util/syncmap"
3537
"github.com/coder/coder/v2/codersdk"
3638
"github.com/coder/coder/v2/testutil"
@@ -893,6 +895,43 @@ func TestCustomNotificationMethod(t *testing.T) {
893895
},testutil.WaitLong,testutil.IntervalFast)
894896
}
895897

898+
funcTestNotificationsTemplates(t*testing.T) {
899+
t.Parallel()
900+
901+
// SETUP
902+
if!dbtestutil.WillUsePostgres() {
903+
// Notification system templates are only served from the database and not dbmem at this time.
904+
t.Skip("This test requires postgres; it relies on business-logic only implemented in the database")
905+
}
906+
907+
ctx:=testutil.Context(t,testutil.WaitLong)
908+
api:=coderdtest.New(t,createOpts(t))
909+
910+
// GIVEN: the first user (owner) and a regular member
911+
firstUser:=coderdtest.CreateFirstUser(t,api)
912+
memberClient,_:=coderdtest.CreateAnotherUser(t,api,firstUser.OrganizationID,rbac.RoleMember())
913+
914+
// WHEN: requesting system notification templates as owner should work
915+
templates,err:=api.GetSystemNotificationTemplates(ctx)
916+
require.NoError(t,err)
917+
require.True(t,len(templates)>1)
918+
919+
// WHEN: requesting system notification templates as member should work
920+
templates,err=memberClient.GetSystemNotificationTemplates(ctx)
921+
require.NoError(t,err)
922+
require.True(t,len(templates)>1)
923+
}
924+
925+
funccreateOpts(t*testing.T)*coderdtest.Options {
926+
t.Helper()
927+
928+
dt:=coderdtest.DeploymentValues(t)
929+
dt.Experiments= []string{string(codersdk.ExperimentNotifications)}
930+
return&coderdtest.Options{
931+
DeploymentValues:dt,
932+
}
933+
}
934+
896935
typefakeHandlerstruct {
897936
mu sync.RWMutex
898937
succeeded,failed []string

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp