OICP virtual User improvements
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -743,7 +743,7 @@ export default class Authorizations {
try {
user = await UserStorage.getUserByTagId(tenantID, tagID);
} finally {
- if (Utils.isTenantComponentActive(tenant, TenantComponents.OICP)) {
+ 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);
}
@@ -769,9 +769,10 @@ export default class Authorizations {
let tag = await TagStorage.getTag(tenantID, tagID, { withUser: true });
if (!tag) {
// Unknown User -> OICP component activated -> return virtual user (do not create inactive Tag)
- if (authAction === Action.AUTHORIZE && Utils.isTenantComponentActive(tenant, TenantComponents.OICP)) {
+ if (Utils.isTenantComponentActive(tenant, TenantComponents.OICP)) {
// 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);
}
// Create the tag as inactive

MODIFY
src/server/rest/v1/service/TenantService.ts
src/server/rest/v1/service/TenantService.ts
@@ -382,28 +382,10 @@ export default class TenantService {
} else if (virtualOICPUser.status !== UserStatus.ACTIVE) {
// Activate user and save user status
await UserStorage.saveUserStatus(tenant.id, virtualOICPUser.id, UserStatus.ACTIVE);
-
- // Activate Default Badge(s)
- const tags = (await TagStorage.getTags(tenant.id, { userIDs: [virtualOICPUser.id] }, Constants.DB_PARAMS_MAX_LIMIT)).result;
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
- tags.forEach(async (tag) => {
- tag.active = true;
- // Save
- await TagStorage.saveTag(tenant.id, tag);
- });
}
} else if (virtualOICPUser && virtualOICPUser?.status === UserStatus.ACTIVE) {
// Deactivate user and save user status
await UserStorage.saveUserStatus(tenant.id, virtualOICPUser.id, UserStatus.INACTIVE);
-
- // Deactivate Default Badge(s)
- const tags = (await TagStorage.getTags(tenant.id, { userIDs: [virtualOICPUser.id] }, Constants.DB_PARAMS_MAX_LIMIT)).result;
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
- tags.forEach(async (tag) => {
- tag.active = false;
- // Save
- await TagStorage.saveTag(tenant.id, tag);
- });
}
}
}

MODIFY
src/storage/mongodb/TagStorage.ts
src/storage/mongodb/TagStorage.ts
@@ -230,29 +230,4 @@ export default class TagStorage {
result: tagsMDB
};
}
-
- public static async createOICPVirtualUserTags(tenantID: string): Promise<void> {
- const defaultTagIds = [OICPDefaultTagId.RemoteIdentification, OICPDefaultTagId.QRCodeIdentification, OICPDefaultTagId.PlugAndChargeIdentification];
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
- defaultTagIds.forEach(async (defaultTagId) => {
- let tag = await this.getTag(tenantID, defaultTagId);
- if (!tag) {
- const virtualOICPUser = await UserStorage.getOICPVirtualUser(tenantID);
- tag = {
- id: defaultTagId,
- userID: virtualOICPUser.id,
- user: virtualOICPUser,
- description: 'Badge for OICP Remote Authorization',
- issuer: false,
- active: true,
- createdOn: new Date(),
- default: false
- } as Tag;
- } else {
- tag.active = true;
- }
- // Save
- await TagStorage.saveTag(tenantID, tag);
- });
- }
}

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -100,7 +100,6 @@ export default class UserStorage {
}
public static async getOICPVirtualUser(tenantID: string): Promise<User> {
- // FIX ME: get virtual User reliably
const email = 'virtual@oicp.com';
const userMDB = await UserStorage.getUsers(tenantID, {
email: email,
@@ -109,7 +108,6 @@ export default class UserStorage {
}
public static async createOICPVirtualUser(tenantID: string): Promise<void> {
- // FIX ME: create virtual User
// Create the virtual OICP user
const newVirtualOICPUser = UserStorage.createNewUser() as User;
newVirtualOICPUser.email = 'virtual@oicp.com';
@@ -123,9 +121,6 @@ export default class UserStorage {
newVirtualOICPUser.id = await UserStorage.saveUser(tenantID, newVirtualOICPUser);
// Save User Status
await UserStorage.saveUserStatus(tenantID, newVirtualOICPUser.id, UserStatus.ACTIVE);
-
- // Create default badges for virtual OICP user
- await TagStorage.createOICPVirtualUserTags(tenantID);
}
public static async getUserByPasswordResetHash(tenantID: string, passwordResetHash: string = Constants.UNKNOWN_STRING_ID): Promise<User> {

OICP virtual User improvements