Ejemplo n.º 1
0
 /**
  * @param int $id - User ID
  *
  * @return \yii\web\Response
  */
 public function actionSetRoles($id)
 {
     if (!Yii::$app->user->isSuperadmin and Yii::$app->user->id == $id) {
         Yii::$app->session->setFlash('error', UserManagementModule::t('back', 'You can not change own permissions'));
         return $this->redirect(['set', 'id' => $id]);
     }
     $oldAssignments = array_keys(Role::getUserRoles($id));
     // To be sure that user didn't attempt to assign himself some unavailable roles
     $newAssignments = array_intersect(Role::getAvailableRoles(Yii::$app->user->isSuperAdmin, true), Yii::$app->request->post('roles', []));
     $toAssign = array_diff($newAssignments, $oldAssignments);
     $toRevoke = array_diff($oldAssignments, $newAssignments);
     foreach ($toRevoke as $role) {
         User::revokeRole($id, $role);
     }
     foreach ($toAssign as $role) {
         User::assignRole($id, $role);
     }
     Yii::$app->session->setFlash('success', UserManagementModule::t('back', 'Saved'));
     return $this->redirect(['set', 'id' => $id]);
 }
Ejemplo n.º 2
0
				<div class="col-sm-6 text-right">
					<?php 
echo GridPageSize::widget(['pjaxId' => 'user-grid-pjax']);
?>
				</div>
			</div>


			<?php 
Pjax::begin(['id' => 'user-grid-pjax']);
?>

			<?php 
