/** * @return bool */ public function updatePermission() { if ($this->validate()) { $permission = $this->authManager->getPermission($this->name); $permission->description = $this->description; return $this->authManager->update($this->name, $permission); } return false; }
/** * Save role to [[\yii\rbac\authManager]] * * @return bool */ public function save() { if ($this->validate()) { if ($this->_item === null) { if ($this->type == Item::TYPE_ROLE) { $this->_item = $this->manager->createRole($this->name); } else { $this->_item = $this->manager->createPermission($this->name); } $isNew = true; $oldName = false; } else { $isNew = false; $oldName = $this->_item->name; } $this->_item->name = $this->name; $this->_item->description = $this->description; $this->_item->ruleName = $this->ruleName; $this->_item->data = Json::decode($this->data); if ($isNew) { $this->manager->add($this->_item); } else { $this->manager->update($oldName, $this->_item); } return true; } return false; }
public function testUpdateRule() { $this->prepareData(); $rule = $this->auth->getRule('isAuthor'); $rule->name = "newName"; $rule->reallyReally = false; $this->auth->update('isAuthor', $rule); $rule = $this->auth->getRule('isAuthor'); $this->assertEquals(null, $rule); $rule = $this->auth->getRule('newName'); $this->assertEquals("newName", $rule->name); $this->assertEquals(false, $rule->reallyReally); $rule->reallyReally = true; $this->auth->update('newName', $rule); $rule = $this->auth->getRule('newName'); $this->assertEquals(true, $rule->reallyReally); }
public function actionView($name) { $role = $this->findRole($name); if (Yii::$app->request->isPost) { $rule = Yii::$app->request->post('rule'); $role->ruleName = $rule ? $rule : null; $role->description = Yii::$app->request->post('desc'); $role->data = Yii::$app->request->post('data'); $this->auth->update($name, $role); return $this->redirect(['view', 'name' => $role->name]); } return $this->render('view', ['model' => $role]); }
/** * @param bool $validate * @return bool */ public function save($validate = true) { if ($validate && !$this->validate()) { return false; } if ($this->isNewRecord) { $this->role = $this->auth->createRole($this->name); $this->role->description = $this->description; if (!$this->auth->add($this->role)) { return false; } } else { $this->role->name = $this->name; $this->role->description = $this->description; if (!$this->auth->update($this->oldName, $this->role)) { return false; } $this->auth->removeChildren($this->role); } foreach ($this->actions as $action) { $this->auth->addChild($this->role, $this->auth->getPermission($action)); } return true; }
/** * @param string $name * @param array $permissions * @param array $roles * @return bool */ public function updateRole($name, array $permissions, array $roles) { if ($this->validate()) { $object = $this->authManager->getRole($name); $object->description = $this->description; if ($this->authManager->update($name, $object)) { $this->authManager->removeChildren($object); foreach ($permissions as $permission) { $this->authManager->addChild($object, $this->authManager->getPermission($permission)); } foreach ($roles as $role) { $this->authManager->addChild($object, $this->authManager->getRole($role)); } return true; } } return false; }
/** * Save rule * * @return bool */ public function save() { if ($this->validate()) { $class = $this->className; if ($this->_item === null) { $this->_item = new $class(); $isNew = true; $oldName = false; } else { $isNew = false; $oldName = $this->_item->name; } $this->_item->name = $this->name; if ($isNew) { $this->manager->add($this->_item); } else { $this->manager->update($oldName, $this->_item); } return true; } return false; }