Import users tested and adjusted
MODIFY
src/async-task/AsyncTaskManager.ts
src/async-task/AsyncTaskManager.ts
@@ -5,13 +5,14 @@ import { ActionsResponse } from '../types/GlobalType';
import AsyncTaskStorage from '../storage/mongodb/AsyncTaskStorage';
import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants';
-import ImportTagsAsyncTask from './tasks/TagsImportAsyncTask';
import LockingHelper from '../locking/LockingHelper';
import LockingManager from '../locking/LockingManager';
import Logging from '../utils/Logging';
import { ServerAction } from '../types/Server';
+import TagsImportAsyncTask from './tasks/TagsImportAsyncTask';
import User from '../types/User';
import UserToken from '../types/UserToken';
+import UsersImportAsyncTask from './tasks/UsersImportAsyncTask';
import Utils from '../utils/Utils';
const MODULE_NAME = 'AsyncTaskManager';
@@ -68,7 +69,10 @@ export default class AsyncTaskManager {
// Tasks
switch (asyncTask.name) {
case AsyncTasks.TAGS_IMPORT:
- abstractAsyncTask = new ImportTagsAsyncTask(asyncTask);
+ abstractAsyncTask = new TagsImportAsyncTask(asyncTask);
+ break;
+ case AsyncTasks.USERS_IMPORT:
+ abstractAsyncTask = new UsersImportAsyncTask(asyncTask);
break;
default:
await Logging.logError({

MODIFY
src/async-task/tasks/UsersImportAsyncTask.ts
src/async-task/tasks/UsersImportAsyncTask.ts
@@ -66,25 +66,19 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask {
continue;
}
// New User
- const user: Partial<User> = {
- firstName: importedUser.firstName,
- name: importedUser.name,
- email: importedUser.email,
- locale: null, // Defaults to the browser locale
- issuer: true,
- deleted: false,
- role: UserRole.BASIC,
- status: UserStatus.ACTIVE,
- createdBy: { id: importedUser.importedBy },
- createdOn: importedUser.importedOn,
- notificationsActive: true
- };
+ const newUser = UserStorage.createNewUser();
+ // Set
+ newUser.firstName = importedUser.firstName;
+ newUser.name = importedUser.name;
+ newUser.email = importedUser.email;
+ newUser.createdBy = { id: importedUser.importedBy };
+ newUser.createdOn = importedUser.importedOn;
// Save the new User
- user.id = await UserStorage.saveUser(tenant.id, user);
+ newUser.id = await UserStorage.saveUser(tenant.id, newUser);
// Role need to be set separately
- await UserStorage.saveUserRole(tenant.id, user.id, UserRole.BASIC);
+ await UserStorage.saveUserRole(tenant.id, newUser.id, UserRole.BASIC);
// Status need to be set separately
- await UserStorage.saveUserStatus(tenant.id, user.id, UserStatus.ACTIVE);
+ await UserStorage.saveUserStatus(tenant.id, newUser.id, UserStatus.PENDING);
// Remove the imported User
await UserStorage.deleteImportedUser(tenant.id, importedUser.id);
result.inSuccess++;

MODIFY
src/locking/LockingManager.ts
src/locking/LockingManager.ts
@@ -116,7 +116,7 @@ export default class LockingManager {
module: MODULE_NAME, method: 'release',
action: ServerAction.LOCKING,
message: `Lock entity '${lock.entity}' ('${lock.key}') of type '${lock.type}' does not exist and cannot be released`,
- detailedMessages: { lock }
+ detailedMessages: { lock, stack: new Error().stack }
});
return false;
}

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -508,9 +508,11 @@ export default class TagService {
let connectionClosed = false;
// eslint-disable-next-line @typescript-eslint/no-misused-promises
req.socket.on('close', async () => {
+ if (!connectionClosed) {
connectionClosed = true;
// Release the lock
await LockingManager.release(importTagsLock);
+ }
});
// eslint-disable-next-line @typescript-eslint/no-misused-promises
busboy.on('file', async (fieldname: string, file: any, filename: string, encoding: string, mimetype: string) => {
@@ -567,6 +569,8 @@ export default class TagService {
// Completed
// eslint-disable-next-line @typescript-eslint/no-misused-promises
}, async () => {
+ // Consider the connection closed
+ connectionClosed = true;
// Insert batched
if (tagsToBeImported.length > 0) {
await TagService.insertTags(req.user.tenantID, req.user, action, tagsToBeImported, result);

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -906,9 +906,11 @@ export default class UserService {
let connectionClosed = false;
// eslint-disable-next-line @typescript-eslint/no-misused-promises
req.socket.on('close', async () => {
+ if (!connectionClosed) {
connectionClosed = true;
// Release the lock
await LockingManager.release(importUsersLock);
+ }
});
// eslint-disable-next-line @typescript-eslint/no-misused-promises
busboy.on('file', async (fieldname, file, filename, encoding, mimetype) => {
@@ -965,6 +967,8 @@ export default class UserService {
// Completed
// eslint-disable-next-line @typescript-eslint/no-misused-promises
}, async () => {
+ // Consider the connection closed
+ connectionClosed = true;
// Insert batched
if (usersToBeImported.length > 0) {
await UserService.insertUsers(req.user.tenantID, req.user, action, usersToBeImported, result);

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -1059,6 +1059,11 @@ export default class UserStorage {
sendEndOfCharge: true,
sendEndOfSession: true,
sendUserAccountStatusChanged: true,
+ sendUserAccountInactivity: true,
+ sendPreparingSessionNotStarted: true,
+ sendSessionNotStarted: true,
+ sendBillingNewInvoice: true,
+ // Admin
sendNewRegisteredUser: false,
sendUnknownUserBadged: false,
sendChargingStationStatusError: false,
@@ -1066,16 +1071,12 @@ export default class UserStorage {
sendOcpiPatchStatusError: false,
sendOicpPatchStatusError: false,
sendSmtpError: false,
- sendUserAccountInactivity: false,
- sendPreparingSessionNotStarted: false,
sendOfflineChargingStations: false,
sendBillingSynchronizationFailed: false,
- sendSessionNotStarted: false,
sendCarCatalogSynchronizationFailed: false,
sendEndUserErrorNotification: false,
sendComputeAndApplyChargingProfilesFailed: false,
- sendBillingNewInvoice: false,
- sendAccountVerificationNotification: true,
+ sendAccountVerificationNotification: false,
sendAdminAccountVerificationNotification: false,
},
role: UserRole.BASIC,

Import users tested and adjusted