echo GridView::widget(['id' => 'user-grid', 'dataProvider' => $dataProvider, 'pager' => ['options' => ['class' => 'pagination pagination-sm'], 'hideOnSinglePage' => true, 'lastPageLabel' => '>>', 'firstPageLabel' => '<<'], 'filterModel' => $searchModel, 'layout' => '{items}<div class="row"><div class="col-sm-8">{pager}</div><div class="col-sm-4 text-right">{summary}' . GridBulkActions::widget(['gridId' => 'user-grid', 'actions' => [Url::to(['bulk-activate', 'attribute' => 'status']) => GridBulkActions::t('app', 'Activate'), Url::to(['bulk-deactivate', 'attribute' => 'status']) => GridBulkActions::t('app', 'Deactivate'), '----' => [Url::to(['bulk-delete']) => GridBulkActions::t('app', 'Delete')]]]) . '</div></div>', 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'options' => ['style' => 'width:10px']], ['class' => 'webvimark\\components\\StatusColumn', 'attribute' => 'superadmin', 'visible' => Yii::$app->user->isSuperadmin], ['attribute' => 'username', 'value' => function (User $model) {
    return Html::a($model->username, ['view', 'id' => $model->id], ['data-pjax' => 0]);
}, 'format' => 'raw'], ['attribute' => 'email', 'format' => 'raw', 'visible' => User::hasPermission('viewUserEmail')], ['class' => 'webvimark\\components\\StatusColumn', 'attribute' => 'email_confirmed', 'visible' => User::hasPermission('viewUserEmail')], ['attribute' => 'gridRoleSearch', 'filter' => ArrayHelper::map(Role::getAvailableRoles(Yii::$app->user->isSuperAdmin), 'name', 'description'), 'value' => function (User $model) {
    return implode(', ', ArrayHelper::map($model->roles, 'name', 'description'));
}, 'format' => 'raw', 'visible' => User::hasPermission('viewUserRoles')], ['attribute' => 'registration_ip', 'value' => function (User $model) {
    return Html::a($model->registration_ip, "http://ipinfo.io/" . $model->registration_ip, ["target" => "_blank"]);
}, 'format' => 'raw', 'visible' => User::hasPermission('viewRegistrationIp')], ['value' => function (User $model) {
    return GhostHtml::a(UserManagementModule::t('back', 'Roles and permissions'), ['/user-management/user-permission/set', 'id' => $model->id], ['class' => 'btn btn-sm btn-primary', 'data-pjax' => 0]);
}, 'format' => 'raw', 'visible' => User::canRoute('/user-management/user-permission/set'), 'options' => ['width' => '10px']], ['value' => function (User $model) {
    return GhostHtml::a(UserManagementModule::t('back', 'Change password'), ['change-password', 'id' => $model->id], ['class' => 'btn btn-sm btn-default', 'data-pjax' => 0]);
}, 'format' => 'raw', 'options' => ['width' => '10px']], ['class' => 'webvimark\\components\\StatusColumn', 'attribute' => 'status', 'optionsArray' => [[User::STATUS_ACTIVE, UserManagementModule::t('back', 'Active'), 'success'], [User::STATUS_INACTIVE, UserManagementModule::t('back', 'Inactive'), 'warning'], [User::STATUS_BANNED, UserManagementModule::t('back', 'Banned'), 'danger']]], ['class' => 'yii\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['class' => 'yii\\grid\\ActionColumn', 'contentOptions' => ['style' => 'width:70px; text-align:center;']]]]);
?>

			<?php 
Pjax::end();
?>

		</div>
Ejemplo n.º 3
0
		<div class="panel panel-default">
			<div class="panel-heading">
				<strong>
					<span class="glyphicon glyphicon-th"></span> <?php 
echo UserManagementModule::t('back', 'Roles');
?>
				</strong>
			</div>
			<div class="panel-body">

				<?php 
echo Html::beginForm(['set-roles', 'id' => $user->id]);
?>

				<?php 
foreach (Role::getAvailableRoles(Yii::$app->getModule('user-management')->userCanAssignAnotherRoles) as $aRole) {
    ?>
					<label>
						<?php 
    $isChecked = in_array($aRole['name'], ArrayHelper::map(Role::getUserRoles($user->id), 'name', 'name')) ? 'checked' : '';
    ?>

						<?php 
    if (Yii::$app->getModule('user-management')->userCanHaveMultipleRoles) {
        ?>
							<input type="checkbox" <?php 
        echo $isChecked;
        ?>
 name="roles[]" value="<?php 
        echo $aRole['name'];
        ?>
Ejemplo n.º 4
0
		<div class="panel panel-default">
			<div class="panel-heading">
				<strong>
					<span class="glyphicon glyphicon-th"></span> <?php 
echo UserManagementModule::t('back', 'Roles');
?>
				</strong>
			</div>
			<div class="panel-body">

				<?php 
echo Html::beginForm(['set-roles', 'id' => $user->id]);
?>

				<?php 
foreach (Role::getAvailableRoles() as $aRole) {
    ?>
					<label>
						<?php 
    $isChecked = in_array($aRole['name'], ArrayHelper::map(Role::getUserRoles($user->id), 'name', 'name')) ? 'checked' : '';
    ?>

						<?php 
    if (Yii::$app->getModule('user-management')->userCanHaveMultipleRoles) {
        ?>
							<input type="checkbox" <?php 
        echo $isChecked;
        ?>
 name="roles[]" value="<?php 
        echo $aRole['name'];
        ?>
Ejemplo n.º 5
0
		<div class="panel panel-default">
			<div class="panel-heading">
				<strong>
					<span class="glyphicon glyphicon-th"></span> <?php 
echo UserManagementModule::t('back', 'Roles');
?>
				</strong>
			</div>
			<div class="panel-body">

				<?php 
echo Html::beginForm(['set-roles', 'id' => $user->id]);
?>

				<?php 
echo Html::checkboxList('roles', ArrayHelper::map(Role::getUserRoles($user->id), 'name', 'name'), ArrayHelper::map(Role::getAvailableRoles(), 'name', 'description'), ['item' => function ($index, $label, $name, $checked, $value) {
    $list = '<ul style="padding-left: 10px">';
    foreach (Role::getPermissionsByRole($value) as $permissionName => $permissionDescription) {
        $list .= $permissionDescription ? "<li>{$permissionDescription}</li>" : "<li>{$permissionName}</li>";
    }
    $list .= '</ul>';
    $helpIcon = Html::beginTag('span', ['title' => UserManagementModule::t('back', 'Permissions for role - "{role}"', ['role' => $label]), 'data-content' => $list, 'data-html' => 'true', 'role' => 'button', 'style' => 'margin-bottom: 5px; padding: 0 5px', 'class' => 'btn btn-sm btn-default role-help-btn']);
    $helpIcon .= '?';
    $helpIcon .= Html::endTag('span');
    $isChecked = $checked ? 'checked' : '';
    $checkbox = "<label><input type='checkbox' name='{$name}' value='{$value}' {$isChecked}> {$label}</label>";
    return $helpIcon . ' ' . $checkbox;
}, 'separator' => '<br>']);
?>
				<br/>