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:
@@ -6,12 +6,14 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
|
||||
type DashboardPermissionFilter struct {
|
||||
OrgRole models.RoleType
|
||||
OrgRole org.RoleType
|
||||
Dialect migrator.Dialect
|
||||
UserId int64
|
||||
OrgId int64
|
||||
@@ -19,13 +21,13 @@ type DashboardPermissionFilter struct {
|
||||
}
|
||||
|
||||
func (d DashboardPermissionFilter) Where() (string, []interface{}) {
|
||||
if d.OrgRole == models.ROLE_ADMIN {
|
||||
if d.OrgRole == org.RoleAdmin {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
okRoles := []interface{}{d.OrgRole}
|
||||
if d.OrgRole == models.ROLE_EDITOR {
|
||||
okRoles = append(okRoles, models.ROLE_VIEWER)
|
||||
if d.OrgRole == org.RoleEditor {
|
||||
okRoles = append(okRoles, org.RoleViewer)
|
||||
}
|
||||
|
||||
falseStr := d.Dialect.BooleanStr(false)
|
||||
@@ -78,13 +80,13 @@ func (d DashboardPermissionFilter) Where() (string, []interface{}) {
|
||||
}
|
||||
|
||||
type AccessControlDashboardPermissionFilter struct {
|
||||
User *models.SignedInUser
|
||||
User *user.SignedInUser
|
||||
dashboardActions []string
|
||||
folderActions []string
|
||||
}
|
||||
|
||||
// NewAccessControlDashboardPermissionFilter creates a new AccessControlDashboardPermissionFilter that is configured with specific actions calculated based on the models.PermissionType and query type
|
||||
func NewAccessControlDashboardPermissionFilter(user *models.SignedInUser, permissionLevel models.PermissionType, queryType string) AccessControlDashboardPermissionFilter {
|
||||
func NewAccessControlDashboardPermissionFilter(user *user.SignedInUser, permissionLevel models.PermissionType, queryType string) AccessControlDashboardPermissionFilter {
|
||||
needEdit := permissionLevel > models.PERMISSION_VIEW
|
||||
folderActions := []string{dashboards.ActionFoldersRead}
|
||||
var dashboardActions []string
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@@ -89,7 +90,7 @@ func TestNewAccessControlDashboardPermissionFilter(t *testing.T) {
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(fmt.Sprintf("query type %s, permissions %s", testCase.queryType, testCase.permission), func(t *testing.T) {
|
||||
filters := NewAccessControlDashboardPermissionFilter(&models.SignedInUser{}, testCase.permission, testCase.queryType)
|
||||
filters := NewAccessControlDashboardPermissionFilter(&user.SignedInUser{}, testCase.permission, testCase.queryType)
|
||||
|
||||
require.Equal(t, testCase.expectedDashboardActions, filters.dashboardActions)
|
||||
require.Equal(t, testCase.expectedFolderActions, filters.folderActions)
|
||||
@@ -133,7 +134,7 @@ func TestAccessControlDashboardPermissionFilter_Where(t *testing.T) {
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.title, func(t *testing.T) {
|
||||
filter := AccessControlDashboardPermissionFilter{
|
||||
User: &models.SignedInUser{Permissions: map[int64]map[string][]string{}},
|
||||
User: &user.SignedInUser{Permissions: map[int64]map[string][]string{}},
|
||||
dashboardActions: testCase.dashboardActions,
|
||||
folderActions: testCase.folderActions,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user