25 $this->_authorizer = $this->module->getAuthorizer();
26 $this->layout = $this->module->layout;
27 $this->defaultAction =
'permissions';
30 $this->module->registerScripts();
66 'users'=>$this->_authorizer->getSuperusers(),
82 $roles = $dataProvider->getRoles();
83 $roleColumnWidth = $roles!==array() ? 75/count($roles) : 0;
88 'name'=>
'description',
92 'class'=>
'permission-column',
99 foreach( $roles as $roleName=>$role )
102 'name'=>strtolower($roleName),
103 'header'=>$role->getNameText(),
105 'htmlOptions'=>array(
106 'class'=>
'role-column',
107 'style'=>
'width:'.$roleColumnWidth.
'%',
112 $view =
'permissions';
114 'dataProvider'=>$dataProvider,
119 isset($_POST[
'ajax'])===
true ? $this->renderPartial($view, $params) : $this->render($view, $params);
127 Yii::app()->user->rightsReturnUrl = array(
'authItem/operations');
130 'type'=>CAuthItem::TYPE_OPERATION,
132 'id'=>
'RightsOperationTableSort',
133 'element'=>
'.operation-table',
134 'url'=>$this->createUrl(
'authItem/sortable'),
139 $this->render(
'operations', array(
140 'dataProvider'=>$dataProvider,
141 'isBizRuleEnabled'=>$this->module->enableBizRule,
142 'isBizRuleDataEnabled'=>$this->module->enableBizRuleData,
151 Yii::app()->user->rightsReturnUrl = array(
'authItem/tasks');
154 'type'=>CAuthItem::TYPE_TASK,
156 'id'=>
'RightsTaskTableSort',
157 'element'=>
'.task-table',
158 'url'=>$this->createUrl(
'authItem/sortable'),
163 $this->render(
'tasks', array(
164 'dataProvider'=>$dataProvider,
165 'isBizRuleEnabled'=>$this->module->enableBizRule,
166 'isBizRuleDataEnabled'=>$this->module->enableBizRuleData,
175 Yii::app()->user->rightsReturnUrl = array(
'authItem/roles');
178 'type'=>CAuthItem::TYPE_ROLE,
180 'id'=>
'RightsRoleTableSort',
181 'element'=>
'.role-table',
182 'url'=>$this->createUrl(
'authItem/sortable'),
187 $this->render(
'roles', array(
188 'dataProvider'=>$dataProvider,
189 'isBizRuleEnabled'=>$this->module->enableBizRule,
190 'isBizRuleDataEnabled'=>$this->module->enableBizRuleData,
200 $generator = $this->module->getGenerator();
206 if( isset($_POST[
'GenerateForm'])===
true )
209 $model->attributes = $_POST[
'GenerateForm'];
210 if( $model->validate()===true )
214 'operations'=>array(),
218 foreach( $model->items as $itemname=>$value )
220 if( (
bool)$value===
true )
222 if( strpos($itemname,
'*')!==
false )
223 $items[
'tasks'][] = $itemname;
225 $items[
'operations'][] = $itemname;
230 $generator->addItems($items[
'tasks'], CAuthItem::TYPE_TASK);
231 $generator->addItems($items[
'operations'], CAuthItem::TYPE_OPERATION);
232 if( ($generatedItems = $generator->run())!==
false && $generatedItems!==array() )
234 Yii::app()->getUser()->setFlash($this->module->flashSuccessKey,
235 Rights::t(
'core',
'Authorization items created.')
237 $this->redirect(array(
'authItem/permissions'));
243 $items = $generator->getControllerActions();
246 $authItems = $this->_authorizer->getAuthItems(array(
247 CAuthItem::TYPE_TASK,
248 CAuthItem::TYPE_OPERATION,
250 $existingItems = array();
251 foreach( $authItems as $itemName=>$item )
252 $existingItems[ $itemName ] = $itemName;
254 Yii::app()->clientScript->registerScript(
'rightsGenerateItemTableSelectRows',
255 "jQuery('.generate-item-table').rightsSelectRows();"
259 $this->render(
'generate', array(
262 'existingItems'=>$existingItems,
277 if( isset($_POST[
'AuthItemForm'])===
true )
279 $formModel->attributes = $_POST[
'AuthItemForm'];
280 if( $formModel->validate()===true )
283 $item = $this->_authorizer->createAuthItem($formModel->name, $type, $formModel->description, $formModel->bizRule, $formModel->data);
284 $item = $this->_authorizer->attachAuthItemBehavior($item);
287 Yii::app()->user->setFlash($this->module->flashSuccessKey,
288 Rights::t(
'core',
':name created.', array(
':name'=>$item->getNameText()))
292 $this->redirect(Yii::app()->user->getRightsReturnUrl(array(
'authItem/permissions')));
297 $this->render(
'create', array(
298 'formModel'=>$formModel,
309 $itemName = $model->getName();
314 if( isset($_POST[
'AuthItemForm'])===
true )
316 $formModel->attributes = $_POST[
'AuthItemForm'];
317 if( $formModel->validate()===true )
320 $this->_authorizer->updateAuthItem($itemName, $formModel->name, $formModel->description, $formModel->bizRule, $formModel->data);
321 $item = $this->_authorizer->authManager->getAuthItem($formModel->name);
322 $item = $this->_authorizer->attachAuthItemBehavior($item);
325 Yii::app()->user->setFlash($this->module->flashSuccessKey,
326 Rights::t(
'core',
':name updated.', array(
':name'=>$item->getNameText()))
330 $this->redirect(Yii::app()->user->getRightsReturnUrl(array(
'authItem/permissions')));
335 $exclude = array($this->module->superuserName);
338 if( $childSelectOptions!==array() )
343 if( isset($_POST[
'AuthChildForm'])===
true )
345 $childFormModel->attributes = $_POST[
'AuthChildForm'];
346 if( $childFormModel->validate()===true )
349 $this->_authorizer->authManager->addItemChild($itemName, $childFormModel->itemname);
350 $child = $this->_authorizer->authManager->getAuthItem($childFormModel->itemname);
351 $child = $this->_authorizer->attachAuthItemBehavior($child);
354 Yii::app()->user->setFlash($this->module->flashSuccessKey,
355 Rights::t(
'core',
'Child :name added.', array(
':name'=>$child->getNameText()))
359 $this->redirect(array(
'authItem/update',
'name'=>urlencode($itemName)));
365 $childFormModel = null;
369 $formModel->name = $model->name;
370 $formModel->description = $model->description;
371 $formModel->type = $model->type;
372 $formModel->bizRule = $model->bizRule!==
'NULL' ? $model->bizRule :
'';
373 $formModel->data = $model->data!==null ? serialize($model->data) :
'';
379 $this->render(
'update', array(
381 'formModel'=>$formModel,
382 'childFormModel'=>$childFormModel,
383 'childSelectOptions'=>$childSelectOptions,
384 'parentDataProvider'=>$parentDataProvider,
385 'childDataProvider'=>$childDataProvider,
395 if( Yii::app()->request->isPostRequest===
true )
400 $item = $this->_authorizer->authManager->getAuthItem($itemName);
401 $item = $this->_authorizer->attachAuthItemBehavior($item);
404 $this->_authorizer->authManager->removeAuthItem($itemName);
407 Yii::app()->user->setFlash($this->module->flashSuccessKey,
408 Rights::t(
'core',
':name deleted.', array(
':name'=>$item->getNameText()))
412 if( isset($_POST[
'ajax'])===false )
413 $this->redirect(Yii::app()->user->getRightsReturnUrl(array(
'authItem/permissions')));
417 throw new CHttpException(400,
Rights::t(
'core',
'Invalid request. Please do not repeat this request again.'));
427 if( Yii::app()->request->isPostRequest===
true )
433 $this->_authorizer->authManager->removeItemChild($itemName, $childName);
434 $child = $this->_authorizer->authManager->getAuthItem($childName);
435 $child = $this->_authorizer->attachAuthItemBehavior($child);
438 Yii::app()->user->setFlash($this->module->flashSuccessKey,
439 Rights::t(
'core',
'Child :name removed.', array(
':name'=>$child->getNameText()))
443 if( isset($_POST[
'ajax'])===false )
444 $this->redirect(array(
'authItem/update',
'name'=>urlencode($itemName)));
448 throw new CHttpException(400,
Rights::t(
'core',
'Invalid request. Please do not repeat this request again.'));
458 if( Yii::app()->request->isPostRequest===
true )
463 if( $childName!==null && $model->hasChild($childName)===false )
464 $model->addChild($childName);
467 if( isset($_POST[
'ajax'])===
false )
468 $this->redirect(array(
'authItem/permissions'));
472 throw new CHttpException(400,
Rights::t(
'core',
'Invalid request. Please do not repeat this request again.'));
482 if( Yii::app()->request->isPostRequest===
true )
487 if( $childName!==null && $model->hasChild($childName)===true )
488 $model->removeChild($childName);
491 if( isset($_POST[
'ajax'])===
false )
492 $this->redirect(array(
'authItem/permissions'));
496 throw new CHttpException(400,
Rights::t(
'core',
'Invalid request. Please do not repeat this request again.'));
506 if( Yii::app()->request->isPostRequest===
true )
508 $this->_authorizer->authManager->updateItemWeight($_POST[
'result']);
512 throw new CHttpException(400,
Rights::t(
'core',
'Invalid request. Please do not repeat this request again.'));
521 return isset($_GET[
'name'])===
true ? urldecode($_GET[
'name']) : null;
529 return isset($_GET[
'child'])===
true ? urldecode($_GET[
'child']) : null;
538 $type = $_GET[
'type'];
539 $validTypes = array(CAuthItem::TYPE_OPERATION, CAuthItem::TYPE_TASK, CAuthItem::TYPE_ROLE);
540 if( in_array($type, $validTypes)===
true )
543 throw new CException(
Rights::t(
'core',
'Invalid authorization item type.'));
552 if( $this->_model===null )
556 if( $itemName!==null )
558 $this->_model = $this->_authorizer->authManager->getAuthItem($itemName);
559 $this->_model = $this->_authorizer->attachAuthItemBehavior($this->_model);
562 if( $this->_model===null )
563 throw new CHttpException(404,
Rights::t(
'core',
'The requested page does not exist.'));
566 return $this->_model;