get rid of isImported
added importedData in db
re arrange autoActivateAtImport handling (put it in importedData object)
MODIFY
src/assets/server/rest/v1/schemas/auth/auth-verify-email.json
src/assets/server/rest/v1/schemas/auth/auth-verify-email.json
"VerificationToken": {
"type": "string",
"sanitize": "mongo"
- },
- "IsImported": {
- "type": "boolean",
- "sanitize": "mongo"
}
},
"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
"siteIDs": {
"type": "string",
"sanitize": "mongo"
+ },
+ "importedData": {
+ "type": "object",
+ "properties": {
+ "autoActivateAtImport": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ }
+ }
}
},
"required": [

MODIFY
src/async-task/tasks/UsersImportAsyncTask.ts
src/async-task/tasks/UsersImportAsyncTask.ts
@@ -75,13 +75,13 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask {
newUser.email = importedUser.email;
newUser.createdBy = { id: importedUser.importedBy };
newUser.createdOn = importedUser.importedOn;
- newUser.status = importedUser.autoActivateAtImport ? UserStatus.ACTIVE : UserStatus.PENDING;
+ 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, newUser.status);
+ 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[] = [];
@@ -125,22 +125,6 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask {
// Init Password info
const resetHash = Utils.generateUUID();
await UserStorage.saveUserPassword(tenant.id, newUser.id, { passwordResetHash: resetHash });
- if (newUser.status === UserStatus.ACTIVE) {
- // Send create password link
- const evseDashboardCreatePasswordURL = Utils.buildEvseURL(tenant.subdomain) +
- '/define-password?hash=' + resetHash;
- // Send account created with create password notification (Async)
- await NotificationHandler.sendUserCreatePassword(
- tenant.id,
- Utils.generateUUID(),
- newUser,
- {
- 'user': newUser,
- 'tenantName': tenant.name,
- 'evseDashboardURL': Utils.buildEvseURL(tenant.subdomain),
- 'evseDashboardCreatePasswordURL': evseDashboardCreatePasswordURL
- });
- } else if (newUser.status === UserStatus.PENDING) {
// Generate new verificationToken
const verificationToken = Utils.generateToken(newUser.email);
// Save User Verification Account
@@ -148,7 +132,7 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask {
// Build account verif email with reset password embeded
const evseDashboardVerifyEmailURL = Utils.buildEvseURL(tenant.subdomain) +
'/verify-email?VerificationToken=' + verificationToken + '&Email=' +
- newUser.email + '&ResetToken=' + resetHash + '&isImported=true';
+ newUser.email + '&ResetToken=' + resetHash;
// Send activate account link
await NotificationHandler.sendVerificationEmailUserImport(
tenant.id,
@@ -160,7 +144,6 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask {
'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
@@ -520,15 +520,18 @@ export default class AuthService {
message: 'Wrong Verification Token'
});
}
+ // Save User Status
let userStatus: UserStatus;
- if (!filteredRequest.IsImported) {
+ // When it's user creation case we take the user settings
+ if (!user.importedData) {
const userSettings = await SettingStorage.getUserSettings(tenantID);
userStatus = userSettings.user.autoActivateAccountAfterValidation ? UserStatus.ACTIVE : UserStatus.INACTIVE;
await UserStorage.saveUserStatus(tenantID, user.id, userStatus);
} else {
- await UserStorage.saveUserStatus(tenantID, user.id, UserStatus.PENDING);
+ // When it's user import case we take checkbox param saved to db
+ userStatus = user.importedData.autoActivateAtImport ? UserStatus.ACTIVE : UserStatus.INACTIVE;
+ await UserStorage.saveUserStatus(tenantID, user.id, UserStatus.ACTIVE);
}
- // Save User Status
// For integration with billing
const billingImpl = await BillingFactory.getBillingImpl(tenant);
if (billingImpl) {

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -486,7 +486,7 @@ export default class UserService {
// Set default value
user.importedBy = importedBy;
user.importedOn = importedOn;
- user.autoActivateAtImport = UtilsSecurity.filterBoolean(req.headers.autoactivateatimport);
+ user.importedData = { 'autoActivateAtImport' : UtilsSecurity.filterBoolean(req.headers.autoactivateatimport) };
// Import
const importSuccess = await UserService.processUser(action, req, user, usersToBeImported);
if (!importSuccess) {
@@ -812,7 +812,7 @@ export default class UserService {
name: importedUser.name.toUpperCase(),
firstName: importedUser.firstName,
email: importedUser.email,
- autoActivateAtImport: importedUser.autoActivateAtImport,
+ importedData: importedUser.importedData,
siteIDs: importedUser.siteIDs
};
// Validate User data

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -217,6 +217,7 @@ export default class UserStorage {
locale: userToSave.locale,
iNumber: userToSave.iNumber,
costCenter: userToSave.costCenter,
+ importedData: userToSave.importedData,
notificationsActive: userToSave.notificationsActive,
notifications: {
sendSessionStarted: userToSave.notifications ? Utils.convertToBoolean(userToSave.notifications.sendSessionStarted) : false,
@@ -285,7 +286,7 @@ export default class UserStorage {
errorDescription: importedUserToSave.errorDescription,
importedOn: Utils.convertToDate(importedUserToSave.importedOn),
importedBy: Utils.convertToObjectID(importedUserToSave.importedBy),
- autoActivateAtImport: importedUserToSave.autoActivateAtImport,
+ importedData: importedUserToSave.importedData,
siteIDs: importedUserToSave.siteIDs,
};
await global.database.getCollection<any>(tenantID, 'importedusers').findOneAndUpdate(
@@ -309,7 +310,7 @@ export default class UserStorage {
errorDescription: importedUserToSave.errorDescription,
importedOn: Utils.convertToDate(importedUserToSave.importedOn),
importedBy: Utils.convertToObjectID(importedUserToSave.importedBy),
- autoActivateAtImport: importedUserToSave.autoActivateAtImport,
+ importedData: importedUserToSave.importedData,
siteIDs: importedUserToSave.siteIDs,
}));
// Insert all at once

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

MODIFY
src/types/requests/HttpUserRequest.ts
src/types/requests/HttpUserRequest.ts
@@ -90,7 +90,6 @@ export interface HttpVerifyEmailRequest {
Email: string;
Tenant: string;
VerificationToken: string;
- IsImported: boolean;
}
export interface HttpResendVerificationMailRequest {

get rid of isImported
added importedData in db
re arrange autoActivateAtImport handling (put it in importedData object)