I need to adjust my menu so that certain sections are only visible to specific users based on their roles. In my database, I have three roles: user, admin1, and admin2. For instance, how can I ensure that Category 2 is only visible to users with the ROLE_ADMIN1 role?
It's important to note that users can have multiple roles simultaneously. As shown in the examples below, each user has the ROLE_USER role, but they may also have ROLE_ADMIN1, ROLE_ADMIN2, or both.
{
"name": "Jack",
"fname": "Daniel",
"roles": [
"ROLE_USER"
]
}
{
"name": "Laly",
"fname": "Dom",
"roles": [
"ROLE_USER",
"ROLE_ADMIN1"
]
}
{
"name": "Admini",
"fname": "Strator",
"roles": [
"ROLE_USER",
"ROLE_ADMIN2"
]
}<br><br; {
"name": "Admini",
"fname": "Strator",
"roles": [
"ROLE_USER",
"ROLE_ADMIN1",
"ROLE_ADMIN2"
]
}
This is what my HTML looks like:
<ion-item class="item-stable animsvdj" ng-click="toggleGroup(group)" ng-class="{active: isGroupShown(group)}">
<i class="icon" ng-class="isGroupShown(group) ? 'ion-android-contacts' : 'ion-android-contacts'"></i>
Category
</ion-item>
<ion-item class="item-accordion menu-border" ng-show="isGroupShown(group)" ui-sref="menu.disponibilites" menu-close=""><i class="ion-ios-calendar-outline menu-icon"></i> Category 1</ion-item>
<!-- This section should only be visible to admins -->
<ion-item class="item-accordion menu-border" ng-show="isGroupShown(group)" ui-sref="menu.organiseVisite" menu-close=""><i class="ion-ios-time-outline menu-icon"></i> Category 2</ion-item>
<!-- This section should only be visible to admins -->
<ion-item class="item-accordion menu-border" ng-show="isGroupShown(group)" ui-sref="menu.trouverUnJeune" menu-close=""><i class="ion-ios-eye-outline menu-icon"></i> Category 3</ion-item>
In my controller:
.controller('menuCtrl', function($scope, $state, $http, $ionicHistory, AppService) {
$scope.group = [];
$scope.toggleGroup = function(group) {
if ($scope.isGroupShown(group)) {
$scope.shownGroup = null;
} else {
$scope.shownGroup = group;
}
};
$scope.isGroupShown = function(group) {
return $scope.shownGroup === group;
};
})
Thank you for your help!