fix: (rbac) create es role

This commit is contained in:
xushuhui 2022-04-21 18:36:40 +08:00
parent 231e174aff
commit 006e162523
2 changed files with 24 additions and 15 deletions

View File

@ -39,10 +39,10 @@ type MenuPermission struct {
Privilege string `json:"privilege"`
}
type ElasticsearchRole struct {
Name string `json:"name"`
Description string `json:"description" `
RoleType string `json:"type" `
Permission interface{} `json:"permission"`
Name string `json:"name"`
Description string `json:"description" `
RoleType string `json:"type" `
rbac.ElasticRole
}
func NewRole(typ string) (r IRole, err error) {
@ -132,8 +132,10 @@ func (role ElasticsearchRole) Create(localUser *User) (id string, err error) {
Name: role.Name,
Description: role.Description,
RoleType: role.RoleType,
Permission: role.Permission,
}
newRole.Cluster = role.Cluster
newRole.Index = role.Index
newRole.ClusterPrivilege = role.ClusterPrivilege
newRole.ID = util.GetUUID()
newRole.Created = time.Now()
newRole.Updated = time.Now()
@ -151,10 +153,10 @@ func (role ElasticsearchRole) Create(localUser *User) (id string, err error) {
"id": id,
"name": role.Name,
"description": role.Description,
"permission": role.Permission,
"type": role.RoleType,
"created": newRole.Created.Format("2006-01-02 15:04:05"),
"updated": newRole.Updated.Format("2006-01-02 15:04:05"),
"type": role.RoleType,
"created": newRole.Created.Format("2006-01-02 15:04:05"),
"updated": newRole.Updated.Format("2006-01-02 15:04:05"),
},
User: util.MapStr{
"userid": localUser.UserId,

View File

@ -9,8 +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" elastic_mapping:"permission:{type:object}"`
Permission interface{} `json:"permission,omitempty" elastic_mapping:"permission:{type:object}"`
BuiltIn bool `json:"builtin" elastic_mapping:"builtin:{type:boolean}"` //是否内置
ElasticRole
}
type ConsolePermission struct {
Api []string `json:"api"`
@ -22,9 +23,15 @@ type Menu struct {
Name string `json:"name"`
Privilege string `json:"privilege"`
}
type ElasticsearchPermission struct {
Cluster []string `json:"cluster" elastic_mapping:"cluster:{type:object}"`
Index []string `json:"index" elastic_mapping:"index:{type:object}"`
ClusterPrivilege []string `json:"cluster_privilege" elastic_mapping:"cluster_privilege:{type:object}"`
IndexPrivilege []string `json:"index_privilege" elastic_mapping:"index_privilege:{type:object}"`
type ElasticRole struct {
Cluster []struct {
Id string `json:"id"`
Name string `json:"name"`
} `json:"cluster,omitempty"`
ClusterPrivilege []map[string][]string `json:"cluster_privilege,omitempty"`
Index []struct {
Name []string `json:"name"`
Privilege []string `json:"privilege"`
} `json:"index,omitempty"`
}