Aligned Setting types naming + Fixed missing auth (refund)
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -53,7 +53,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
{ resource: Entity.TRANSACTIONS, action: [Action.LIST, Action.EXPORT, Action.IN_ERROR], attributes: ['*'] },
{
resource: Entity.TRANSACTION,
- action: [Action.READ, Action.UPDATE, Action.DELETE],
+ action: [Action.READ, Action.UPDATE, Action.DELETE, Action.REFUND_TRANSACTION],
attributes: ['*']
},
{

MODIFY
src/migration/tasks/MigrateCryptoSettingsFromConfigToDBTask.ts
src/migration/tasks/MigrateCryptoSettingsFromConfigToDBTask.ts
-import { CryptoKeySetting, CryptoSettingsType, TechnicalSettings } from '../../types/Setting';
+import { CryptoSettings, CryptoSettingsType, TechnicalSettings } from '../../types/Setting';
import Configuration from '../../utils/Configuration';
import Constants from '../../utils/Constants';
@@ -24,9 +24,9 @@ export default class MigrateCryptoSettingsFromConfigToDBTask extends MigrationTa
// Crypto Key Properties from config file
const configCryptoKeyProperties = Utils.parseConfigCryptoAlgorithm(Configuration.getCryptoConfig().algorithm);
// Crypto Key Setting from db
- const keySettings = await SettingStorage.getCryptoSettings(tenant.id);
+ const cryptoSettings = await SettingStorage.getCryptoSettings(tenant.id);
// If no Crypto Key Setting exist, initialize them with Crypto Key from config file
- if (!keySettings) {
+ if (!cryptoSettings) {
// Create New Crypto Key in Tenant Settings
const keySettingToSave = {
identifier: TechnicalSettings.CRYPTO,
@@ -35,8 +35,8 @@ export default class MigrateCryptoSettingsFromConfigToDBTask extends MigrationTa
key: configCryptoKey,
keyProperties: configCryptoKeyProperties,
}
- } as CryptoKeySetting;
- await Cypher.saveCryptoSetting(tenant.id, keySettingToSave);
+ } as CryptoSettings;
+ await SettingStorage.saveCryptoSettings(tenant.id, keySettingToSave);
}
}

