feat: support RBAC model in permission (#1006)

Signed-off-by: Yixiang Zhao <seriouszyx@foxmail.com>

Signed-off-by: Yixiang Zhao <seriouszyx@foxmail.com>
This commit is contained in:
Yixiang Zhao
2022-08-15 10:24:26 +08:00
committed by GitHub
parent ba732b3075
commit dfbf7753c3
7 changed files with 104 additions and 9 deletions

View File

@ -29,6 +29,7 @@ type Role struct {
Users []string `xorm:"mediumtext" json:"users"`
Roles []string `xorm:"mediumtext" json:"roles"`
Domains []string `xorm:"mediumtext" json:"domains"`
IsEnabled bool `json:"isEnabled"`
}
@ -88,7 +89,8 @@ func GetRole(id string) *Role {
func UpdateRole(id string, role *Role) bool {
owner, name := util.GetOwnerAndNameFromId(id)
if getRole(owner, name) == nil {
oldRole := getRole(owner, name)
if oldRole == nil {
return false
}
@ -97,6 +99,11 @@ func UpdateRole(id string, role *Role) bool {
panic(err)
}
if affected != 0 {
removeGroupingPolicies(oldRole)
addGroupingPolicies(role)
}
return affected != 0
}
@ -106,6 +113,10 @@ func AddRole(role *Role) bool {
panic(err)
}
if affected != 0 {
addGroupingPolicies(role)
}
return affected != 0
}
@ -115,6 +126,10 @@ func DeleteRole(role *Role) bool {
panic(err)
}
if affected != 0 {
removeGroupingPolicies(role)
}
return affected != 0
}