user-management
user-management copied to clipboard
Can i use your module to make menu items appear?
Hello,
Can i use your module to make menu items appear? For example: I want to hide the "Application Management" complete if no admin role: echo Nav::widget([ 'options' => ['class' => 'navbar-nav navbar-right'], 'items' => [ ['label' => 'Home', 'url' => ['/site/index']], ['label' => 'About', 'url' => ['/site/about'], ], ['label' => 'Contact', 'url' => ['/site/contact'], ],
['label' => 'Application Management', 'url' => ['#'], 'visible' => 0,
'items' => [
//Manage Users
['label' => 'Users Management',],
['label' => 'Edit Users','url' => ['/user-management/user/index']],
['label' => 'Edit Roles','url' => ['/user-management/role/index']],
['label' => 'Edit Permissions','url' => ['/user-management/permission/index']],
['label' => 'Edit Permission Groups','url' => ['/user-management/auth-item-group/index']],
//Manage Companies
['label' => 'Company Management'],
['label' => 'Edit Companies', 'url' => ['/user/admin']],
['label' => 'Create New Company', 'url' => ['/user/admin/create']],
],
],
Yii::$app->user->isGuest ?
['label' => 'Login', 'url' => ['/user-management/auth/login']] :
[
'label' => 'Logout (' . Yii::$app->user->username . ')',
'url' => ['/user-management/auth/logout'],
'linkOptions' => ['data-method' => 'post']
],
],
]);
I'm not sure, but you might look at GhostNav and related functions that are provided. The do a lot automatically. To use it just change Nav::widget([
to GhostNav::widget([
Their are other GhostXXX functions that may also do what you need.
Sandy
echo GhostNav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'encodeLabels'=>false, // don't encode stuff in the label, needed for UserManagementModule::menuItems()
'items' => [
['label' => 'Equalizer', 'url' => ['/equalizer']],
['label' => 'Reviews', 'url' => ['/reviews']],
['label' => 'Recipe', 'url' => ['/recipes']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
Yii::$app->user->isGuest ?
['label' => 'Login', 'url' => ['/user-management/auth/login']] :
['label' => 'Logout (' . Yii::$app->user->identity->username . ')', 'url' => ['/user-management/auth/logout']],
[
'label' => 'Admin',
'items'=> array_merge(UserManagementModule::menuItems(), [ ['label'=>'Change Password', 'url'=>['/user-management/auth/change-own-password']]]),
],
/*
Yii::$app->user->isGuest ?
['label' => 'Login', 'url' => ['/site/login']] :
[
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
],*/
],
]);
This is my simple menu bar with some of the integration. Might not be exactly what you need but maybe some help.
I allready considdered that, but thanks anyway. I need for example that: ['label' => 'Users Management',], ['label' => 'Edit Users','url' => ['/user-management/user/index']], //Visible to admin ['label' => 'Edit Roles','url' => ['/user-management/role/index']], //Visible to admin ['label' => 'Edit Permissions','url' => ['/user-management/permission/index']], //Visible to superadmin ['label' => 'Edit Permission Groups','url' => ['/user-management/auth-item-group/index']], //Visible to superadmin
Look at these static functions -
User::hasRole($roles, $superAdminAllowed = true)
User::hasPermission($permission, $superAdminAllowed = true)
They look like they might give you the ability to check for what you need. Also if you look at the code in them they will also give you some clue as to what it's looking at. I would expect you would just need to set the $role to what you are checking.
Also this is in the code to see if a user is superadmin -
return Yii::$app->user->identity->superadmin == 1;
Sandy
sganz gave you nice example.
GhostNav automatically hide items if user has no access to it's route. If items have some sub-items, it will be hidden if user has no access to none of it's children.
Although you can override visibility settings by 'visibility' attribute
Briljant examples, tested it and works, thanks. @webvimark i've seen you're example on adding a profile table but i want to use it for profile and customer. I was always building apps on Yii1.x but Yii2 is a different ballgame.
Like issue #96 Can you assist me in expanding you briljant module?
@arnoschrijver80 what exactly do you need ?
@webvimark : An expension of your module with the folowing info (sql) I wan't to be able to link a user to an exsisting or new customer (linked via user_profile table or perhaps a new junction table). A customer can have more users. Or if you have other suggestions. New customers have to sign up and customer created if not exist The admins need to be able to create and change accordingly.
I'm struggeling with the new YII2 relations.
Any help would be appreciated.