提交 1ffdf3d2 编写于 作者: U Ulric Qin

bugfix: AdminRole

上级 94a49c17
......@@ -2,7 +2,7 @@
NOW = $(shell date -u '+%Y%m%d%I%M%S')
RELEASE_VERSION = 5.4.0
RELEASE_VERSION = 5.4.1
APP = n9e
SERVER_BIN = $(APP)
......
......@@ -7,6 +7,8 @@ import (
"github.com/didi/nightingale/v5/src/storage"
)
const AdminRole = "Admin"
func DB() *gorm.DB {
return storage.DB
}
......
package models
import (
"github.com/didi/nightingale/v5/src/webapi/config"
"github.com/toolkits/pkg/slice"
)
......@@ -25,7 +24,7 @@ func RoleHasOperation(roles []string, operation string) (bool, error) {
func OperationsOfRole(roles []string) ([]string, error) {
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)
}
......
......@@ -40,7 +40,7 @@ func (u *User) TableName() string {
func (u *User) IsAdmin() bool {
for i := 0; i < len(u.RolesLst); i++ {
if u.RolesLst[i] == config.C.AdminRole {
if u.RolesLst[i] == AdminRole {
return true
}
}
......
......@@ -169,7 +169,7 @@ func admin() gin.HandlerFunc {
roles := strings.Fields(user.Roles)
found := false
for i := 0; i < len(roles); i++ {
if roles[i] == config.C.AdminRole {
if roles[i] == models.AdminRole {
found = true
break
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册