bugfix: AdminRole
This commit is contained in:
parent
94a49c17f7
commit
1ffdf3d283
2
Makefile
2
Makefile
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue