mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
feat: implement access control using casbin (#806)
* feat: implement access control using casbin Signed-off-by: Yixiang Zhao <seriouszyx@foxmail.com> * chore: sort imports Signed-off-by: Yixiang Zhao <seriouszyx@foxmail.com> * fix: remove Signed-off-by: Yixiang Zhao <seriouszyx@foxmail.com> * Update auth.go Co-authored-by: Gucheng <85475922+nomeguy@users.noreply.github.com>
This commit is contained in:
@ -229,4 +229,21 @@ func CheckUserPermission(requestUserId, userId string, strict bool) (bool, error
|
||||
}
|
||||
|
||||
return hasPermission, fmt.Errorf("you don't have the permission to do this")
|
||||
}
|
||||
|
||||
func CheckPermission(userId string, application *Application) (bool, error) {
|
||||
permissions := GetPermissions(application.Organization)
|
||||
allow := true
|
||||
var err error
|
||||
for _, permission := range permissions {
|
||||
if permission.IsEnabled {
|
||||
for _, resource := range permission.Resources {
|
||||
if resource == application.Name {
|
||||
enforcer := getEnforcer(permission)
|
||||
allow, err = enforcer.Enforce(userId, application.Name, "read")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return allow, err
|
||||
}
|
Reference in New Issue
Block a user