Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement first step of modular #25

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
rules: {
'vue/multi-word-component-names': 'off',
'no-undef': 'off',
'vue/require-v-for-key': 'warn',
},
parserOptions: {
ecmaVersion: 'latest',
Expand Down
5 changes: 1 addition & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
<title>geOrchestra header</title>
</head>
<body style="margin: 0">
<geor-header
logo-url="https://www.georchestra.org/public/georchestra-logo.svg"
active-app="datahub"
></geor-header>
<geor-header config-file="/config.json" stylesheet=""></geor-header>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
58 changes: 58 additions & 0 deletions public/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"config": {
"legacyHeader": false,
"legacyUrl": "/header",
"stylesheet": "https://data.lillemetropole.fr/public/georchestra.css",
"logoUrl": "https://data.lillemetropole.fr/public/logo-mel.jpg",
"hideLogin": false,
"lang": "es"
},
"menu": [
{
"label": "Catalogue",
"i18n": "hello",
"url": "/datahub/",
"activeAppUrl" : "/datahub"
},
{
"label": "My other service",
"url": "/geoserver/web",
"activeAppUrl": "/geoserver"
},
{
"label": "Mapstore",
"url": "/mapstore/#/",
"activeAppUrl": "/mapstore"
},
{
"label": "Mapstore home",
"url": "/mapstore/#/home",
"activeAppUrl": "/mapstore/#/home"
},
{
"label": "Cadastrapp",
"url": "/mapstore/#/context/cadastre",
"activeAppUrl": "includes:/#/context/cadastre"
},
{
"type": "dropdown",
"label": "A dropdown",
"items": [
{
"label": "Console",
"i18n": "users",
"url": "/console/manager/home",
"activeAppUrl": "/console"
}
]
}
],
"i18n": {
"en": {
"hello": "Hello"
},
"fr": {
"hello": "Bonjour"
}
}
}
54 changes: 5 additions & 49 deletions src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
const AUTH_API_URL = '/whoami'
const CONSOLE_PLATFORM_API_URL = '/console/private/platform/infos'

type KNOWN_ROLES =
| 'ROLE_SUPERUSER'
| 'ROLE_ORGADMIN'
| 'ROLE_MAPSTORE_ADMIN'
| 'ROLE_USER'
| 'ROLE_ADMINISTRATOR'
| 'ROLE_EXTRACTORAPP'
| 'ROLE_GN_REVIEWER'
| 'ROLE_GN_EDITOR'
| 'ROLE_GN_ADMIN'
| 'ROLE_EMAILPROXY'
| 'ROLE_ANONYMOUS'
| 'ROLE_IMPORT'

interface WhoAmIResponse {
GeorchestraUser: {
roles: KNOWN_ROLES[]
roles: string[]
username: string
firstName: string
lastName: string
Expand All @@ -33,17 +20,7 @@ export interface User {
anonymous: boolean
warned: boolean
remainingDays: string
adminRoles: AdminRoles | null
}

export interface AdminRoles {
superUser: boolean
admin: boolean
console: boolean
catalog: boolean
catalogAdmin: boolean
viewer: boolean
import: boolean
roles: string[]
}

export async function getUserDetails(): Promise<User> {
Expand All @@ -57,42 +34,21 @@ export async function getUserDetails(): Promise<User> {
warned: false,
remainingDays: '0',
anonymous: true,
adminRoles: null,
roles: ['ROLE_ANONYMOUS'],
}
}
const roles = user.roles
return {
username: user.username,
firstname: user.firstName,
lastname: user.lastName,
warned: user.ldapWarn,
remainingDays: user.ldapRemainingDays,
anonymous: roles.indexOf('ROLE_ANONYMOUS') > -1,
adminRoles: getAdminRoles(roles),
anonymous: user.roles.indexOf('ROLE_ANONYMOUS') > -1,
roles: user.roles,
}
})
}

