@@ -13,19 +13,12 @@ import (
13
13
"github.com/stretchr/testify/assert"
14
14
"github.com/stretchr/testify/require"
15
15
16
- "github.com/grafana/grafana/pkg/infra/db"
17
16
"github.com/grafana/grafana/pkg/infra/log"
18
- "github.com/grafana/grafana/pkg/infra/tracing"
19
17
"github.com/grafana/grafana/pkg/services/accesscontrol"
20
18
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
21
19
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
22
- "github.com/grafana/grafana/pkg/services/org/orgimpl"
23
- "github.com/grafana/grafana/pkg/services/quota/quotatest"
24
- "github.com/grafana/grafana/pkg/services/supportbundles/supportbundlestest"
25
- "github.com/grafana/grafana/pkg/services/team/teamimpl"
20
+ "github.com/grafana/grafana/pkg/services/team"
26
21
"github.com/grafana/grafana/pkg/services/user"
27
- "github.com/grafana/grafana/pkg/services/user/userimpl"
28
- "github.com/grafana/grafana/pkg/setting"
29
22
"github.com/grafana/grafana/pkg/web"
30
23
)
31
24
@@ -117,7 +110,7 @@ func TestApi_getDescription(t *testing.T) {
117
110
118
111
for _ , tt := range tests {
119
112
t .Run (tt .desc , func (t * testing.T ) {
120
- service , _ , _ , _ := setupTestEnvironment (t , tt .options )
113
+ service , _ , _ := setupTestEnvironment (t , tt .options )
121
114
server := setupTestServer (t , & user.SignedInUser {OrgID : 1 , Permissions : map [int64 ]map [string ][]string {1 : accesscontrol .GroupScopesByAction (tt .permissions )}}, service )
122
115
123
116
req , err := http .NewRequest (http .MethodGet , fmt .Sprintf ("/api/access-control/%s/description" , tt .options .Resource ), nil )
@@ -164,10 +157,10 @@ func TestApi_getPermissions(t *testing.T) {
164
157
165
158
for _ , tt := range tests {
166
159
t .Run (tt .desc , func (t * testing.T ) {
167
- service , sql , cfg , _ := setupTestEnvironment (t , testOptions )
160
+ service , usrSvc , teamSvc := setupTestEnvironment (t , testOptions )
168
161
server := setupTestServer (t , & user.SignedInUser {OrgID : 1 , Permissions : map [int64 ]map [string ][]string {1 : accesscontrol .GroupScopesByAction (tt .permissions )}}, service )
169
162
170
- seedPermissions (t , tt .resourceID , sql , cfg , service )
163
+ seedPermissions (t , tt .resourceID , usrSvc , teamSvc , service )
171
164
172
165
permissions , recorder := getPermission (t , server , testOptions .Resource , tt .resourceID )
173
166
assert .Equal (t , tt .expectedStatus , recorder .Code )
@@ -241,7 +234,7 @@ func TestApi_setBuiltinRolePermission(t *testing.T) {
241
234
242
235
for _ , tt := range tests {
243
236
t .Run (tt .desc , func (t * testing.T ) {
244
- service , _ , _ , _ := setupTestEnvironment (t , testOptions )
237
+ service , _ , _ := setupTestEnvironment (t , testOptions )
245
238
server := setupTestServer (t , & user.SignedInUser {OrgID : 1 , Permissions : map [int64 ]map [string ][]string {1 : accesscontrol .GroupScopesByAction (tt .permissions )}}, service )
246
239
247
240
recorder := setPermission (t , server , testOptions .Resource , tt .resourceID , tt .permission , "builtInRoles" , tt .builtInRole )
@@ -319,7 +312,7 @@ func TestApi_setTeamPermission(t *testing.T) {
319
312
320
313
for _ , tt := range tests {
321
314
t .Run (tt .desc , func (t * testing.T ) {
322
- service , _ , _ , teamSvc := setupTestEnvironment (t , testOptions )
315
+ service , _ , teamSvc := setupTestEnvironment (t , testOptions )
323
316
server := setupTestServer (t , & user.SignedInUser {OrgID : 1 , Permissions : map [int64 ]map [string ][]string {1 : accesscontrol .GroupScopesByAction (tt .permissions )}}, service )
324
317
325
318
// seed team
@@ -402,18 +395,13 @@ func TestApi_setUserPermission(t *testing.T) {
402
395
403
396
for _ , tt := range tests {
404
397
t .Run (tt .desc , func (t * testing.T ) {
405
- service , sql , cfg , _ := setupTestEnvironment (t , testOptions )
398
+ service , usrSvc , _ := setupTestEnvironment (t , testOptions )
406
399
server := setupTestServer (t , & user.SignedInUser {
407
400
OrgID : 1 ,
408
401
Permissions : map [int64 ]map [string ][]string {1 : accesscontrol .GroupScopesByAction (tt .permissions )},
409
402
}, service )
410
403
411
- // seed user
412
- orgSvc , err := orgimpl .ProvideService (sql , cfg , quotatest .New (false , nil ))
413
- require .NoError (t , err )
414
- usrSvc , err := userimpl .ProvideService (sql , orgSvc , cfg , nil , nil , & quotatest.FakeQuotaService {}, supportbundlestest .NewFakeBundleService ())
415
- require .NoError (t , err )
416
- _ , err = usrSvc .Create (context .Background (), & user.CreateUserCommand {Login : "test" , OrgID : 1 })
404
+ _ , err := usrSvc .Create (context .Background (), & user.CreateUserCommand {Login : "test" , OrgID : 1 })
417
405
require .NoError (t , err )
418
406
419
407
recorder := setPermission (t , server , testOptions .Resource , tt .resourceID , tt .permission , "users" , strconv .Itoa (int (tt .userID )))
@@ -507,20 +495,15 @@ func checkSeededPermissions(t *testing.T, permissions []resourcePermissionDTO) {
507
495
}
508
496
}
509
497
510
- func seedPermissions (t * testing.T , resourceID string , sql db. DB , cfg * setting. Cfg , service * Service ) {
498
+ func seedPermissions (t * testing.T , resourceID string , usrSvc user. Service , teamSvc team. Service , service * Service ) {
511
499
t .Helper ()
500
+
512
501
// seed team 1 with "Edit" permission on dashboard 1
513
- teamSvc , err := teamimpl .ProvideService (sql , cfg , tracing .InitializeTracerForTest ())
514
- require .NoError (t , err )
515
502
team ,
err := teamSvc .
CreateTeam (
context .
Background (),
"test" ,
"[email protected] " ,
1 )
516
503
require .NoError (t , err )
517
504
_ , err = service .SetTeamPermission (context .Background (), team .OrgID , team .ID , resourceID , "Edit" )
518
505
require .NoError (t , err )
519
506
// seed user 1 with "View" permission on dashboard 1
520
- orgSvc , err := orgimpl .ProvideService (sql , cfg , quotatest .New (false , nil ))
521
- require .NoError (t , err )
522
- usrSvc , err := userimpl .ProvideService (sql , orgSvc , cfg , nil , nil , & quotatest.FakeQuotaService {}, supportbundlestest .NewFakeBundleService ())
523
- require .NoError (t , err )
524
507
u , err := usrSvc .Create (context .Background (), & user.CreateUserCommand {Login : "test" , OrgID : 1 })
525
508
require .NoError (t , err )
526
509
_ , err = service .SetUserPermission (context .Background (), u .OrgID , accesscontrol.User {ID : u .ID }, resourceID , "View" )
0 commit comments