26 $this->_authorizer = $this->module->getAuthorizer();
27 $this->
layout = $this->module->layout;
28 $this->defaultAction =
'permissions';
31 $this->module->registerScripts();
68 'users' => $this->_authorizer->getSuperusers(),
71 'users' => array(
'*'),
84 $roles = $dataProvider->getRoles();
85 $roleColumnWidth = $roles !== array() ? 75/count($roles) : 0;
90 'name' =>
'description',
93 'htmlOptions' => array(
94 'class' =>
'permission-column',
95 'style' =>
'width:25%',
101 foreach ($roles as $roleName => $role) {
103 'name' => strtolower($roleName),
104 'header' => $role->getNameText(),
106 'htmlOptions' => array(
107 'class' =>
'role-column',
108 'style' =>
'width:'.$roleColumnWidth.
'%',
113 $view =
'permissions';
115 'dataProvider' => $dataProvider,
116 'columns' => $columns,
120 isset($_POST[
'ajax']) ===
true ? $this->renderPartial($view, $params) : $this->render($view, $params);
128 Yii::app()->user->rightsReturnUrl = array(
'authItem/operations');
131 'type' => CAuthItem::TYPE_OPERATION,
133 'id' =>
'RightsOperationTableSort',
134 'element' =>
'.operation-table',
135 'url' => $this->createUrl(
'authItem/sortable'),
140 $this->render(
'operations', array(
141 'dataProvider' => $dataProvider,
142 'isBizRuleEnabled' => $this->module->enableBizRule,
143 'isBizRuleDataEnabled' => $this->module->enableBizRuleData,
152 Yii::app()->user->rightsReturnUrl = array(
'authItem/tasks');
155 'type' => CAuthItem::TYPE_TASK,
157 'id' =>
'RightsTaskTableSort',
158 'element' =>
'.task-table',
159 'url' => $this->createUrl(
'authItem/sortable'),
164 $this->render(
'tasks', array(
165 'dataProvider' => $dataProvider,
166 'isBizRuleEnabled' => $this->module->enableBizRule,
167 'isBizRuleDataEnabled' => $this->module->enableBizRuleData,
176 Yii::app()->user->rightsReturnUrl = array(
'authItem/roles');
179 'type' => CAuthItem::TYPE_ROLE,
181 'id' =>
'RightsRoleTableSort',
182 'element' =>
'.role-table',
183 'url' => $this->createUrl(
'authItem/sortable'),
188 $this->render(
'roles', array(
189 'dataProvider' => $dataProvider,
190 'isBizRuleEnabled' => $this->module->enableBizRule,
191 'isBizRuleDataEnabled' => $this->module->enableBizRuleData,
201 $generator = $this->module->getGenerator();
207 if (isset($_POST[
'GenerateForm']) ===
true) {
209 $model->attributes = $_POST[
'GenerateForm'];
210 if ($model->validate() ===
true) {
213 'operations' => array(),
217 foreach ($model->items as $itemname => $value) {
218 if ((
bool) $value ===
true) {
219 if (strpos($itemname,
'*') !==
false) {
220 $items[
'tasks'][] = $itemname;
222 $items[
'operations'][] = $itemname;
228 $generator->addItems($items[
'tasks'], CAuthItem::TYPE_TASK);
229 $generator->addItems($items[
'operations'], CAuthItem::TYPE_OPERATION);
230 if (($generatedItems = $generator->run()) !==
false && $generatedItems !== array()) {
231 Yii::app()->getUser()->setFlash($this->module->flashSuccessKey,
232 Rights::t(
'core',
'Authorization items created.')
234 $this->redirect(array(
'authItem/permissions'));
240 $items = $generator->getControllerActions();
243 $authItems = $this->_authorizer->getAuthItems(array(
244 CAuthItem::TYPE_TASK,
245 CAuthItem::TYPE_OPERATION,
247 $existingItems = array();
248 foreach ($authItems as $itemName => $item) {
249 $existingItems[ $itemName ] = $itemName;
252 Yii::app()->clientScript->registerScript(
'rightsGenerateItemTableSelectRows',
253 "jQuery('.generate-item-table').rightsSelectRows();"
257 $this->render(
'generate', array(
260 'existingItems' => $existingItems,
276 if (isset($_POST[
'AuthItemForm']) ===
true) {
277 $formModel->attributes = $_POST[
'AuthItemForm'];
278 if ($formModel->validate() ===
true) {
280 $item = $this->_authorizer->createAuthItem($formModel->name, $type, $formModel->description, $formModel->bizRule, $formModel->data);
281 $item = $this->_authorizer->attachAuthItemBehavior($item);
284 Yii::app()->user->setFlash($this->module->flashSuccessKey,
285 Rights::t(
'core',
':name created.', array(
':name' => $item->getNameText()))
289 $this->redirect(Yii::app()->user->getRightsReturnUrl(array(
'authItem/permissions')));
294 $this->render(
'create', array(
295 'formModel' => $formModel,
306 $itemName = $model->getName();
311 if (isset($_POST[
'AuthItemForm']) ===
true) {
312 $formModel->attributes = $_POST[
'AuthItemForm'];
313 if ($formModel->validate() ===
true) {
315 $this->_authorizer->updateAuthItem($itemName, $formModel->name, $formModel->description, $formModel->bizRule, $formModel->data);
316 $item = $this->_authorizer->authManager->getAuthItem($formModel->name);
317 $item = $this->_authorizer->attachAuthItemBehavior($item);
320 Yii::app()->user->setFlash($this->module->flashSuccessKey,
321 Rights::t(
'core',
':name updated.', array(
':name' => $item->getNameText()))
325 $this->redirect(Yii::app()->user->getRightsReturnUrl(array(
'authItem/permissions')));
330 $exclude = array($this->module->superuserName);
333 if ($childSelectOptions !== array()) {
337 if (isset($_POST[
'AuthChildForm']) ===
true) {
338 $childFormModel->attributes = $_POST[
'AuthChildForm'];
339 if ($childFormModel->validate() ===
true) {
341 $this->_authorizer->authManager->addItemChild($itemName, $childFormModel->itemname);
342 $child = $this->_authorizer->authManager->getAuthItem($childFormModel->itemname);
343 $child = $this->_authorizer->attachAuthItemBehavior($child);
346 Yii::app()->user->setFlash($this->module->flashSuccessKey,
347 Rights::t(
'core',
'Child :name added.', array(
':name' => $child->getNameText()))
351 $this->redirect(array(
'authItem/update',
'name' => urlencode($itemName)));
355 $childFormModel = null;
359 $formModel->name = $model->name;
360 $formModel->description = $model->description;
361 $formModel->type = $model->type;
362 $formModel->bizRule = $model->bizRule !==
'NULL' ? $model->bizRule :
'';
363 $formModel->data = $model->data !== null ? serialize($model->data) :
'';
369 $this->render(
'update', array(
371 'formModel' => $formModel,
372 'childFormModel' => $childFormModel,
373 'childSelectOptions' => $childSelectOptions,
374 'parentDataProvider' => $parentDataProvider,
375 'childDataProvider' => $childDataProvider,
385 if (Yii::app()->request->isPostRequest ===
true) {
389 $item = $this->_authorizer->authManager->getAuthItem($itemName);
390 $item = $this->_authorizer->attachAuthItemBehavior($item);
393 $this->_authorizer->authManager->removeAuthItem($itemName);
396 Yii::app()->user->setFlash($this->module->flashSuccessKey,
397 Rights::t(
'core',
':name deleted.', array(
':name' => $item->getNameText()))
401 if (isset($_POST[
'ajax']) ===
false) {
402 $this->redirect(Yii::app()->user->getRightsReturnUrl(array(
'authItem/permissions')));
405 throw new CHttpException(400,
Rights::t(
'core',
'Invalid request. Please do not repeat this request again.'));
415 if (Yii::app()->request->isPostRequest ===
true) {
420 $this->_authorizer->authManager->removeItemChild($itemName, $childName);
421 $child = $this->_authorizer->authManager->getAuthItem($childName);
422 $child = $this->_authorizer->attachAuthItemBehavior($child);
425 Yii::app()->user->setFlash($this->module->flashSuccessKey,
426 Rights::t(
'core',
'Child :name removed.', array(
':name' => $child->getNameText()))
430 if (isset($_POST[
'ajax']) ===
false) {
431 $this->redirect(array(
'authItem/update',
'name' => urlencode($itemName)));
434 throw new CHttpException(400,
Rights::t(
'core',
'Invalid request. Please do not repeat this request again.'));
444 if (Yii::app()->request->isPostRequest ===
true) {
448 if ($childName !== null && $model->hasChild($childName) ===
false) {
449 $model->addChild($childName);
453 if (isset($_POST[
'ajax']) ===
false) {
454 $this->redirect(array(
'authItem/permissions'));
457 throw new CHttpException(400,
Rights::t(
'core',
'Invalid request. Please do not repeat this request again.'));
467 if (Yii::app()->request->isPostRequest ===
true) {
471 if ($childName !== null && $model->hasChild($childName) ===
true) {
472 $model->removeChild($childName);
476 if (isset($_POST[
'ajax']) ===
false) {
477 $this->redirect(array(
'authItem/permissions'));
480 throw new CHttpException(400,
Rights::t(
'core',
'Invalid request. Please do not repeat this request again.'));
490 if (Yii::app()->request->isPostRequest ===
true) {
491 $this->_authorizer->authManager->updateItemWeight($_POST[
'result']);
493 throw new CHttpException(400,
Rights::t(
'core',
'Invalid request. Please do not repeat this request again.'));
502 return isset($_GET[
'name']) ===
true ? urldecode($_GET[
'name']) : null;
510 return isset($_GET[
'child']) ===
true ? urldecode($_GET[
'child']) : null;
520 $type = $_GET[
'type'];
521 $validTypes = array(CAuthItem::TYPE_OPERATION, CAuthItem::TYPE_TASK, CAuthItem::TYPE_ROLE);
522 if (in_array($type, $validTypes) ===
true) {
525 throw new CException(
Rights::t(
'core',
'Invalid authorization item type.'));
535 if ($this->_model === null) {
538 if ($itemName !== null) {
539 $this->_model = $this->_authorizer->authManager->getAuthItem($itemName);
540 $this->_model = $this->_authorizer->attachAuthItemBehavior($this->_model);
543 if ($this->_model === null) {
544 throw new CHttpException(404,
Rights::t(
'core',
'The requested page does not exist.'));