export function getAdminRoles(roles: KNOWN_ROLES[]): AdminRoles | null {
const superUser = roles.indexOf('ROLE_SUPERUSER') > -1
const console = superUser || roles.indexOf('ROLE_ORGADMIN') > -1
const catalogAdmin = superUser || roles.indexOf('ROLE_GN_ADMIN') > -1
const catalog = !catalogAdmin && (roles.indexOf('ROLE_GN_EDITOR') > -1 || roles.indexOf('ROLE_GN_REVIEWER') > -1)
const viewer = superUser || roles.indexOf('ROLE_MAPSTORE_ADMIN') > -1
const admin =
superUser || console || catalog || viewer || catalogAdmin
if (!admin && roles.indexOf('ROLE_IMPORT') === -1) return null
return {
superUser,
admin,
console,
catalog,
catalogAdmin,
viewer,
import: superUser || roles.indexOf('ROLE_IMPORT') > -1,
}
}

export interface PlatformInfos {
analyticsEnabled: boolean
extractorappEnabled: boolean
Expand Down
32 changes: 32 additions & 0 deletions src/config-interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
interface MenuItem {
type?: string
hasRole?: string
blockedRole?: string
}

export interface Link extends MenuItem {
label: string
url: string
i18n?: string
activeAppUrl?: string
}

export interface Dropdown extends MenuItem {
label: string
i18n?: string
items?: Array<Link>
}

export interface Separator extends MenuItem {}

export interface Config {
legacyHeader?: boolean
legacyUrl?: string
logoUrl?: string
logoTitle?: string
hideLogin?: boolean
style?: string
stylesheet?: string
lang?: string
adminRoles: string[]
}
90 changes: 90 additions & 0 deletions src/default-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"defaultConfig": {
"legacyHeader": false,
"legacyUrl": "/header/",
"hideLogin": false,
"style": "",
"adminRoles": [
"ROLE_SUPERUSER",
"ROLE_ORGADMIN",
"ROLE_GN_ADMIN",
"ROLE_GN_REVIEWER",
"ROLE_GN_EDITOR",
"ROLE_MAPSTORE_ADMIN"
]
},
"defaultMenu": [
{
"label": "Catalogue",
"i18n": "catalogue",
"url": "/datahub/",
"activeAppUrl": "/datahub"
},
{
"label": "Mapstore viewer",
"i18n": "viewer",
"url": "/mapstore",
"activeAppUrl": "/mapstore"
},
{
"label": "Maps",
"i18n": "maps",
"url": "/mapstore/#/home",
"activeAppUrl": "/mapstore/#/home"
},
{
"label": "Services",
"i18n": "services",
"url": "/geoserver/web",
"activeAppUrl": "/geoserver"
},
{
"label": "Datafeeder",
"i18n": "datafeeder",
"url": "/import",
"activeAppUrl": "/import",
"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/catalog.edit#/board",
"activeAppUrl": "/geonetwork",
"hasRole": "ROLE_GN_EDITOR",
"blockedRole": "ROLE_SUPERUSER,ROLE_GN_REVIEWER,ROLE_GN_ADMIN"
},
{
"label": "Geonetwork",
"i18n": "catalogue",
"url": "/geonetwork/srv/:lang3/admin.console",
"activeAppUrl": "/geonetwork",
"hasRole": "ROLE_SUPERUSER,ROLE_GN_REVIEWER,ROLE_GN_ADMIN"
},
{
"label": "Viewer",
"i18n": "viewer",
"url": "/mapstore/#/admin",
"activeAppUrl": "/mapstore/#/admin",
"hasRole": "ROLE_SUPERUSER,ROLE_MAPSTORE_ADMIN"
},
{
"label": "Console",
"i18n": "users",
"url": "/console/manager/home",
"activeAppUrl": "/console/manager",
"hasRole": "ROLE_SUPERUSER"
}
]
}
]
}
Loading