$model->type = \insolita\simplerbac\models\RbacModel::TYPE_PERMISSION; ?> <div class="panel-body rbaclist" style="overflow: auto; max-height: 650px;" id="permlist"> <?php echo $this->render('_itemlist', ['model' => $model]); ?> </div> </div> </div> </div> </div> <div> <div id="suberr" style="display: none"></div> <div id="vldr" style="display:none"><i class="fa fa-circle-o-notch fa-2x fa-spin"></i> <?php echo RbacModule::t('simplerbac', 'Loading....'); ?> </div> <div class="col-lg-12" id="viewitem"> </div> </div> <div class="pull-right offset-1" id="totop"><?php echo Html::button('<i class="fa fa-4x fa-arrow-circle-o-up"></i>', []); ?> </div> <?php $loadroles = \yii\helpers\Url::to(['/simplerbac/default/loadroles'], true); $loadperms = \yii\helpers\Url::to(['/simplerbac/default/loadperms'], true); $js = <<<JS \$.ajaxHelper('button.aj','click','send',[{loader:'#ldr'}]);
/** * @var yii\web\View $this * @var yii\widgets\ActiveForm $form * @var yii\widgets\ActiveField $field * @var insolita\simplerbac\models\RbacModel $model */ ?> <div class="col-lg-10"> <?php $form = ActiveForm::begin(['id' => 'addrbac-form', 'options' => ['class' => 'form-horizontal ajaxform', 'data-errtarget' => 'div#add-error', 'data-trigger' => 'rbacitem_update', 'data-scroll' => 1], 'enableAjaxValidation' => false, 'enableClientValidation' => true, 'action' => \Yii::$app->getUrlManager()->createAbsoluteUrl('/simplerbac/default/additem')]); ?> <div class="alert alert-danger" id="add-error" style="display: none;">...</div> <?php echo $form->field($model, 'name'); ?> <?php echo $form->field($model, 'description'); ?> <?php echo $form->field($model, 'type')->dropDownList([RbacModel::TYPE_ROLE => Yii::t('app', 'Роль', [], 'ru'), RbacModel::TYPE_PERMISSION => RbacModule::t('simplerbac', 'Операция')]); ?> <div class="form-group"> <?php echo Html::submitButton('<span id="ldr" style="display: none;"><i class="fa fa-circle-o-notch fa-2x fa-spin"></i></span>' . RbacModule::t('simplerbac', 'Добавить'), ['class' => 'btn btn-primary addbtn']); ?> </div> <?php ActiveForm::end(); ?> </div>
*/ ?> <div class="well well-small"> <b><?php echo $user->{Yii::$app->getModule('simplerbac')->usernameAttribute}; ?> </b> <div id="ldr" style="display:none"><i class="fa fa-circle-o-notch fa-2x fa-spin"></i> <?php echo RbacModule::t('simplerbac', 'Loading....'); ?> </div> <?php $form = ActiveForm::begin(['id' => 'userassign-form', 'options' => ['class' => 'form-horizontal ajaxform', 'data-errtarget' => 'div#ch-error', 'data-bsmodalid' => '#Assigs', 'data-scroll' => 1], 'enableAjaxValidation' => false, 'enableClientValidation' => false, 'action' => \Yii::$app->getUrlManager()->createAbsoluteUrl(['/simplerbac/default/assign', 'userid' => $user->{Yii::$app->getModule('simplerbac')->userPk}])]); ?> <div class="alert alert-danger" id="ch-error" style="display: none;">...</div> <?php echo $form->field($model, 'forassign')->dropDownList($model->getItemsForAssignUser($user->{Yii::$app->getModule('simplerbac')->userPk})); ?> <div class="form-group"> <?php echo Html::submitButton(RbacModule::t('simplerbac', 'Update'), ['class' => 'btn btn-primary userassign', 'data-pjax' => 1]); ?> </div> <?php ActiveForm::end(); ?> </div>
} ?> <div class="row"> <div class="col-lg-6"> <div class="panel panel-primary"> <div class="panel-heading"><?php echo RbacModule::t('simplerbac', 'Inherits the rights of:'); ?> </div> <div class="panel-body" style="overflow: auto; max-height: 650px;" id="parentlist"> <?php echo $this->render('_childview', ['model' => $model, 'ct' => 'childs', 'model' => $model]); ?> </div> </div> </div> <div class="col-lg-6"> <div class="panel panel-primary"> <div class="panel-heading"><?php echo RbacModule::t('simplerbac', 'Grants rights to:'); ?> </div> <div class="panel-body" style="overflow: auto; max-height: 650px;" id="childlist"> <?php echo $this->render('_list', ['data' => $model->getParents(), 'ct' => 'parents', 'model' => $model]); ?> </div> </div> </div> </div>
$this->registerAssetBundle('\\insolita\\simplerbac\\assets\\CytoscapeAsset', View::POS_HEAD); $this->title = RbacModule::t('simplerbac', 'RBAC Graph'); $this->params['breadcrumbs'][] = $this->title; echo Html::a(RbacModule::t('simplerbac', 'Roles and operations'), ['/simplerbac/default/index'], ['class' => 'btn btn-primary']); ?> <?php echo Html::a(RbacModule::t('simplerbac', 'Assign roles'), ['/simplerbac/default/users'], ['class' => 'btn btn-primary']); ?> <?php echo Html::a(RbacModule::t('simplerbac', 'RBAC Graph'), ['/simplerbac/default/all-items'], ['class' => 'btn btn-primary']); ?> <?php echo Html::a(RbacModule::t('simplerbac', 'User Graph'), ['/simplerbac/default/all-users'], ['class' => 'btn btn-primary']); ?> <div id="cy"> </div> <?php $this->registerCss('#cy { height: 90%; width: 90%; position: absolute; left: 0; top: 100; }'); $js = <<<JS jQuery(function(){
*/ ?> <ul class="list-group"> <?php $data = $model->type == RbacModel::TYPE_PERMISSION ? $model->getPerms() : $model->getRoles(); ?> <?php foreach ($data as $subdata) { ?> <li class="list-group-item"> <div class="pull-right"> <?php echo Html::button('<i class="fa fa-cog"></i>', ['title' => RbacModule::t('simplerbac', 'Info'), 'class' => 'aj', 'data-type' => $subdata->type, 'data-action' => Url::to(['/simplerbac/default/view']), 'data-name' => $subdata->name, 'data-oktarget' => '#viewitem', 'data-scroll' => 1]); ?> <?php echo Html::button('<i class="fa fa-pencil"></i>', ['title' => RbacModule::t('simplerbac', 'Edit'), 'class' => 'aj', 'data-type' => $subdata->type, 'data-action' => Url::to(['/simplerbac/default/upditem']), 'data-name' => $subdata->name, 'data-oktarget' => '#rbacform']); ?> <?php echo Html::button('<i class="fa fa-trash-o"></i>', ['title' => RbacModule::t('simplerbac', 'Remove'), 'class' => 'aj', 'data-type' => $subdata->type, 'data-action' => Url::to(['/simplerbac/default/delete']), 'data-name' => $subdata->name, 'data-trigger' => 'rbacitem_update']); ?> </div> <?php echo $subdata->name . '(' . $subdata->description . ')'; ?> </li> <?php } ?> </ul>
<?php /** * @var yii\web\View $this * @var yii\data\ActiveDataProvider $dataProvider * @var insolita\simplerbac\models\RbacModel $model */ use yii\grid\GridView; use insolita\simplerbac\RbacModule; ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $model, 'columns' => [Yii::$app->getModule('simplerbac')->userPk, Yii::$app->getModule('simplerbac')->usernameAttribute, 'role' => ['format' => 'html', 'value' => function ($data) { return '<span class="label label-success">' . implode('</span><br/><br/><span class="label label-primary">', insolita\simplerbac\models\RbacModel::getUserRoles($data->{Yii::$app->getModule('simplerbac')->userPk})) . '</span>'; }], 'userperms' => ['format' => 'html', 'value' => function ($data) { return '<span class="label label-primary">' . implode('</span><br/><br/><span class="label label-primary">', insolita\simplerbac\models\RbacModel::getUserperms($data->{Yii::$app->getModule('simplerbac')->userPk})) . '</span>'; }], ['class' => 'yii\\grid\\ActionColumn', 'header' => 'Grant', 'buttons' => ['view' => function ($url, $model) { $url = Yii::$app->getUrlManager()->createAbsoluteUrl(['/simplerbac/default/assign-form', 'userid' => $model->{Yii::$app->getModule('simplerbac')->userPk}]); return \yii\helpers\Html::a('<i class="fa fa-link"></i>', '#Assigs', ['class' => 'btn btn-default ajaxmodal', 'title' => RbacModule::t('simplerbac', 'Grant'), 'data-toggle' => 'modal', 'data-backdrop' => false, 'data-action' => $url, 'data-oktarget' => "#Assigs .modal-body"]); }], 'template' => '{view}']]]);
echo Html::a(RbacModule::t('simplerbac', 'Users Graph'), ['/simplerbac/default/all-users'], ['class' => 'btn btn-primary']); ?> <div class="rbacuser-index"> <div class="page-header"><h1><?php echo Html::encode($this->title); ?> </h1></div> <?php \yii\widgets\Pjax::begin(['id' => 'userpjax', 'timeout' => 5000]); ?> <?php echo $this->render('_usergrid', ['model' => $model, 'dataProvider' => $dataProvider]); ?> <?php \yii\widgets\Pjax::end(); ?> </div> <?php \yii\bootstrap\Modal::begin(['header' => RbacModule::t('simplerbac', 'Assign to user'), 'id' => 'Assigs']); \yii\bootstrap\Modal::end(); ?> <?php $js = <<<JS \$('[rel="popover"]').popover(); \$.ajaxHelper('.ajaxmodal','click','send',[{loader:'#ldr'}]); \$.ajaxHelper("form#userassign-form",'submit','send',[{loader:'#ldr',pjaxid:'#userpjax'}]); JS; $this->registerJs($js);
public function actionAllUsers() { $nodes = $edges = []; $assignments = RbacModel::getAllAssignments(); $uids = array_keys($assignments); $uClass = $this->module->userClass; if (count($uids) > $this->module->maxUsersForGraph) { \Yii::$app->session->setFlash('error', RbacModule::t('simplerbac', 'Too many users for show')); return $this->redirect(['index']); } $users = $uClass::find()->where([$this->module->userPk => $uids])->indexBy($this->module->userPk)->asArray()->all(); foreach ($assignments as $uid => $data) { if (!isset($users[$uid])) { continue; } $nodes[] = ['data' => ['id' => "u{$uid}", 'username' => $users[$uid][$this->module->usernameAttribute], 'faveColor' => '#E13A69', 'faveShape' => 'ellipse', 'width' => mb_strlen($users[$uid][$this->module->usernameAttribute])]]; $roles = \Yii::$app->authManager->getRolesByUser($uid); if (!empty($roles)) { foreach ($roles as $rol) { $nodes[] = ['data' => ['id' => $rol->name, 'faveColor' => '#5F40B8', 'faveShape' => 'star', 'width' => mb_strlen($rol->name)]]; $edges[] = ['data' => ["id" => $rol->name . '_' . "{$uid}", 'source' => $rol->name, 'target' => "u{$uid}", 'faveColor' => '#5F40B8']]; $perms = \Yii::$app->authManager->getPermissionsByRole($rol->name); if (!empty($perms)) { foreach ($perms as $p) { $nodes[] = ['data' => ['id' => $p->name, 'faveColor' => '#3AB5E1', 'faveShape' => 'rectangle', 'width' => mb_strlen($p->name)]]; $edges[] = ['data' => ["id" => $p->name . '_' . $rol->name, 'source' => $p->name, 'target' => $rol->name, 'faveColor' => '#3AB5E1']]; } } } } } return $this->render('ugraph', ['elems' => Json::encode(['nodes' => $nodes, 'edges' => $edges])]); }
/** * Непосредственно привязка роли к юзеру * * @param $userid * * @return bool|string */ public function userAssign($userid) { $role = $this->getItem($this->forassign, self::TYPE_ROLE); $oldroles = $this->_authMan->getRolesByUser($userid); $this->_authMan->revokeAll($userid); try { if ($this->beforeAssign($userid, $role, $oldroles)) { $this->_authMan->assign($role, $userid); $this->afterAssign($userid, $role, $oldroles); return true; } else { return false; } } catch (\yii\base\Exception $e) { foreach ($oldroles as $orole) { $this->_authMan->assign($orole, $userid); } return RbacModule::t('simplerbac', 'Can`t assign this item for this user'); } }
echo Html::button('<i class="fa fa-cog"></i>', ['title' => RbacModule::t('simplerbac', 'Info'), 'class' => 'aj', 'data-type' => $subdata->type, 'data-action' => Url::to(['/simplerbac/default/view']), 'data-name' => $subdata->name, 'data-oktarget' => '#viewitem', 'data-scroll' => 1]); ?> <?php echo $ct == 'childs' ? Html::button('<i class="fa fa-chain-broken"></i>', ['title' => RbacModule::t('simplerbac', 'Unlink'), 'class' => 'unchild', 'data-type' => $model->type, 'data-action' => Url::to(['/simplerbac/default/unchild']), 'data-name' => $model->name, 'data-new_child' => $subdata->name . '_t' . $subdata->type, 'data-oktarget' => '#viewitem', 'data-errtarget' => '#suberr', 'data-scroll' => 1]) : Html::button('<i class="fa fa-chain-broken"></i>', ['title' => RbacModule::t('simplerbac', 'Unlink'), 'class' => 'unchild', 'data-type' => $subdata->type, 'data-action' => Url::to(['/simplerbac/default/unchild']), 'data-name' => $subdata->name, 'data-new_child' => $model->name . '_t' . $model->type, 'data-oktarget' => '#viewitem', 'data-errtarget' => '#suberr', 'data-scroll' => 1]); ?> </div> <?php echo $subdata->name . '(' . $subdata->description . ') '; ?> <span class="label label-info"><?php echo $model->typenames[$subdata->type]; ?> </span> </li> <?php } ?> <?php } else { ?> <li class="list-group-item"><?php echo RbacModule::t('simplerbac', 'No items'); ?> </li> <?php } ?> </ul>
* @var yii\widgets\ActiveForm $form * @var yii\widgets\ActiveField $field * @var insolita\simplerbac\models\RbacModel $model */ ?> <div class="col-lg-10"> <?php $form = ActiveForm::begin(['id' => 'addchild-form', 'options' => ['class' => 'form-horizontal ajaxform', 'data-errtarget' => 'div#ch-error', 'data-oktarget' => '#viewitem', 'data-scroll' => 1], 'enableAjaxValidation' => false, 'enableClientValidation' => false, 'action' => \Yii::$app->getUrlManager()->createAbsoluteUrl('/simplerbac/default/addchild')]); ?> <div class="alert alert-danger" id="ch-error" style="display: none;">...</div> <input type="hidden" name="RbacModel[type]" value="<?php echo $model->type; ?> "> <input type="hidden" name="RbacModel[name]" value="<?php echo $model->name; ?> "> <?php echo $form->field($model, 'new_child')->dropDownList($model->getItemsForAssign()); ?> <div class="form-group"> <?php echo Html::submitButton(RbacModule::t('simplerbac', 'Add'), ['class' => 'btn btn-primary addchild']); ?> </div> <?php ActiveForm::end(); ?> </div>