I have a use case where I need to assign a user the right to edit highly dynamic items, which can be in the hundreds or thousands. Each user, while belonging to the same type or group, must be assigned to some of these items (and different users may have access to the same Company Items). Furthermore, these items can rapidly grow in number or disappear. These items have no intrinsic relationship with the users, but must be arbitrarily assigned to them.
Lets call these items Company Items.
So, I want to be able to assign Company Items to users, and revoke that access dynamically. These assignments are then used inside controllers to check if some action can go on... Conceptually, the problem is always the same: test if a user has access to a specific item/row in a table, the Company Items' table.
My idea was to use the yii RBAC system, while trying to keep the authorization tree static, thus avoiding creating/deleting roles or tasks every time a Company Item is created or deleted. Instead, I was wondering If I could do this using the $data
parameter in assign($itemName, $userId, $bizRule, $data)
and a tree similar to the following:
- adminUser: role
- companyAdmin: role
- editCompanyItemRole: role with bizrule; bizrule tests access to Company Item by simply checking if
$params['companyItemId']
exists inside$data['companyItemsAllowed']
; at assignment time, should receive a$data
containing an array of Company Items' ids the user should be allowed to edit!- editItem: operation; used to check access in the Controllers, and should be provided with the Company Item id one wishes to check the user against, e.g.,
Yii::app()->user->checkAccess('editItem', array('companyItemId' => 666));
- editItem: operation; used to check access in the Controllers, and should be provided with the Company Item id one wishes to check the user against, e.g.,
- editCompanyItemRole: role with bizrule; bizrule tests access to Company Item by simply checking if
- companyAdmin: role
This way, whenever we need to change the user assignment to Company Items, the only thing we need to do is to alter the $data['companyItemsAllowed']
array inside the original assignment. The role is always the same!
Questions:
- Does this system work, can I use Yii's RBAC system in this fashion ??
- Is this the ideal way to accomplish the requirements, assuming we have thousands of Company Items, and we may have dozens of those assigned to each user ?? Why ??