replace tag visualID cypther with ObjectID
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -10,7 +10,6 @@ import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants';
import CpoOCPIClient from '../client/ocpi/CpoOCPIClient';
import CpoOICPClient from '../client/oicp/CpoOICPClient';
-import Cypher from '../utils/Cypher';
import Logging from '../utils/Logging';
import NotificationHandler from '../notification/NotificationHandler';
import OCPIClientFactory from '../client/ocpi/OCPIClientFactory';
@@ -20,6 +19,7 @@ import { OICPAuthorizationStatus } from '../types/oicp/OICPAuthentication';
import OICPClientFactory from '../client/oicp/OICPClientFactory';
import { OICPDefaultTagId } from '../types/oicp/OICPIdentification';
import { OICPRole } from '../types/oicp/OICPRole';
+import { ObjectID } from 'mongodb';
import { PricingSettingsType } from '../types/Setting';
import { ServerAction } from '../types/Server';
import SessionHashService from '../server/rest/v1/service/SessionHashService';
@@ -879,7 +879,7 @@ export default class Authorizations {
// Create the tag as inactive
tag = {
id: tagID,
- visualID: Cypher.hash(tagID),
+ visualID: new ObjectID().toString(),
description: `Badged on '${chargingStation.id}'`,
issuer: true,
active: false,

MODIFY
src/migration/tasks/AddVisualIDPropertyToTagsTask.ts
src/migration/tasks/AddVisualIDPropertyToTagsTask.ts
import Constants from '../../utils/Constants';
-import Cypher from '../../utils/Cypher';
import Logging from '../../utils/Logging';
import MigrationTask from '../MigrationTask';
+import { ObjectID } from 'mongodb';
import { ServerAction } from '../../types/Server';
import Tenant from '../../types/Tenant';
import TenantStorage from '../../storage/mongodb/TenantStorage';
@@ -28,7 +28,7 @@ export default class AddVisualIDPropertyToTagsTask extends MigrationTask {
for (const tagMDB of tagsMDB) {
await global.database.getCollection<any>(tenant.id, 'tags').findOneAndUpdate(
{ _id: tagMDB._id },
- { $set: { visualID: Cypher.hash(tagMDB._id) } });
+ { $set: { visualID: new ObjectID().toString() } });
updated++;
}
}
@@ -44,7 +44,7 @@ export default class AddVisualIDPropertyToTagsTask extends MigrationTask {
}
getVersion(): string {
- return '1.0';
+ return '1.1';
}
getName(): string {

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
@@ -18,7 +18,6 @@ import Configuration from '../../../../utils/Configuration';
import Constants from '../../../../utils/Constants';
import Consumption from '../../../../types/Consumption';
import ConsumptionStorage from '../../../../storage/mongodb/ConsumptionStorage';
-import Cypher from '../../../../utils/Cypher';
import { DataResult } from '../../../../types/DataResult';
import DbParams from '../../../../types/database/DbParams';
import { HTTPError } from '../../../../types/HTTPError';
@@ -30,6 +29,7 @@ import { OCPIResponse } from '../../../../types/ocpi/OCPIResponse';
import { OCPIRole } from '../../../../types/ocpi/OCPIRole';
import { OCPIStatusCode } from '../../../../types/ocpi/OCPIStatusCode';
import OCPIUtils from '../../OCPIUtils';
+import { ObjectID } from 'mongodb';
import { PricingSource } from '../../../../types/Pricing';
import RoamingUtils from '../../../../utils/RoamingUtils';
import { ServerAction } from '../../../../types/Server';
@@ -626,7 +626,7 @@ export default class OCPIUtilsService {
}
const tagToSave = {
id: token.uid,
- visualID: Cypher.hash(token.uid),
+ visualID: new ObjectID().toString(),
issuer: false,
userID: emspUser.id,
active: token.valid === true ? true : false,
@@ -667,7 +667,7 @@ export default class OCPIUtilsService {
await UserStorage.saveUserStatus(tenantId, emspUser.id, UserStatus.ACTIVE);
const tagToSave = {
id: token.uid,
- visualID: Cypher.hash(token.uid),
+ visualID: new ObjectID().toString(),
issuer: false,
userID: emspUser.id,
active: token.valid === true ? true : false,

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -10,11 +10,11 @@ import AxiosFactory from '../../../../utils/AxiosFactory';
import BillingFactory from '../../../../integration/billing/BillingFactory';
import Configuration from '../../../../utils/Configuration';
import Constants from '../../../../utils/Constants';
-import Cypher from '../../../../utils/Cypher';
import { HTTPError } from '../../../../types/HTTPError';
import I18nManager from '../../../../utils/I18nManager';
import Logging from '../../../../utils/Logging';
import NotificationHandler from '../../../../notification/NotificationHandler';
+import { ObjectID } from 'mongodb';
import { ServerAction } from '../../../../types/Server';
import SessionHashService from './SessionHashService';
import SettingStorage from '../../../../storage/mongodb/SettingStorage';
@@ -209,7 +209,7 @@ export default class AuthService {
const i18nManager = I18nManager.getInstanceForLocale(newUser.locale);
const tag: Tag = {
id: newUser.name[0] + newUser.firstName[0] + Utils.getRandomIntSafe().toString(),
- visualID: Cypher.hash(newUser.name[0] + newUser.firstName[0] + Utils.getRandomIntSafe().toString()),
+ visualID: new ObjectID().toString(),
active: true,
issuer: true,
userID: newUser.id,

MODIFY
test/api/context/ContextDefinition.ts
test/api/context/ContextDefinition.ts
import { AnalyticsSettingsType, BillingSettingsType, PricingSettingsType, RefundSettingsType, RoamingSettingsType, SettingDBContent, SmartChargingSettingsType } from '../../../src/types/Setting';
-import Cypher from '../../../src/utils/Cypher';
import { OCPPVersion } from '../../../src/types/ocpp/OCPPServer';
+import { ObjectID } from 'mongodb';
import { Voltage } from '../../../src/types/ChargingStation';
import faker from 'faker';
@@ -402,7 +402,7 @@ export default class ContextDefinition {
emailPrefix: 'a-unassigned-',
tags: (ContextDefinition.USER_CONTEXTS.ADMIN_UNASSIGNED.withTags ? [{
id: 'A12341',
- visualID: Cypher.hash('A12341'),
+ visualID: new ObjectID().toString(),
issuer: false,
active: true
}] : null)
@@ -422,7 +422,7 @@ export default class ContextDefinition {
emailPrefix: 'basic-',
tags: (ContextDefinition.USER_CONTEXTS.BASIC_USER.withTags ? [{
id: 'A12342',
- visualID: Cypher.hash('A12342'),
+ visualID: new ObjectID().toString(),
issuer: false,
active: true
}] : null)
@@ -442,7 +442,7 @@ export default class ContextDefinition {
emailPrefix: 'demo-',
tags: (ContextDefinition.USER_CONTEXTS.DEMO_USER.withTags ? [{
id: 'A12343',
- visualID: Cypher.hash('A12343'),
+ visualID: new ObjectID().toString(),
issuer: false,
active: true
}] : null)
@@ -462,7 +462,7 @@ export default class ContextDefinition {
emailPrefix: 'b-unassigned-',
tags: (ContextDefinition.USER_CONTEXTS.BASIC_USER_UNASSIGNED.withTags ? [{
id: 'A12348',
- visualID: Cypher.hash('A12348'),
+ visualID: new ObjectID().toString(),
issuer: false,
active: true
}] : null)
@@ -482,7 +482,7 @@ export default class ContextDefinition {
emailPrefix: 'b-pending-',
tags: (ContextDefinition.USER_CONTEXTS.BASIC_USER_PENDING.withTags ? [{
id: 'A12349',
- visualID: Cypher.hash('A12349'),
+ visualID: new ObjectID().toString(),
issuer: false,
active: true
}] : null)
@@ -502,7 +502,7 @@ export default class ContextDefinition {
emailPrefix: 'b-locked-',
tags: (ContextDefinition.USER_CONTEXTS.BASIC_USER_LOCKED.withTags ? [{
id: 'A123410',
- visualID: Cypher.hash('A123410'),
+ visualID: new ObjectID().toString(),
issuer: false,
active: true
}] : null)
@@ -522,7 +522,7 @@ export default class ContextDefinition {
emailPrefix: 'b-notTag',
tags: (ContextDefinition.USER_CONTEXTS.BASIC_USER_NO_TAGS.withTags ? [{
id: 'A123411',
- visualID: Cypher.hash('A123411'),
+ visualID: new ObjectID().toString(),
issuer: false,
active: true
}] : null)
@@ -542,7 +542,7 @@ export default class ContextDefinition {
emailPrefix: 'b-external-',
tags: (ContextDefinition.USER_CONTEXTS.EXTERNAL_USER.withTags ? [{
id: 'A220311',
- visualID: Cypher.hash('A220311'),
+ visualID: new ObjectID().toString(),
issuer: false,
active: true
}] : null)

MODIFY
test/factories/TagFactory.ts
test/factories/TagFactory.ts
-import Cypher from '../../src/utils/Cypher';
import { Factory } from 'rosie';
+import { ObjectID } from 'mongodb';
import faker from 'faker';
export default Factory.define('tag')
.attr('id', () => faker.random.alphaNumeric(20).toString().toUpperCase())
- .attr('visualID', () => Cypher.hash(faker.random.alphaNumeric(20).toString().toUpperCase()))
+ .attr('visualID', () => new ObjectID().toString())
.attr('active', true)
.attr('issuer', () => true)
.attr('default', () => false)

replace tag visualID cypther with ObjectID