Move SignedInUser to user service and RoleType and Roles to org (#53445)

* Move SignedInUser to user service and RoleType and Roles to org

* Use go naming convention for roles

* Fix some imports and leftovers

* Fix ldap debug test

* Fix lint

* Fix lint 2

* Fix lint 3

* Fix type and not needed conversion

* Clean up messages in api tests

* Clean up api tests 2
This commit is contained in:
idafurjes
2022-08-10 11:56:48 +02:00
committed by GitHub
parent 46004037e2
commit 6afad51761
278 changed files with 1758 additions and 1543 deletions
+8 -7
View File
@@ -11,6 +11,7 @@ import (
"github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/models"
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/util"
)
@@ -157,16 +158,16 @@ func (ss *SQLStore) createUser(ctx context.Context, sess *DBSession, args user.C
orgUser := models.OrgUser{
OrgId: orgID,
UserId: usr.ID,
Role: models.ROLE_ADMIN,
Role: org.RoleAdmin,
Created: time.Now(),
Updated: time.Now(),
}
if ss.Cfg.AutoAssignOrg && !usr.IsAdmin {
if len(args.DefaultOrgRole) > 0 {
orgUser.Role = models.RoleType(args.DefaultOrgRole)
orgUser.Role = org.RoleType(args.DefaultOrgRole)
} else {
orgUser.Role = models.RoleType(ss.Cfg.AutoAssignOrgRole)
orgUser.Role = org.RoleType(ss.Cfg.AutoAssignOrgRole)
}
}
@@ -475,7 +476,7 @@ func newSignedInUserCacheKey(orgID, userID int64) string {
func (ss *SQLStore) GetSignedInUserWithCacheCtx(ctx context.Context, query *models.GetSignedInUserQuery) error {
cacheKey := newSignedInUserCacheKey(query.OrgId, query.UserId)
if cached, found := ss.CacheService.Get(cacheKey); found {
cachedUser := cached.(models.SignedInUser)
cachedUser := cached.(user.SignedInUser)
query.Result = &cachedUser
return nil
}
@@ -536,7 +537,7 @@ func (ss *SQLStore) GetSignedInUser(ctx context.Context, query *models.GetSigned
}
}
var usr models.SignedInUser
var usr user.SignedInUser
has, err := sess.Get(&usr)
if err != nil {
return err
@@ -554,7 +555,7 @@ func (ss *SQLStore) GetSignedInUser(ctx context.Context, query *models.GetSigned
}
// tempUser is used to retrieve the teams for the signed in user for internal use.
tempUser := &models.SignedInUser{
tempUser := &user.SignedInUser{
OrgId: usr.OrgId,
Permissions: map[int64]map[string][]string{
usr.OrgId: {
@@ -847,7 +848,7 @@ func (ss *SQLStore) SetUserHelpFlag(ctx context.Context, cmd *models.SetUserHelp
return ss.WithTransactionalDbSession(ctx, func(sess *DBSession) error {
user := user.User{
ID: cmd.UserId,
HelpFlags1: user.HelpFlags1(cmd.HelpFlags1),
HelpFlags1: cmd.HelpFlags1,
Updated: time.Now(),
}