I'm trying to query some models but it has to filter out based on some permissions
The permission table is as follows:
id, user_id, role_id, action, resource_type, resource_id, allow
- Either user_id or role_id exists
For example
user_id, role_id, action, resource_type, resource_id, allow
1 null , project.view, App\Models\Project 1 true
This indicates that the user "1" can view the project (therefore should be included in the query).
The system makes this exception : If the user has allow set to true nomatter what the role says, it should be granted this permission. For example:
user_id, role_id, action, resource_type, resource_id, allow
1 null , project.view, App\Models\Project 1 true
null 1 , project.view, App\Models\Project 1 false
Assuming user 1 has role 1, he would still be granted access since it is being overridden on the user.
However:
user_id, role_id, action, resource_type, resource_id, allow
1 null , project.view, App\Models\Project 1 false
null 1 , project.view, App\Models\Project 1 true
he would not be granted access since it is being overridden on the user.
Whenever a user permission is missing, it is assumed to grab it from the role. So in the following case:
user_id, role_id, action, resource_type, resource_id, allow
null 1 , project.view, App\Models\Project 1 true
It is allowed for any user in the role 1 to see the project 1.
(continued in comment)