Reputation: 359
I am trying to create custom rule for my Yii2 app, but I there is some kind of problem when I run migration. This is how my migration looks:
$manager = $auth->createRole('manager');
$auth->add($manager);
//Allow manager to create work items for own employees.
$manager_rule = new ManagerRule();
$auth->add($manager_rule);
$create_employee_work_item = $auth->createPermission('create_employee_work_item');
$create_employee_work_item->description = 'Create employee work item';
$create_employee_work_item->ruleName = $manager_rule->name;
$auth->add($create_employee_work_item);
$auth->addChild($manager, $create_employee_work_item);
Code from ManagerRule class:
namespace app\rbac;
use yii\rbac\Rule;
class ManagerRule extends Rule
{
public $name = 'isManagerOf';
public function execute($user, $item, $params)
{
return isset($params['user']) ? $params['user']->manager_id === $user : false;
}
}
And when I try to do migration, I have this error.
This happens here $auth->add($create_employee_work_item);
Then I noticed something weird in my auth_rule table.
I beleive that hex at data column is creating problems, and im not sure that data should be stored in hex format there. Any ideas how to solve it?
I use MSSQL as my DB.
Upvotes: 1
Views: 98
Reputation: 359
The problem was in initial RBAC migration file m140506_102106_rbac_init.php
I found that auth_item.data column type was binary:
$this->createTable($authManager->ruleTable, [
'name' => $this->string(64)->notNull(),
'data' => $this->binary(),
'created_at' => $this->integer(),
'updated_at' => $this->integer(),
'PRIMARY KEY ([[name]])',
], $tableOptions);
So I changed it to text:
'data' => $this->text(),
Upvotes: 1