MODIFY
src/migration/tasks/MigrateUserSettingsTask.ts
src/migration/tasks/MigrateUserSettingsTask.ts
-import { TechnicalSettings, UserSetting, UserSettingsType } from '../../types/Setting';
+import { TechnicalSettings, UserSettings, UserSettingsType } from '../../types/Setting';
import Constants from '../../utils/Constants';
import MigrationTask from '../MigrationTask';
@@ -15,9 +15,9 @@ export default class MigrateUserSettingsTask extends MigrationTask {
}
public async migrateTenant(tenant: Tenant): Promise<void> {
- const userSetting = await SettingStorage.getUserSettings(tenant.id);
+ const userSettings = await SettingStorage.getUserSettings(tenant.id);
// If no user setting exists, initialize it
- if (!userSetting) {
+ if (!userSettings) {
// Create new user setting with account activation param
const settingsToSave = {
identifier: TechnicalSettings.USER,

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -539,8 +539,8 @@ export default class AuthService {
message: 'Wrong Verification Token'
});
}
- const userSetting = await SettingStorage.getUserSettings(tenantID);
- const userStatus = userSetting.user.autoActivateAccountAfterValidation ? UserStatus.ACTIVE : UserStatus.INACTIVE;
+ const userSettings = await SettingStorage.getUserSettings(tenantID);
+ const userStatus = userSettings.user.autoActivateAccountAfterValidation ? UserStatus.ACTIVE : UserStatus.INACTIVE;
// Save User Status
await UserStorage.saveUserStatus(tenantID, user.id, userStatus);
// For integration with billing

MODIFY
src/server/rest/v1/service/TenantService.ts
src/server/rest/v1/service/TenantService.ts
import { Action, Entity } from '../../../../types/Authorization';
-import { CryptoKeySetting, CryptoSettingsType, SettingDB, SettingDBContent, TechnicalSettings, UserSetting, UserSettingsType } from '../../../../types/Setting';
+import { CryptoSettings, CryptoSettingsType, SettingDB, SettingDBContent, TechnicalSettings, UserSettings, UserSettingsType } from '../../../../types/Setting';
import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
import Tenant, { TenantLogo } from '../../../../types/Tenant';
@@ -9,7 +9,6 @@ import AppAuthError from '../../../../exception/AppAuthError';
import AppError from '../../../../exception/AppError';
import Authorizations from '../../../../authorization/Authorizations';
import Constants from '../../../../utils/Constants';
-import Cypher from '../../../../utils/Cypher';
import { LockEntity } from '../../../../types/Locking';
import LockingManager from '../../../../locking/LockingManager';
import Logging from '../../../../utils/Logging';
@@ -18,7 +17,6 @@ import { ServerAction } from '../../../../types/Server';
import SettingStorage from '../../../../storage/mongodb/SettingStorage';
import SiteAreaStorage from '../../../../storage/mongodb/SiteAreaStorage';
import { StatusCodes } from 'http-status-codes';
-import TenantComponents from '../../../../types/TenantComponents';
import TenantStorage from '../../../../storage/mongodb/TenantStorage';
import TenantValidator from '../validator/TenantValidation';
import UserStorage from '../../../../storage/mongodb/UserStorage';
@@ -166,44 +164,42 @@ export default class TenantService {
}
public static async createInitialSettingsForTenant(tenantID: string): Promise<void> {
- await this.createInitialCryptoSetting(tenantID);
- await this.createInitialUserSetting(tenantID);
+ await this.createInitialCryptoSettings(tenantID);
+ await this.createInitialUserSettings(tenantID);
}
- public static async createInitialCryptoSetting(tenantID: string): Promise<void> {
+ public static async createInitialCryptoSettings(tenantID: string): Promise<void> {
// Check for settings in db
const keySettings = await SettingStorage.getCryptoSettings(tenantID);
- // Generate Crypto Key Settings
+ // Create Crypto Key Settings
if (!keySettings) {
- const keySettingToSave = {
+ const keySettingToSave: CryptoSettings = {
identifier: TechnicalSettings.CRYPTO,
type: CryptoSettingsType.CRYPTO,
crypto: {
key: Utils.generateKey(),
keyProperties: Utils.getDefaultKeyProperties()
}
- } as CryptoKeySetting;
+ } as CryptoSettings;
// Save Crypto Key Settings
- await Cypher.saveCryptoSetting(tenantID, keySettingToSave);
+ await SettingStorage.saveCryptoSettings(tenantID, keySettingToSave);
}
}
- public static async createInitialUserSetting(tenantID: string): Promise<void> {
+ public static async createInitialUserSettings(tenantID: string): Promise<void> {
// Check for settings in db
const userSettings = await SettingStorage.getUserSettings(tenantID);
+ // Create new user settings
if (!userSettings) {
- // Create new user setting with account activation param
- const settingsToSave = {
+ const settingsToSave: UserSettings = {
identifier: TechnicalSettings.USER,
- content: {
type: UserSettingsType.USER,
user: {
autoActivateAccountAfterValidation: true
- }
},
createdOn: new Date(),
- } as UserSetting;
- await SettingStorage.saveSettings(tenantID, settingsToSave);
+ };
+ await SettingStorage.saveUserSettings(tenantID, settingsToSave);
}
}

MODIFY
src/storage/mongodb/SettingStorage.ts
src/storage/mongodb/SettingStorage.ts
-import { AnalyticsSettings, AnalyticsSettingsType, AssetSettings, AssetSettingsType, BillingSettings, BillingSettingsType, CryptoKeySetting, CryptoSetting, CryptoSettingsType, PricingSettings, PricingSettingsType, RefundSettings, RefundSettingsType, RoamingSettings, SettingDB, SmartChargingSettings, SmartChargingSettingsType, TechnicalSettings, UserSetting } from '../../types/Setting';
+import { AnalyticsSettings, AnalyticsSettingsType, AssetSettings, AssetSettingsType, BillingSettings, BillingSettingsType, CryptoSetting, CryptoSettings, CryptoSettingsType, PricingSettings, PricingSettingsType, RefundSettings, RefundSettingsType, RoamingSettings, SettingDB, SmartChargingSettings, SmartChargingSettingsType, TechnicalSettings, UserSettings, UserSettingsType } from '../../types/Setting';
import global, { FilterParams } from '../../types/GlobalType';
import BackendError from '../../exception/BackendError';
@@ -304,7 +304,7 @@ export default class SettingStorage {
}
}
- public static async getCryptoSettings(tenantID: string): Promise<CryptoKeySetting> {
+ public static async getCryptoSettings(tenantID: string): Promise<CryptoSettings> {
// Get the Crypto Key settings
const settings = await SettingStorage.getSettings(tenantID,
{ identifier: TechnicalSettings.CRYPTO },
@@ -335,14 +335,19 @@ export default class SettingStorage {
}
}
- public static async getUserSettings(tenantID: string): Promise<UserSetting> {
- let userSetting : UserSetting;
+ public static async getUserSettings(tenantID: string): Promise<UserSettings> {
+ let userSettings: UserSettings;
// Get the user settings
const settings = await SettingStorage.getSettings(tenantID, { identifier: TechnicalSettings.USER }, Constants.DB_PARAMS_SINGLE_RECORD);
- if (settings && settings.count > 0 && settings.result[0]) {
- userSetting = settings.result[0] as UserSetting;
+ if (settings.count > 0) {
+ userSettings = {
+ id: settings.result[0].id,
+ identifier: TechnicalSettings.USER,
+ type: UserSettingsType.USER,
+ user: settings.result[0].content.user,
+ };
}
- return userSetting;
+ return userSettings;
}
public static async getSettings(tenantID: string,
@@ -427,4 +432,34 @@ export default class SettingStorage {
// Debug
Logging.traceEnd(tenantID, MODULE_NAME, 'deleteSetting', uniqueTimerID, { id });
}
+
+ public static async saveUserSettings(tenantID: string, userSettingToSave: UserSettings): Promise<void> {
+ // Build internal structure
+ const settingsToSave = {
+ id: userSettingToSave.id,
+ identifier: TechnicalSettings.USER,
+ lastChangedOn: new Date(),
+ content: {
+ type: UserSettingsType.USER,
+ user: userSettingToSave.user
+ },
+ } as SettingDB;
+ // Save
+ await SettingStorage.saveSettings(tenantID, settingsToSave);
+ }
+
+ public static async saveCryptoSettings(tenantID: string, cryptoSettingsToSave: CryptoSettings): Promise<void> {
+ // Build internal structure
+ const settingsToSave = {
+ id: cryptoSettingsToSave.id,
+ identifier: TechnicalSettings.CRYPTO,
+ lastChangedOn: new Date(),
+ content: {
+ type: CryptoSettingsType.CRYPTO,
+ crypto: cryptoSettingsToSave.crypto
+ },
+ } as SettingDB;
+ // Save
+ await SettingStorage.saveSettings(tenantID, settingsToSave);
+ }
}

MODIFY
src/types/Setting.ts
src/types/Setting.ts
@@ -6,7 +6,7 @@ export enum TechnicalSettings {
CRYPTO = 'crypto'
}
-export interface Setting {
+export interface Setting extends CreatedUpdatedProps {
id?: string;
identifier: TenantComponents | TechnicalSettings;
sensitiveData?: string[];
@@ -47,7 +47,7 @@ export interface SettingDBContent {
sapSmartCharging?: SapSmartChargingSetting;
asset?: AssetSetting;
crypto?: CryptoSetting;
- user?: UserSettings;
+ user?: UserSetting;
}
export enum PricingSettingsType {
@@ -254,6 +254,11 @@ export interface AssetUserPasswordConnectionType {
password: string;
}
+export interface AssetGreencomConnectionType {
+ clientId: string;
+ clientSecret: string;
+}
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AssetSchneiderConnectionType extends AssetUserPasswordConnectionType {
}
@@ -262,38 +267,33 @@ export enum CryptoSettingsType {
CRYPTO = 'crypto'
}
-export interface CryptoKeySetting extends Setting {
+export interface CryptoSettings extends Setting {
identifier: TechnicalSettings.CRYPTO;
type: CryptoSettingsType;
crypto: CryptoSetting;
}
-export interface CryptoKeyProperties {
- blockCypher: string;
- blockSize: number;
- operationMode: string;
-}
-
export interface CryptoSetting {
key: string;
keyProperties: CryptoKeyProperties;
formerKey?: string;
formerKeyProperties?: CryptoKeyProperties;
}
-export interface AssetGreencomConnectionType {
- clientId: string;
- clientSecret: string;
+export interface CryptoKeyProperties {
+ blockCypher: string;
+ blockSize: number;
+ operationMode: string;
}
-
export enum UserSettingsType {
USER = 'user',
}
-export interface UserSetting extends Setting {
+export interface UserSettings extends Setting {
identifier: TechnicalSettings.USER;
- user?: UserSettings;
+ type: UserSettingsType;
+ user?: UserSetting;
}
-export interface UserSettings {
+export interface UserSetting {
autoActivateAccountAfterValidation: boolean;
}

MODIFY
src/utils/Cypher.ts
src/utils/Cypher.ts
-import { CryptoKeySetting, CryptoSetting, SettingDB } from '../types/Setting';
-
import BackendError from '../exception/BackendError';
import Constants from './Constants';
+import { CryptoSetting } from '../types/Setting';
import SettingStorage from '../storage/mongodb/SettingStorage';
import Utils from './Utils';
import _ from 'lodash';
@@ -147,18 +146,4 @@ export default class Cypher {
}
return cryptoSettings.crypto;
}
-
- public static async saveCryptoSetting(tenantID: string, cryptoSettingToSave: CryptoKeySetting): Promise<void> {
- // Build internal structure
- const settingsToSave = {
- id: cryptoSettingToSave.id,
- identifier: 'crypto',
- lastChangedOn: new Date(),
- content: {
- crypto: cryptoSettingToSave.crypto
- },
- } as SettingDB;
- // Save
- await SettingStorage.saveSettings(tenantID, settingsToSave);
- }
}

Aligned Setting types naming + Fixed missing auth (refund)