Chore: Copy user methods over to user store (#56000)
* Chore: Copy user methods over to user store * Fix some tests and bugs * Add some more tests * Move tests to user store * Move back the tests * Add some tests
This commit is contained in:
@@ -394,7 +394,7 @@ func setupHTTPServerWithCfgDb(
|
||||
acService, err = acimpl.ProvideService(cfg, db, routeRegister, localcache.ProvideService())
|
||||
require.NoError(t, err)
|
||||
ac = acimpl.ProvideAccessControl(cfg)
|
||||
userSvc = userimpl.ProvideService(db, nil, cfg, db)
|
||||
userSvc = userimpl.ProvideService(db, nil, cfg, db, teamimpl.ProvideService(db, cfg), localcache.ProvideService())
|
||||
}
|
||||
teamPermissionService, err := ossaccesscontrol.ProvideTeamPermissions(cfg, routeRegister, db, ac, license, acService, teamService, userSvc)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/localcache"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
@@ -22,6 +23,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/org/orgtest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
||||
"github.com/grafana/grafana/pkg/services/team/teamimpl"
|
||||
"github.com/grafana/grafana/pkg/services/temp_user/tempuserimpl"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||
@@ -388,7 +390,7 @@ func TestGetOrgUsersAPIEndpoint_AccessControlMetadata(t *testing.T) {
|
||||
cfg.RBACEnabled = tc.enableAccessControl
|
||||
sc := setupHTTPServerWithCfg(t, false, cfg, func(hs *HTTPServer) {
|
||||
hs.userService = userimpl.ProvideService(
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore), teamimpl.ProvideService(hs.SQLStore.(*sqlstore.SQLStore), cfg), localcache.ProvideService(),
|
||||
)
|
||||
hs.orgService = orgimpl.ProvideService(hs.SQLStore, cfg)
|
||||
})
|
||||
@@ -471,7 +473,7 @@ func TestGetOrgUsersAPIEndpoint_AccessControl(t *testing.T) {
|
||||
targetOrg: 2,
|
||||
},
|
||||
{
|
||||
name: "org admin can get users in his org",
|
||||
name: "org admin can get users in their org",
|
||||
enableAccessControl: true,
|
||||
expectedCode: http.StatusOK,
|
||||
expectedUserCount: 2,
|
||||
@@ -492,7 +494,7 @@ func TestGetOrgUsersAPIEndpoint_AccessControl(t *testing.T) {
|
||||
cfg.RBACEnabled = tc.enableAccessControl
|
||||
sc := setupHTTPServerWithCfg(t, false, cfg, func(hs *HTTPServer) {
|
||||
hs.userService = userimpl.ProvideService(
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore), teamimpl.ProvideService(hs.SQLStore.(*sqlstore.SQLStore), cfg), localcache.ProvideService(),
|
||||
)
|
||||
hs.orgService = orgimpl.ProvideService(hs.SQLStore, cfg)
|
||||
})
|
||||
@@ -597,7 +599,7 @@ func TestPostOrgUsersAPIEndpoint_AccessControl(t *testing.T) {
|
||||
cfg.RBACEnabled = tc.enableAccessControl
|
||||
sc := setupHTTPServerWithCfg(t, false, cfg, func(hs *HTTPServer) {
|
||||
hs.userService = userimpl.ProvideService(
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore), teamimpl.ProvideService(hs.SQLStore.(*sqlstore.SQLStore), cfg), localcache.ProvideService(),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -716,7 +718,7 @@ func TestOrgUsersAPIEndpointWithSetPerms_AccessControl(t *testing.T) {
|
||||
sc := setupHTTPServer(t, true, func(hs *HTTPServer) {
|
||||
hs.tempUserService = tempuserimpl.ProvideService(hs.SQLStore)
|
||||
hs.userService = userimpl.ProvideService(
|
||||
hs.SQLStore, nil, setting.NewCfg(), hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, setting.NewCfg(), hs.SQLStore.(*sqlstore.SQLStore), teamimpl.ProvideService(hs.SQLStore.(*sqlstore.SQLStore), setting.NewCfg()), localcache.ProvideService(),
|
||||
)
|
||||
})
|
||||
setInitCtxSignedInViewer(sc.initCtx)
|
||||
@@ -834,7 +836,7 @@ func TestPatchOrgUsersAPIEndpoint_AccessControl(t *testing.T) {
|
||||
cfg.RBACEnabled = tc.enableAccessControl
|
||||
sc := setupHTTPServerWithCfg(t, false, cfg, func(hs *HTTPServer) {
|
||||
hs.userService = userimpl.ProvideService(
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore), teamimpl.ProvideService(hs.SQLStore.(*sqlstore.SQLStore), cfg), localcache.ProvideService(),
|
||||
)
|
||||
hs.orgService = orgimpl.ProvideService(hs.SQLStore, cfg)
|
||||
})
|
||||
@@ -961,7 +963,7 @@ func TestDeleteOrgUsersAPIEndpoint_AccessControl(t *testing.T) {
|
||||
cfg.RBACEnabled = tc.enableAccessControl
|
||||
sc := setupHTTPServerWithCfg(t, false, cfg, func(hs *HTTPServer) {
|
||||
hs.userService = userimpl.ProvideService(
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore), teamimpl.ProvideService(hs.SQLStore.(*sqlstore.SQLStore), cfg), localcache.ProvideService(),
|
||||
)
|
||||
hs.orgService = orgimpl.ProvideService(hs.SQLStore, cfg)
|
||||
})
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
}
|
||||
user, err := sqlStore.CreateUser(context.Background(), createUserCmd)
|
||||
require.Nil(t, err)
|
||||
hs.userService = userimpl.ProvideService(sqlStore, nil, sc.cfg, sqlStore)
|
||||
hs.userService = userimpl.ProvideService(sqlStore, nil, sc.cfg, sqlStore, nil, nil)
|
||||
|
||||
sc.handlerFunc = hs.GetUserByID
|
||||
|
||||
|
||||
Reference in New Issue
Block a user