fixed escape/unescape (again)
removed blank line and useless comment
MODIFY
src/async-task/tasks/TagsImportAsyncTask.ts
src/async-task/tasks/TagsImportAsyncTask.ts
@@ -99,7 +99,7 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask {
message: `Error when importing Tag ID '${importedTag.id}': ${error.message}`,
detailedMessages: { tag: importedTag, error: error.message, stack: error.stack }
});
- } // Do we add a finally that delete tags if the error comes from "foundTag" ? for now the found tags are left as is in the importedTag collection
+ }
}
// Log
if (!Utils.isEmptyArray(importedTags.result) && (result.inError + result.inSuccess) > 0) {

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -761,10 +761,10 @@ export default class TagService {
try {
const newImportedTag: ImportedTag = {
id: importedTag.id.toUpperCase(),
- description: importedTag.description ? Utils.escapeCsvValue(importedTag.description) : `Badge ID '${importedTag.id}'`,
- name: Utils.escapeCsvValue(importedTag.name.toUpperCase()),
- firstName: Utils.escapeCsvValue(importedTag.firstName),
- email: Utils.escapeCsvValue(importedTag.email),
+ description: importedTag.description ? Utils.unescapeCsvValue(importedTag.description) : `Badge ID '${importedTag.id}'`,
+ name: Utils.unescapeCsvValue(importedTag.name.toUpperCase()),
+ firstName: Utils.unescapeCsvValue(importedTag.firstName),
+ email: Utils.unescapeCsvValue(importedTag.email),
};
// Validate Tag data
TagValidator.getInstance().validateImportedTagCreation(newImportedTag);
@@ -778,6 +778,13 @@ export default class TagService {
newImportedTag.email = '';
newImportedTag.name = '';
newImportedTag.firstName = '';
+ await Logging.logWarning({
+ tenantID: req.user.tenantID,
+ module: MODULE_NAME, method: 'processTag',
+ action: action,
+ message: `User cannot be imported tag ${newImportedTag.id}`,
+ detailedMessages: { tag: newImportedTag, error: error.message, stack: error.stack }
+ });
}
// Save it later on
tagsToBeImported.push(newImportedTag);

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -1345,7 +1345,6 @@ export default class UserService {
firstName: Utils.unescapeCsvValue(importedUser.firstName),
email: Utils.unescapeCsvValue(importedUser.email),
};
-
// Validate User data
UserValidator.getInstance().validateImportedUserCreation(newImportedUser);
// Set properties

MODIFY
src/storage/mongodb/TagStorage.ts
src/storage/mongodb/TagStorage.ts
@@ -42,14 +42,14 @@ export default class TagStorage {
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveImportedTag');
const tagMDB = {
_id: importedTagToSave.id,
- description: Utils.unescapeCsvValue(importedTagToSave.description),
- name: Utils.unescapeCsvValue(importedTagToSave.name),
- firstName: Utils.unescapeCsvValue(importedTagToSave.firstName),
- email: Utils.unescapeCsvValue(importedTagToSave.email),
+ description: importedTagToSave.description,
+ name: importedTagToSave.name,
+ firstName: importedTagToSave.firstName,
+ email: importedTagToSave.email,
status: importedTagToSave.status,
errorDescription: importedTagToSave.errorDescription,
- importedOn: Utils.convertToDate(importedTagToSave.importedOn),
- importedBy: Utils.convertToObjectID(importedTagToSave.importedBy)
+ importedOn: importedTagToSave.importedOn,
+ importedBy: importedTagToSave.importedBy
};
await global.database.getCollection<any>(tenantID, 'importedtags').findOneAndUpdate(
{ _id: tagMDB._id },
@@ -65,14 +65,14 @@ export default class TagStorage {
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'saveImportedTags');
const importedTagsToSaveMDB: any = importedTagsToSave.map((importedTagToSave) => ({
_id: importedTagToSave.id,
- description: Utils.unescapeCsvValue(importedTagToSave.description),
- name: Utils.unescapeCsvValue(importedTagToSave.name),
- firstName: Utils.unescapeCsvValue(importedTagToSave.firstName),
- email: Utils.unescapeCsvValue(importedTagToSave.email),
+ description: importedTagToSave.description,
+ name: importedTagToSave.name,
+ firstName: importedTagToSave.firstName,
+ email: importedTagToSave.email,
status: importedTagToSave.status,
errorDescription: importedTagToSave.errorDescription,
- importedOn: Utils.convertToDate(importedTagToSave.importedOn),
- importedBy: Utils.convertToObjectID(importedTagToSave.importedBy)
+ importedOn: importedTagToSave.importedOn,
+ importedBy: importedTagToSave.importedBy
}));
// Insert all at once
const result = await global.database.getCollection<any>(tenantID, 'importedtags').insertMany(

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -1503,14 +1503,17 @@ export default class Utils {
return Configuration.isCloudFoundry() ? cfenv.getAppEnv().name : os.hostname();
}
+ // when exporting values
public static escapeCsvValue(value: any): string {
- // replace starting and ending double quotes by nothing
- // replace double quotes inside value to double double quotes to display double quote in csv editor
+ // add double quote start and end
+ // replace double quotes inside value to double double quotes to display double quote correctly in csv editor
return typeof value === 'string' ? '"' + value.replace(/"/g, '""') + '"' : value;
}
+ // when importing values
public static unescapeCsvValue(value: any): string {
+ // starting and ending double quotes are handle by csvToJson
// replace double double quotes inside value into simple double quotes
- return typeof value === 'string' ? value.replace(/^"|"$/g, '').replace(/""/g, '"') : value;
+ return typeof value === 'string' ? value.replace(/""/g, '"') : value;
}
}

fixed escape/unescape (again)
removed blank line and useless comment