UserService: use the UserService instead of calling sqlstore directly (#55745)
* UserService: update callers to use the UserService instead of calling sqlstore directly There is one major change hiding in this PR. UserService.Delete originally called a number of services to delete user-related records. I moved everything except the actual call to the user table, and moved those into the API. This was done to avoid dependencies cycles; many of our services depend on the user service, so the user service itself should have as few dependencies as possible.
This commit is contained in:
+12
-17
@@ -388,8 +388,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, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
)
|
||||
hs.orgService = orgimpl.ProvideService(hs.SQLStore, cfg)
|
||||
})
|
||||
@@ -493,8 +492,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, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
)
|
||||
hs.orgService = orgimpl.ProvideService(hs.SQLStore, cfg)
|
||||
})
|
||||
@@ -599,10 +597,10 @@ 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, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
)
|
||||
})
|
||||
|
||||
setupOrgUsersDBForAccessControlTests(t, sc.db)
|
||||
setInitCtxSignedInUser(sc.initCtx, tc.user)
|
||||
|
||||
@@ -718,8 +716,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, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, nil, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
)
|
||||
})
|
||||
setInitCtxSignedInViewer(sc.initCtx)
|
||||
@@ -837,8 +834,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, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
)
|
||||
hs.orgService = orgimpl.ProvideService(hs.SQLStore, cfg)
|
||||
})
|
||||
@@ -858,13 +854,13 @@ func TestPatchOrgUsersAPIEndpoint_AccessControl(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.expectedMessage, message)
|
||||
|
||||
getUserQuery := models.GetSignedInUserQuery{
|
||||
UserId: tc.targetUserId,
|
||||
OrgId: tc.targetOrg,
|
||||
getUserQuery := user.GetSignedInUserQuery{
|
||||
UserID: tc.targetUserId,
|
||||
OrgID: tc.targetOrg,
|
||||
}
|
||||
err = sc.db.GetSignedInUser(context.Background(), &getUserQuery)
|
||||
usr, err := sc.userService.GetSignedInUser(context.Background(), &getUserQuery)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.expectedUserRole, getUserQuery.Result.OrgRole)
|
||||
assert.Equal(t, tc.expectedUserRole, usr.OrgRole)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -965,8 +961,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, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
hs.SQLStore, nil, cfg, hs.SQLStore.(*sqlstore.SQLStore),
|
||||
)
|
||||
hs.orgService = orgimpl.ProvideService(hs.SQLStore, cfg)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user