mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 15:02:28 +08: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:
@ -10,6 +10,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/middleware/cookies"
|
||||
"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/setting"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@ -75,12 +76,12 @@ func removeForceLoginParams(str string) string {
|
||||
}
|
||||
|
||||
func EnsureEditorOrViewerCanEdit(c *models.ReqContext) {
|
||||
if !c.SignedInUser.HasRole(models.ROLE_EDITOR) && !setting.ViewersCanEdit {
|
||||
if !c.SignedInUser.HasRole(org.RoleEditor) && !setting.ViewersCanEdit {
|
||||
accessForbidden(c)
|
||||
}
|
||||
}
|
||||
|
||||
func RoleAuth(roles ...models.RoleType) web.Handler {
|
||||
func RoleAuth(roles ...org.RoleType) web.Handler {
|
||||
return func(c *models.ReqContext) {
|
||||
ok := false
|
||||
for _, role := range roles {
|
||||
@ -136,11 +137,11 @@ func Auth(options *AuthOptions) web.Handler {
|
||||
// are otherwise only available to admins.
|
||||
func AdminOrEditorAndFeatureEnabled(enabled bool) web.Handler {
|
||||
return func(c *models.ReqContext) {
|
||||
if c.OrgRole == models.ROLE_ADMIN {
|
||||
if c.OrgRole == org.RoleAdmin {
|
||||
return
|
||||
}
|
||||
|
||||
if c.OrgRole == models.ROLE_EDITOR && enabled {
|
||||
if c.OrgRole == org.RoleEditor && enabled {
|
||||
return
|
||||
}
|
||||
|
||||
@ -194,7 +195,7 @@ func shouldForceLogin(c *models.ReqContext) bool {
|
||||
|
||||
func OrgAdminDashOrFolderAdminOrTeamAdmin(ss sqlstore.Store, ds dashboards.DashboardService) func(c *models.ReqContext) {
|
||||
return func(c *models.ReqContext) {
|
||||
if c.OrgRole == models.ROLE_ADMIN {
|
||||
if c.OrgRole == org.RoleAdmin {
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user