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

View File

@@ -8,6 +8,7 @@ import (
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/util"
)
@@ -20,8 +21,8 @@ func ProvideService(sqlStore *sqlstore.SQLStore) *ShortURLService {
}
type Service interface {
GetShortURLByUID(ctx context.Context, user *models.SignedInUser, uid string) (*models.ShortUrl, error)
CreateShortURL(ctx context.Context, user *models.SignedInUser, path string) (*models.ShortUrl, error)
GetShortURLByUID(ctx context.Context, user *user.SignedInUser, uid string) (*models.ShortUrl, error)
CreateShortURL(ctx context.Context, user *user.SignedInUser, path string) (*models.ShortUrl, error)
UpdateLastSeenAt(ctx context.Context, shortURL *models.ShortUrl) error
DeleteStaleShortURLs(ctx context.Context, cmd *models.DeleteShortUrlCommand) error
}
@@ -30,7 +31,7 @@ type ShortURLService struct {
SQLStore *sqlstore.SQLStore
}
func (s ShortURLService) GetShortURLByUID(ctx context.Context, user *models.SignedInUser, uid string) (*models.ShortUrl, error) {
func (s ShortURLService) GetShortURLByUID(ctx context.Context, user *user.SignedInUser, uid string) (*models.ShortUrl, error) {
var shortURL models.ShortUrl
err := s.SQLStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
exists, err := dbSession.Where("org_id=? AND uid=?", user.OrgId, uid).Get(&shortURL)
@@ -62,7 +63,7 @@ func (s ShortURLService) UpdateLastSeenAt(ctx context.Context, shortURL *models.
})
}
func (s ShortURLService) CreateShortURL(ctx context.Context, user *models.SignedInUser, relPath string) (*models.ShortUrl, error) {
func (s ShortURLService) CreateShortURL(ctx context.Context, user *user.SignedInUser, relPath string) (*models.ShortUrl, error) {
relPath = strings.TrimSpace(relPath)
if path.IsAbs(relPath) {

View File

@@ -9,10 +9,11 @@ import (
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/services/user"
)
func TestShortURLService(t *testing.T) {
user := &models.SignedInUser{UserId: 1}
user := &user.SignedInUser{UserId: 1}
sqlStore := sqlstore.InitTestDB(t)
t.Run("User can create and read short URLs", func(t *testing.T) {