bugfix: AdminRole

This commit is contained in:
Ulric Qin 2022-03-07 18:19:19 +08:00
parent 94a49c17f7
commit 1ffdf3d283
5 changed files with 6 additions and 5 deletions

View File

@ -2,7 +2,7 @@
NOW = $(shell date -u '+%Y%m%d%I%M%S') NOW = $(shell date -u '+%Y%m%d%I%M%S')
RELEASE_VERSION = 5.4.0 RELEASE_VERSION = 5.4.1
APP = n9e APP = n9e
SERVER_BIN = $(APP) SERVER_BIN = $(APP)

View File

@ -7,6 +7,8 @@ import (
"github.com/didi/nightingale/v5/src/storage" "github.com/didi/nightingale/v5/src/storage"
) )
const AdminRole = "Admin"
func DB() *gorm.DB { func DB() *gorm.DB {
return storage.DB return storage.DB
} }

View File

@ -1,7 +1,6 @@
package models package models
import ( import (
"github.com/didi/nightingale/v5/src/webapi/config"
"github.com/toolkits/pkg/slice" "github.com/toolkits/pkg/slice"
) )
@ -25,7 +24,7 @@ func RoleHasOperation(roles []string, operation string) (bool, error) {
func OperationsOfRole(roles []string) ([]string, error) { func OperationsOfRole(roles []string) ([]string, error) {
session := DB().Model(&RoleOperation{}).Select("distinct(operation) as operation") session := DB().Model(&RoleOperation{}).Select("distinct(operation) as operation")
if !slice.ContainsString(roles, config.C.AdminRole) { if !slice.ContainsString(roles, AdminRole) {
session = session.Where("role_name in ?", roles) session = session.Where("role_name in ?", roles)
} }

View File

@ -40,7 +40,7 @@ func (u *User) TableName() string {
func (u *User) IsAdmin() bool { func (u *User) IsAdmin() bool {
for i := 0; i < len(u.RolesLst); i++ { for i := 0; i < len(u.RolesLst); i++ {
if u.RolesLst[i] == config.C.AdminRole { if u.RolesLst[i] == AdminRole {
return true return true
} }
} }

View File

@ -169,7 +169,7 @@ func admin() gin.HandlerFunc {
roles := strings.Fields(user.Roles) roles := strings.Fields(user.Roles)
found := false found := false
for i := 0; i < len(roles); i++ { for i := 0; i < len(roles); i++ {
if roles[i] == config.C.AdminRole { if roles[i] == models.AdminRole {
found = true found = true
break break
} }