Skip to content
Snippets Groups Projects
Commit 6fb3bd17 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

app-shell: Add a required_roles field to the activity metadata

This field specifies a list of roles that the logged-in user needs to
have to interact with this activity.

In the case of the app-shell this means the activity is hidden until
the user information is loaded after login.
parent f550ed42
No related branches found
No related tags found
No related merge requests found
Pipeline #16937 passed with warnings
{ {
"extends": "./../../eslint.common.json" "extends": "./../../eslint.common.json",
"root": true
} }
\ No newline at end of file
...@@ -61,6 +61,7 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) { ...@@ -61,6 +61,7 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
this.buildUrl = ''; this.buildUrl = '';
this.buildTime = ''; this.buildTime = '';
this._loginStatus = 'unknown'; this._loginStatus = 'unknown';
this._roles = [];
this.matomoUrl = ''; this.matomoUrl = '';
this.matomoSiteId = -1; this.matomoSiteId = -1;
...@@ -138,6 +139,7 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) { ...@@ -138,6 +139,7 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
activity.visible = visible; activity.visible = visible;
// Resolve module_src relative to the location of the json file // Resolve module_src relative to the location of the json file
activity.module_src = new URL(activity.module_src, actURL).href; activity.module_src = new URL(activity.module_src, actURL).href;
activity.required_roles = activity.required_roles || [];
metadata[activity.routing_name] = activity; metadata[activity.routing_name] = activity;
routes.push(activity.routing_name); routes.push(activity.routing_name);
} catch (error) { } catch (error) {
...@@ -238,6 +240,7 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) { ...@@ -238,6 +240,7 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
subtitle: { type: String, attribute: false }, subtitle: { type: String, attribute: false },
description: { type: String, attribute: false }, description: { type: String, attribute: false },
_loginStatus: { type: Boolean, attribute: false }, _loginStatus: { type: Boolean, attribute: false },
_roles: { type: Array, attribute: false },
matomoUrl: { type: String, attribute: "matomo-url" }, matomoUrl: { type: String, attribute: "matomo-url" },
matomoSiteId: { type: Number, attribute: "matomo-site-id" }, matomoSiteId: { type: Number, attribute: "matomo-site-id" },
noWelcomePage: { type: Boolean, attribute: "no-welcome-page" }, noWelcomePage: { type: Boolean, attribute: "no-welcome-page" },
...@@ -290,6 +293,12 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) { ...@@ -290,6 +293,12 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
break; break;
case 'auth': case 'auth':
{ {
if (this.auth.person) {
this._roles = this.auth.person['roles'];
} else {
this._roles = [];
}
const loginStatus = this.auth['login-status']; const loginStatus = this.auth['login-status'];
if (loginStatus !== this._loginStatus) { if (loginStatus !== this._loginStatus) {
console.log('Login status: ' + loginStatus); console.log('Login status: ' + loginStatus);
...@@ -790,8 +799,18 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) { ...@@ -790,8 +799,18 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
let menuTemplates = []; let menuTemplates = [];
for (let routingName of this.routes) { for (let routingName of this.routes) {
const data = this.metadata[routingName]; 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>`); 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>`);
} }
} }
......
...@@ -95,7 +95,8 @@ export const appWelcomeMeta = { ...@@ -95,7 +95,8 @@ export const appWelcomeMeta = {
"de": "", "de": "",
"en": "" "en": ""
}, },
visible: true visible: true,
required_roles: [],
}; };
commonUtils.defineCustomElement('dbp-app-shell-welcome', AppShellWelcome); commonUtils.defineCustomElement('dbp-app-shell-welcome', AppShellWelcome);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment