feat: support groups in app login permissions (#2413)

* fix(permission): fix CheckLoginPermission() logic

* style: fix code format

---------

Co-authored-by: aidenlu <aiden_lu@wochacha.com>
This commit is contained in:
aiden 2023-10-17 01:35:13 -05:00 committed by GitHub
parent 2dd1dc582f
commit cbdeb91ee8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -370,7 +370,7 @@ func CheckLoginPermission(userId string, application *Application) (bool, error)
continue
}
if !permission.isUserHit(userId) {
if !permission.isUserHit(userId) && !permission.isRoleHit(userId) {
if permission.Effect == "Allow" {
allowPermissionCount += 1
} else {

View File

@ -434,6 +434,21 @@ func (p *Permission) isUserHit(name string) bool {
return false
}
func (p *Permission) isRoleHit(userId string) bool {
targetRoles, err := getRolesByUser(userId)
if err != nil {
return false
}
for _, role := range p.Roles {
for _, targetRole := range targetRoles {
if targetRole.GetId() == role {
return true
}
}
}
return false
}
func (p *Permission) isResourceHit(name string) bool {
for _, resource := range p.Resources {
if resource == "*" || resource == name {