Remove UserStorage.getOICPVirtualUser() and use UserStorage.getUserByEmail() instead
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -744,14 +744,10 @@ export default class Authorizations {
// Access Control Enabled?
if (!chargingStation.siteArea.accessControl) {
// No ACL: Always try to get the user
- let user;
- try {
- user = await UserStorage.getUserByTagId(tenantID, tagID);
- } finally {
+ let user = await UserStorage.getUserByTagId(tenantID, tagID);
if (!user && Utils.isTenantComponentActive(tenant, TenantComponents.OICP)) {
// In case of OICP, use virtual user if there is no user in the db
- user = await UserStorage.getOICPVirtualUser(tenantID);
- }
+ user = await UserStorage.getUserByEmail(tenantID, Constants.OICP_VIRTUAL_USER_EMAIL);
}
return user;
}
@@ -778,7 +774,7 @@ export default class Authorizations {
// FIXME: No tag will be created if OICP component is activated. What if unknown user is no OICP User? No information beforehand.
// You have to try the OICP authorization first (with a successful OICP authorization the session starts)
// Problem: Even if the user is no roaming user, the OICP virtual user will be returned
- return await UserStorage.getOICPVirtualUser(tenantID);
+ return UserStorage.getUserByEmail(tenantID, Constants.OICP_VIRTUAL_USER_EMAIL);
}
// Create the tag as inactive
tag = {

MODIFY
src/server/rest/v1/service/TenantService.ts
src/server/rest/v1/service/TenantService.ts
@@ -376,7 +376,7 @@ export default class TenantService {
if (tenant.components && tenant.components?.oicp) {
const checkOICPComponent = tenant.components.oicp;
// Virtual user needed for unknown roaming user
- const virtualOICPUser = await UserStorage.getOICPVirtualUser(tenant.id);
+ const virtualOICPUser = await UserStorage.getUserByEmail(tenant.id, Constants.OICP_VIRTUAL_USER_EMAIL);
// Activate or deactivate virtual user depending on the oicp component status
if (checkOICPComponent.active) {
if (!virtualOICPUser) {

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -99,24 +99,15 @@ export default class UserStorage {
return userMDB.count === 1 ? userMDB.result[0] : null;
}
- public static async getOICPVirtualUser(tenantID: string): Promise<User> {
- const email = 'virtual@oicp.com';
- const userMDB = await UserStorage.getUsers(tenantID, {
- email: email,
- }, Constants.DB_PARAMS_SINGLE_RECORD);
- return userMDB.count === 1 ? userMDB.result[0] : null;
- }
-
public static async createOICPVirtualUser(tenantID: string): Promise<void> {
// Create the virtual OICP user
const newVirtualOICPUser = UserStorage.createNewUser() as User;
- newVirtualOICPUser.email = 'virtual@oicp.com';
+ newVirtualOICPUser.email = Constants.OICP_VIRTUAL_USER_EMAIL;
newVirtualOICPUser.name = 'OICP';
newVirtualOICPUser.firstName = 'Virtual';
newVirtualOICPUser.issuer = false;
newVirtualOICPUser.status = UserStatus.ACTIVE;
newVirtualOICPUser.notificationsActive = false;
-
// Save User
newVirtualOICPUser.id = await UserStorage.saveUser(tenantID, newVirtualOICPUser);
// Save User Status

MODIFY
src/utils/Constants.ts
src/utils/Constants.ts
@@ -54,7 +54,7 @@ export default class Constants {
// OICP constants
public static readonly OICP_PROGRESS_NOTIFICATION_MAX_INTERVAL = 300; // Hubject restriction: "Progress Notification can be sent only at interval of at least 300 seconds." (5 Minutes)
-
+ public static readonly OICP_VIRTUAL_USER_EMAIL = 'virtual@oicp.com';
public static readonly WITH_CHARGING_STATIONS = true; // Not used
public static readonly WITHOUT_CHARGING_STATIONS = false; // Not used

Remove UserStorage.getOICPVirtualUser() and use UserStorage.getUserByEmail() instead