diff --git a/packages/app-shell/.eslintrc.json b/packages/app-shell/.eslintrc.json index 806e1095014e8e6b81f1e79ecd2fbfd93a37c64f..d09b0d8759921ea078920a8e50961d8ad7262f7a 100644 --- a/packages/app-shell/.eslintrc.json +++ b/packages/app-shell/.eslintrc.json @@ -1,3 +1,4 @@ { - "extends": "./../../eslint.common.json" + "extends": "./../../eslint.common.json", + "root": true } \ No newline at end of file diff --git a/packages/app-shell/src/app-shell.js b/packages/app-shell/src/app-shell.js index 60110ef6edb636f131c952a6e3673b55b82e941c..6e6a41712e727c6e8c8c84a6d5487459d3976393 100644 --- a/packages/app-shell/src/app-shell.js +++ b/packages/app-shell/src/app-shell.js @@ -61,6 +61,7 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) { this.buildUrl = ''; this.buildTime = ''; this._loginStatus = 'unknown'; + this._roles = []; this.matomoUrl = ''; this.matomoSiteId = -1; @@ -138,6 +139,7 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) { activity.visible = visible; // Resolve module_src relative to the location of the json file activity.module_src = new URL(activity.module_src, actURL).href; + activity.required_roles = activity.required_roles || []; metadata[activity.routing_name] = activity; routes.push(activity.routing_name); } catch (error) { @@ -238,6 +240,7 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) { subtitle: { type: String, attribute: false }, description: { type: String, attribute: false }, _loginStatus: { type: Boolean, attribute: false }, + _roles: { type: Array, attribute: false }, matomoUrl: { type: String, attribute: "matomo-url" }, matomoSiteId: { type: Number, attribute: "matomo-site-id" }, noWelcomePage: { type: Boolean, attribute: "no-welcome-page" }, @@ -290,6 +293,12 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) { break; case 'auth': { + if (this.auth.person) { + this._roles = this.auth.person['roles']; + } else { + this._roles = []; + } + const loginStatus = this.auth['login-status']; if (loginStatus !== this._loginStatus) { console.log('Login status: ' + loginStatus); @@ -790,8 +799,18 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) { let menuTemplates = []; for (let routingName of this.routes) { const data = this.metadata[routingName]; + const requiredRoles = data['required_roles']; + let visible = data['visible']; + + // Hide them until the user is logged in and we knwo the roles of the user + for (let role of requiredRoles) { + if (!this._roles.includes(role)) { + visible = false; + break; + } + } - if (data['visible']) { + if (visible) { menuTemplates.push(html`<li><a @click="${(e) => this.onMenuItemClick(e)}" href="${this.router.getPathname({component: routingName})}" data-nav class="${getSelectClasses(routingName)}" title="${this.metaDataText(routingName, "description")}">${this.metaDataText(routingName, "short_name")}</a></li>`); } } diff --git a/packages/app-shell/src/dbp-app-shell-welcome.js b/packages/app-shell/src/dbp-app-shell-welcome.js index 12500e1e439c259afeba40f531b466d2db7f572b..d75db3cea9c3c9e8dbe116df05dfff4062dbaea1 100644 --- a/packages/app-shell/src/dbp-app-shell-welcome.js +++ b/packages/app-shell/src/dbp-app-shell-welcome.js @@ -95,7 +95,8 @@ export const appWelcomeMeta = { "de": "", "en": "" }, - visible: true + visible: true, + required_roles: [], }; commonUtils.defineCustomElement('dbp-app-shell-welcome', AppShellWelcome);