mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 19:48:50 +03:00
Removed invalid and duplicate email validations in members importer
This commit is contained in:
parent
3086ac1439
commit
bcfc3792cd
@ -61,14 +61,7 @@ export default Service.extend({
|
|||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
// check can be done on whole set as it won't be too slow
|
// check can be done on whole set as it won't be too slow
|
||||||
const {invalidCount, emptyCount, duplicateCount} = this._checkEmails(data, mapping);
|
const {emptyCount} = this._checkEmails(data, mapping);
|
||||||
if (invalidCount) {
|
|
||||||
// @TODO: Remove error from displayed errors
|
|
||||||
validationErrors.push(new MemberImportError({
|
|
||||||
message: `Invalid email address (${formatNumber(invalidCount)})`,
|
|
||||||
type: 'warning'
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (emptyCount) {
|
if (emptyCount) {
|
||||||
validationErrors.push(new MemberImportError({
|
validationErrors.push(new MemberImportError({
|
||||||
@ -76,14 +69,6 @@ export default Service.extend({
|
|||||||
type: 'warning'
|
type: 'warning'
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (duplicateCount) {
|
|
||||||
// @TODO: Remove error from displayed errors
|
|
||||||
validationErrors.push(new MemberImportError({
|
|
||||||
message: `Duplicate email address (${formatNumber(duplicateCount)})`,
|
|
||||||
type: 'warning'
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {validationErrors, mapping};
|
return {validationErrors, mapping};
|
||||||
@ -184,29 +169,15 @@ export default Service.extend({
|
|||||||
|
|
||||||
_checkEmails(validatedSet, mapping) {
|
_checkEmails(validatedSet, mapping) {
|
||||||
let emptyCount = 0;
|
let emptyCount = 0;
|
||||||
let invalidCount = 0;
|
|
||||||
let duplicateCount = 0;
|
|
||||||
let emailMap = {};
|
|
||||||
|
|
||||||
validatedSet.forEach((member) => {
|
validatedSet.forEach((member) => {
|
||||||
let emailValue = member[mapping.email];
|
let emailValue = member[mapping.email];
|
||||||
if (!emailValue) {
|
if (!emailValue) {
|
||||||
emptyCount += 1;
|
emptyCount += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (emailValue && !validator.isEmail(emailValue)) {
|
|
||||||
invalidCount += 1;
|
|
||||||
} else if (emailValue) {
|
|
||||||
if (emailMap[emailValue]) {
|
|
||||||
emailMap[emailValue] += 1;
|
|
||||||
duplicateCount += 1;
|
|
||||||
} else {
|
|
||||||
emailMap[emailValue] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return {invalidCount, emptyCount, duplicateCount};
|
return {emptyCount};
|
||||||
},
|
},
|
||||||
|
|
||||||
_countStripeRecors(validatedSet, mapping) {
|
_countStripeRecors(validatedSet, mapping) {
|
||||||
|
@ -77,7 +77,7 @@ describe('Integration: Service: member-import-validator', function () {
|
|||||||
expect(validationErrors[0].message).to.equal('No email addresses found in the uploaded CSV.');
|
expect(validationErrors[0].message).to.equal('No email addresses found in the uploaded CSV.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns validation error for invalid email', async function () {
|
it('ignores validation for invalid email', async function () {
|
||||||
this.owner.register('service:membersUtils', Service.extend({
|
this.owner.register('service:membersUtils', Service.extend({
|
||||||
isStripeEnabled: false
|
isStripeEnabled: false
|
||||||
}));
|
}));
|
||||||
@ -90,8 +90,7 @@ describe('Integration: Service: member-import-validator', function () {
|
|||||||
email: 'email@example.com'
|
email: 'email@example.com'
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
expect(validationErrors.length).to.equal(1);
|
expect(validationErrors.length).to.equal(0);
|
||||||
expect(validationErrors[0].message).to.equal('Invalid email address (1)');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('data sampling method', function () {
|
describe('data sampling method', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user