|
|
@ -24,8 +24,6 @@ use yii\base\InvalidParamException; |
|
|
|
* the three tables used to store the authorization data by setting [[itemTable]], |
|
|
|
* the three tables used to store the authorization data by setting [[itemTable]], |
|
|
|
* [[itemChildTable]] and [[assignmentTable]]. |
|
|
|
* [[itemChildTable]] and [[assignmentTable]]. |
|
|
|
* |
|
|
|
* |
|
|
|
* @property array $authItems The authorization items of the specific type. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @author Qiang Xue <qiang.xue@gmail.com> |
|
|
|
* @author Qiang Xue <qiang.xue@gmail.com> |
|
|
|
* @author Alexander Kochetov <creocoder@gmail.com> |
|
|
|
* @author Alexander Kochetov <creocoder@gmail.com> |
|
|
|
* @since 2.0 |
|
|
|
* @since 2.0 |
|
|
@ -106,13 +104,13 @@ class DbManager extends Manager |
|
|
|
if (!isset($params['userId'])) { |
|
|
|
if (!isset($params['userId'])) { |
|
|
|
$params['userId'] = $userId; |
|
|
|
$params['userId'] = $userId; |
|
|
|
} |
|
|
|
} |
|
|
|
if ($this->executeBizRule($item->getBizRule(), $params, $item->getData())) { |
|
|
|
if ($this->executeBizRule($item->bizRule, $params, $item->data)) { |
|
|
|
if (in_array($itemName, $this->defaultRoles)) { |
|
|
|
if (in_array($itemName, $this->defaultRoles)) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
if (isset($assignments[$itemName])) { |
|
|
|
if (isset($assignments[$itemName])) { |
|
|
|
$assignment = $assignments[$itemName]; |
|
|
|
$assignment = $assignments[$itemName]; |
|
|
|
if ($this->executeBizRule($assignment->getBizRule(), $params, $assignment->getData())) { |
|
|
|
if ($this->executeBizRule($assignment->bizRule, $params, $assignment->data)) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -207,7 +205,7 @@ class DbManager extends Manager |
|
|
|
public function getItemChildren($names) |
|
|
|
public function getItemChildren($names) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$query = new Query; |
|
|
|
$query = new Query; |
|
|
|
$rows = $query->select(array('name', 'type', 'description', 'bizrule', 'data')) |
|
|
|
$rows = $query->select(array('name', 'type', 'description', 'biz_rule', 'data')) |
|
|
|
->from(array($this->itemTable, $this->itemChildTable)) |
|
|
|
->from(array($this->itemTable, $this->itemChildTable)) |
|
|
|
->where(array('parent' => $names, 'name' => new Expression('child'))) |
|
|
|
->where(array('parent' => $names, 'name' => new Expression('child'))) |
|
|
|
->createCommand($this->db) |
|
|
|
->createCommand($this->db) |
|
|
@ -217,7 +215,14 @@ class DbManager extends Manager |
|
|
|
if (($data = @unserialize($row['data'])) === false) { |
|
|
|
if (($data = @unserialize($row['data'])) === false) { |
|
|
|
$data = null; |
|
|
|
$data = null; |
|
|
|
} |
|
|
|
} |
|
|
|
$children[$row['name']] = new Item($this, $row['name'], $row['type'], $row['description'], $row['bizrule'], $data); |
|
|
|
$children[$row['name']] = new Item(array( |
|
|
|
|
|
|
|
'manager' => $this, |
|
|
|
|
|
|
|
'name' => $row['name'], |
|
|
|
|
|
|
|
'type' => $row['type'], |
|
|
|
|
|
|
|
'description' => $row['description'], |
|
|
|
|
|
|
|
'bizRule' => $row['biz_rule'], |
|
|
|
|
|
|
|
'data' => $data, |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
return $children; |
|
|
|
return $children; |
|
|
|
} |
|
|
|
} |
|
|
@ -241,10 +246,16 @@ class DbManager extends Manager |
|
|
|
->insert($this->assignmentTable, array( |
|
|
|
->insert($this->assignmentTable, array( |
|
|
|
'user_id' => $userId, |
|
|
|
'user_id' => $userId, |
|
|
|
'item_name' => $itemName, |
|
|
|
'item_name' => $itemName, |
|
|
|
'bizrule' => $bizRule, |
|
|
|
'biz_rule' => $bizRule, |
|
|
|
'data' => serialize($data), |
|
|
|
'data' => serialize($data), |
|
|
|
)); |
|
|
|
)); |
|
|
|
return new Assignment($this, $userId, $itemName, $bizRule, $data); |
|
|
|
return new Assignment(array( |
|
|
|
|
|
|
|
'manager' => $this, |
|
|
|
|
|
|
|
'userId' => $userId, |
|
|
|
|
|
|
|
'itemName' => $itemName, |
|
|
|
|
|
|
|
'bizRule' => $bizRule, |
|
|
|
|
|
|
|
'data' => $data, |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -293,7 +304,13 @@ class DbManager extends Manager |
|
|
|
if (($data = @unserialize($row['data'])) === false) { |
|
|
|
if (($data = @unserialize($row['data'])) === false) { |
|
|
|
$data = null; |
|
|
|
$data = null; |
|
|
|
} |
|
|
|
} |
|
|
|
return new Assignment($this, $row['user_id'], $row['item_name'], $row['bizrule'], $data); |
|
|
|
return new Assignment(array( |
|
|
|
|
|
|
|
'manager' => $this, |
|
|
|
|
|
|
|
'userId' => $row['user_id'], |
|
|
|
|
|
|
|
'itemName' => $row['item_name'], |
|
|
|
|
|
|
|
'bizRule' => $row['biz_rule'], |
|
|
|
|
|
|
|
'data' => $data, |
|
|
|
|
|
|
|
)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
@ -317,7 +334,13 @@ class DbManager extends Manager |
|
|
|
if (($data = @unserialize($row['data'])) === false) { |
|
|
|
if (($data = @unserialize($row['data'])) === false) { |
|
|
|
$data = null; |
|
|
|
$data = null; |
|
|
|
} |
|
|
|
} |
|
|
|
$assignments[$row['item_name']] = new Assignment($this, $row['user_id'], $row['item_name'], $row['bizrule'], $data); |
|
|
|
$assignments[$row['item_name']] = new Assignment(array( |
|
|
|
|
|
|
|
'manager' => $this, |
|
|
|
|
|
|
|
'userId' => $row['user_id'], |
|
|
|
|
|
|
|
'itemName' => $row['item_name'], |
|
|
|
|
|
|
|
'bizRule' => $row['biz_rule'], |
|
|
|
|
|
|
|
'data' => $data, |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
return $assignments; |
|
|
|
return $assignments; |
|
|
|
} |
|
|
|
} |
|
|
@ -330,11 +353,11 @@ class DbManager extends Manager |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->db->createCommand() |
|
|
|
$this->db->createCommand() |
|
|
|
->update($this->assignmentTable, array( |
|
|
|
->update($this->assignmentTable, array( |
|
|
|
'bizrule' => $assignment->getBizRule(), |
|
|
|
'biz_rule' => $assignment->bizRule, |
|
|
|
'data' => serialize($assignment->getData()), |
|
|
|
'data' => serialize($assignment->data), |
|
|
|
), array( |
|
|
|
), array( |
|
|
|
'user_id' => $assignment->getUserId(), |
|
|
|
'user_id' => $assignment->userId, |
|
|
|
'item_name' => $assignment->getItemName(), |
|
|
|
'item_name' => $assignment->itemName, |
|
|
|
)); |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -357,12 +380,12 @@ class DbManager extends Manager |
|
|
|
->where(array('type' => $type)) |
|
|
|
->where(array('type' => $type)) |
|
|
|
->createCommand($this->db); |
|
|
|
->createCommand($this->db); |
|
|
|
} elseif ($type === null) { |
|
|
|
} elseif ($type === null) { |
|
|
|
$command = $query->select(array('name', 'type', 'description', 't1.bizrule', 't1.data')) |
|
|
|
$command = $query->select(array('name', 'type', 'description', 't1.biz_rule', 't1.data')) |
|
|
|
->from(array($this->itemTable . ' t1', $this->assignmentTable . ' t2')) |
|
|
|
->from(array($this->itemTable . ' t1', $this->assignmentTable . ' t2')) |
|
|
|
->where(array('user_id' => $userId, 'name' => new Expression('item_name'))) |
|
|
|
->where(array('user_id' => $userId, 'name' => new Expression('item_name'))) |
|
|
|
->createCommand($this->db); |
|
|
|
->createCommand($this->db); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$command = $query->select('name', 'type', 'description', 't1.bizrule', 't1.data') |
|
|
|
$command = $query->select('name', 'type', 'description', 't1.biz_rule', 't1.data') |
|
|
|
->from(array($this->itemTable . ' t1', $this->assignmentTable . ' t2')) |
|
|
|
->from(array($this->itemTable . ' t1', $this->assignmentTable . ' t2')) |
|
|
|
->where(array('user_id' => $userId, 'type' => $type, 'name' => new Expression('item_name'))) |
|
|
|
->where(array('user_id' => $userId, 'type' => $type, 'name' => new Expression('item_name'))) |
|
|
|
->createCommand($this->db); |
|
|
|
->createCommand($this->db); |
|
|
@ -372,7 +395,14 @@ class DbManager extends Manager |
|
|
|
if (($data = @unserialize($row['data'])) === false) { |
|
|
|
if (($data = @unserialize($row['data'])) === false) { |
|
|
|
$data = null; |
|
|
|
$data = null; |
|
|
|
} |
|
|
|
} |
|
|
|
$items[$row['name']] = new Item($this, $row['name'], $row['type'], $row['description'], $row['bizrule'], $data); |
|
|
|
$items[$row['name']] = new Item(array( |
|
|
|
|
|
|
|
'manager' => $this, |
|
|
|
|
|
|
|
'name' => $row['name'], |
|
|
|
|
|
|
|
'type' => $row['type'], |
|
|
|
|
|
|
|
'description' => $row['description'], |
|
|
|
|
|
|
|
'bizRule' => $row['biz_rule'], |
|
|
|
|
|
|
|
'data' => $data, |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
return $items; |
|
|
|
return $items; |
|
|
|
} |
|
|
|
} |
|
|
@ -399,10 +429,17 @@ class DbManager extends Manager |
|
|
|
'name' => $name, |
|
|
|
'name' => $name, |
|
|
|
'type' => $type, |
|
|
|
'type' => $type, |
|
|
|
'description' => $description, |
|
|
|
'description' => $description, |
|
|
|
'bizrule' => $bizRule, |
|
|
|
'biz_rule' => $bizRule, |
|
|
|
'data' => serialize($data), |
|
|
|
'data' => serialize($data), |
|
|
|
)); |
|
|
|
)); |
|
|
|
return new Item($this, $name, $type, $description, $bizRule, $data); |
|
|
|
return new Item(array( |
|
|
|
|
|
|
|
'manager' => $this, |
|
|
|
|
|
|
|
'name' => $name, |
|
|
|
|
|
|
|
'type' => $type, |
|
|
|
|
|
|
|
'description' => $description, |
|
|
|
|
|
|
|
'bizRule' => $bizRule, |
|
|
|
|
|
|
|
'data' => $data, |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -439,7 +476,14 @@ class DbManager extends Manager |
|
|
|
if (($data = @unserialize($row['data'])) === false) { |
|
|
|
if (($data = @unserialize($row['data'])) === false) { |
|
|
|
$data = null; |
|
|
|
$data = null; |
|
|
|
} |
|
|
|
} |
|
|
|
return new Item($this, $row['name'], $row['type'], $row['description'], $row['bizrule'], $data); |
|
|
|
return new Item(array( |
|
|
|
|
|
|
|
'manager' => $this, |
|
|
|
|
|
|
|
'name' => $row['name'], |
|
|
|
|
|
|
|
'type' => $row['type'], |
|
|
|
|
|
|
|
'description' => $row['description'], |
|
|
|
|
|
|
|
'bizRule' => $row['biz_rule'], |
|
|
|
|
|
|
|
'data' => $data, |
|
|
|
|
|
|
|
)); |
|
|
|
} else |
|
|
|
} else |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
@ -463,10 +507,10 @@ class DbManager extends Manager |
|
|
|
$this->db->createCommand() |
|
|
|
$this->db->createCommand() |
|
|
|
->update($this->itemTable, array( |
|
|
|
->update($this->itemTable, array( |
|
|
|
'name' => $item->getName(), |
|
|
|
'name' => $item->getName(), |
|
|
|
'type' => $item->getType(), |
|
|
|
'type' => $item->type, |
|
|
|
'description' => $item->getDescription(), |
|
|
|
'description' => $item->description, |
|
|
|
'bizrule' => $item->getBizRule(), |
|
|
|
'biz_rule' => $item->bizRule, |
|
|
|
'data' => serialize($item->getData()), |
|
|
|
'data' => serialize($item->data), |
|
|
|
), array( |
|
|
|
), array( |
|
|
|
'name' => $oldName === null ? $item->getName() : $oldName, |
|
|
|
'name' => $oldName === null ? $item->getName() : $oldName, |
|
|
|
)); |
|
|
|
)); |
|
|
|