A platform for community discussion. Free, open, simple.
REFACTOR: remove disallowEmails option from user-selector
Sam07b856700ded
diff --git a/app/assets/javascripts/discourse/components/user-selector.js.es6 b/app/assets/javascripts/discourse/components/user-selector.js.es6index a25b3f65e9c..1ad76ba6ab5 100644--- a/app/assets/javascripts/discourse/components/user-selector.js.es6+++ b/app/assets/javascripts/discourse/components/user-selector.js.es6@@ -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;},diff --git a/app/assets/javascripts/discourse/lib/user-search.js.es6 b/app/assets/javascripts/discourse/lib/user-search.js.es6index c64ec385de3..43359845e72 100644--- a/app/assets/javascripts/discourse/lib/user-search.js.es6+++ b/app/assets/javascripts/discourse/lib/user-search.js.es6@@ -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;}diff --git a/app/assets/javascripts/discourse/templates/components/composer-user-selector.hbs b/app/assets/javascripts/discourse/templates/components/composer-user-selector.hbsindex 7ee33ef939a..9a9b1cfcf87 100644--- a/app/assets/javascripts/discourse/templates/components/composer-user-selector.hbs+++ b/app/assets/javascripts/discourse/templates/components/composer-user-selector.hbs@@ -7,6 +7,7 @@tabindex="1"usernames=usernameshasGroups=hasGroups+ allowEmails='true'autocomplete="discourse"}}{{else}}<div class='ac-wrap composer-user-selector-limited' {{action "toggleSelector"}}>diff --git a/app/assets/javascripts/discourse/templates/components/invite-panel.hbs b/app/assets/javascripts/discourse/templates/components/invite-panel.hbsindex 10275ebf971..5887a3231e4 100644--- a/app/assets/javascripts/discourse/templates/components/invite-panel.hbs+++ b/app/assets/javascripts/discourse/templates/components/invite-panel.hbs@@ -29,6 +29,7 @@hasGroups=hasGroupsusernames=emailOrUsernameplaceholderKey=placeholderKey+ allowEmails=trueclass="invite-user-input"autocomplete="discourse"}}{{else}}diff --git a/app/assets/javascripts/discourse/templates/modal/group-add-members.hbs b/app/assets/javascripts/discourse/templates/modal/group-add-members.hbsindex c07c81a1d7f..ae13193ea11 100644--- a/app/assets/javascripts/discourse/templates/modal/group-add-members.hbs+++ b/app/assets/javascripts/discourse/templates/modal/group-add-members.hbs@@ -9,8 +9,7 @@class="input-xxlarge"usernames=model.usernamesplaceholderKey="groups.selector_placeholder"- id="group-add-members-user-selector"- disallowEmails=true}}+ id="group-add-members-user-selector"}}</div>{{#if currentUser.admin}}diff --git a/test/javascripts/lib/user-search-test.js.es6 b/test/javascripts/lib/user-search-test.js.es6index 28e3da7d3c8..fc676db348c 100644--- a/test/javascripts/lib/user-search-test.js.es6+++ b/test/javascripts/lib/user-search-test.js.es6@@ -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: "[email protected]", allowEmails: true });+ // 6 + email+ assert.equal(results.length, 7);++ results = await userSearch({ term: "[email protected]" });+ assert.equal(results.length, 0);});