mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user