/** * Displays the authorization assignments for an user. */ public function actionUser() { // Create the user model and attach the required behavior $userClass = $this->module->userClass; $model = CActiveRecord::model($userClass)->findByPk($_GET['id']); $model->attachBehavior('rights', new RightsUserBehavior()); $assignedItems = $this->_authorizer->getAuthItems(null, $model->getId(), null, true); $assignments = array_keys($assignedItems); // Make sure we have items to be selected $selectOptions = Rights::getAuthItemSelectOptions(null, $assignments); if ($selectOptions !== array()) { // Create a from to add a child for the authorization item $form = new CForm(array('elements' => array('itemname' => array('label' => false, 'type' => 'dropdownlist', 'items' => $selectOptions)), 'buttons' => array('submit' => array('type' => 'submit', 'label' => Rights::t('core', 'Assign')))), new AssignmentForm()); // Form is submitted and data is valid, redirect the user if ($form->submitted() === true && $form->validate() === true) { // Update and redirect $this->_authorizer->authManager->assign($form->model->itemname, $model->getId()); $item = $this->_authorizer->authManager->getAuthItem($form->model->itemname); $item = $this->_authorizer->attachAuthItemBehavior($item); Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', 'Permission :name assigned.', array(':name' => $item->getNameText()))); $this->redirect(array('assignment/user', 'id' => $model->getId())); } } else { $form = null; } // Create a data provider for listing the assignments $dataProvider = new AuthItemDataProvider('assignments', array('userId' => $model->getId())); // Render the view $this->render('user', array('model' => $model, 'dataProvider' => $dataProvider, 'form' => $form)); }
/** * Displays the authorization assignments for an user. */ public function actionUser() { // Create the user model and attach the required behavior $userClass = $this->module->userClass; $model = CActiveRecord::model($userClass)->findByPk($_GET['id']); $this->_authorizer->attachUserBehavior($model); $assignedItems = $this->_authorizer->getAuthItems(null, $model->getId()); $assignments = array_keys($assignedItems); // Make sure we have items to be selected $assignSelectOptions = Rights::getAuthItemSelectOptions(null, $assignments); if ($assignSelectOptions !== array()) { $formModel = new AssignmentForm(); // Form is submitted and data is valid, redirect the user if (isset($_POST['AssignmentForm']) === true) { $formModel->attributes = $_POST['AssignmentForm']; if ($formModel->validate() === true) { // Update and redirect $this->_authorizer->authManager->assign($formModel->itemname, $model->getId()); $item = $this->_authorizer->authManager->getAuthItem($formModel->itemname); $item = $this->_authorizer->attachAuthItemBehavior($item); Yii::app()->user->setFlash($this->module->flashSuccessKey, Rights::t('core', 'Permission :name assigned.', array(':name' => $item->getNameText()))); $this->redirect(array('assignment/user', 'id' => $model->getId())); } } } else { $formModel = null; } // Create a data provider for listing the assignments $dataProvider = new RAuthItemDataProvider('assignments', array('userId' => $model->getId())); // Render the view $this->render('user', array('model' => $model, 'dataProvider' => $dataProvider, 'formModel' => $formModel, 'assignSelectOptions' => $assignSelectOptions)); }
public function getAuthItemSelectOptions() { $authorizer = Yii::app()->getComponent('authorizer'); return Rights::getAuthItemSelectOptions(); }