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:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
)
|
||||
|
||||
@@ -97,7 +98,7 @@ func (d *DashboardStore) GetDashboardACLInfoList(ctx context.Context, query *mod
|
||||
// HasEditPermissionInFolders validates that an user have access to a certain folder
|
||||
func (d *DashboardStore) HasEditPermissionInFolders(ctx context.Context, query *models.HasEditPermissionInFoldersQuery) error {
|
||||
return d.sqlStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
||||
if query.SignedInUser.HasRole(models.ROLE_EDITOR) {
|
||||
if query.SignedInUser.HasRole(org.RoleEditor) {
|
||||
query.Result = true
|
||||
return nil
|
||||
}
|
||||
@@ -125,7 +126,7 @@ func (d *DashboardStore) HasEditPermissionInFolders(ctx context.Context, query *
|
||||
|
||||
func (d *DashboardStore) HasAdminPermissionInDashboardsOrFolders(ctx context.Context, query *models.HasAdminPermissionInDashboardsOrFoldersQuery) error {
|
||||
return d.sqlStore.WithDbSession(ctx, func(dbSession *sqlstore.DBSession) error {
|
||||
if query.SignedInUser.HasRole(models.ROLE_ADMIN) {
|
||||
if query.SignedInUser.HasRole(org.RoleAdmin) {
|
||||
query.Result = true
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -47,10 +48,10 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
require.Equal(t, 2, len(query.Result))
|
||||
defaultPermissionsId := int64(-1)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[0].DashboardId)
|
||||
require.Equal(t, models.ROLE_VIEWER, *query.Result[0].Role)
|
||||
require.Equal(t, org.RoleViewer, *query.Result[0].Role)
|
||||
require.False(t, query.Result[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[1].DashboardId)
|
||||
require.Equal(t, models.ROLE_EDITOR, *query.Result[1].Role)
|
||||
require.Equal(t, org.RoleEditor, *query.Result[1].Role)
|
||||
require.False(t, query.Result[1].Inherited)
|
||||
})
|
||||
|
||||
@@ -64,10 +65,10 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
require.Equal(t, 2, len(query.Result))
|
||||
defaultPermissionsId := int64(-1)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[0].DashboardId)
|
||||
require.Equal(t, models.ROLE_VIEWER, *query.Result[0].Role)
|
||||
require.Equal(t, org.RoleViewer, *query.Result[0].Role)
|
||||
require.True(t, query.Result[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[1].DashboardId)
|
||||
require.Equal(t, models.ROLE_EDITOR, *query.Result[1].Role)
|
||||
require.Equal(t, org.RoleEditor, *query.Result[1].Role)
|
||||
require.True(t, query.Result[1].Inherited)
|
||||
})
|
||||
|
||||
@@ -146,10 +147,10 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
defaultPermissionsId := int64(-1)
|
||||
require.Equal(t, 3, len(query.Result))
|
||||
require.Equal(t, defaultPermissionsId, query.Result[0].DashboardId)
|
||||
require.Equal(t, models.ROLE_VIEWER, *query.Result[0].Role)
|
||||
require.Equal(t, org.RoleViewer, *query.Result[0].Role)
|
||||
require.True(t, query.Result[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[1].DashboardId)
|
||||
require.Equal(t, models.ROLE_EDITOR, *query.Result[1].Role)
|
||||
require.Equal(t, org.RoleEditor, *query.Result[1].Role)
|
||||
require.True(t, query.Result[1].Inherited)
|
||||
require.Equal(t, childDash.Id, query.Result[2].DashboardId)
|
||||
require.False(t, query.Result[2].Inherited)
|
||||
@@ -241,10 +242,10 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
require.Equal(t, 2, len(query.Result))
|
||||
defaultPermissionsId := int64(-1)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[0].DashboardId)
|
||||
require.Equal(t, models.ROLE_VIEWER, *query.Result[0].Role)
|
||||
require.Equal(t, org.RoleViewer, *query.Result[0].Role)
|
||||
require.False(t, query.Result[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[1].DashboardId)
|
||||
require.Equal(t, models.ROLE_EDITOR, *query.Result[1].Role)
|
||||
require.Equal(t, org.RoleEditor, *query.Result[1].Role)
|
||||
require.False(t, query.Result[1].Inherited)
|
||||
})
|
||||
|
||||
@@ -266,6 +267,6 @@ func createUser(t *testing.T, sqlStore *sqlstore.SQLStore, name string, role str
|
||||
q1 := models.GetUserOrgListQuery{UserId: currentUser.ID}
|
||||
err = sqlStore.GetUserOrgList(context.Background(), &q1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, models.RoleType(role), q1.Result[0].Role)
|
||||
require.Equal(t, org.RoleType(role), q1.Result[0].Role)
|
||||
return *currentUser
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
@@ -43,7 +44,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
t.Run("and no acls are set", func(t *testing.T) {
|
||||
t.Run("should return all dashboards", func(t *testing.T) {
|
||||
query := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER},
|
||||
SignedInUser: &user.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: org.RoleViewer},
|
||||
OrgId: 1,
|
||||
DashboardIds: []int64{folder.Id, dashInRoot.Id},
|
||||
}
|
||||
@@ -67,7 +68,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should not return folder", func(t *testing.T) {
|
||||
query := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER},
|
||||
SignedInUser: &user.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: org.RoleViewer},
|
||||
OrgId: 1, DashboardIds: []int64{folder.Id, dashInRoot.Id},
|
||||
}
|
||||
err := testSearchDashboards(dashboardStore, query)
|
||||
@@ -85,7 +86,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should be able to access folder", func(t *testing.T) {
|
||||
query := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER},
|
||||
SignedInUser: &user.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: org.RoleViewer},
|
||||
OrgId: 1,
|
||||
DashboardIds: []int64{folder.Id, dashInRoot.Id},
|
||||
}
|
||||
@@ -100,10 +101,10 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
t.Run("when the user is an admin", func(t *testing.T) {
|
||||
t.Run("should be able to access folder", func(t *testing.T) {
|
||||
query := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
UserId: currentUser.ID,
|
||||
OrgId: 1,
|
||||
OrgRole: models.ROLE_ADMIN,
|
||||
OrgRole: org.RoleAdmin,
|
||||
},
|
||||
OrgId: 1,
|
||||
DashboardIds: []int64{folder.Id, dashInRoot.Id},
|
||||
@@ -128,7 +129,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should not return folder or child", func(t *testing.T) {
|
||||
query := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER}, OrgId: 1, DashboardIds: []int64{folder.Id, childDash.Id, dashInRoot.Id},
|
||||
SignedInUser: &user.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: org.RoleViewer}, OrgId: 1, DashboardIds: []int64{folder.Id, childDash.Id, dashInRoot.Id},
|
||||
}
|
||||
err := testSearchDashboards(dashboardStore, query)
|
||||
require.NoError(t, err)
|
||||
@@ -143,7 +144,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("should be able to search for child dashboard but not folder", func(t *testing.T) {
|
||||
query := &models.FindPersistedDashboardsQuery{SignedInUser: &models.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER}, OrgId: 1, DashboardIds: []int64{folder.Id, childDash.Id, dashInRoot.Id}}
|
||||
query := &models.FindPersistedDashboardsQuery{SignedInUser: &user.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: org.RoleViewer}, OrgId: 1, DashboardIds: []int64{folder.Id, childDash.Id, dashInRoot.Id}}
|
||||
err := testSearchDashboards(dashboardStore, query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(query.Result), 2)
|
||||
@@ -155,10 +156,10 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
t.Run("when the user is an admin", func(t *testing.T) {
|
||||
t.Run("should be able to search for child dash and folder", func(t *testing.T) {
|
||||
query := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
UserId: currentUser.ID,
|
||||
OrgId: 1,
|
||||
OrgRole: models.ROLE_ADMIN,
|
||||
OrgRole: org.RoleAdmin,
|
||||
},
|
||||
OrgId: 1,
|
||||
DashboardIds: []int64{folder.Id, dashInRoot.Id, childDash.Id},
|
||||
@@ -197,8 +198,8 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
t.Run("should return dashboards in root and expanded folder", func(t *testing.T) {
|
||||
query := &models.FindPersistedDashboardsQuery{
|
||||
FolderIds: []int64{
|
||||
rootFolderId, folder1.Id}, SignedInUser: &models.SignedInUser{UserId: currentUser.ID,
|
||||
OrgId: 1, OrgRole: models.ROLE_VIEWER,
|
||||
rootFolderId, folder1.Id}, SignedInUser: &user.SignedInUser{UserId: currentUser.ID,
|
||||
OrgId: 1, OrgRole: org.RoleViewer,
|
||||
},
|
||||
OrgId: 1,
|
||||
}
|
||||
@@ -224,7 +225,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should not return folder with acl or its children", func(t *testing.T) {
|
||||
query := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER},
|
||||
SignedInUser: &user.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: org.RoleViewer},
|
||||
OrgId: 1,
|
||||
DashboardIds: []int64{folder1.Id, childDash1.Id, childDash2.Id, dashInRoot.Id},
|
||||
}
|
||||
@@ -240,7 +241,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should return folder without acl and its children", func(t *testing.T) {
|
||||
query := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER},
|
||||
SignedInUser: &user.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: org.RoleViewer},
|
||||
OrgId: 1,
|
||||
DashboardIds: []int64{folder2.Id, childDash1.Id, childDash2.Id, dashInRoot.Id},
|
||||
}
|
||||
@@ -264,7 +265,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should return folder without acl but not the dashboard with acl", func(t *testing.T) {
|
||||
query := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER},
|
||||
SignedInUser: &user.SignedInUser{UserId: currentUser.ID, OrgId: 1, OrgRole: org.RoleViewer},
|
||||
OrgId: 1,
|
||||
DashboardIds: []int64{folder2.Id, childDash1.Id, childDash2.Id, dashInRoot.Id},
|
||||
}
|
||||
@@ -302,7 +303,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
t.Run("Should have write access to all dashboard folders in their org", func(t *testing.T) {
|
||||
query := models.FindPersistedDashboardsQuery{
|
||||
OrgId: 1,
|
||||
SignedInUser: &models.SignedInUser{UserId: adminUser.ID, OrgRole: models.ROLE_ADMIN, OrgId: 1},
|
||||
SignedInUser: &user.SignedInUser{UserId: adminUser.ID, OrgRole: org.RoleAdmin, OrgId: 1},
|
||||
Permission: models.PERMISSION_VIEW,
|
||||
Type: "dash-folder",
|
||||
}
|
||||
@@ -317,7 +318,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should have edit permission in folders", func(t *testing.T) {
|
||||
query := &models.HasEditPermissionInFoldersQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: adminUser.ID, OrgId: 1, OrgRole: models.ROLE_ADMIN},
|
||||
SignedInUser: &user.SignedInUser{UserId: adminUser.ID, OrgId: 1, OrgRole: org.RoleAdmin},
|
||||
}
|
||||
err := dashboardStore.HasEditPermissionInFolders(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
@@ -326,7 +327,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should have admin permission in folders", func(t *testing.T) {
|
||||
query := &models.HasAdminPermissionInDashboardsOrFoldersQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: adminUser.ID, OrgId: 1, OrgRole: models.ROLE_ADMIN},
|
||||
SignedInUser: &user.SignedInUser{UserId: adminUser.ID, OrgId: 1, OrgRole: org.RoleAdmin},
|
||||
}
|
||||
err := dashboardStore.HasAdminPermissionInDashboardsOrFolders(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
@@ -337,7 +338,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
t.Run("Editor users", func(t *testing.T) {
|
||||
query := models.FindPersistedDashboardsQuery{
|
||||
OrgId: 1,
|
||||
SignedInUser: &models.SignedInUser{UserId: editorUser.ID, OrgRole: models.ROLE_EDITOR, OrgId: 1},
|
||||
SignedInUser: &user.SignedInUser{UserId: editorUser.ID, OrgRole: org.RoleEditor, OrgId: 1},
|
||||
Permission: models.PERMISSION_EDIT,
|
||||
}
|
||||
|
||||
@@ -365,7 +366,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should have edit permission in folders", func(t *testing.T) {
|
||||
query := &models.HasEditPermissionInFoldersQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: editorUser.ID, OrgId: 1, OrgRole: models.ROLE_EDITOR},
|
||||
SignedInUser: &user.SignedInUser{UserId: editorUser.ID, OrgId: 1, OrgRole: org.RoleEditor},
|
||||
}
|
||||
err := dashboardStore.HasEditPermissionInFolders(context.Background(), query)
|
||||
go require.NoError(t, err)
|
||||
@@ -374,7 +375,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should not have admin permission in folders", func(t *testing.T) {
|
||||
query := &models.HasAdminPermissionInDashboardsOrFoldersQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: adminUser.ID, OrgId: 1, OrgRole: models.ROLE_EDITOR},
|
||||
SignedInUser: &user.SignedInUser{UserId: adminUser.ID, OrgId: 1, OrgRole: org.RoleEditor},
|
||||
}
|
||||
err := dashboardStore.HasAdminPermissionInDashboardsOrFolders(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
@@ -385,7 +386,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
t.Run("Viewer users", func(t *testing.T) {
|
||||
query := models.FindPersistedDashboardsQuery{
|
||||
OrgId: 1,
|
||||
SignedInUser: &models.SignedInUser{UserId: viewerUser.ID, OrgRole: models.ROLE_VIEWER, OrgId: 1},
|
||||
SignedInUser: &user.SignedInUser{UserId: viewerUser.ID, OrgRole: org.RoleViewer, OrgId: 1},
|
||||
Permission: models.PERMISSION_EDIT,
|
||||
}
|
||||
|
||||
@@ -413,7 +414,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
setup3()
|
||||
|
||||
query := &models.HasEditPermissionInFoldersQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: viewerUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER},
|
||||
SignedInUser: &user.SignedInUser{UserId: viewerUser.ID, OrgId: 1, OrgRole: org.RoleViewer},
|
||||
}
|
||||
err := dashboardStore.HasEditPermissionInFolders(context.Background(), query)
|
||||
go require.NoError(t, err)
|
||||
@@ -422,7 +423,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should not have admin permission in folders", func(t *testing.T) {
|
||||
query := &models.HasAdminPermissionInDashboardsOrFoldersQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: adminUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER},
|
||||
SignedInUser: &user.SignedInUser{UserId: adminUser.ID, OrgId: 1, OrgRole: org.RoleViewer},
|
||||
}
|
||||
err := dashboardStore.HasAdminPermissionInDashboardsOrFolders(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
@@ -437,7 +438,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should have edit permission in folders", func(t *testing.T) {
|
||||
query := &models.HasEditPermissionInFoldersQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: viewerUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER},
|
||||
SignedInUser: &user.SignedInUser{UserId: viewerUser.ID, OrgId: 1, OrgRole: org.RoleViewer},
|
||||
}
|
||||
err := dashboardStore.HasEditPermissionInFolders(context.Background(), query)
|
||||
go require.NoError(t, err)
|
||||
@@ -453,7 +454,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should have edit permission in folders", func(t *testing.T) {
|
||||
query := &models.HasEditPermissionInFoldersQuery{
|
||||
SignedInUser: &models.SignedInUser{UserId: viewerUser.ID, OrgId: 1, OrgRole: models.ROLE_VIEWER},
|
||||
SignedInUser: &user.SignedInUser{UserId: viewerUser.ID, OrgId: 1, OrgRole: org.RoleViewer},
|
||||
}
|
||||
err := dashboardStore.HasEditPermissionInFolders(context.Background(), query)
|
||||
go require.NoError(t, err)
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
@@ -239,7 +240,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
query := models.FindPersistedDashboardsQuery{
|
||||
OrgId: 1,
|
||||
FolderIds: []int64{savedFolder.Id},
|
||||
SignedInUser: &models.SignedInUser{},
|
||||
SignedInUser: &user.SignedInUser{},
|
||||
}
|
||||
|
||||
res, err := dashboardStore.FindDashboards(context.Background(), &query)
|
||||
@@ -306,9 +307,9 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
query := models.FindPersistedDashboardsQuery{
|
||||
Title: "1 test dash folder",
|
||||
OrgId: 1,
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgId: 1,
|
||||
OrgRole: models.ROLE_EDITOR,
|
||||
OrgRole: org.RoleEditor,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {dashboards.ActionFoldersRead: []string{dashboards.ScopeFoldersAll}},
|
||||
},
|
||||
@@ -330,9 +331,9 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
query := models.FindPersistedDashboardsQuery{
|
||||
OrgId: 1,
|
||||
Limit: 1,
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgId: 1,
|
||||
OrgRole: models.ROLE_EDITOR,
|
||||
OrgRole: org.RoleEditor,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {dashboards.ActionFoldersRead: []string{dashboards.ScopeFoldersAll}},
|
||||
},
|
||||
@@ -352,9 +353,9 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
OrgId: 1,
|
||||
Limit: 1,
|
||||
Page: 2,
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgId: 1,
|
||||
OrgRole: models.ROLE_EDITOR,
|
||||
OrgRole: org.RoleEditor,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {
|
||||
dashboards.ActionDashboardsRead: []string{dashboards.ScopeDashboardsAll},
|
||||
@@ -377,9 +378,9 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
OrgId: 1,
|
||||
Type: "dash-db",
|
||||
Tags: []string{"prod"},
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgId: 1,
|
||||
OrgRole: models.ROLE_EDITOR,
|
||||
OrgRole: org.RoleEditor,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {dashboards.ActionDashboardsRead: []string{dashboards.ScopeDashboardsAll}},
|
||||
},
|
||||
@@ -398,9 +399,9 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
query := models.FindPersistedDashboardsQuery{
|
||||
OrgId: 1,
|
||||
FolderIds: []int64{savedFolder.Id},
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgId: 1,
|
||||
OrgRole: models.ROLE_EDITOR,
|
||||
OrgRole: org.RoleEditor,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {dashboards.ActionDashboardsRead: []string{dashboards.ScopeDashboardsAll}},
|
||||
},
|
||||
@@ -424,9 +425,9 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
setup()
|
||||
query := models.FindPersistedDashboardsQuery{
|
||||
DashboardIds: []int64{savedDash.Id, savedDash2.Id},
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgId: 1,
|
||||
OrgRole: models.ROLE_EDITOR,
|
||||
OrgRole: org.RoleEditor,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {dashboards.ActionDashboardsRead: []string{dashboards.ScopeDashboardsAll}},
|
||||
},
|
||||
@@ -461,10 +462,10 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
query := models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
UserId: 10,
|
||||
OrgId: 1,
|
||||
OrgRole: models.ROLE_EDITOR,
|
||||
OrgRole: org.RoleEditor,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {dashboards.ActionDashboardsRead: []string{dashboards.ScopeDashboardsAll}},
|
||||
},
|
||||
@@ -513,10 +514,10 @@ func TestIntegrationDashboard_SortingOptions(t *testing.T) {
|
||||
assert.NotZero(t, dashA.Id)
|
||||
assert.Less(t, dashB.Id, dashA.Id)
|
||||
qNoSort := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
OrgRole: models.ROLE_ADMIN,
|
||||
OrgRole: org.RoleAdmin,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {dashboards.ActionDashboardsRead: []string{dashboards.ScopeDashboardsAll}},
|
||||
},
|
||||
@@ -529,10 +530,10 @@ func TestIntegrationDashboard_SortingOptions(t *testing.T) {
|
||||
assert.Equal(t, dashB.Id, results[1].ID)
|
||||
|
||||
qSort := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
OrgRole: models.ROLE_ADMIN,
|
||||
OrgRole: org.RoleAdmin,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {dashboards.ActionDashboardsRead: []string{dashboards.ScopeDashboardsAll}},
|
||||
},
|
||||
@@ -559,10 +560,10 @@ func TestIntegrationDashboard_Filter(t *testing.T) {
|
||||
insertTestDashboard(t, dashboardStore, "Alfa", 1, 0, false)
|
||||
dashB := insertTestDashboard(t, dashboardStore, "Beta", 1, 0, false)
|
||||
qNoFilter := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
OrgRole: models.ROLE_ADMIN,
|
||||
OrgRole: org.RoleAdmin,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {dashboards.ActionDashboardsRead: []string{dashboards.ScopeDashboardsAll}},
|
||||
},
|
||||
@@ -573,10 +574,10 @@ func TestIntegrationDashboard_Filter(t *testing.T) {
|
||||
require.Len(t, results, 2)
|
||||
|
||||
qFilter := &models.FindPersistedDashboardsQuery{
|
||||
SignedInUser: &models.SignedInUser{
|
||||
SignedInUser: &user.SignedInUser{
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
OrgRole: models.ROLE_ADMIN,
|
||||
OrgRole: org.RoleAdmin,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {dashboards.ActionDashboardsRead: []string{dashboards.ScopeDashboardsAll}},
|
||||
},
|
||||
@@ -678,7 +679,7 @@ func CreateUser(t *testing.T, sqlStore *sqlstore.SQLStore, name string, role str
|
||||
q1 := models.GetUserOrgListQuery{UserId: currentUser.ID}
|
||||
err = sqlStore.GetUserOrgList(context.Background(), &q1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, models.RoleType(role), q1.Result[0].Role)
|
||||
require.Equal(t, org.RoleType(role), q1.Result[0].Role)
|
||||
return *currentUser
|
||||
}
|
||||
|
||||
|
||||
@@ -4,17 +4,18 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
|
||||
//go:generate mockery --name FolderService --structname FakeFolderService --inpackage --filename folder_service_mock.go
|
||||
// FolderService is a service for operating on folders.
|
||||
type FolderService interface {
|
||||
GetFolders(ctx context.Context, user *models.SignedInUser, orgID int64, limit int64, page int64) ([]*models.Folder, error)
|
||||
GetFolderByID(ctx context.Context, user *models.SignedInUser, id int64, orgID int64) (*models.Folder, error)
|
||||
GetFolderByUID(ctx context.Context, user *models.SignedInUser, orgID int64, uid string) (*models.Folder, error)
|
||||
GetFolderByTitle(ctx context.Context, user *models.SignedInUser, orgID int64, title string) (*models.Folder, error)
|
||||
CreateFolder(ctx context.Context, user *models.SignedInUser, orgID int64, title, uid string) (*models.Folder, error)
|
||||
UpdateFolder(ctx context.Context, user *models.SignedInUser, orgID int64, existingUid string, cmd *models.UpdateFolderCommand) error
|
||||
DeleteFolder(ctx context.Context, user *models.SignedInUser, orgID int64, uid string, forceDeleteRules bool) (*models.Folder, error)
|
||||
GetFolders(ctx context.Context, user *user.SignedInUser, orgID int64, limit int64, page int64) ([]*models.Folder, error)
|
||||
GetFolderByID(ctx context.Context, user *user.SignedInUser, id int64, orgID int64) (*models.Folder, error)
|
||||
GetFolderByUID(ctx context.Context, user *user.SignedInUser, orgID int64, uid string) (*models.Folder, error)
|
||||
GetFolderByTitle(ctx context.Context, user *user.SignedInUser, orgID int64, title string) (*models.Folder, error)
|
||||
CreateFolder(ctx context.Context, user *user.SignedInUser, orgID int64, title, uid string) (*models.Folder, error)
|
||||
UpdateFolder(ctx context.Context, user *user.SignedInUser, orgID int64, existingUid string, cmd *models.UpdateFolderCommand) error
|
||||
DeleteFolder(ctx context.Context, user *user.SignedInUser, orgID int64, uid string, forceDeleteRules bool) (*models.Folder, error)
|
||||
MakeUserAdmin(ctx context.Context, orgID int64, userID, folderID int64, setViewAndEditPermissions bool) error
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
context "context"
|
||||
|
||||
models "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
testing "testing"
|
||||
@@ -17,12 +18,12 @@ type FakeFolderService struct {
|
||||
}
|
||||
|
||||
// CreateFolder provides a mock function with given fields: ctx, user, orgID, title, uid
|
||||
func (_m *FakeFolderService) CreateFolder(ctx context.Context, user *models.SignedInUser, orgID int64, title string, uid string) (*models.Folder, error) {
|
||||
ret := _m.Called(ctx, user, orgID, title, uid)
|
||||
func (_m *FakeFolderService) CreateFolder(ctx context.Context, usr *user.SignedInUser, orgID int64, title string, uid string) (*models.Folder, error) {
|
||||
ret := _m.Called(ctx, usr, orgID, title, uid)
|
||||
|
||||
var r0 *models.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.SignedInUser, int64, string, string) *models.Folder); ok {
|
||||
r0 = rf(ctx, user, orgID, title, uid)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, string, string) *models.Folder); ok {
|
||||
r0 = rf(ctx, usr, orgID, title, uid)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.Folder)
|
||||
@@ -30,8 +31,8 @@ func (_m *FakeFolderService) CreateFolder(ctx context.Context, user *models.Sign
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *models.SignedInUser, int64, string, string) error); ok {
|
||||
r1 = rf(ctx, user, orgID, title, uid)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, string, string) error); ok {
|
||||
r1 = rf(ctx, usr, orgID, title, uid)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -40,12 +41,12 @@ func (_m *FakeFolderService) CreateFolder(ctx context.Context, user *models.Sign
|
||||
}
|
||||
|
||||
// DeleteFolder provides a mock function with given fields: ctx, user, orgID, uid, forceDeleteRules
|
||||
func (_m *FakeFolderService) DeleteFolder(ctx context.Context, user *models.SignedInUser, orgID int64, uid string, forceDeleteRules bool) (*models.Folder, error) {
|
||||
ret := _m.Called(ctx, user, orgID, uid, forceDeleteRules)
|
||||
func (_m *FakeFolderService) DeleteFolder(ctx context.Context, usr *user.SignedInUser, orgID int64, uid string, forceDeleteRules bool) (*models.Folder, error) {
|
||||
ret := _m.Called(ctx, usr, orgID, uid, forceDeleteRules)
|
||||
|
||||
var r0 *models.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.SignedInUser, int64, string, bool) *models.Folder); ok {
|
||||
r0 = rf(ctx, user, orgID, uid, forceDeleteRules)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, string, bool) *models.Folder); ok {
|
||||
r0 = rf(ctx, usr, orgID, uid, forceDeleteRules)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.Folder)
|
||||
@@ -53,8 +54,8 @@ func (_m *FakeFolderService) DeleteFolder(ctx context.Context, user *models.Sign
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *models.SignedInUser, int64, string, bool) error); ok {
|
||||
r1 = rf(ctx, user, orgID, uid, forceDeleteRules)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, string, bool) error); ok {
|
||||
r1 = rf(ctx, usr, orgID, uid, forceDeleteRules)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -63,12 +64,12 @@ func (_m *FakeFolderService) DeleteFolder(ctx context.Context, user *models.Sign
|
||||
}
|
||||
|
||||
// GetFolderByID provides a mock function with given fields: ctx, user, id, orgID
|
||||
func (_m *FakeFolderService) GetFolderByID(ctx context.Context, user *models.SignedInUser, id int64, orgID int64) (*models.Folder, error) {
|
||||
ret := _m.Called(ctx, user, id, orgID)
|
||||
func (_m *FakeFolderService) GetFolderByID(ctx context.Context, usr *user.SignedInUser, id int64, orgID int64) (*models.Folder, error) {
|
||||
ret := _m.Called(ctx, usr, id, orgID)
|
||||
|
||||
var r0 *models.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.SignedInUser, int64, int64) *models.Folder); ok {
|
||||
r0 = rf(ctx, user, id, orgID)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, int64) *models.Folder); ok {
|
||||
r0 = rf(ctx, usr, id, orgID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.Folder)
|
||||
@@ -76,8 +77,8 @@ func (_m *FakeFolderService) GetFolderByID(ctx context.Context, user *models.Sig
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *models.SignedInUser, int64, int64) error); ok {
|
||||
r1 = rf(ctx, user, id, orgID)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, int64) error); ok {
|
||||
r1 = rf(ctx, usr, id, orgID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -86,12 +87,12 @@ func (_m *FakeFolderService) GetFolderByID(ctx context.Context, user *models.Sig
|
||||
}
|
||||
|
||||
// GetFolderByTitle provides a mock function with given fields: ctx, user, orgID, title
|
||||
func (_m *FakeFolderService) GetFolderByTitle(ctx context.Context, user *models.SignedInUser, orgID int64, title string) (*models.Folder, error) {
|
||||
ret := _m.Called(ctx, user, orgID, title)
|
||||
func (_m *FakeFolderService) GetFolderByTitle(ctx context.Context, usr *user.SignedInUser, orgID int64, title string) (*models.Folder, error) {
|
||||
ret := _m.Called(ctx, usr, orgID, title)
|
||||
|
||||
var r0 *models.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.SignedInUser, int64, string) *models.Folder); ok {
|
||||
r0 = rf(ctx, user, orgID, title)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, string) *models.Folder); ok {
|
||||
r0 = rf(ctx, usr, orgID, title)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.Folder)
|
||||
@@ -99,8 +100,8 @@ func (_m *FakeFolderService) GetFolderByTitle(ctx context.Context, user *models.
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *models.SignedInUser, int64, string) error); ok {
|
||||
r1 = rf(ctx, user, orgID, title)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, string) error); ok {
|
||||
r1 = rf(ctx, usr, orgID, title)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -109,12 +110,12 @@ func (_m *FakeFolderService) GetFolderByTitle(ctx context.Context, user *models.
|
||||
}
|
||||
|
||||
// GetFolderByUID provides a mock function with given fields: ctx, user, orgID, uid
|
||||
func (_m *FakeFolderService) GetFolderByUID(ctx context.Context, user *models.SignedInUser, orgID int64, uid string) (*models.Folder, error) {
|
||||
ret := _m.Called(ctx, user, orgID, uid)
|
||||
func (_m *FakeFolderService) GetFolderByUID(ctx context.Context, usr *user.SignedInUser, orgID int64, uid string) (*models.Folder, error) {
|
||||
ret := _m.Called(ctx, usr, orgID, uid)
|
||||
|
||||
var r0 *models.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.SignedInUser, int64, string) *models.Folder); ok {
|
||||
r0 = rf(ctx, user, orgID, uid)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, string) *models.Folder); ok {
|
||||
r0 = rf(ctx, usr, orgID, uid)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.Folder)
|
||||
@@ -122,8 +123,8 @@ func (_m *FakeFolderService) GetFolderByUID(ctx context.Context, user *models.Si
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *models.SignedInUser, int64, string) error); ok {
|
||||
r1 = rf(ctx, user, orgID, uid)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, string) error); ok {
|
||||
r1 = rf(ctx, usr, orgID, uid)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -132,12 +133,12 @@ func (_m *FakeFolderService) GetFolderByUID(ctx context.Context, user *models.Si
|
||||
}
|
||||
|
||||
// GetFolders provides a mock function with given fields: ctx, user, orgID, limit, page
|
||||
func (_m *FakeFolderService) GetFolders(ctx context.Context, user *models.SignedInUser, orgID int64, limit int64, page int64) ([]*models.Folder, error) {
|
||||
ret := _m.Called(ctx, user, orgID, limit, page)
|
||||
func (_m *FakeFolderService) GetFolders(ctx context.Context, usr *user.SignedInUser, orgID int64, limit int64, page int64) ([]*models.Folder, error) {
|
||||
ret := _m.Called(ctx, usr, orgID, limit, page)
|
||||
|
||||
var r0 []*models.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.SignedInUser, int64, int64, int64) []*models.Folder); ok {
|
||||
r0 = rf(ctx, user, orgID, limit, page)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, int64, int64) []*models.Folder); ok {
|
||||
r0 = rf(ctx, usr, orgID, limit, page)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*models.Folder)
|
||||
@@ -145,8 +146,8 @@ func (_m *FakeFolderService) GetFolders(ctx context.Context, user *models.Signed
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *models.SignedInUser, int64, int64, int64) error); ok {
|
||||
r1 = rf(ctx, user, orgID, limit, page)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *user.SignedInUser, int64, int64, int64) error); ok {
|
||||
r1 = rf(ctx, usr, orgID, limit, page)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -169,12 +170,12 @@ func (_m *FakeFolderService) MakeUserAdmin(ctx context.Context, orgID int64, use
|
||||
}
|
||||
|
||||
// UpdateFolder provides a mock function with given fields: ctx, user, orgID, existingUid, cmd
|
||||
func (_m *FakeFolderService) UpdateFolder(ctx context.Context, user *models.SignedInUser, orgID int64, existingUid string, cmd *models.UpdateFolderCommand) error {
|
||||
ret := _m.Called(ctx, user, orgID, existingUid, cmd)
|
||||
func (_m *FakeFolderService) UpdateFolder(ctx context.Context, usr *user.SignedInUser, orgID int64, existingUid string, cmd *models.UpdateFolderCommand) error {
|
||||
ret := _m.Called(ctx, usr, orgID, existingUid, cmd)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.SignedInUser, int64, string, *models.UpdateFolderCommand) error); ok {
|
||||
r0 = rf(ctx, user, orgID, existingUid, cmd)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *user.SignedInUser, int64, string, *models.UpdateFolderCommand) error); ok {
|
||||
r0 = rf(ctx, usr, orgID, existingUid, cmd)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
|
||||
type SaveDashboardDTO struct {
|
||||
OrgId int64
|
||||
UpdatedAt time.Time
|
||||
User *models.SignedInUser
|
||||
User *user.SignedInUser
|
||||
Message string
|
||||
Overwrite bool
|
||||
Dashboard *models.Dashboard
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
@@ -216,9 +218,9 @@ func (dr *DashboardServiceImpl) SaveProvisionedDashboard(ctx context.Context, dt
|
||||
dto.Dashboard.Data.Set("refresh", setting.MinRefreshInterval)
|
||||
}
|
||||
|
||||
dto.User = &models.SignedInUser{
|
||||
dto.User = &user.SignedInUser{
|
||||
UserId: 0,
|
||||
OrgRole: models.ROLE_ADMIN,
|
||||
OrgRole: org.RoleAdmin,
|
||||
OrgId: dto.OrgId,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
dto.OrgId: provisionerPermissions,
|
||||
@@ -266,9 +268,9 @@ func (dr *DashboardServiceImpl) SaveProvisionedDashboard(ctx context.Context, dt
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) SaveFolderForProvisionedDashboards(ctx context.Context, dto *dashboards.SaveDashboardDTO) (*models.Dashboard, error) {
|
||||
dto.User = &models.SignedInUser{
|
||||
dto.User = &user.SignedInUser{
|
||||
UserId: 0,
|
||||
OrgRole: models.ROLE_ADMIN,
|
||||
OrgRole: org.RoleAdmin,
|
||||
Permissions: map[int64]map[string][]string{dto.OrgId: provisionerPermissions},
|
||||
}
|
||||
cmd, err := dr.BuildSaveDashboardCommand(ctx, dto, false, false)
|
||||
@@ -368,8 +370,8 @@ func (dr *DashboardServiceImpl) GetDashboardByPublicUid(ctx context.Context, das
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) MakeUserAdmin(ctx context.Context, orgID int64, userID int64, dashboardID int64, setViewAndEditPermissions bool) error {
|
||||
rtEditor := models.ROLE_EDITOR
|
||||
rtViewer := models.ROLE_VIEWER
|
||||
rtEditor := org.RoleEditor
|
||||
rtViewer := org.RoleViewer
|
||||
|
||||
items := []*models.DashboardACL{
|
||||
{
|
||||
@@ -478,8 +480,8 @@ func (dr *DashboardServiceImpl) setDefaultPermissions(ctx context.Context, dto *
|
||||
|
||||
if !inFolder {
|
||||
permissions = append(permissions, []accesscontrol.SetResourcePermissionCommand{
|
||||
{BuiltinRole: string(models.ROLE_EDITOR), Permission: models.PERMISSION_EDIT.String()},
|
||||
{BuiltinRole: string(models.ROLE_VIEWER), Permission: models.PERMISSION_VIEW.String()},
|
||||
{BuiltinRole: string(org.RoleEditor), Permission: models.PERMISSION_EDIT.String()},
|
||||
{BuiltinRole: string(org.RoleViewer), Permission: models.PERMISSION_VIEW.String()},
|
||||
}...)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
@@ -916,9 +918,9 @@ func saveTestDashboard(t *testing.T, title string, orgID, folderID int64, sqlSto
|
||||
dto := dashboards.SaveDashboardDTO{
|
||||
OrgId: orgID,
|
||||
Dashboard: cmd.GetDashboardModel(),
|
||||
User: &models.SignedInUser{
|
||||
User: &user.SignedInUser{
|
||||
UserId: 1,
|
||||
OrgRole: models.ROLE_ADMIN,
|
||||
OrgRole: org.RoleAdmin,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -953,9 +955,9 @@ func saveTestFolder(t *testing.T, title string, orgID int64, sqlStore *sqlstore.
|
||||
dto := dashboards.SaveDashboardDTO{
|
||||
OrgId: orgID,
|
||||
Dashboard: cmd.GetDashboardModel(),
|
||||
User: &models.SignedInUser{
|
||||
User: &user.SignedInUser{
|
||||
UserId: 1,
|
||||
OrgRole: models.ROLE_ADMIN,
|
||||
OrgRole: org.RoleAdmin,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -982,7 +984,7 @@ func toSaveDashboardDto(cmd models.SaveDashboardCommand) dashboards.SaveDashboar
|
||||
Dashboard: dash,
|
||||
Message: cmd.Message,
|
||||
OrgId: cmd.OrgId,
|
||||
User: &models.SignedInUser{UserId: cmd.UserId},
|
||||
User: &user.SignedInUser{UserId: cmd.UserId},
|
||||
Overwrite: cmd.Overwrite,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
@@ -76,7 +77,7 @@ func TestDashboardService(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
dto.Dashboard = models.NewDashboard("title")
|
||||
dto.Dashboard.SetUid(tc.Uid)
|
||||
dto.User = &models.SignedInUser{}
|
||||
dto.User = &user.SignedInUser{}
|
||||
|
||||
if tc.Error == nil {
|
||||
fakeStore.On("ValidateDashboardBeforeSave", mock.Anything, mock.Anything).Return(true, nil).Once()
|
||||
@@ -92,7 +93,7 @@ func TestDashboardService(t *testing.T) {
|
||||
|
||||
dto.Dashboard = models.NewDashboard("Dash")
|
||||
dto.Dashboard.SetId(3)
|
||||
dto.User = &models.SignedInUser{UserId: 1}
|
||||
dto.User = &user.SignedInUser{UserId: 1}
|
||||
_, err := service.SaveDashboard(context.Background(), dto, false)
|
||||
require.Equal(t, err, dashboards.ErrDashboardCannotSaveProvisionedDashboard)
|
||||
})
|
||||
@@ -103,7 +104,7 @@ func TestDashboardService(t *testing.T) {
|
||||
|
||||
dto.Dashboard = models.NewDashboard("Dash")
|
||||
dto.Dashboard.SetId(3)
|
||||
dto.User = &models.SignedInUser{UserId: 1}
|
||||
dto.User = &user.SignedInUser{UserId: 1}
|
||||
_, err := service.SaveDashboard(context.Background(), dto, true)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
@@ -129,7 +130,7 @@ func TestDashboardService(t *testing.T) {
|
||||
fakeStore.On("SaveAlerts", mock.Anything, mock.Anything, mock.Anything).Return(errors.New("alert validation error")).Once()
|
||||
|
||||
dto.Dashboard = models.NewDashboard("Dash")
|
||||
dto.User = &models.SignedInUser{UserId: 1}
|
||||
dto.User = &user.SignedInUser{UserId: 1}
|
||||
_, err := service.SaveDashboard(context.Background(), dto, false)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, err.Error(), "alert validation error")
|
||||
@@ -145,7 +146,7 @@ func TestDashboardService(t *testing.T) {
|
||||
|
||||
dto.Dashboard = models.NewDashboard("Dash")
|
||||
dto.Dashboard.SetId(3)
|
||||
dto.User = &models.SignedInUser{UserId: 1}
|
||||
dto.User = &user.SignedInUser{UserId: 1}
|
||||
_, err := service.SaveProvisionedDashboard(context.Background(), dto, nil)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
@@ -160,7 +161,7 @@ func TestDashboardService(t *testing.T) {
|
||||
|
||||
dto.Dashboard = models.NewDashboard("Dash")
|
||||
dto.Dashboard.SetId(3)
|
||||
dto.User = &models.SignedInUser{UserId: 1}
|
||||
dto.User = &user.SignedInUser{UserId: 1}
|
||||
dto.Dashboard.Data.Set("refresh", "1s")
|
||||
_, err := service.SaveProvisionedDashboard(context.Background(), dto, nil)
|
||||
require.NoError(t, err)
|
||||
@@ -177,7 +178,7 @@ func TestDashboardService(t *testing.T) {
|
||||
|
||||
dto.Dashboard = models.NewDashboard("Dash")
|
||||
dto.Dashboard.SetId(3)
|
||||
dto.User = &models.SignedInUser{UserId: 1}
|
||||
dto.User = &user.SignedInUser{UserId: 1}
|
||||
_, err := service.ImportDashboard(context.Background(), dto)
|
||||
require.Equal(t, err, dashboards.ErrDashboardCannotSaveProvisionedDashboard)
|
||||
})
|
||||
|
||||
@@ -13,7 +13,9 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
@@ -50,7 +52,7 @@ func ProvideFolderService(
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FolderServiceImpl) GetFolders(ctx context.Context, user *models.SignedInUser, orgID int64, limit int64, page int64) ([]*models.Folder, error) {
|
||||
func (f *FolderServiceImpl) GetFolders(ctx context.Context, user *user.SignedInUser, orgID int64, limit int64, page int64) ([]*models.Folder, error) {
|
||||
searchQuery := search.Query{
|
||||
SignedInUser: user,
|
||||
DashboardIds: make([]int64, 0),
|
||||
@@ -79,7 +81,7 @@ func (f *FolderServiceImpl) GetFolders(ctx context.Context, user *models.SignedI
|
||||
return folders, nil
|
||||
}
|
||||
|
||||
func (f *FolderServiceImpl) GetFolderByID(ctx context.Context, user *models.SignedInUser, id int64, orgID int64) (*models.Folder, error) {
|
||||
func (f *FolderServiceImpl) GetFolderByID(ctx context.Context, user *user.SignedInUser, id int64, orgID int64) (*models.Folder, error) {
|
||||
if id == 0 {
|
||||
return &models.Folder{Id: id, Title: "General"}, nil
|
||||
}
|
||||
@@ -99,7 +101,7 @@ func (f *FolderServiceImpl) GetFolderByID(ctx context.Context, user *models.Sign
|
||||
return dashFolder, nil
|
||||
}
|
||||
|
||||
func (f *FolderServiceImpl) GetFolderByUID(ctx context.Context, user *models.SignedInUser, orgID int64, uid string) (*models.Folder, error) {
|
||||
func (f *FolderServiceImpl) GetFolderByUID(ctx context.Context, user *user.SignedInUser, orgID int64, uid string) (*models.Folder, error) {
|
||||
dashFolder, err := f.dashboardStore.GetFolderByUID(ctx, orgID, uid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -116,7 +118,7 @@ func (f *FolderServiceImpl) GetFolderByUID(ctx context.Context, user *models.Sig
|
||||
return dashFolder, nil
|
||||
}
|
||||
|
||||
func (f *FolderServiceImpl) GetFolderByTitle(ctx context.Context, user *models.SignedInUser, orgID int64, title string) (*models.Folder, error) {
|
||||
func (f *FolderServiceImpl) GetFolderByTitle(ctx context.Context, user *user.SignedInUser, orgID int64, title string) (*models.Folder, error) {
|
||||
dashFolder, err := f.dashboardStore.GetFolderByTitle(ctx, orgID, title)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -133,7 +135,7 @@ func (f *FolderServiceImpl) GetFolderByTitle(ctx context.Context, user *models.S
|
||||
return dashFolder, nil
|
||||
}
|
||||
|
||||
func (f *FolderServiceImpl) CreateFolder(ctx context.Context, user *models.SignedInUser, orgID int64, title, uid string) (*models.Folder, error) {
|
||||
func (f *FolderServiceImpl) CreateFolder(ctx context.Context, user *user.SignedInUser, orgID int64, title, uid string) (*models.Folder, error) {
|
||||
dashFolder := models.NewDashboardFolder(title)
|
||||
dashFolder.OrgId = orgID
|
||||
|
||||
@@ -183,8 +185,8 @@ func (f *FolderServiceImpl) CreateFolder(ctx context.Context, user *models.Signe
|
||||
}
|
||||
|
||||
permissions = append(permissions, []accesscontrol.SetResourcePermissionCommand{
|
||||
{BuiltinRole: string(models.ROLE_EDITOR), Permission: models.PERMISSION_EDIT.String()},
|
||||
{BuiltinRole: string(models.ROLE_VIEWER), Permission: models.PERMISSION_VIEW.String()},
|
||||
{BuiltinRole: string(org.RoleEditor), Permission: models.PERMISSION_EDIT.String()},
|
||||
{BuiltinRole: string(org.RoleViewer), Permission: models.PERMISSION_VIEW.String()},
|
||||
}...)
|
||||
|
||||
_, permissionErr = f.permissions.SetPermissions(ctx, orgID, folder.Uid, permissions...)
|
||||
@@ -199,7 +201,7 @@ func (f *FolderServiceImpl) CreateFolder(ctx context.Context, user *models.Signe
|
||||
return folder, nil
|
||||
}
|
||||
|
||||
func (f *FolderServiceImpl) UpdateFolder(ctx context.Context, user *models.SignedInUser, orgID int64, existingUid string, cmd *models.UpdateFolderCommand) error {
|
||||
func (f *FolderServiceImpl) UpdateFolder(ctx context.Context, user *user.SignedInUser, orgID int64, existingUid string, cmd *models.UpdateFolderCommand) error {
|
||||
query := models.GetDashboardQuery{OrgId: orgID, Uid: existingUid}
|
||||
if _, err := f.dashboardStore.GetDashboard(ctx, &query); err != nil {
|
||||
return toFolderError(err)
|
||||
@@ -253,7 +255,7 @@ func (f *FolderServiceImpl) UpdateFolder(ctx context.Context, user *models.Signe
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *FolderServiceImpl) DeleteFolder(ctx context.Context, user *models.SignedInUser, orgID int64, uid string, forceDeleteRules bool) (*models.Folder, error) {
|
||||
func (f *FolderServiceImpl) DeleteFolder(ctx context.Context, user *user.SignedInUser, orgID int64, uid string, forceDeleteRules bool) (*models.Folder, error) {
|
||||
dashFolder, err := f.dashboardStore.GetFolderByUID(ctx, orgID, uid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -16,12 +16,13 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
var orgID = int64(1)
|
||||
var user = &models.SignedInUser{UserId: 1}
|
||||
var usr = &user.SignedInUser{UserId: 1}
|
||||
|
||||
func TestIntegrationProvideFolderService(t *testing.T) {
|
||||
if testing.Short() {
|
||||
@@ -76,24 +77,24 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
store.On("GetFolderByUID", mock.Anything, orgID, folderUID).Return(folder, nil)
|
||||
|
||||
t.Run("When get folder by id should return access denied error", func(t *testing.T) {
|
||||
_, err := service.GetFolderByID(context.Background(), user, folderId, orgID)
|
||||
_, err := service.GetFolderByID(context.Background(), usr, folderId, orgID)
|
||||
require.Equal(t, err, dashboards.ErrFolderAccessDenied)
|
||||
})
|
||||
|
||||
t.Run("When get folder by id, with id = 0 should return default folder", func(t *testing.T) {
|
||||
folder, err := service.GetFolderByID(context.Background(), user, 0, orgID)
|
||||
folder, err := service.GetFolderByID(context.Background(), usr, 0, orgID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, folder, &models.Folder{Id: 0, Title: "General"})
|
||||
})
|
||||
|
||||
t.Run("When get folder by uid should return access denied error", func(t *testing.T) {
|
||||
_, err := service.GetFolderByUID(context.Background(), user, orgID, folderUID)
|
||||
_, err := service.GetFolderByUID(context.Background(), usr, orgID, folderUID)
|
||||
require.Equal(t, err, dashboards.ErrFolderAccessDenied)
|
||||
})
|
||||
|
||||
t.Run("When creating folder should return access denied error", func(t *testing.T) {
|
||||
store.On("ValidateDashboardBeforeSave", mock.Anything, mock.Anything).Return(true, nil).Times(2)
|
||||
_, err := service.CreateFolder(context.Background(), user, orgID, folder.Title, folderUID)
|
||||
_, err := service.CreateFolder(context.Background(), usr, orgID, folder.Title, folderUID)
|
||||
require.Equal(t, err, dashboards.ErrFolderAccessDenied)
|
||||
})
|
||||
|
||||
@@ -103,7 +104,7 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
folder.Result = models.NewDashboard("dashboard-test")
|
||||
folder.Result.IsFolder = true
|
||||
}).Return(&models.Dashboard{}, nil)
|
||||
err := service.UpdateFolder(context.Background(), user, orgID, folderUID, &models.UpdateFolderCommand{
|
||||
err := service.UpdateFolder(context.Background(), usr, orgID, folderUID, &models.UpdateFolderCommand{
|
||||
Uid: folderUID,
|
||||
Title: "Folder-TEST",
|
||||
})
|
||||
@@ -111,7 +112,7 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("When deleting folder by uid should return access denied error", func(t *testing.T) {
|
||||
_, err := service.DeleteFolder(context.Background(), user, orgID, folderUID, false)
|
||||
_, err := service.DeleteFolder(context.Background(), usr, orgID, folderUID, false)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, err, dashboards.ErrFolderAccessDenied)
|
||||
})
|
||||
@@ -134,7 +135,7 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
store.On("SaveDashboard", mock.Anything).Return(dash, nil).Once()
|
||||
store.On("GetFolderByID", mock.Anything, orgID, dash.Id).Return(f, nil)
|
||||
|
||||
actualFolder, err := service.CreateFolder(context.Background(), user, orgID, dash.Title, "")
|
||||
actualFolder, err := service.CreateFolder(context.Background(), usr, orgID, dash.Title, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, f, actualFolder)
|
||||
})
|
||||
@@ -143,7 +144,7 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
dash := models.NewDashboardFolder("Test-Folder")
|
||||
dash.Id = rand.Int63()
|
||||
|
||||
_, err := service.CreateFolder(context.Background(), user, orgID, dash.Title, "general")
|
||||
_, err := service.CreateFolder(context.Background(), usr, orgID, dash.Title, "general")
|
||||
require.ErrorIs(t, err, dashboards.ErrFolderInvalidUID)
|
||||
})
|
||||
|
||||
@@ -162,7 +163,7 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
Title: "TEST-Folder",
|
||||
}
|
||||
|
||||
err := service.UpdateFolder(context.Background(), user, orgID, dashboardFolder.Uid, req)
|
||||
err := service.UpdateFolder(context.Background(), usr, orgID, dashboardFolder.Uid, req)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, f, req.Result)
|
||||
})
|
||||
@@ -179,7 +180,7 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
}).Return(nil).Once()
|
||||
|
||||
expectedForceDeleteRules := rand.Int63()%2 == 0
|
||||
_, err := service.DeleteFolder(context.Background(), user, orgID, f.Uid, expectedForceDeleteRules)
|
||||
_, err := service.DeleteFolder(context.Background(), usr, orgID, f.Uid, expectedForceDeleteRules)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, actualCmd)
|
||||
require.Equal(t, f.Id, actualCmd.Id)
|
||||
@@ -202,7 +203,7 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
|
||||
store.On("GetFolderByID", mock.Anything, orgID, expected.Id).Return(expected, nil)
|
||||
|
||||
actual, err := service.GetFolderByID(context.Background(), user, expected.Id, orgID)
|
||||
actual, err := service.GetFolderByID(context.Background(), usr, expected.Id, orgID)
|
||||
require.Equal(t, expected, actual)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
@@ -213,7 +214,7 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
|
||||
store.On("GetFolderByUID", mock.Anything, orgID, expected.Uid).Return(expected, nil)
|
||||
|
||||
actual, err := service.GetFolderByUID(context.Background(), user, orgID, expected.Uid)
|
||||
actual, err := service.GetFolderByUID(context.Background(), usr, orgID, expected.Uid)
|
||||
require.Equal(t, expected, actual)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
@@ -223,7 +224,7 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
|
||||
store.On("GetFolderByTitle", mock.Anything, orgID, expected.Title).Return(expected, nil)
|
||||
|
||||
actual, err := service.GetFolderByTitle(context.Background(), user, orgID, expected.Title)
|
||||
actual, err := service.GetFolderByTitle(context.Background(), usr, orgID, expected.Title)
|
||||
require.Equal(t, expected, actual)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user