Skip to content

Commit

Permalink
feat: set menu config file and block account
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Dec 6, 2024
1 parent 4ebe0c0 commit 47aa4a1
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 94 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<geor-header
logo-url="https://www.georchestra.org/public/georchestra-logo.svg"
active-app="datahub"
menu-file="/menu.json"
></geor-header>
<script type="module" src="/src/main.ts"></script>
</body>
Expand Down
30 changes: 30 additions & 0 deletions public/menu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"config": {

},
"menu": [
{
"label": "Catalogue",
"i18n": "catalogue",
"url": "/datahub/",
"active-app" : "datahub"
},
{
"label": "My other service",
"url": "/geoserver/web",
"active-app" : "geoserver"
},
{
"type": "dropdown",
"label": "A dropdown",
"items": [
{
"label": "Console",
"i18n": "users",
"url": "/console/manager/home",
"active-app": "console"
}
]
}
]
}
1 change: 0 additions & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export async function getUserDetails(): Promise<User> {
"roles": [
"ROLE_MAPSTORE_ADMIN",
"ROLE_DSP_ILEVIA",
"ROLE_GN_EDITOR",
"ROLE_USER",
"ROLE_ADMINISTRATOR",
"ROLE_SUPERUSER"
Expand Down
55 changes: 29 additions & 26 deletions src/header.ce.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import { getUserDetails, getPlatformInfos } from './auth'
import type { User, PlatformInfos } from './auth'
import UserIcon from './ui/UserIcon.vue'
import GeorchestraLogo from './ui/GeorchestraLogo.vue'
import CatalogIcon from '@/ui/CatalogIcon.vue'
import MapIcon from '@/ui/MapIcon.vue'
import ChartPieIcon from '@/ui/ChartPieIcon.vue'
import UsersIcon from '@/ui/UsersIcon.vue'
import ChevronDownIcon from '@/ui/ChevronDownIcon.vue'
import { LANG_2_TO_3_MAPPER, t } from '@/i18n'
import menu from '@/menu.json'
import { defaultMenu } from '@/menu.json'
const props = defineProps<{
hideLogin?: string
Expand All @@ -22,21 +18,20 @@ const props = defineProps<{
legacyUrl?: string
style?: string
stylesheet?: string
menuFile?: string
}>()
const state = reactive({
user: null as null | User,
mobileMenuOpen: false,
lang3: props.lang,
platformInfos: null as null | PlatformInfos,
menu: defaultMenu,
})
const isAnonymous = computed(() => !state.user || state.user.anonymous)
const isAdmin = computed(() => state.user?.adminRoles?.admin)
const isWarned = computed(() => state.user?.warned)
const remainingDays = computed(() => state.user?.remainingDays)
const adminRoles = computed(() => state.user?.adminRoles)
const cond = computed(condition => state.user?.roles?.[condition])
const loginUrl = computed(() => {
const current = new URL(window.location.href)
Expand All @@ -49,13 +44,28 @@ function toggleMenu(): void {
state.mobileMenuOpen = !state.mobileMenuOpen
}
function checkCondition(condition: string): boolean {
function checkCondition(item: object): boolean {
const hasRole = item.hasRole
if (!state.user) return false
if (!condition) return true
return condition.split(',').some(c => state.user?.roles?.indexOf(c) !== -1)
if (!hasRole) return true
const isBlocked = item.blockedRole
?.split(',')
.some(c => state.user?.roles?.indexOf(c) !== -1)
if (isBlocked) return false
return hasRole.split(',').some(c => state.user?.roles?.indexOf(c) !== -1)
}
function computeUrl(url: string): string {
return url.replace(/:lang3/, state.lang3)
}
onMounted(() => {
if (props.menuFile)
fetch(props.menuFile)
.then(res => res.json())
.then(file => {
state.menu = file.menu
})
state.lang3 =
LANG_2_TO_3_MAPPER[props.lang || navigator.language.substring(0, 2)] ||
'eng'
Expand Down Expand Up @@ -89,10 +99,7 @@ onMounted(() => {
</component>
<div class="justify-between text-slate-600 sm:flex hidden h-full bg-white">
<div class="flex">
<a
href="/"
class="flex justify-center items-center px-8 rounded-r-lg py-2 bg-primary-light"
>
<a href="/" class="flex justify-center items-center px-8 py-2">
<img
v-if="props.logoUrl"
:src="props.logoUrl"
Expand All @@ -105,8 +112,8 @@ onMounted(() => {
></GeorchestraLogo>
</a>
<nav class="flex justify-center items-center font-semibold">
<template v-for="(item, index) in menu.menu" :key="index">
<template v-if="!item.type && checkCondition(item.condition)">
<template v-for="(item, index) in state.menu" :key="index">
<template v-if="!item.type && checkCondition(item)">
<a
:href="item.url"
class="nav-item"
Expand All @@ -115,16 +122,12 @@ onMounted(() => {
>
</template>
<template
v-else-if="
item.type === 'separator' && checkCondition(item.condition)
"
v-else-if="item.type === 'separator' && checkCondition(item)"
>
<span class="text-gray-400">|</span>
</template>
<template
v-else-if="
item.type === 'dropdown' && checkCondition(item.condition)
"
v-else-if="item.type === 'dropdown' && checkCondition(item)"
>
<div class="group inline-block relative">
<button
Expand All @@ -143,12 +146,12 @@ onMounted(() => {
>
<template v-for="subitem in item.items">
<li
v-if="checkCondition(subitem.condition)"
v-if="checkCondition(subitem)"
:class="{
active: props.activeApp === subitem['active-app'],
}"
>
<a :href="subitem.url" class="capitalize">
<a :href="computeUrl(subitem.url)" class="capitalize">
{{ subitem.i18n ? t(subitem.i18n) : subitem.label }}</a
>
</li>
Expand Down Expand Up @@ -288,7 +291,7 @@ onMounted(() => {
@apply relative text-lg w-fit block after:hover:scale-x-[82%] px-2 mx-2 hover:text-black first-letter:capitalize;
}
.nav-item:after {
@apply block content-[''] absolute h-[3px] bg-gradient-to-r from-primary to-secondary-light w-full scale-x-0 transition duration-300 origin-left;
@apply block content-[''] absolute h-[3px] bg-primary w-full scale-x-0 transition duration-300 origin-left;
}
.nav-item.active {
@apply after:scale-x-[82%] after:bg-primary after:bg-none text-gray-900;
Expand Down
143 changes: 76 additions & 67 deletions src/menu.json
Original file line number Diff line number Diff line change
@@ -1,68 +1,77 @@
{
"menu": [
{
"label": "Catalogue",
"i18n": "catalogue",
"url": "/datahub/",
"active-app" : "datahub"
},
{
"label": "Mapstore viewer",
"i18n": "viewer",
"url": "/mapstore",
"active-app" : "mapstore"
},
{
"label": "Maps",
"i18n": "maps",
"url": "/mapstore/#/home",
"active-app" : "mapstore-home"
},
{
"label": "Services",
"i18n": "services",
"url": "/geoserver/web",
"active-app" : "geoserver"
},
{
"label": "Datafeeder",
"i18n": "datafeeder",
"url": "/datafeeder",
"active-app" : "datafeeder",
"condition": "ROLE_SUPERUSER,ROLE_IMPORT"
},
{
"condition": "ROLE_SUPERUSER",
"type": "separator"
},
{
"type": "dropdown",
"label": "Administration",
"i18n": "admin",
"condition": "ROLE_SUPERUSER",
"items": [
{
"label": "Geonetwork",
"i18n": "catalogue",
"url": "/georchestra/ldap/users",
"active-app": "geonetwork",
"condition": "ROLE_SUPERUSER,ROLE_GN_EDITOR,ROLE_GN_ADMIN"
},
{
"label": "Viewer",
"i18n": "viewer",
"url": "/mapstore/#/admin",
"active-app": "msadmin",
"condition": "ROLE_SUPERUSER,ROLE_MAPSTORE_ADMIN"
},
{
"label": "Console",
"i18n": "users",
"url": "/console/manager/home",
"active-app": "console",
"condition": "ROLE_SUPERUSER"
}
]
}
]
}
"defaultMenu": [
{
"label": "Catalogue",
"i18n": "catalogue",
"url": "/datahub/",
"active-app": "datahub"
},
{
"label": "Mapstore viewer",
"i18n": "viewer",
"url": "/mapstore",
"active-app": "mapstore"
},
{
"label": "Maps",
"i18n": "maps",
"url": "/mapstore/#/home",
"active-app": "mapstore-home"
},
{
"label": "Services",
"i18n": "services",
"url": "/geoserver/web",
"active-app": "geoserver"
},
{
"label": "Datafeeder",
"i18n": "datafeeder",
"url": "/datafeeder",
"active-app": "datafeeder",
"hasRole": "ROLE_SUPERUSER,ROLE_IMPORT"
},
{
"hasRole": "ROLE_SUPERUSER,ROLE_GN_EDITOR,ROLE_GN_ADMIN,ROLE_MAPSTORE_ADMIN",
"type": "separator"
},
{
"type": "dropdown",
"label": "Administration",
"i18n": "admin",
"hasRole": "ROLE_SUPERUSER,ROLE_GN_EDITOR,ROLE_GN_ADMIN,ROLE_MAPSTORE_ADMIN",
"items": [
{
"label": "Geonetwork",
"i18n": "catalogue",
"url": "/geonetwork/srv/:lang3/admin.console",
"active-app": "geonetwork",
"hasRole": "ROLE_SUPERUSER,ROLE_GN_EDITOR,ROLE_GN_ADMIN",
"blockedRole": "ROLE_GN_EDITOR,ROLE_SUPERUSER"
},
{
"label": "Geonetwork",
"i18n": "catalogue",
"url": "/geonetwork/srv/:lang3/catalog.edit#/board",
"active-app": "geonetwork",
"hasRole": "ROLE_SUPERUSER,ROLE_GN_EDITOR,ROLE_GN_ADMIN",
"blockedRole": "ROLE_GN_REVIEWER"
},
{
"label": "Viewer",
"i18n": "viewer",
"url": "/mapstore/#/admin",
"active-app": "msadmin",
"hasRole": "ROLE_SUPERUSER,ROLE_MAPSTORE_ADMIN"
},
{
"label": "Console",
"i18n": "users",
"url": "/console/manager/home",
"active-app": "console",
"hasRole": "ROLE_SUPERUSER"
}
]
}
]
}

0 comments on commit 47aa4a1

Please sign in to comment.