updated all "accountActivation" to "user"
also updated the db object tree with content: {id, type ...}
MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
@@ -26,11 +26,11 @@ import { LockEntity } from '../types/Locking';
import LockingManager from '../locking/LockingManager';
import Logging from '../utils/Logging';
import LogicallyDeleteTagsOfDeletedUsersTask from './tasks/LogicallyDeleteTagsOfDeletedUsersTask';
-import MigrateAccountActivationSettingsFromConfigToDBTask from './tasks/MigrateAccountActivationSettingsFromConfigToDBTask';
import MigrateCoordinatesTask from './tasks/MigrateCoordinatesTask';
import MigrateCryptoSettingsFromConfigToDBTask from './tasks/MigrateCryptoSettingsFromConfigToDBTask';
import MigrateOcpiSettingTask from './tasks/MigrateOcpiSettingTask';
import MigrateOcpiTransactionsTask from './tasks/MigrateOcpiTransactionsTask';
+import MigrateUserSettingsTask from './tasks/MigrateUserSettingsTask';
import MigrationStorage from '../storage/mongodb/MigrationStorage';
import MigrationTask from './MigrationTask';
import RecomputeAllTransactionsConsumptionsTask from './tasks/RecomputeAllTransactionsConsumptionsTask';
@@ -108,7 +108,7 @@ export default class MigrationHandler {
currentMigrationTasks.push(new MigrateCryptoSettingsFromConfigToDBTask());
currentMigrationTasks.push(new ImportLocalCarCatalogTask());
currentMigrationTasks.push(new AddLastChangedOnToCarCatalogTask());
- currentMigrationTasks.push(new MigrateAccountActivationSettingsFromConfigToDBTask());
+ currentMigrationTasks.push(new MigrateUserSettingsTask());
// Get the already done migrations from the DB
const migrationTasksDone = await MigrationStorage.getMigrations();
// Check

RENAME
src/migration/tasks/MigrateAccountActivationSettingsFromConfigToDBTask.ts
src/migration/tasks/MigrateUserSettingsTask.ts
-import { AccountActivationSetting, CryptoKeySetting, CryptoSettingsType, SettingDB } from '../../types/Setting';
+import { UserSetting, UserSettingsContentType, UserSettingsType } from '../../types/Setting';
import Constants from '../../utils/Constants';
import MigrationTask from '../MigrationTask';
import SettingStorage from '../../storage/mongodb/SettingStorage';
import Tenant from '../../types/Tenant';
-import TenantComponents from '../../types/TenantComponents';
import TenantStorage from '../../storage/mongodb/TenantStorage';
import Utils from '../../utils/Utils';
-export default class MigrateAccountActivationSettingsFromConfigToDBTask extends MigrationTask {
+export default class MigrateUserSettingsTask extends MigrationTask {
public async migrate(): Promise<void> {
const tenants = await TenantStorage.getTenants({}, Constants.DB_PARAMS_MAX_LIMIT);
for (const tenant of tenants.result) {
@@ -17,15 +16,20 @@ export default class MigrateAccountActivationSettingsFromConfigToDBTask extends
}
public async migrateTenant(tenant: Tenant): Promise<void> {
- const accountActivationSetting = await SettingStorage.getAccountActivationSettings(tenant.id);
- // If no account activation setting exists, initialize it
- if (Utils.isEmptyObject(accountActivationSetting)) {
- // Create new account activation setting in tenant
+ const userSetting = await SettingStorage.getUserSettings(tenant.id);
+ // If no user setting exists, initialize it
+ if (Utils.isEmptyObject(userSetting)) {
+ // Create new user setting with account activation param
const settingsToSave = {
- identifier: TenantComponents.ACCOUNT_ACTIVATION,
- createdOn: new Date(),
+ identifier: UserSettingsType.USER,
+ content: {
+ type: UserSettingsContentType.ACCOUNT_ACTIVATION,
+ accountActivation: {
doNotActivateByDefault: false
- } as AccountActivationSetting;
+ }
+ },
+ createdOn: new Date(),
+ } as UserSetting;
await SettingStorage.saveSettings(tenant.id, settingsToSave);
}
@@ -36,6 +40,6 @@ export default class MigrateAccountActivationSettingsFromConfigToDBTask extends
}
public getName(): string {
- return 'MigrateAccountActivationSettingsFromConfig';
+ return 'MigrateUserSettings';
}
}

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -21,6 +21,7 @@ import { StatusCodes } from 'http-status-codes';
import Tag from '../../../../types/Tag';
import TagStorage from '../../../../storage/mongodb/TagStorage';
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';
@@ -652,8 +653,8 @@ export default class AuthService {
message: 'Wrong Verification Token'
});
}
- const accountActivationSetting = await SettingStorage.getSettingByIdentifier(tenantID, 'accountActivation');
- const userStatus = accountActivationSetting.doNotActivateByDefault ? UserStatus.INACTIVE : UserStatus.ACTIVE;
+ const accountActivationSetting = await SettingStorage.getSettingByIdentifier(tenantID, UserSettingsType.USER);
+ const userStatus = accountActivationSetting.content.accountActivation.doNotActivateByDefault ? UserStatus.INACTIVE : UserStatus.ACTIVE;
// Save User Status
await UserStorage.saveUserStatus(tenantID, user.id, userStatus);
// For integration with billing

MODIFY
src/server/rest/v1/service/SettingService.ts
src/server/rest/v1/service/SettingService.ts
@@ -173,7 +173,7 @@ export default class SettingService {
MODULE_NAME, 'handleUpdateSetting', req.user);
// Process the sensitive data if any
// Preprocess the data to take care of updated values
- if (settingUpdate.sensitiveData && settingUpdate.sensitiveData.length > 0) {
+ if (settingUpdate.sensitiveData) {
if (!Array.isArray(settingUpdate.sensitiveData)) {
throw new AppError({
source: Constants.CENTRAL_SERVER,

MODIFY
src/server/rest/v1/service/security/SettingSecurity.ts
src/server/rest/v1/service/security/SettingSecurity.ts
-import { AnalyticsSettingsType, AssetConnectionSetting, AssetConnectionType, AssetSettingsType, BillingSettingsType, ConcurRefundSetting, OcpiBusinessDetails, OcpiSetting, PricingSettingsType, RefundSettingsType, RoamingSettingsType, SettingDB, SettingDBContent, SettingLink, SimplePricingSetting, SmartChargingSettingsType } from '../../../../../types/Setting';
+import { AnalyticsSettingsType, AssetConnectionSetting, AssetConnectionType, AssetSettingsType, BillingSettingsType, ConcurRefundSetting, OcpiBusinessDetails, OcpiSetting, PricingSettingsType, RefundSettingsType, RoamingSettingsType, SettingDB, SettingDBContent, SettingLink, SimplePricingSetting, SmartChargingSettingsType, UserSettingsContentType } from '../../../../../types/Setting';
import { HttpSettingRequest, HttpSettingsRequest } from '../../../../../types/requests/HttpSettingRequest';
-import TenantComponents from '../../../../../types/TenantComponents';
import Utils from '../../../../../utils/Utils';
import UtilsSecurity from './UtilsSecurity';
import sanitize from 'mongo-sanitize';
@@ -189,12 +188,14 @@ export default class SettingSecurity {
settings.content.asset.connections.push(sanitizedConnection);
}
break;
+ case UserSettingsContentType.ACCOUNT_ACTIVATION:
+ settings.content.accountActivation =
+ {
+ doNotActivateByDefault: request.content.accountActivation.doNotActivateByDefault
+ };
+ break;
}
}
- if (request.identifier === TenantComponents.ACCOUNT_ACTIVATION) {
- // If (request.identifier.toString() === 'accountActivation') {
- settings.doNotActivateByDefault = request.doNotActivateByDefault;
- }
return settings;
}
}

MODIFY
src/storage/mongodb/SettingStorage.ts
src/storage/mongodb/SettingStorage.ts
-import { AccountActivationSetting, AnalyticsSettings, AnalyticsSettingsType, AssetSettings, AssetSettingsType, BillingSettings, BillingSettingsType, CryptoKeySetting, CryptoSetting, CryptoSettingsType, PricingSettings, PricingSettingsType, RefundSettings, RefundSettingsType, RoamingSettings, SettingDB, SmartChargingSettings, SmartChargingSettingsType } from '../../types/Setting';
+import { AnalyticsSettings, AnalyticsSettingsType, AssetSettings, AssetSettingsType, BillingSettings, BillingSettingsType, CryptoKeySetting, CryptoSetting, CryptoSettingsType, PricingSettings, PricingSettingsType, RefundSettings, RefundSettingsType, RoamingSettings, SettingDB, SmartChargingSettings, SmartChargingSettingsType, UserSetting, UserSettingsType } from '../../types/Setting';
import global, { FilterParams } from '../../types/GlobalType';
import BackendError from '../../exception/BackendError';
@@ -51,21 +51,12 @@ export default class SettingStorage {
settingFilter._id = new ObjectID();
}
// Properties to save
- const settingMDB = (() => {
- if (settingToSave.identifier === 'accountActivation') {
- return {
- _id: settingFilter._id,
- identifier: settingToSave.identifier,
- doNotActivateByDefault: settingToSave.doNotActivateByDefault,
- };
- }
- return {
+ const settingMDB = {
_id: settingFilter._id,
identifier: settingToSave.identifier,
content: settingToSave.content,
sensitiveData: settingToSave.sensitiveData
};
- })();
DatabaseUtils.addLastChangedCreatedProps(settingMDB, settingToSave);
// Modify
await global.database.getCollection<SettingDB>(tenantID, 'settings').findOneAndUpdate(
@@ -344,17 +335,16 @@ export default class SettingStorage {
}
}
- public static async getAccountActivationSettings(tenantID: string): Promise<AccountActivationSetting> {
+ public static async getUserSettings(tenantID: string): Promise<UserSetting> {
// Get the account activation settings
const settings = await SettingStorage.getSettings(tenantID,
- { identifier: TenantComponents.ACCOUNT_ACTIVATION },
+ { identifier: UserSettingsType.USER },
Constants.DB_PARAMS_MAX_LIMIT);
- const accountActivationSettings = {} as AccountActivationSetting;
+ const userSettings = {} as UserSetting;
if (settings && settings.count > 0 && settings.result[0]) {
- accountActivationSettings.identifier = settings.result[0].identifier,
- accountActivationSettings.doNotActivateByDefault = settings.result[0].doNotActivateByDefault;
+ userSettings.id = settings.result[0].id;
}
- return accountActivationSettings;
+ return userSettings;
}
public static async getSettings(tenantID: string,

MODIFY
src/types/Setting.ts
src/types/Setting.ts
@@ -3,10 +3,9 @@ import TenantComponents from './TenantComponents';
export interface Setting {
id?: string;
- identifier: TenantComponents;
+ identifier: TenantComponents | UserSettingsType;
sensitiveData?: string[];
category?: 'business' | 'technical';
- doNotActivateByDefault?: boolean;
}
export interface SettingDB extends CreatedUpdatedProps, Setting {
@@ -22,7 +21,7 @@ export interface SettingLink {
}
export interface SettingDBContent {
- type: RoamingSettingsType | AnalyticsSettingsType | RefundSettingsType | PricingSettingsType | BillingSettingsType | SmartChargingSettingsType | AssetSettingsType | SmartChargingContentType | CryptoSettingsType;
+ type: RoamingSettingsType | AnalyticsSettingsType | RefundSettingsType | PricingSettingsType | BillingSettingsType | SmartChargingSettingsType | AssetSettingsType | SmartChargingContentType | CryptoSettingsType | UserSettingsContentType;
ocpi?: OcpiSetting;
simple?: SimplePricingSetting;
convergentCharging?: ConvergentChargingPricingSetting;
@@ -33,6 +32,7 @@ export interface SettingDBContent {
sapSmartCharging?: SapSmartChargingSetting;
asset?: AssetSetting;
crypto?: CryptoSetting;
+ accountActivation?: AccountActivationSetting;
}
export enum PricingSettingsType {
@@ -269,6 +269,19 @@ export interface AssetGreencomConnectionType {
clientId: string;
clientSecret: string;
}
-export interface AccountActivationSetting extends Setting {
+
+export enum UserSettingsType {
+ USER = 'user'
+}
+
+export enum UserSettingsContentType {
+ ACCOUNT_ACTIVATION = 'accountActivation',
+}
+
+export interface UserSetting extends Setting {
+ identifier: UserSettingsType.USER;
+ accountActivation?: AccountActivationSetting;
+}
+export interface AccountActivationSetting {
doNotActivateByDefault: boolean;
}

MODIFY
src/types/TenantComponents.ts
src/types/TenantComponents.ts
@@ -10,6 +10,5 @@ enum TenantComponents {
SMART_CHARGING = 'smartCharging',
CAR = 'car',
CRYPTO = 'crypto',
- ACCOUNT_ACTIVATION = 'accountActivation'
}
export default TenantComponents;

updated all "accountActivation" to "user"
also updated the db object tree with content: {id, type ...}