REFACTOR: remove disallowEmails option from user-selector

Negative option was leading to a fair amount of confusion, going forward
if we want to allow selection of emails from user selector it must be
supplied with `allowEmails=true`

This corrects a regression in 1f4ace4f which broke invite by emails and
start PM to email
This commit is contained in:
Sam 2019-02-21 16:23:11 +11:00
parent 79841cf7dd
commit 07b856700d
6 changed files with 23 additions and 10 deletions

View File

@ -34,7 +34,7 @@ export default TextField.extend({
single = bool("single"),
allowAny = bool("allowAny"),
disabled = bool("disabled"),
disallowEmails = bool("disallowEmails"),
allowEmails = bool("allowEmails"),
fullWidthWrap = bool("fullWidthWrap");
function excludedUsernames() {
@ -67,7 +67,7 @@ export default TextField.extend({
includeMentionableGroups,
includeMessageableGroups,
group: self.get("group"),
disallowEmails
allowEmails
});
return results;
},

View File

@ -85,7 +85,7 @@ function organizeResults(r, options) {
});
}
if (!options.disallowEmails && emailValid(options.term)) {
if (options.allowEmails && emailValid(options.term)) {
let e = { username: options.term };
emails = [e];
results.push(e);
@ -118,9 +118,13 @@ function organizeResults(r, options) {
// will not find me, which is a reasonable compromise
//
// we also ignore if we notice a double space or a string that is only a space
const ignoreRegex = /([\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-\/:;<=>?@\[\]^_`{|}~])|\s\s|^\s$/;
const ignoreRegex = /([\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-\/:;<=>?\[\]^_`{|}~])|\s\s|^\s$/;
function skipSearch(term, allowEmails) {
if (term.indexOf("@") > -1 && !allowEmails) {
return true;
}
function skipSearch(term) {
return !!term.match(ignoreRegex);
}
@ -155,7 +159,7 @@ export default function userSearch(options) {
resolve(CANCELLED_STATUS);
}, 5000);
if (skipSearch(term)) {
if (skipSearch(term, options.allowEmails)) {
resolve([]);
return;
}

View File

@ -7,6 +7,7 @@
tabindex="1"
usernames=usernames
hasGroups=hasGroups
allowEmails='true'
autocomplete="discourse"}}
{{else}}
<div class='ac-wrap composer-user-selector-limited' {{action "toggleSelector"}}>

View File

@ -29,6 +29,7 @@
hasGroups=hasGroups
usernames=emailOrUsername
placeholderKey=placeholderKey
allowEmails=true
class="invite-user-input"
autocomplete="discourse"}}
{{else}}

View File

@ -9,8 +9,7 @@
class="input-xxlarge"
usernames=model.usernames
placeholderKey="groups.selector_placeholder"
id="group-add-members-user-selector"
disallowEmails=true}}
id="group-add-members-user-selector"}}
</div>
{{#if currentUser.admin}}

View File

@ -73,6 +73,7 @@ QUnit.test("it strips @ from the beginning", async assert => {
});
QUnit.test("it skips a search depending on punctuations", async assert => {
let results;
let skippedTerms = [
"@sam s", // double space is not allowed
"@sam;",
@ -81,7 +82,7 @@ QUnit.test("it skips a search depending on punctuations", async assert => {
];
for (let term of skippedTerms) {
let results = await userSearch({ term });
results = await userSearch({ term });
assert.equal(results.length, 0);
}
@ -94,7 +95,14 @@ QUnit.test("it skips a search depending on punctuations", async assert => {
let topicId = 100;
for (let term of allowedTerms) {
let results = await userSearch({ term, topicId });
results = await userSearch({ term, topicId });
assert.equal(results.length, 6);
}
results = await userSearch({ term: "sam@sam.com", allowEmails: true });
// 6 + email
assert.equal(results.length, 7);
results = await userSearch({ term: "sam@sam.com" });
assert.equal(results.length, 0);
});