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
@@ -6,8 +6,8 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/services/sqlstore/db"
"github.com/grafana/grafana/pkg/setting"
@@ -115,7 +115,7 @@ func (d *DashboardSnapshotStore) SearchDashboardSnapshots(ctx context.Context, q
// admins can see all snapshots, everyone else can only see their own snapshots
switch {
case query.SignedInUser.OrgRole == models.ROLE_ADMIN:
case query.SignedInUser.OrgRole == org.RoleAdmin:
sess.Where("org_id = ?", query.OrgId)
case !query.SignedInUser.IsAnonymous:
sess.Where("org_id = ? AND user_id = ?", query.OrgId, query.SignedInUser.UserId)
@@ -9,11 +9,12 @@ import (
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/secrets"
"github.com/grafana/grafana/pkg/services/secrets/fakes"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/setting"
)
@@ -71,7 +72,7 @@ func TestIntegrationDashboardSnapshotDBAccess(t *testing.T) {
t.Run("And the user has the admin role", func(t *testing.T) {
query := dashboardsnapshots.GetDashboardSnapshotsQuery{
OrgId: 1,
SignedInUser: &models.SignedInUser{OrgRole: models.ROLE_ADMIN},
SignedInUser: &user.SignedInUser{OrgRole: org.RoleAdmin},
}
err := dashStore.SearchDashboardSnapshots(context.Background(), &query)
require.NoError(t, err)
@@ -85,7 +86,7 @@ func TestIntegrationDashboardSnapshotDBAccess(t *testing.T) {
t.Run("And the user has the editor role and has created a snapshot", func(t *testing.T) {
query := dashboardsnapshots.GetDashboardSnapshotsQuery{
OrgId: 1,
SignedInUser: &models.SignedInUser{OrgRole: models.ROLE_EDITOR, UserId: 1000},
SignedInUser: &user.SignedInUser{OrgRole: org.RoleEditor, UserId: 1000},
}
err := dashStore.SearchDashboardSnapshots(context.Background(), &query)
require.NoError(t, err)
@@ -99,7 +100,7 @@ func TestIntegrationDashboardSnapshotDBAccess(t *testing.T) {
t.Run("And the user has the editor role and has not created any snapshot", func(t *testing.T) {
query := dashboardsnapshots.GetDashboardSnapshotsQuery{
OrgId: 1,
SignedInUser: &models.SignedInUser{OrgRole: models.ROLE_EDITOR, UserId: 2},
SignedInUser: &user.SignedInUser{OrgRole: org.RoleEditor, UserId: 2},
}
err := dashStore.SearchDashboardSnapshots(context.Background(), &query)
require.NoError(t, err)
@@ -126,7 +127,7 @@ func TestIntegrationDashboardSnapshotDBAccess(t *testing.T) {
t.Run("Should not return any snapshots", func(t *testing.T) {
query := dashboardsnapshots.GetDashboardSnapshotsQuery{
OrgId: 1,
SignedInUser: &models.SignedInUser{OrgRole: models.ROLE_EDITOR, IsAnonymous: true, UserId: 0},
SignedInUser: &user.SignedInUser{OrgRole: org.RoleEditor, IsAnonymous: true, UserId: 0},
}
err := dashStore.SearchDashboardSnapshots(context.Background(), &query)
require.NoError(t, err)
@@ -167,7 +168,7 @@ func TestIntegrationDeleteExpiredSnapshots(t *testing.T) {
query := dashboardsnapshots.GetDashboardSnapshotsQuery{
OrgId: 1,
SignedInUser: &models.SignedInUser{OrgRole: models.ROLE_ADMIN},
SignedInUser: &user.SignedInUser{OrgRole: org.RoleAdmin},
}
err = dashStore.SearchDashboardSnapshots(context.Background(), &query)
require.NoError(t, err)
@@ -180,7 +181,7 @@ func TestIntegrationDeleteExpiredSnapshots(t *testing.T) {
query = dashboardsnapshots.GetDashboardSnapshotsQuery{
OrgId: 1,
SignedInUser: &models.SignedInUser{OrgRole: models.ROLE_ADMIN},
SignedInUser: &user.SignedInUser{OrgRole: org.RoleAdmin},
}
err = dashStore.SearchDashboardSnapshots(context.Background(), &query)
require.NoError(t, err)