diff options
author | Damian Celico <damianx.celico@intel.com> | 2022-11-24 04:00:53 +0300 |
---|---|---|
committer | Kiran Kumar Ballapalli <kirankumarb@ami.com> | 2023-03-27 19:39:34 +0300 |
commit | aeb19816e67f6d3ffb1b37c95d813a25b8be1d7b (patch) | |
tree | 0b760854f8adc45a3e909a3b1ccd88655a139705 /src/components/AppNavigation/AppNavigation.vue | |
parent | 568b8a93af49d35891f042f73add850cfa651308 (diff) | |
download | webui-vue-aeb19816e67f6d3ffb1b37c95d813a25b8be1d7b.tar.xz |
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
Diffstat (limited to 'src/components/AppNavigation/AppNavigation.vue')
-rw-r--r-- | src/components/AppNavigation/AppNavigation.vue | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/components/AppNavigation/AppNavigation.vue b/src/components/AppNavigation/AppNavigation.vue index acfabe76..a5f81051 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 @@ export default { data() { return { isNavigationOpen: false, + currentUserRole: null, }; }, watch: { @@ -78,12 +79,24 @@ export default { }, }, 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> |