@genesislcap/blank-app-seed 3.12.4 → 3.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/blank-app-seed-config",
3
3
  "description": "Genesis Blank App Seed Configuration",
4
- "version": "3.12.4",
4
+ "version": "3.13.1",
5
5
  "license": "Apache-2.0",
6
6
  "genxSeedConfig": {
7
7
  "exclude": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "UI": "14.184.0",
2
+ "UI": "14.188.0",
3
3
  "GSF": "8.0.1",
4
4
  "Auth": "8.0.0"
5
5
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.13.1](https://github.com/genesiscommunitysuccess/blank-app-seed/compare/v3.13.0...v3.13.1) (2024-06-17)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * foundation-ui resource and datasource enhancements [skip-ci] [FUI-1993](https://github.com/genesiscommunitysuccess/blank-app-seed/issues/1993) (#256) 2e64739
9
+
10
+ ## [3.13.0](https://github.com/genesiscommunitysuccess/blank-app-seed/compare/v3.12.4...v3.13.0) (2024-06-14)
11
+
12
+
13
+ ### Features
14
+
15
+ * support for route permissions based on right codes GENC-469 (#255) c7f4358
16
+
3
17
  ## [3.12.4](https://github.com/genesiscommunitysuccess/blank-app-seed/compare/v3.12.3...v3.12.4) (2024-06-07)
4
18
 
5
19
 
@@ -1,16 +1,15 @@
1
1
  import { Auth, Session } from '@genesislcap/foundation-comms';
2
- import {
3
- defaultLoginConfig,
4
- LoginConfig,
5
- Settings as LoginSettings,
6
- } from '@genesislcap/foundation-login';
2
+ import { defaultLoginConfig, LoginConfig } from '@genesislcap/foundation-login';
7
3
  import { FoundationRouterConfiguration } from '@genesislcap/foundation-ui';
8
- import { optional, Route } from '@genesislcap/web-core';
4
+ import { NavigationPhase, optional, Route } from '@genesislcap/web-core';
9
5
  import { defaultLayout, loginLayout } from '../layouts';
6
+ import { logger } from '../utils';
10
7
  {{#each routes}}
11
8
  import { {{pascalCase this.name}} } from './{{kebabCase this.name}}/{{kebabCase this.name}}';
12
9
  {{/each}}
13
10
  import { NotFound } from './not-found/not-found';
11
+ import { defaultNotPermittedRoute, NotPermitted } from './not-permitted/not-permitted';
12
+ import { LoginSettings } from './types';
14
13
 
15
14
  // eslint-disable-next-line
16
15
  declare var ENABLE_SSO: string;
@@ -72,12 +71,21 @@ export class MainRouterConfig extends FoundationRouterConfiguration<LoginSetting
72
71
  childRouters: true,
73
72
  },
74
73
  { path: 'not-found', element: NotFound, title: 'Not Found', name: 'not-found' },
74
+ {
75
+ path: defaultNotPermittedRoute,
76
+ element: NotPermitted,
77
+ title: 'Not Permitted',
78
+ name: defaultNotPermittedRoute,
79
+ },
75
80
  {{#each routes}}
76
81
  {
77
82
  path: '{{kebabCase this.name}}',
78
83
  element: {{pascalCase this.name}},
79
84
  title: '{{sentenceCase this.name}}',
80
85
  name: '{{kebabCase this.name}}',
86
+ {{#if this.permissions.viewRight}}
87
+ settings: { isPermitted: () => this.auth.currentUser.hasPermission('{{this.permissions.viewRight}}') },
88
+ {{/if}}
81
89
  navItems: [
82
90
  {
83
91
  title: '{{sentenceCase this.name}}',
@@ -85,6 +93,7 @@ export class MainRouterConfig extends FoundationRouterConfiguration<LoginSetting
85
93
  name: 'cog',
86
94
  variant: 'solid',
87
95
  },
96
+ permission: '{{this.permissions.viewRight}}',
88
97
  },
89
98
  ],
90
99
  },
@@ -116,13 +125,14 @@ export class MainRouterConfig extends FoundationRouterConfiguration<LoginSetting
116
125
  * If logged in don't block
117
126
  */
118
127
  if (this.auth.isLoggedIn) {
128
+ this.redirectIfNotPermitted(settings, phase);
119
129
  return;
120
130
  }
121
131
 
122
132
  /**
123
133
  * If allowAutoAuth and session is valid try to connect+auto-login
124
134
  */
125
- if (this.loginConfig.autoAuth && (await this.auth.reAuthFromSession())) {
135
+ if (this.loginConfig.autoAuth && (await this.reAuthFromSession(settings, phase))) {
126
136
  return;
127
137
  }
128
138
 
@@ -136,4 +146,24 @@ export class MainRouterConfig extends FoundationRouterConfiguration<LoginSetting
136
146
  },
137
147
  });
138
148
  }
149
+
150
+ private async reAuthFromSession(settings: LoginSettings, phase: NavigationPhase) {
151
+ return this.auth.reAuthFromSession().then((authenticated) => {
152
+ logger.info(`reAuthFromSession. authenticated: ${authenticated}`);
153
+ if (authenticated) {
154
+ this.redirectIfNotPermitted(settings, phase);
155
+ }
156
+ return authenticated;
157
+ });
158
+ }
159
+
160
+ private redirectIfNotPermitted(settings: LoginSettings, phase: NavigationPhase) {
161
+ const { path } = phase.route.endpoint;
162
+ if (settings?.isPermitted && !settings.isPermitted()) {
163
+ logger.warn(`Not permitted - Redirecting URL from ${path} to ${defaultNotPermittedRoute}.`);
164
+ phase.cancel(() => {
165
+ Route.name.replace(phase.router, defaultNotPermittedRoute);
166
+ });
167
+ }
168
+ }
139
169
  }
@@ -8,4 +8,8 @@ export const NotFoundStyles = css`
8
8
  align-items: center;
9
9
  justify-content: center;
10
10
  }
11
+
12
+ h1 {
13
+ color: var(--neutral-foreground-rest);
14
+ }
11
15
  `;
@@ -0,0 +1,16 @@
1
+ import { css } from '@genesislcap/web-core';
2
+ import { mixinScreen } from '../../styles';
3
+
4
+ export const NotPermittedStyles = css`
5
+ :host {
6
+ ${mixinScreen('flex')}
7
+
8
+ align-items: center;
9
+ justify-content: center;
10
+ }
11
+
12
+ h1 {
13
+ text-align: center;
14
+ color: var(--neutral-foreground-rest);
15
+ }
16
+ `;
@@ -0,0 +1,9 @@
1
+ import { html } from '@genesislcap/web-core';
2
+ import type { NotPermitted } from './not-permitted';
3
+
4
+ export const NotPermittedTemplate = html<NotPermitted>`
5
+ <h1>
6
+ You do not have permission to access this part of the application, please contact your
7
+ administrator.
8
+ </h1>
9
+ `;
@@ -0,0 +1,18 @@
1
+ import { customElement, GenesisElement } from '@genesislcap/web-core';
2
+ import { logger } from '../../utils';
3
+ import { NotPermittedStyles as styles } from './not-permitted.styles';
4
+ import { NotPermittedTemplate as template } from './not-permitted.template';
5
+
6
+ export const defaultNotPermittedRoute = 'not-permitted';
7
+
8
+ @customElement({
9
+ name: 'not-permitted-route',
10
+ template,
11
+ styles,
12
+ })
13
+ export class NotPermitted extends GenesisElement {
14
+ public connectedCallback() {
15
+ super.connectedCallback();
16
+ logger.debug(`${name} is now connected to the DOM`);
17
+ }
18
+ }
@@ -0,0 +1,5 @@
1
+ import { Settings } from '@genesislcap/foundation-login';
2
+
3
+ export type LoginSettings = Settings & {
4
+ isPermitted?: () => boolean;
5
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/blank-app-seed",
3
3
  "description": "Genesis Blank App Seed",
4
- "version": "3.12.4",
4
+ "version": "3.13.1",
5
5
  "license": "Apache-2.0",
6
6
  "scripts": {
7
7
  "release": "semantic-release"