modified UserSettingsType to TechnicalSettingsType
way we handle return of getUserSettings method
manualActivation to AutoActivation
MODIFY
src/migration/tasks/MigrateUserSettingsTask.ts
src/migration/tasks/MigrateUserSettingsTask.ts
-import { UserSetting, UserSettingsContentType, UserSettingsType } from '../../types/Setting';
+import { TechnicalSettingsType, UserSetting, UserSettingsContentType } from '../../types/Setting';
import Constants from '../../utils/Constants';
import MigrationTask from '../MigrationTask';
import SettingStorage from '../../storage/mongodb/SettingStorage';
import Tenant from '../../types/Tenant';
import TenantStorage from '../../storage/mongodb/TenantStorage';
-import Utils from '../../utils/Utils';
export default class MigrateUserSettingsTask extends MigrationTask {
public async migrate(): Promise<void> {
@@ -18,19 +17,18 @@ export default class MigrateUserSettingsTask extends MigrationTask {
public async migrateTenant(tenant: Tenant): Promise<void> {
const userSetting = await SettingStorage.getUserSettings(tenant.id);
// If no user setting exists, initialize it
- if (Utils.isEmptyObject(userSetting)) {
+ if (!userSetting) {
// Create new user setting with account activation param
const settingsToSave = {
- identifier: UserSettingsType.USER,
+ identifier: TechnicalSettingsType.USER,
content: {
type: UserSettingsContentType.USER,
user: {
- manualAccountActivation: false
+ autoAccountActivation: true
}
},
createdOn: new Date(),
} as UserSetting;
-
await SettingStorage.saveSettings(tenant.id, settingsToSave);
}
}

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -20,8 +20,8 @@ import SiteStorage from '../../../../storage/mongodb/SiteStorage';
import { StatusCodes } from 'http-status-codes';
import Tag from '../../../../types/Tag';
import TagStorage from '../../../../storage/mongodb/TagStorage';
+import { TechnicalSettingsType } from '../../../../types/Setting';
import TenantStorage from '../../../../storage/mongodb/TenantStorage';
-import { UserSettingsType } from '../../../../types/Setting';
import UserStorage from '../../../../storage/mongodb/UserStorage';
import UserToken from '../../../../types/UserToken';
import Utils from '../../../../utils/Utils';
@@ -539,8 +539,8 @@ export default class AuthService {
message: 'Wrong Verification Token'
});
}
- const userSetting = await SettingStorage.getSettingByIdentifier(tenantID, UserSettingsType.USER);
- const userStatus = userSetting.content.user.manualAccountActivation ? UserStatus.INACTIVE : UserStatus.ACTIVE;
+ const userSetting = await SettingStorage.getSettingByIdentifier(tenantID, TechnicalSettingsType.USER);
+ const userStatus = userSetting.content.user.autoAccountActivation ? 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, UserSetting, UserSettingsContentType, UserSettingsType } from '../../../../types/Setting';
+import { CryptoKeySetting, CryptoSettingsType, SettingDB, SettingDBContent, TechnicalSettingsType, UserSetting, UserSettingsContentType } from '../../../../types/Setting';
import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
import Tenant, { TenantLogo } from '../../../../types/Tenant';
@@ -191,14 +191,14 @@ export default class TenantService {
public static async createInitialUserSetting(tenantID: string): Promise<void> {
// Check for settings in db
const userSettings = await SettingStorage.getUserSettings(tenantID);
- if (Utils.isEmptyObject(userSettings)) {
+ if (!userSettings) {
// Create new user setting with account activation param
const settingsToSave = {
- identifier: UserSettingsType.USER,
+ identifier: TechnicalSettingsType.USER,
content: {
type: UserSettingsContentType.USER,
user: {
- manualAccountActivation: false
+ autoAccountActivation: true
}
},
createdOn: new Date(),

MODIFY
src/server/rest/v1/service/security/SettingSecurity.ts
src/server/rest/v1/service/security/SettingSecurity.ts
@@ -189,9 +189,8 @@ export default class SettingSecurity {
}
break;
case UserSettingsContentType.USER:
- settings.content.user =
- {
- manualAccountActivation: request.content.user.manualAccountActivation
+ settings.content.user = {
+ autoAccountActivation: sanitize(request.content.user.autoAccountActivation)
};
break;
}

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, UserSetting, UserSettings, UserSettingsType } from '../../types/Setting';
+import { AnalyticsSettings, AnalyticsSettingsType, AssetSettings, AssetSettingsType, BillingSettings, BillingSettingsType, CryptoKeySetting, CryptoSetting, CryptoSettingsType, PricingSettings, PricingSettingsType, RefundSettings, RefundSettingsType, RoamingSettings, SettingDB, SmartChargingSettings, SmartChargingSettingsType, TechnicalSettingsType, UserSetting } from '../../types/Setting';
import global, { FilterParams } from '../../types/GlobalType';
import BackendError from '../../exception/BackendError';
@@ -336,15 +336,13 @@ export default class SettingStorage {
}
public static async getUserSettings(tenantID: string): Promise<UserSetting> {
+ let userSetting : UserSetting = null;
// Get the user settings
- const settings = await SettingStorage.getSettings(tenantID,
- { identifier: UserSettingsType.USER },
- Constants.DB_PARAMS_MAX_LIMIT);
- const userSettings = {} as UserSetting;
+ const settings = await SettingStorage.getSettings(tenantID, { identifier: TechnicalSettingsType.USER }, Constants.DB_PARAMS_SINGLE_RECORD);
if (settings && settings.count > 0 && settings.result[0]) {
- userSettings.id = settings.result[0].id;
+ userSetting = settings.result[0] as UserSetting;
}
- return userSettings;
+ return userSetting;
}
public static async getSettings(tenantID: string,

MODIFY
src/types/Setting.ts
src/types/Setting.ts
@@ -3,7 +3,7 @@ import TenantComponents from './TenantComponents';
export interface Setting {
id?: string;
- identifier: TenantComponents | UserSettingsType;
+ identifier: TenantComponents | TechnicalSettingsType;
sensitiveData?: string[];
category?: 'business' | 'technical';
}
@@ -270,8 +270,9 @@ export interface AssetGreencomConnectionType {
clientSecret: string;
}
-export enum UserSettingsType {
- USER = 'user'
+export enum TechnicalSettingsType {
+ USER = 'user',
+ // TODO: Ajouter CRYPTO = 'crypto'
}
export enum UserSettingsContentType {
@@ -279,9 +280,9 @@ export enum UserSettingsContentType {
}
export interface UserSetting extends Setting {
- identifier: UserSettingsType.USER;
+ identifier: TechnicalSettingsType.USER;
user?: UserSettings;
}
export interface UserSettings {
- manualAccountActivation: boolean;
+ autoAccountActivation: boolean;
}

modified UserSettingsType to TechnicalSettingsType
way we handle return of getUserSettings method
manualActivation to AutoActivation