Added page visibility configurability.
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
<script>
|
||||
import IconBurger from '@/assets/interface-icons/burger-menu.svg';
|
||||
import { makePageSlug } from '@/utils/ConfigHelpers';
|
||||
import { checkPageVisibility } from '@/utils/CheckPageVisibility';
|
||||
|
||||
export default {
|
||||
name: 'Nav',
|
||||
@@ -45,10 +46,11 @@ export default {
|
||||
computed: {
|
||||
/* Get links to sub-pages, and combine with nav-links */
|
||||
allLinks() {
|
||||
const subPages = this.$store.getters.pages.map((subPage) => ({
|
||||
path: makePageSlug(subPage.name, 'home'),
|
||||
title: subPage.name,
|
||||
}));
|
||||
const subPages = this.$store.getters.pages.filter((page) => checkPageVisibility(page))
|
||||
.map((subPage) => ({
|
||||
path: makePageSlug(subPage.name, 'home'),
|
||||
title: subPage.name,
|
||||
}));
|
||||
const navLinks = this.links || [];
|
||||
return [...navLinks, ...subPages];
|
||||
},
|
||||
|
||||
18
src/utils/CheckPageVisibility.js
Normal file
18
src/utils/CheckPageVisibility.js
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* A helper function that checks if a page is visible based on current users permissions
|
||||
* Checks a page's displayData for hideForUsers, showForUsers and hideForGuests
|
||||
* Returns a boolean that determines if the user has the required permissions
|
||||
*/
|
||||
|
||||
// Import helper functions from auth, to get current user, and check if guest
|
||||
import { getCurrentUser } from '@/utils/Auth';
|
||||
import { isVisibleToUser } from '@/utils/IsVisibleToUser';
|
||||
|
||||
/* Putting it all together, the function to export */
|
||||
export const checkPageVisibility = (page) => {
|
||||
const currentUser = getCurrentUser(); // Get current user object
|
||||
const displayData = page.displayData || {};
|
||||
return isVisibleToUser(displayData, currentUser);
|
||||
};
|
||||
|
||||
export default checkPageVisibility;
|
||||
Reference in New Issue
Block a user