Added route restrictions based on user privilege
This commit allows us to add 'exclusiveToRoles' field to
route config files, with the list of roles that can access
this resource, if needed. In this case, only Administrator
can access Virtual-Media page and SOL console, and it is blocked for other
users.
Signed-off-by: Sivaprabu Ganesan <sivaprabug@ami.com>
Change-Id: Ibcee18bd92d97c34414ecaf2caf6af28070c5538
diff --git a/src/components/AppNavigation/AppNavigation.vue b/src/components/AppNavigation/AppNavigation.vue
index acfabe7..a5f8105 100644
--- a/src/components/AppNavigation/AppNavigation.vue
+++ b/src/components/AppNavigation/AppNavigation.vue
@@ -29,7 +29,7 @@
<b-collapse :id="navItem.id" tag="ul" class="nav-item__nav">
<li class="nav-item">
<router-link
- v-for="(subNavItem, i) of navItem.children"
+ v-for="(subNavItem, i) of filteredNavItem(navItem.children)"
:key="i"
:to="subNavItem.route"
:data-test-id="`nav-item-${subNavItem.id}`"
@@ -67,6 +67,7 @@
data() {
return {
isNavigationOpen: false,
+ currentUserRole: null,
};
},
watch: {
@@ -78,12 +79,24 @@
},
},
mounted() {
+ this.getPrivilege();
this.$root.$on('toggle-navigation', () => this.toggleIsOpen());
},
methods: {
toggleIsOpen() {
this.isNavigationOpen = !this.isNavigationOpen;
},
+ getPrivilege() {
+ this.currentUserRole = this.$store?.getters['global/userPrivilege'];
+ },
+ filteredNavItem(navItem) {
+ if (this.currentUserRole) {
+ return navItem.filter(({ exclusiveToRoles }) => {
+ if (!exclusiveToRoles?.length) return true;
+ return exclusiveToRoles.includes(this.currentUserRole);
+ });
+ } else return navItem;
+ },
},
};
</script>