yii rbac acf multiple roles and params

260 Views Asked by At

So I have an action which I need multiple permissions to have access to.

(for example manageUsers (admin) and manageCompanyUsers (company manager))

access behaviour in controller has rule like:

'allow' => true,
'actions' => ['index'],
'roles' => [
   'manageUsers',
   'manageCompanyUsers'
],
'roleParams' => ['company' => 'some id']

1) how do I pass different params for different roles in it? (with this code it passes company to manageCompanyUsers anyway)

2) how can I make sure that if manageUsers is a child of manageCompanyUsers and user has manageUsers assigned directly to not trigger manageCompanyUsers rules (it triggers now)

1

There are 1 best solutions below

0
On

Make several rules with different params and roles applied to each:

[ //rule1
  'allow' => true,
  'actions' => ['index'],
  'roles' => [
     'manageUsers',
  ],
  'roleParams' => ['company' => 'some id']
],
[ //rule2
  'allow' => true,
  'actions' => ['index'],
  'roles' => [
     'manageCompanyUsers',
  ],
  'roleParams' => ['some' => 'other id']
],