Skip to content

Commit 710eeb3

Browse files
Add support for user avatar configuration via USER_AVATAR_URL (#320)
- Improve validation configuration handling. --------- Co-authored-by: Grzegorz Krajniak <[email protected]>
1 parent d880dee commit 710eeb3

File tree

6 files changed

+39
-27
lines changed

6 files changed

+39
-27
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ The portal can run without any authentication infrastructure. Authentication con
3535
| TOKEN*URL*${idp} | The URL for the authentication token service provider specific to the idp name. This URL is used for retrieveing an auth tokens. |
3636
| OIDC*CLIENT_ID*${idp} | Client ID for the OpenID Connect (OIDC) configuration. The Client ID is used to identify the application to the OIDC provider (e.g., an authorization server). |
3737
| OIDC*CLIENT_SECRET*${idp} | Client Secret for the OIDC configuration. The Client Secret is a confidential value known only to the application and the OIDC provider, used to authenticate the application to the provider. |
38-
| CONTENT_CONFIGURATION_VALIDATOR_API_URL | Endpoint URL for custom content configuration validation. Endpoint returns useful error message when configuration is invalid. |
3938

4039
- **Optional**
4140

42-
| Property name | Description |
43-
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
44-
| HEALTH_CHECK_INTERVAL | The interval in _milliseconds_ at which the application performs health checks to ensure its components are functioning correctly. Default 2000 ms. |
45-
| LOGOUT_REDIRECT_URL | The url to redirect user after logout action, by default _/logout_. |
46-
| ENVIRONMENT | This property indicates the environment in which the application is running, _local_ indicates development environment. |
47-
| DEVELOPMENT_INSTANCE | This property indicates if the portal runs in development mode. |
48-
| FRONTEND_PORT | Set the port number on which the frontend of the application will run. |
49-
| VALID_WEBCOMPONENT_URLS | To enable CORS Web component Loading: basically you need to add external domains where the Web Components are hosted; `".?"` in this examle, we are sepcify that we can load Web Components from everyhere. |
50-
| FEATURE_TOGGLES | Comma separated values of features following the convention `featureName=boolean`. Boolean value indicates is the feature is on/off (true/false) |
41+
| Property name | Description |
42+
|-----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
43+
| CONTENT_CONFIGURATION_VALIDATOR_API_URL | Endpoint URL for custom content configuration validation. Endpoint returns useful error message when configuration is invalid. |
44+
| HEALTH_CHECK_INTERVAL | The interval in _milliseconds_ at which the application performs health checks to ensure its components are functioning correctly. Default 2000 ms. |
45+
| LOGOUT_REDIRECT_URL | The url to redirect user after logout action, by default _/logout_. |
46+
| ENVIRONMENT | This property indicates the environment in which the application is running, _local_ indicates development environment. |
47+
| DEVELOPMENT_INSTANCE | This property indicates if the portal runs in development mode. |
48+
| FRONTEND_PORT | Set the port number on which the frontend of the application will run. |
49+
| VALID_WEBCOMPONENT_URLS | To enable CORS Web component Loading: basically you need to add external domains where the Web Components are hosted; `".?"` in this examle, we are sepcify that we can load Web Components from everywhere. |
50+
| FEATURE_TOGGLES | Comma separated values of features following the convention `featureName=boolean`. Boolean value indicates is the feature is on/off (true/false) |
51+
| USER_AVATAR_URL | Url that indicates where to find a user avatar to be displayed in the application along with the user information. Should contain a user id placeholder ${userId} which will be automatically replaced with the value. |
5152

5253
#### Full configuration (with authentication)
5354

@@ -71,6 +72,7 @@ DEVELOPMENT_INSTANCE=true
7172
ENVIRONMENT='local'
7273
VALID_WEBCOMPONENT_URLS=".?"
7374
FEATURE_TOGGLES="foo=true,boo=false"
75+
USER_AVATAR_URL=https://example.com/avatar/${userId}
7476
```
7577

7678
## Consuming the library

integration-tests/localnodes.integration-spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ describe('LocalnodesController', () => {
101101

102102
it('should call the getLuigiData method on valid params', async () => {
103103
const resultingNodes: LuigiNode[] = [];
104+
process.env.CONTENT_CONFIGURATION_VALIDATOR_API_URL =
105+
'http://localhost:8080';
104106

105107
const validateContentConfiguration = jest
106108
.spyOn(

src/env/env-variables.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class EnvVariablesServiceImpl implements EnvVariablesService {
4343
isLocal,
4444
developmentInstance,
4545
uiOptions,
46+
userAvatarUrl,
4647
} = this.envService.getEnv();
4748
return {
4849
idpName,
@@ -56,6 +57,7 @@ export class EnvVariablesServiceImpl implements EnvVariablesService {
5657
isLocal,
5758
developmentInstance,
5859
uiOptions,
60+
userAvatarUrl,
5961
};
6062
}
6163
}

src/env/env.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface EnvVariables extends Record<string, any> {
88
logoutRedirectUrl?: string;
99
healthCheckInterval?: number;
1010
isLocal?: boolean;
11+
userAvatarUrl?: string;
1112
developmentInstance?: boolean;
1213
validWebcomponentUrls?: string[];
1314
uiOptions?: string[];
@@ -21,6 +22,7 @@ export class EnvService {
2122
return {
2223
idpNames: this.getIdpNames(),
2324
healthCheckInterval: parseInt(process.env.HEALTH_CHECK_INTERVAL, 10),
25+
userAvatarUrl: process.env.USER_AVATAR_URL || '',
2426
logoutRedirectUrl: process.env.LOGOUT_REDIRECT_URL || '/logout',
2527
isLocal: process.env.ENVIRONMENT === 'local',
2628
developmentInstance: process.env.DEVELOPMENT_INSTANCE === 'true',

src/local-nodes/local-nodes.controller.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import {
55
IntentResolveService,
66
LuigiNode,
77
ValidationResult,
8-
} from '../config';
9-
import { ConfigTransferNodeService } from '../config/luigi/luigi-data/config-transfer-node.service';
10-
import { NodeExtendedDataService } from '../config/luigi/luigi-data/node-extended-data.service';
11-
import { TextsTranslateService } from '../config/luigi/luigi-data/texts-translate.service';
8+
} from '../config/index.js';
9+
import { ConfigTransferNodeService } from '../config/luigi/luigi-data/config-transfer-node.service.js';
10+
import { NodeExtendedDataService } from '../config/luigi/luigi-data/node-extended-data.service.js';
11+
import { TextsTranslateService } from '../config/luigi/luigi-data/texts-translate.service.js';
1212
import { ConfigDto, LocalNodesController } from './local-nodes.controller.js';
1313
import { HttpModule } from '@nestjs/axios';
1414
import { HttpException, HttpStatus, Logger } from '@nestjs/common';
1515
import { Test, TestingModule } from '@nestjs/testing';
16-
import { AxiosResponse } from 'axios';
1716
import type { Request, Response } from 'express';
1817
import { mock } from 'jest-mock-extended';
1918

@@ -135,6 +134,7 @@ describe('LocalNodesController', () => {
135134

136135
it('should return HttpException when local nodes validator throws error', async () => {
137136
//Arrange
137+
process.env.CONTENT_CONFIGURATION_VALIDATOR_API_URL = 'http://localhost';
138138
const validationResult: ValidationResult = {
139139
url: 'http://localhost:8080',
140140
validationErrors: [

src/local-nodes/local-nodes.controller.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,23 @@ export class LocalNodesController {
4646
@Body() config: ConfigDto,
4747
@Res({ passthrough: true }) response: ExpressResponse,
4848
): Promise<TransformResult> {
49-
const validationResults =
50-
await this.contentConfigurationValidatorService.validateContentConfigurations(
51-
config.contentConfigurations,
52-
);
49+
const ccValidatorApiUrl =
50+
process.env.CONTENT_CONFIGURATION_VALIDATOR_API_URL;
51+
if (ccValidatorApiUrl) {
52+
const validationResults =
53+
await this.contentConfigurationValidatorService.validateContentConfigurations(
54+
config.contentConfigurations,
55+
);
5356

54-
if (
55-
validationResults.some(
56-
(validationResult) =>
57-
validationResult.validationErrors &&
58-
validationResult.validationErrors.length,
59-
)
60-
) {
61-
return { errors: validationResults };
57+
if (
58+
validationResults.some(
59+
(validationResult) =>
60+
validationResult.validationErrors &&
61+
validationResult.validationErrors.length,
62+
)
63+
) {
64+
return { errors: validationResults };
65+
}
6266
}
6367

6468
try {

0 commit comments

Comments
 (0)