getParentRolePermissions 获取父角色权限
(role *Role)
| 795 | |
| 796 | // getParentRolePermissions 获取父角色权限 |
| 797 | func (ac *AccessController) getParentRolePermissions(role *Role) []string { |
| 798 | var permissions []string |
| 799 | |
| 800 | for _, parentID := range role.Parents { |
| 801 | if parentRole, exists := ac.roles[parentID]; exists { |
| 802 | // 获取父角色的直接权限 |
| 803 | permissions = append(permissions, parentRole.Permissions...) |
| 804 | |
| 805 | // 递归获取祖先角色的权限 |
| 806 | ancestorPermissions := ac.getParentRolePermissions(parentRole) |
| 807 | permissions = append(permissions, ancestorPermissions...) |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | return permissions |
| 812 | } |
| 813 | |
| 814 | // checkPermissionList 检查权限列表 |
| 815 | func (ac *AccessController) checkPermissionList(permissionIDs []string, resource, action string, context map[string]any) bool { |