Example #1
0
 /**
  * Displays a form for updating the item with the given name.
  * @param string $name name of the item.
  */
 public function actionUpdate($name)
 {
     /* @var $am CAuthManager|AuthBehavior */
     $am = Yii::app()->getAuthManager();
     $item = $am->getAuthItem($name);
     if ($item === null) {
         throw new CHttpException(404, Yii::t('AuthModule.main', 'Page not found.'));
     }
     $model = new AuthItemForm('update');
     if (isset($_POST['AuthItemForm'])) {
         $model->attributes = $_POST['AuthItemForm'];
         if ($model->validate()) {
             $item->description = $model->description;
             $am->saveAuthItem($item);
             if ($am instanceof CPhpAuthManager) {
                 $am->save();
             }
             $this->redirect(array('index'));
         }
     }
     $model->name = $name;
     $model->description = $item->description;
     $model->type = $item->type;
     $this->render('update', array('item' => $item, 'model' => $model));
 }
Example #2
0
 public function actionSaveAuthItem()
 {
     $json = array('error' => 'none');
     $model = new AuthItemForm();
     if (isset($_POST['AuthItemForm'])) {
         $model->attributes = $_POST['AuthItemForm'];
         if ($model->validate()) {
             $auth = Yii::app()->authManager;
             if (empty($model->oldname)) {
                 // creation
                 if ($auth->getAuthItem($model->name) === null) {
                     $auth->createAuthItem($model->name, $model->type, $model->description, $model->bizRule, $model->data);
                 } else {
                     $json['error'] = array('AuthItemForm_name' => array(Yii::t('RbacuiModule.rbacui', 'An authorization item name must be unique')));
                 }
             } else {
                 // update
                 if ($model->name != $model->oldname && $auth->getAuthItem($model->name) !== null) {
                     $json['error'] = array('AuthItemForm_name' => array(Yii::t('RbacuiModule.rbacui', 'An authorization item name must be unique')));
                 } else {
                     $authItem = $auth->getAuthItem($model->oldname);
                     $authItem->name = $model->name;
                     $authItem->description = $model->description;
                     $authItem->bizRule = $model->bizRule;
                     $authItem->data = $model->data;
                     $auth->saveAuthItem($authItem, $model->oldname);
                 }
             }
         } else {
             $json['error'] = json_decode(CActiveForm::validate($model));
         }
     }
     echo json_encode($json);
     Yii::app()->end();
 }
Example #3
0
 /**
  * Updates an authorization item.
  */
 public function actionUpdate()
 {
     // Get the authorization item
     $model = $this->loadModel();
     $itemName = $model->getName();
     // Create the authorization item form
     $formModel = new AuthItemForm('update');
     if (isset($_POST['AuthItemForm']) === true) {
         $formModel->attributes = $_POST['AuthItemForm'];
         if ($formModel->validate() === true) {
             // Update the item and load it
             $this->_authorizer->updateAuthItem($itemName, $formModel->name, $formModel->description, $formModel->bizRule, $formModel->data);
             $item = $this->_authorizer->authManager->getAuthItem($formModel->name);
             $item = $this->_authorizer->attachAuthItemBehavior($item);
             // Set a flash message for updating the item
             Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', ':name updated.', array(':name' => $item->getNameText())));
             // Redirect to the correct destination
             $this->redirect(Yii::app()->user->getRightsReturnUrl(array('authItem/permissions')));
         }
     }
     $type = Rights::getValidChildTypes($model->type);
     $exclude = array($this->module->superuserName);
     $childSelectOptions = Rights::getParentAuthItemSelectOptions($model, $type, $exclude);
     if ($childSelectOptions !== array()) {
         $childFormModel = new AuthChildForm();
         // Child form is submitted and data is valid
         if (isset($_POST['AuthChildForm']) === true) {
             $childFormModel->attributes = $_POST['AuthChildForm'];
             if ($childFormModel->validate() === true) {
                 // Add the child and load it
                 $this->_authorizer->authManager->addItemChild($itemName, $childFormModel->itemname);
                 $child = $this->_authorizer->authManager->getAuthItem($childFormModel->itemname);
                 $child = $this->_authorizer->attachAuthItemBehavior($child);
                 // Set a flash message for adding the child
                 Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', 'Child :name added.', array(':name' => $child->getNameText())));
                 // Reidrect to the same page
                 $this->redirect(array('authItem/update', 'name' => urlencode($itemName)));
             }
         }
     } else {
         $childFormModel = null;
     }
     // Set the values for the form fields
     $formModel->name = $model->name;
     $formModel->description = $model->description;
     $formModel->type = $model->type;
     $formModel->bizRule = $model->bizRule !== 'NULL' ? $model->bizRule : '';
     $formModel->data = $model->data !== null ? serialize($model->data) : '';
     $parentDataProvider = new RAuthItemParentDataProvider($model);
     $childDataProvider = new RAuthItemChildDataProvider($model);
     // Render the view
     $this->render('update', array('model' => $model, 'formModel' => $formModel, 'childFormModel' => $childFormModel, 'childSelectOptions' => $childSelectOptions, 'parentDataProvider' => $parentDataProvider, 'childDataProvider' => $childDataProvider));
 }