handling sites in tags import
added importedData in db for tags also
MODIFY
src/assets/server/rest/v1/schemas/tag/imported-tag-create-req.json
src/assets/server/rest/v1/schemas/tag/imported-tag-create-req.json
},
"visualID": {
"$ref": "tag.json#/definitions/visualID"
+ },
+ "siteIDs": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "importedData": {
+ "type": "object",
+ "properties": {
+ "autoActivateUserAtImport": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ },
+ "autoActivateTagAtImport": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ }
+ }
+ },
+ "email": {
+ "$ref": "user.json#/definitions/email"
+ },
+ "name": {
+ "$ref": "user.json#/definitions/name"
+ },
+ "firstName": {
+ "$ref": "user.json#/definitions/firstName"
}
},
"required": [

MODIFY
src/assets/server/rest/v1/schemas/user/imported-user-create-req.json
src/assets/server/rest/v1/schemas/user/imported-user-create-req.json
"importedData": {
"type": "object",
"properties": {
- "autoActivateAtImport": {
+ "autoActivateUserAtImport": {
"type": "boolean",
"sanitize": "mongo"
}

MODIFY
src/assets/server/rest/v1/schemas/user/users-get.json
src/assets/server/rest/v1/schemas/user/users-get.json
"type": "boolean",
"sanitize": "mongo"
},
- "WithTag": {
- "type": "boolean",
- "sanitize": "mongo"
- },
"SiteID": {
"$ref": "common.json#/definitions/ids"
},

ADD
src/async-task/tasks/ImportAsyncTask.ts
+import User, { ImportedUser, UserRole, UserStatus } from '../../types/User';
+
+import AbstractAsyncTask from '../AsyncTask';
+import { ActionsResponse } from '../../types/GlobalType';
+import Constants from '../../utils/Constants';
+import { ImportedTag } from '../../types/Tag';
+import Logging from '../../utils/Logging';
+import NotificationHandler from '../../notification/NotificationHandler';
+import { ServerAction } from '../../types/Server';
+import Site from '../../types/Site';
+import SiteStorage from '../../storage/mongodb/SiteStorage';
+import Tenant from '../../types/Tenant';
+import TenantComponents from '../../types/TenantComponents';
+import UserStorage from '../../storage/mongodb/UserStorage';
+import Utils from '../../utils/Utils';
+
+const MODULE_NAME = 'ImportAsyncTask';
+
+export default class ImportAsyncTask extends AbstractAsyncTask {
+ // To store existing sites to avoid getting the site erverytime
+ existingSitesToAutoAssign: Record<string, boolean> = {};
+ // To store users by site
+ // usersSite: Map<string, string[]> = new Map();
+ usersSite: Record<string, string[]> = {};
+
+ protected async checkUserExists(tenant: Tenant, importedUser: ImportedUser|ImportedTag): Promise<User> {
+ // Existing Users
+ const foundUser = await UserStorage.getUserByEmail(tenant.id, importedUser.email);
+ if (foundUser) {
+ // Check tag is already in use
+ if (!foundUser.issuer) {
+ throw new Error('User is not local to the organization');
+ }
+ if (foundUser.status !== UserStatus.PENDING) {
+ throw new Error('User account is already in use');
+ }
+ // Update it
+ foundUser.name = importedUser.name;
+ foundUser.firstName = importedUser.firstName;
+ await UserStorage.saveUser(tenant.id, foundUser);
+ if (importedUser.siteIDs && Utils.isTenantComponentActive(tenant, TenantComponents.ORGANIZATION)) {
+ await this.checkSitesAndAssign(tenant, foundUser, importedUser);
+ }
+ }
+ return foundUser;
+ }
+
+ protected async createUser(tenant: Tenant, importedUser: ImportedUser|ImportedTag, result?: ActionsResponse): Promise<User> {
+ // New User
+ const newUser = UserStorage.createNewUser() as User;
+ // Set
+ newUser.firstName = importedUser.firstName;
+ newUser.name = importedUser.name;
+ newUser.email = importedUser.email;
+ newUser.createdBy = { id: importedUser.importedBy };
+ newUser.createdOn = importedUser.importedOn;
+ newUser.importedData = importedUser.importedData;
+ // Save the new User
+ newUser.id = await UserStorage.saveUser(tenant.id, newUser);
+ // Role need to be set separately
+ await UserStorage.saveUserRole(tenant.id, newUser.id, UserRole.BASIC);
+ // Status need to be set separately
+ await UserStorage.saveUserStatus(tenant.id, newUser.id, importedUser.importedData.autoActivateUserAtImport ? UserStatus.ACTIVE : UserStatus.INACTIVE);
+ if (importedUser.siteIDs && Utils.isTenantComponentActive(tenant, TenantComponents.ORGANIZATION)) {
+ await this.checkSitesAndAssign(tenant, newUser, importedUser);
+ }
+ await this.sendNotifications(tenant, newUser);
+ return newUser;
+ }
+
+ protected async checkSitesAndAssign(tenant: Tenant, newUser: User, importedUser: ImportedUser|ImportedTag): Promise<void> {
+ let site: Site = null;
+ // Saved sites for assignement
+ const sitesToBeAssigned: string[] = [];
+ const importedSites = importedUser.siteIDs.split('|');
+ for (const siteID of importedSites) {
+ if (siteID in this.existingSitesToAutoAssign) {
+ // if siteID has already been checked and it's not already in the sitesToBeAssigned array
+ if (this.existingSitesToAutoAssign[siteID] && !(Object.values(sitesToBeAssigned).includes(siteID))) {
+ sitesToBeAssigned.push(siteID);
+ }
+ continue;
+ // check if site exists
+ } else if (!Utils.isNullOrUndefined(site = await SiteStorage.getSite(tenant, siteID))) {
+ if (site.autoUserSiteAssignment) {
+ this.existingSitesToAutoAssign[siteID] = true;
+ sitesToBeAssigned.push(siteID);
+ // if site exists but does not allow auto assignment
+ } else {
+ this.existingSitesToAutoAssign[siteID] = false;
+ await Logging.logWarning({
+ tenantID: tenant.id,
+ action: ServerAction.USERS_IMPORT,
+ module: MODULE_NAME, method: 'executeAsyncTask',
+ message: `Site ${siteID} does not accept auto assignment`
+ });
+ }
+ // if site does not exist
+ } else {
+ this.existingSitesToAutoAssign[siteID] = false;
+ await Logging.logWarning({
+ tenantID: tenant.id,
+ action: ServerAction.USERS_IMPORT,
+ module: MODULE_NAME, method: 'executeAsyncTask',
+ message: `Cannot assign user to site ${siteID} as this site has not been found`
+ });
+ }
+ }
+
+ if (!Utils.isEmptyArray(sitesToBeAssigned)) {
+ // To avoid useless call to storage
+ const sitesToGet: string[] = [];
+ for (const siteToBeAssigned of sitesToBeAssigned) {
+ if (!Object.keys(this.usersSite).includes(siteToBeAssigned)) {
+ sitesToGet.push(siteToBeAssigned);
+ this.usersSite[siteToBeAssigned] = [];
+ }
+ }
+ // Get list of userSites from sites we don't already have in this.userSites
+ if (sitesToGet.length > 0) {
+ const allSitesUsers = await SiteStorage.getSiteUsers(tenant, {
+ siteIDs: sitesToGet
+ }, {
+ limit: Constants.IMPORT_PAGE_SIZE, skip: 0
+ },
+ [ 'userID', 'siteID']
+ );
+ // create the map <siteID : [userids]>
+ for (const userSite of allSitesUsers.result) {
+ this.usersSite[userSite.siteID].push(userSite.userID);
+ }
+ }
+ }
+ for (const siteID of sitesToBeAssigned) {
+ const index = this.usersSite[siteID].indexOf(newUser.id) || -1;
+ if (index > -1) {
+ sitesToBeAssigned.splice(index, 1);
+ }
+ }
+ if (sitesToBeAssigned) {
+ await UserStorage.addSitesToUser(tenant.id, newUser.id, sitesToBeAssigned);
+ }
+ }
+
+ protected async sendNotifications(tenant: Tenant, newUser: User): Promise<void> {
+ // Handle sending email for reseting password if user auto activated
+ // Init Password info
+ const resetHash = Utils.generateUUID();
+ await UserStorage.saveUserPassword(tenant.id, newUser.id, { passwordResetHash: resetHash });
+ // Generate new verificationToken
+ const verificationToken = Utils.generateToken(newUser.email);
+ // Save User Verification Account
+ await UserStorage.saveUserAccountVerification(tenant.id, newUser.id, { verificationToken });
+ // Build account verif email with reset password embeded
+ const evseDashboardVerifyEmailURL = Utils.buildEvseURL(tenant.subdomain) +
+ '/verify-email?VerificationToken=' + verificationToken + '&Email=' +
+ newUser.email + '&ResetToken=' + resetHash;
+ // Send activate account link
+ await NotificationHandler.sendVerificationEmailUserImport(
+ tenant.id,
+ Utils.generateUUID(),
+ newUser,
+ {
+ 'tenantName': tenant.name,
+ 'user': newUser,
+ 'evseDashboardURL': Utils.buildEvseURL(tenant.subdomain),
+ 'evseDashboardVerifyEmailURL': evseDashboardVerifyEmailURL
+ });
+ }
+
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
+ protected async executeAsyncTask(): Promise<void> {
+ // const tenant = await TenantStorage.getTenant(this.asyncTask.tenantID);
+ }
+}
+

MODIFY
src/async-task/tasks/TagsImportAsyncTask.ts
src/async-task/tasks/TagsImportAsyncTask.ts
import { ActionsResponse, ImportStatus } from '../../types/GlobalType';
import Tag, { ImportedTag } from '../../types/Tag';
-import User, { UserRole, UserStatus } from '../../types/User';
-import AbstractAsyncTask from '../AsyncTask';
import Constants from '../../utils/Constants';
import { DataResult } from '../../types/DataResult';
import DbParams from '../../types/database/DbParams';
+import ImportAsyncTask from './ImportAsyncTask';
import LockingHelper from '../../locking/LockingHelper';
import LockingManager from '../../locking/LockingManager';
import Logging from '../../utils/Logging';
@@ -13,12 +12,12 @@ import { ServerAction } from '../../types/Server';
import TagStorage from '../../storage/mongodb/TagStorage';
import Tenant from '../../types/Tenant';
import TenantStorage from '../../storage/mongodb/TenantStorage';
-import UserStorage from '../../storage/mongodb/UserStorage';
+import User from '../../types/User';
import Utils from '../../utils/Utils';
const MODULE_NAME = 'TagsImportAsyncTask';
-export default class TagsImportAsyncTask extends AbstractAsyncTask {
+export default class TagsImportAsyncTask extends ImportAsyncTask {
protected async executeAsyncTask(): Promise<void> {
const importTagsLock = await LockingHelper.acquireImportTagsLock(this.asyncTask.tenantID);
if (importTagsLock) {
@@ -56,7 +55,7 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask {
throw new Error('Tag is not local to the organization');
}
if (foundTag.userID) {
- throw new Error('Tag is already assigned to an user');
+ throw new Error('Tag is already assigned to a user');
}
if (foundTag.active) {
throw new Error('Tag is already active');
@@ -75,14 +74,15 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask {
visualID: importedTag.visualID,
description: importedTag.description,
issuer: true,
- active: false,
+ active: importedTag.importedData.autoActivateTagAtImport,
createdBy: { id: importedTag.importedBy },
createdOn: importedTag.importedOn,
+ importedData: importedTag.importedData
};
}
// Save user if any and get the ID to assign tag
if (importedTag.email && importedTag.name && importedTag.firstName) {
- await this.assignTag(tenant, importedTag, tagToSave);
+ await this.createUserAndAssignTag(tenant, importedTag, tagToSave);
}
// Save the new Tag
await TagStorage.saveTag(tenant.id, tagToSave);
@@ -135,26 +135,14 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask {
}
}
- private async assignTag(tenant: Tenant, importedTag: ImportedTag, tag: Tag) {
- // Save user if any and get the ID to assign tag
- const foundUser = await UserStorage.getUserByEmail(tenant.id, importedTag.email);
- if (!foundUser) {
- const user = {
- name: importedTag.name,
- firstName: importedTag.firstName,
- email: importedTag.email,
- createdBy: { id: importedTag.importedBy },
- createdOn: Utils.convertToDate(importedTag.importedOn),
- issuer: true,
- status: UserStatus.PENDING,
- role: UserRole.BASIC,
- } as User;
- const userID = await UserStorage.saveUser(tenant.id, user);
- await UserStorage.saveUserStatus(tenant.id, userID, user.status);
- await UserStorage.saveUserRole(tenant.id, userID, user.role);
- tag.userID = userID;
- } else {
- tag.userID = foundUser.id;
- }
+ private async createUserAndAssignTag(tenant: Tenant, importedTag: ImportedTag, tag: Tag) {
+ let user: User = null;
+ // if user not found we create one
+ if (Utils.isNullOrUndefined(user = await this.checkUserExists(tenant, importedTag))) {
+ user = await this.createUser(tenant, importedTag);
+ }
+ tag.userID = user.id;
+ await TagStorage.clearDefaultUserTag(tenant.id, user.id);
+ tag.default = true;
}
}

MODIFY
src/async-task/tasks/UsersImportAsyncTask.ts
src/async-task/tasks/UsersImportAsyncTask.ts
import { ActionsResponse, ImportStatus } from '../../types/GlobalType';
-import User, { ImportedUser, UserRole, UserStatus } from '../../types/User';
-import AbstractAsyncTask from '../AsyncTask';
import Constants from '../../utils/Constants';
import { DataResult } from '../../types/DataResult';
import DbParams from '../../types/database/DbParams';
+import ImportAsyncTask from './ImportAsyncTask';
+import { ImportedUser } from '../../types/User';
import LockingHelper from '../../locking/LockingHelper';
import LockingManager from '../../locking/LockingManager';
import Logging from '../../utils/Logging';
-import NotificationHandler from '../../notification/NotificationHandler';
import { ServerAction } from '../../types/Server';
-import Site from '../../types/Site';
-import SiteStorage from '../../storage/mongodb/SiteStorage';
import TenantStorage from '../../storage/mongodb/TenantStorage';
import UserStorage from '../../storage/mongodb/UserStorage';
import Utils from '../../utils/Utils';
const MODULE_NAME = 'UsersImportAsyncTask';
-export default class UsersImportAsyncTask extends AbstractAsyncTask {
+export default class UsersImportAsyncTask extends ImportAsyncTask {
protected async executeAsyncTask(): Promise<void> {
const importUsersLock = await LockingHelper.acquireImportUsersLock(this.asyncTask.tenantID);
if (importUsersLock) {
@@ -44,106 +41,14 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask {
do {
// Get the imported users
importedUsers = await UserStorage.getImportedUsers(tenant.id, { status: ImportStatus.READY }, dbParams);
- // To store existing sites to avoid getting the site erverytime
- const existingSitesToAutoAssign: Record<string, boolean> = {};
for (const importedUser of importedUsers.result) {
try {
- // Existing Users
- const foundUser = await UserStorage.getUserByEmail(tenant.id, importedUser.email);
- if (foundUser) {
- // Check tag is already in use
- if (!foundUser.issuer) {
- throw new Error('User is not local to the organization');
- }
- if (foundUser.status !== UserStatus.PENDING) {
- throw new Error('User account is already in use');
- }
- // Update it
- foundUser.name = importedUser.name;
- foundUser.firstName = importedUser.firstName;
- await UserStorage.saveUser(tenant.id, foundUser);
- // Remove the imported User
- await UserStorage.deleteImportedUser(tenant.id, importedUser.id);
- result.inSuccess++;
- continue;
- }
- // New User
- const newUser = UserStorage.createNewUser() as User;
- // Set
- newUser.firstName = importedUser.firstName;
- newUser.name = importedUser.name;
- newUser.email = importedUser.email;
- newUser.createdBy = { id: importedUser.importedBy };
- newUser.createdOn = importedUser.importedOn;
- newUser.importedData = importedUser.importedData;
- // Save the new User
- newUser.id = await UserStorage.saveUser(tenant.id, newUser);
- // Role need to be set separately
- await UserStorage.saveUserRole(tenant.id, newUser.id, UserRole.BASIC);
- // Status need to be set separately
- await UserStorage.saveUserStatus(tenant.id, newUser.id, UserStatus.PENDING);
- if (importedUser.siteIDs) {
- // Check wheter site exists and save them to an array for assignement
- const sitesToBeAssigned: string[] = [];
- let site: Site = null;
- for (const siteID of importedUser.siteIDs.split('|')) {
- if (siteID in existingSitesToAutoAssign) {
- // if siteID has been checked and it's not already in the sitesToBeAssigned array
- if (existingSitesToAutoAssign[siteID] === true && !(Object.values(sitesToBeAssigned).includes(siteID))) {
- sitesToBeAssigned.push(siteID);
- }
- continue;
- } else if (!Utils.isNullOrUndefined(site = await SiteStorage.getSite(tenant, siteID))) {
- if (site.autoUserSiteAssignment) {
- existingSitesToAutoAssign[siteID] = true;
- sitesToBeAssigned.push(siteID);
- } else {
- existingSitesToAutoAssign[siteID] = false;
- await Logging.logWarning({
- tenantID: tenant.id,
- action: ServerAction.USERS_IMPORT,
- module: MODULE_NAME, method: 'executeAsyncTask',
- message: `Site ${siteID} does not accept auto assignment`
- });
- }
- } else {
- existingSitesToAutoAssign[siteID] = false;
- await Logging.logWarning({
- tenantID: tenant.id,
- action: ServerAction.USERS_IMPORT,
- module: MODULE_NAME, method: 'executeAsyncTask',
- message: `Cannot assign user to site ${siteID} as this site has not been found`
- });
- }
- }
- if (!Utils.isEmptyArray(sitesToBeAssigned)) {
- await UserStorage.addSitesToUser(tenant.id, newUser.id, sitesToBeAssigned);
- }
+ // if user not found we create one
+ if (Utils.isNullOrUndefined(await this.checkUserExists(tenant, importedUser))) {
+ await this.createUser(tenant, importedUser, result);
}
+ // Remove the imported User either it's found or not
await UserStorage.deleteImportedUser(tenant.id, importedUser.id);
- // Handle sending email for reseting password if user auto activated
- // Init Password info
- const resetHash = Utils.generateUUID();
- await UserStorage.saveUserPassword(tenant.id, newUser.id, { passwordResetHash: resetHash });
- // Generate new verificationToken
- const verificationToken = Utils.generateToken(newUser.email);
- // Save User Verification Account
- await UserStorage.saveUserAccountVerification(tenant.id, newUser.id, { verificationToken });
- // Build account verif email with reset password embeded
- const evseDashboardVerifyEmailURL = Utils.buildEvseURL(tenant.subdomain) +
- '/verify-email?VerificationToken=' + verificationToken + '&Email=' +
- newUser.email + '&ResetToken=' + resetHash;
- // Send activate account link
- await NotificationHandler.sendVerificationEmailUserImport(
- tenant.id,
- Utils.generateUUID(),
- newUser,
- {
- 'tenantName': tenant.name,
- 'user': newUser,
- 'evseDashboardURL': Utils.buildEvseURL(tenant.subdomain),
- 'evseDashboardVerifyEmailURL': evseDashboardVerifyEmailURL
- });
result.inSuccess++;
} catch (error) {
importedUser.status = ImportStatus.ERROR;

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -511,12 +511,11 @@ export default class AuthService {
if (!user.importedData) {
const userSettings = await SettingStorage.getUserSettings(tenant.id);
userStatus = userSettings.user.autoActivateAccountAfterValidation ? UserStatus.ACTIVE : UserStatus.INACTIVE;
- await UserStorage.saveUserStatus(tenant.id, user.id, userStatus);
} else {
// When it's user import case we take checkbox param saved to db
- userStatus = user.importedData.autoActivateAtImport ? UserStatus.ACTIVE : UserStatus.INACTIVE;
- await UserStorage.saveUserStatus(tenant.id, user.id, UserStatus.ACTIVE);
+ userStatus = user.importedData.autoActivateUserAtImport ? UserStatus.ACTIVE : UserStatus.INACTIVE;
}
+ await UserStorage.saveUserStatus(tenant.id, user.id, userStatus);
// Save User Status
await UserStorage.saveUserStatus(tenant.id, user.id, userStatus);
// For integration with billing

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -36,6 +36,7 @@ import UserStorage from '../../../../storage/mongodb/UserStorage';
import UserToken from '../../../../types/UserToken';
import UserValidator from '../validator/UserValidator';
import Utils from '../../../../utils/Utils';
+import UtilsSecurity from './security/UtilsSecurity';
import UtilsService from './UtilsService';
import csvToJson from 'csvtojson/v2';
@@ -444,6 +445,10 @@ export default class TagService {
// Set default value
tag.importedBy = importedBy;
tag.importedOn = importedOn;
+ tag.importedData = {
+ 'autoActivateUserAtImport' : UtilsSecurity.filterBoolean(req.headers.autoactivateuseratimport),
+ 'autoActivateTagAtImport' : UtilsSecurity.filterBoolean(req.headers.autoactivatetagatimport)
+ };
// Import
const importSuccess = await TagService.processTag(action, req, tag, tagsToBeImported);
if (!importSuccess) {
@@ -772,32 +777,39 @@ export default class TagService {
const newImportedTag: ImportedTag = {
id: importedTag.id.toUpperCase(),
visualID: importedTag.visualID,
- description: importedTag.description ? importedTag.description : `Badge ID '${importedTag.id}'`
+ description: importedTag.description ? importedTag.description : `Badge ID '${importedTag.id}'`,
+ importedData: importedTag.importedData
};
- if (importedTag.name && importedTag.firstName && importedTag.email) {
- newImportedTag.name = importedTag.name.toUpperCase();
- newImportedTag.firstName = importedTag.firstName;
- newImportedTag.email = importedTag.email;
- }
// Validate Tag data
TagValidator.getInstance().validateImportedTagCreation(newImportedTag);
// Set properties
newImportedTag.importedBy = importedTag.importedBy;
newImportedTag.importedOn = importedTag.importedOn;
newImportedTag.status = ImportStatus.READY;
+ let tagToImport = newImportedTag;
+ // handle user part
+ if (importedTag.name && importedTag.firstName && importedTag.email) {
+ const newImportedUser: ImportedUser = {
+ name: importedTag.name.toUpperCase(),
+ firstName: importedTag.firstName,
+ email: importedTag.email,
+ siteIDs: importedTag.siteIDs
+ };
try {
- UserValidator.getInstance().validateImportedUserCreation(newImportedTag as ImportedUser);
+ UserValidator.getInstance().validateImportedUserCreation(newImportedUser);
+ tagToImport = { ...tagToImport, ...newImportedUser };
} catch (error) {
await Logging.logWarning({
tenantID: req.user.tenantID,
module: MODULE_NAME, method: 'processTag',
action: action,
- message: `User cannot be imported tag ${newImportedTag.id}`,
+ message: `User cannot be imported with tag ${newImportedTag.id}`,
detailedMessages: { tag: newImportedTag, error: error.message, stack: error.stack }
});
}
+ }
// Save it later on
- tagsToBeImported.push(newImportedTag);
+ tagsToBeImported.push(tagToImport);
return true;
} catch (error) {
await Logging.logError({

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -484,7 +484,10 @@ export default class UserService {
// Set default value
user.importedBy = importedBy;
user.importedOn = importedOn;
- user.importedData = { 'autoActivateAtImport' : UtilsSecurity.filterBoolean(req.headers.autoactivateatimport) };
+ user.importedData = {
+ 'autoActivateUserAtImport' : UtilsSecurity.filterBoolean(req.headers.autoactivateuseratimport),
+ 'autoActivateTagAtImport' : UtilsSecurity.filterBoolean(req.headers.autoactivatetagatimport)
+ };
// Import
const importSuccess = await UserService.processUser(action, req, user, usersToBeImported);
if (!importSuccess) {

MODIFY
src/storage/mongodb/TagStorage.ts
src/storage/mongodb/TagStorage.ts
@@ -26,7 +26,8 @@ export default class TagStorage {
default: Utils.convertToBoolean(tag.default),
visualID: tag.visualID,
ocpiToken: tag.ocpiToken,
- description: tag.description
+ description: tag.description,
+ importedData: tag.importedData
};
// Check Created/Last Changed By
DatabaseUtils.addLastChangedCreatedProps(tagMDB, tag);
@@ -51,7 +52,9 @@ export default class TagStorage {
status: importedTagToSave.status,
errorDescription: importedTagToSave.errorDescription,
importedOn: importedTagToSave.importedOn,
- importedBy: importedTagToSave.importedBy
+ importedBy: importedTagToSave.importedBy,
+ siteIDs: importedTagToSave.siteIDs,
+ importedData: importedTagToSave.importedData
};
await global.database.getCollection<any>(tenantID, 'importedtags').findOneAndUpdate(
{ _id: tagMDB._id },
@@ -75,7 +78,9 @@ export default class TagStorage {
status: importedTagToSave.status,
errorDescription: importedTagToSave.errorDescription,
importedOn: importedTagToSave.importedOn,
- importedBy: importedTagToSave.importedBy
+ importedBy: importedTagToSave.importedBy,
+ siteIDs: importedTagToSave.siteIDs,
+ importedData: importedTagToSave.importedData
}));
// Insert all at once
const result = await global.database.getCollection<any>(tenantID, 'importedtags').insertMany(

MODIFY
src/types/Tag.ts
src/types/Tag.ts
@@ -15,6 +15,10 @@ export default interface Tag extends CreatedUpdatedProps, AuthorizationActions {
ocpiToken?: OCPIToken;
user?: User;
default?: boolean
+ importedData?: {
+ autoActivateUserAtImport: boolean;
+ autoActivateTagAtImport: boolean;
+ };
}
export interface ImportedTag {
@@ -28,6 +32,11 @@ export interface ImportedTag {
name?: string;
firstName?: string;
email?: string;
+ importedData?: {
+ autoActivateUserAtImport: boolean;
+ autoActivateTagAtImport: boolean;
+ };
+ siteIDs?: string;
}
export const TagRequiredImportProperties = [

MODIFY
src/types/User.ts
src/types/User.ts
@@ -38,7 +38,10 @@ export default interface User extends CreatedUpdatedProps, AuthorizationActions
mobileLastChangedOn: Date;
lastSelectedCarID?: string;
authorizationID?: string;
- importedData?: { autoActivateAtImport: boolean; };
+ importedData?: {
+ autoActivateUserAtImport: boolean;
+ autoActivateTagAtImport: boolean;
+ };
}
export interface UserSite {
@@ -66,7 +69,10 @@ export interface ImportedUser {
importedOn?: Date;
status?: ImportStatus
errorDescription?: string;
- importedData?: { autoActivateAtImport: boolean; };
+ importedData?: {
+ autoActivateUserAtImport: boolean;
+ autoActivateTagAtImport: boolean;
+ };
siteIDs?: string;
}

handling sites in tags import
added importedData in db for tags also