mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AccessControl: Only return action and scope for user permissions and make them unique (#48939)
* Only return action and scope for user permissions and make them unique
This commit is contained in:
@@ -21,7 +21,7 @@ type AccessControl interface {
|
|||||||
// Evaluate evaluates access to the given resources.
|
// Evaluate evaluates access to the given resources.
|
||||||
Evaluate(ctx context.Context, user *models.SignedInUser, evaluator Evaluator) (bool, error)
|
Evaluate(ctx context.Context, user *models.SignedInUser, evaluator Evaluator) (bool, error)
|
||||||
|
|
||||||
// GetUserPermissions returns user permissions.
|
// GetUserPermissions returns user permissions with only action and scope fields set.
|
||||||
GetUserPermissions(ctx context.Context, user *models.SignedInUser, options Options) ([]*Permission, error)
|
GetUserPermissions(ctx context.Context, user *models.SignedInUser, options Options) ([]*Permission, error)
|
||||||
|
|
||||||
// GetUserRoles returns user roles.
|
// GetUserRoles returns user roles.
|
||||||
@@ -40,6 +40,7 @@ type AccessControl interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PermissionsProvider interface {
|
type PermissionsProvider interface {
|
||||||
|
// GetUserPermissions returns user permissions with only action and scope fields set.
|
||||||
GetUserPermissions(ctx context.Context, query GetUserPermissionsQuery) ([]*Permission, error)
|
GetUserPermissions(ctx context.Context, query GetUserPermissionsQuery) ([]*Permission, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,13 +26,9 @@ func (s *AccessControlStore) GetUserPermissions(ctx context.Context, query acces
|
|||||||
filter, params := userRolesFilter(query.OrgID, query.UserID, query.Roles)
|
filter, params := userRolesFilter(query.OrgID, query.UserID, query.Roles)
|
||||||
|
|
||||||
// TODO: optimize this
|
// TODO: optimize this
|
||||||
q := `SELECT
|
q := `SELECT DISTINCT
|
||||||
permission.id,
|
|
||||||
permission.role_id,
|
|
||||||
permission.action,
|
permission.action,
|
||||||
permission.scope,
|
permission.scope
|
||||||
permission.updated,
|
|
||||||
permission.created
|
|
||||||
FROM permission
|
FROM permission
|
||||||
INNER JOIN role ON role.id = permission.role_id
|
INNER JOIN role ON role.id = permission.role_id
|
||||||
` + filter
|
` + filter
|
||||||
|
|||||||
Reference in New Issue
Block a user