|
|
|
@ -36,11 +36,10 @@ var ( |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type accessControlGuardianTestCase struct { |
|
|
|
|
desc string |
|
|
|
|
dashboard *dashboards.Dashboard |
|
|
|
|
permissions []accesscontrol.Permission |
|
|
|
|
viewersCanEdit bool |
|
|
|
|
expected bool |
|
|
|
|
desc string |
|
|
|
|
dashboard *dashboards.Dashboard |
|
|
|
|
permissions []accesscontrol.Permission |
|
|
|
|
expected bool |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestAccessControlDashboardGuardian_CanSave(t *testing.T) { |
|
|
|
@ -257,18 +256,6 @@ func TestAccessControlDashboardGuardian_CanEdit(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
expected: false, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
desc: "should be able to edit dashboard with read action when viewer_can_edit is true", |
|
|
|
|
dashboard: dashboard, |
|
|
|
|
permissions: []accesscontrol.Permission{ |
|
|
|
|
{ |
|
|
|
|
Action: dashboards.ActionDashboardsRead, |
|
|
|
|
Scope: "dashboards:uid:1", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
viewersCanEdit: true, |
|
|
|
|
expected: true, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
desc: "should not be able to edit folder with folder write and dashboard wildcard scope", |
|
|
|
|
dashboard: fldr, |
|
|
|
@ -324,25 +311,11 @@ func TestAccessControlDashboardGuardian_CanEdit(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
expected: false, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
desc: "should be able to edit folder with folder read action when viewer_can_edit is true", |
|
|
|
|
dashboard: fldr, |
|
|
|
|
permissions: []accesscontrol.Permission{ |
|
|
|
|
{ |
|
|
|
|
Action: dashboards.ActionFoldersRead, |
|
|
|
|
Scope: folderUIDScope, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
viewersCanEdit: true, |
|
|
|
|
expected: true, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.desc, func(t *testing.T) { |
|
|
|
|
cfg := setting.NewCfg() |
|
|
|
|
//nolint:staticcheck
|
|
|
|
|
cfg.ViewersCanEdit = tt.viewersCanEdit |
|
|
|
|
guardian := setupAccessControlGuardianTest(t, tt.dashboard, tt.permissions, cfg) |
|
|
|
|
|
|
|
|
|
can, err := guardian.CanEdit() |
|
|
|
|