Esempio n. 1
0
 /**
  * @return bool
  */
 public function load()
 {
     $_items = [];
     $items = $this->loadFromFile(Yii::getAlias($this->itemFile));
     $itemsMtime = @filemtime(Yii::getAlias($this->itemFile));
     $assignments = $this->loadFromFile(Yii::getAlias($this->assignmentFile));
     $rules = $this->loadFromFile(Yii::getAlias($this->ruleFile));
     foreach ($rules as $ruleData) {
         $this->addRule(unserialize($ruleData));
     }
     foreach ($items as $name => $item) {
         $class = $item['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className();
         $_items[$name] = new $class(['name' => $name, 'description' => isset($item['description']) ? $item['description'] : null, 'ruleName' => isset($item['ruleName']) ? $item['ruleName'] : null, 'data' => isset($item['data']) ? $item['data'] : null, 'createdAt' => $itemsMtime, 'updatedAt' => $itemsMtime]);
         $this->addItem($_items[$name]);
     }
     foreach ($items as $name => $item) {
         if (isset($item['children'])) {
             foreach ($item['children'] as $childName) {
                 if (isset($_items[$childName])) {
                     $this->addChild($_items[$name], $_items[$childName]);
                 }
             }
         }
     }
     foreach ($assignments as $userId => $role) {
         $this->assign($_items[$role], $userId);
     }
     return true;
 }
Esempio n. 2
0
 public function init()
 {
     $this->name = \Yii::t('app', "Управление привилегиями");
     $this->modelShowAttribute = "name";
     $this->modelPkAttribute = "name";
     $this->modelClassName = Permission::className();
     parent::init();
 }
Esempio n. 3
0
 protected function getHookPermissions()
 {
     if ($this->_hookPermissions != null) {
         return $this->_hookPermissions;
     }
     $parameters = Hook::trigger(\hass\rbac\Module::EVENT_RBAC_PERMISSION)->parameters;
     foreach ($parameters as $config) {
         foreach ($config['permissions'] as $name => $item) {
             $class = $item['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className();
             $this->_hookPermissions[$name] = new $class(['name' => $name, 'description' => isset($item['description']) ? $item['description'] : null, 'ruleName' => isset($item['ruleName']) ? $item['ruleName'] : null, 'data' => isset($item['data']) ? $item['data'] : null, 'createdAt' => null, 'updatedAt' => null]);
         }
     }
     return $this->_hookPermissions;
 }
 /**
  * Populates an auth item with the data fetched from database
  * @param array $row the data from the auth item table
  * @return Item the populated auth item instance (either Role or Permission)
  */
 protected function populateItem($row)
 {
     $class = $row['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className();
     if (!isset($row['data']) || ($data = @unserialize($row['data'])) === false) {
         $data = null;
     }
     return new $class(['name' => $row['name'], 'type' => $row['type'], 'description' => $row['description'], 'ruleName' => $row['rule_name'], 'data' => $data, 'createdAt' => $row['created_at'], 'updatedAt' => $row['updated_at']]);
 }
Esempio n. 5
0
 /**
  * Loads authorization data from persistent storage.
  */
 protected function load()
 {
     $this->children = [];
     $this->rules = [];
     $this->assignments = [];
     $this->items = [];
     $items = $this->loadFromFile($this->itemFile);
     $itemsMtime = @filemtime($this->itemFile);
     $assignments = $this->loadFromFile($this->assignmentFile);
     $assignmentsMtime = @filemtime($this->assignmentFile);
     $rules = $this->loadFromFile($this->ruleFile);
     foreach ($items as $name => $item) {
         $class = $item['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className();
         $this->items[$name] = new $class(['name' => $name, 'description' => isset($item['description']) ? $item['description'] : null, 'ruleName' => isset($item['ruleName']) ? $item['ruleName'] : null, 'data' => isset($item['data']) ? $item['data'] : null, 'createdAt' => $itemsMtime, 'updatedAt' => $itemsMtime]);
     }
     foreach ($items as $name => $item) {
         if (isset($item['children'])) {
             foreach ($item['children'] as $childName) {
                 if (isset($this->items[$childName])) {
                     $this->children[$name][$childName] = $this->items[$childName];
                 }
             }
         }
     }
     foreach ($assignments as $userId => $roles) {
         foreach ($roles as $role) {
             $this->assignments[$userId][$role] = new Assignment(['userId' => $userId, 'roleName' => $role, 'createdAt' => $assignmentsMtime]);
         }
     }
     foreach ($rules as $name => $ruleData) {
         $this->rules[$name] = unserialize($ruleData);
     }
 }
Esempio n. 6
0
 /**
  * @inheritdoc
  */
 public function getPermissions()
 {
     return $this->getItems($this->_permissionsConfig, Permission::className());
 }
Esempio n. 7
0
 protected function populateItem($row)
 {
     $class = $row['type'] == \matacms\rbac\Item::TYPE_PERMISSION ? \yii\rbac\Permission::className() : \matacms\rbac\Role::className();
     if (!isset($row['data']) || ($data = @unserialize($row['data'])) === false) {
         $data = null;
     }
     $children = $this->getChildren($row['name']);
     $item = new $class(['name' => $row['name'], 'type' => $row['type'], 'description' => $row['description'], 'ruleName' => $row['rule_name'], 'data' => $data, 'createdAt' => $row['created_at'], 'updatedAt' => $row['updated_at'], 'children' => $children]);
     return $item;
 }
Esempio n. 8
0
 /**
  * Loads authorization data from persistent storage.
  */
 public function load()
 {
     $this->_children = [];
     $this->_rules = [];
     $this->_assignments = [];
     $this->_items = [];
     $data = $this->loadFromFile($this->authFile);
     if (isset($data['items'])) {
         foreach ($data['items'] as $name => $item) {
             $class = $item['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className();
             $this->_items[$name] = new $class(['name' => $name, 'description' => isset($item['description']) ? $item['description'] : null, 'ruleName' => isset($item['ruleName']) ? $item['ruleName'] : null, 'data' => isset($item['data']) ? $item['data'] : null, 'createdAt' => isset($item['createdAt']) ? $item['createdAt'] : null, 'updatedAt' => isset($item['updatedAt']) ? $item['updatedAt'] : null]);
         }
         foreach ($data['items'] as $name => $item) {
             if (isset($item['children'])) {
                 foreach ($item['children'] as $childName) {
                     if (isset($this->_items[$childName])) {
                         $this->_children[$name][$childName] = $this->_items[$childName];
                     }
                 }
             }
             if (isset($item['assignments'])) {
                 foreach ($item['assignments'] as $userId => $assignment) {
                     $this->_assignments[$userId][$name] = new Assignment(['userId' => $userId, 'roleName' => $assignment['roleName'], 'createdAt' => isset($assignment['createdAt']) ? $assignment['createdAt'] : null]);
                 }
             }
         }
     }
     if (isset($data['rules'])) {
         foreach ($data['rules'] as $name => $ruleData) {
             $this->_rules[$name] = unserialize($ruleData);
         }
     }
 }