fix: (rbac)
This commit is contained in:
parent
0c7d037e07
commit
a6f3c2203f
|
@ -25,6 +25,7 @@ type User struct {
|
|||
Username string `json:"username"`
|
||||
UserId string `json:"user_id"`
|
||||
Roles []string `json:"roles"`
|
||||
Privilege []string `json:"privilege"`
|
||||
}
|
||||
type Account struct {
|
||||
ID string `json:"id,omitempty" `
|
||||
|
|
|
@ -24,12 +24,11 @@ func init() {
|
|||
|
||||
UserMenu := Menu{
|
||||
Id: "system_user",
|
||||
Name: "用户管理",
|
||||
Privilege: "all",
|
||||
}
|
||||
RoleMenu := Menu{
|
||||
Id: "system_role",
|
||||
Name: "角色管理",
|
||||
|
||||
Privilege: "all",
|
||||
}
|
||||
AdminMenu := []Menu{
|
||||
|
|
|
@ -2,6 +2,6 @@ package enum
|
|||
|
||||
type Menu struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
||||
Privilege string `json:"privilege,omitempty"`
|
||||
}
|
||||
|
|
|
@ -21,18 +21,16 @@ const (
|
|||
)
|
||||
|
||||
type IRole interface {
|
||||
ListPermission() interface{}
|
||||
Create(localUser *User) (id string, err error)
|
||||
//Delete(localUser *User, id string) (err error)
|
||||
}
|
||||
type ConsoleRole struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description" `
|
||||
RoleType string `json:"type" `
|
||||
Permission Permission `json:"permission"`
|
||||
}
|
||||
type Permission struct {
|
||||
Menu []MenuPermission `json:"menu"`
|
||||
Platform []string `json:"platform,omitempty"`
|
||||
}
|
||||
|
||||
type MenuPermission struct {
|
||||
Id string `json:"id"`
|
||||
Privilege string `json:"privilege"`
|
||||
|
@ -82,7 +80,7 @@ func (role ConsoleRole) Create(localUser *User) (id string, err error) {
|
|||
Name: role.Name,
|
||||
Description: role.Description,
|
||||
RoleType: role.RoleType,
|
||||
Permission: role.Permission,
|
||||
Platform: role.Platform,
|
||||
}
|
||||
newRole.ID = util.GetUUID()
|
||||
newRole.Created = time.Now()
|
||||
|
@ -101,7 +99,7 @@ func (role ConsoleRole) Create(localUser *User) (id string, err error) {
|
|||
"id": id,
|
||||
"name": role.Name,
|
||||
"description": role.Description,
|
||||
"permission": role.Permission,
|
||||
"platform": role.Platform,
|
||||
"type": role.RoleType,
|
||||
"created": newRole.Created.Format("2006-01-02 15:04:05"),
|
||||
"updated": newRole.Updated.Format("2006-01-02 15:04:05"),
|
||||
|
@ -136,7 +134,7 @@ func (role ElasticsearchRole) Create(localUser *User) (id string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
newRole := rbac.Role{
|
||||
newRole := rbac.ElasticRole{
|
||||
Name: role.Name,
|
||||
Description: role.Description,
|
||||
RoleType: role.RoleType,
|
||||
|
@ -205,7 +203,7 @@ func DeleteRole(localUser *User, id string) (err error) {
|
|||
"id": id,
|
||||
"name": role.Name,
|
||||
"description": role.Description,
|
||||
"permission": role.Permission,
|
||||
"platform": role.Platform,
|
||||
"type": role.RoleType,
|
||||
"created": role.Created.Format("2006-01-02 15:04:05"),
|
||||
"updated": role.Updated.Format("2006-01-02 15:04:05"),
|
||||
|
@ -224,7 +222,7 @@ func UpdateRole(localUser *User, id string, req dto.UpdateConsoleRole) (err erro
|
|||
}
|
||||
changeLog, _ := util.DiffTwoObject(role, req)
|
||||
role.Description = req.Description
|
||||
role.Permission = req.Permission
|
||||
role.Platform = req.Platform
|
||||
role.Updated = time.Now()
|
||||
err = orm.Save(role)
|
||||
if err != nil {
|
||||
|
@ -238,7 +236,7 @@ func UpdateRole(localUser *User, id string, req dto.UpdateConsoleRole) (err erro
|
|||
Labels: util.MapStr{
|
||||
"id": id,
|
||||
"description": role.Description,
|
||||
"permission": role.Permission,
|
||||
"platform": role.Platform,
|
||||
"updated": role.Updated,
|
||||
},
|
||||
User: util.MapStr{
|
||||
|
|
|
@ -11,7 +11,7 @@ type Menu struct {
|
|||
}
|
||||
type UpdateConsoleRole struct {
|
||||
Description string `json:"description" `
|
||||
Permission RolePermission `json:"permission"`
|
||||
Platform []string `json:"platform"`
|
||||
}
|
||||
type CreateEsRole struct {
|
||||
Name string `json:"name"`
|
||||
|
|
|
@ -9,9 +9,9 @@ type Role struct {
|
|||
Name string `json:"name" elastic_mapping:"name:{type:keyword}"`
|
||||
Description string `json:"description" elastic_mapping:"description:{type:text}"`
|
||||
RoleType string `json:"type" elastic_mapping:"type:{type:keyword}"`
|
||||
Permission interface{} `json:"permission,omitempty" elastic_mapping:"permission:{type:object}"`
|
||||
Platform []string `json:"platform,omitempty" `
|
||||
BuiltIn bool `json:"builtin" elastic_mapping:"builtin:{type:boolean}"` //是否内置
|
||||
ElasticRole
|
||||
|
||||
}
|
||||
type ConsolePermission struct {
|
||||
Api []string `json:"api"`
|
||||
|
@ -25,6 +25,11 @@ type Menu struct {
|
|||
}
|
||||
|
||||
type ElasticRole struct {
|
||||
orm.ORMObjectBase
|
||||
Name string `json:"name" elastic_mapping:"name:{type:keyword}"`
|
||||
Description string `json:"description" elastic_mapping:"description:{type:text}"`
|
||||
RoleType string `json:"type" elastic_mapping:"type:{type:keyword}"`
|
||||
BuiltIn bool `json:"builtin" elastic_mapping:"builtin:{type:boolean}"` //是否内置
|
||||
Cluster []struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package rbac
|
||||
|
||||
import (
|
||||
log "github.com/cihub/seelog"
|
||||
"infini.sh/console/internal/biz"
|
||||
httprouter "infini.sh/framework/core/api/router"
|
||||
"net/http"
|
||||
)
|
||||
|
@ -10,19 +8,19 @@ import (
|
|||
func (h Rbac) ListPermission(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
typ := ps.MustGetParameter("type")
|
||||
|
||||
err := biz.IsAllowRoleType(typ)
|
||||
if err != nil {
|
||||
h.Error400(w, err.Error())
|
||||
return
|
||||
}
|
||||
role, err := biz.NewRole(typ)
|
||||
//err := biz.IsAllowRoleType(typ)
|
||||
//if err != nil {
|
||||
// h.Error400(w, err.Error())
|
||||
// return
|
||||
//}
|
||||
//role, err := biz.NewRole(typ)
|
||||
//
|
||||
//if err != nil {
|
||||
// _ = log.Error(err.Error())
|
||||
// h.Error(w, err)
|
||||
// return
|
||||
//}
|
||||
|
||||
if err != nil {
|
||||
_ = log.Error(err.Error())
|
||||
h.Error(w, err)
|
||||
return
|
||||
}
|
||||
permissions := role.ListPermission()
|
||||
h.WriteOKJSON(w, permissions)
|
||||
h.WriteOKJSON(w, typ)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue