REFACTOR: remove disallowEmails option from user-selector

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

diff --git a/app/assets/javascripts/discourse/components/user-selector.js.es6 b/app/assets/javascripts/discourse/components/user-selector.js.es6
index a25b3f6..1ad76ba 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.es6
index c64ec38..4335984 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.hbs
index 7ee33ef..9a9b1cf 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=usernames
                   hasGroups=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.hbs
index 10275eb..5887a32 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=hasGroups
           usernames=emailOrUsername
           placeholderKey=placeholderKey
+          allowEmails=true
           class="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.hbs
index c07c81a..ae13193 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.usernames
           placeholderKey="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.es6
index 28e3da7..fc676db 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: "sam@sam.com", allowEmails: true });
+  // 6 + email
+  assert.equal(results.length, 7);
+
+  results = await userSearch({ term: "sam@sam.com" });
+  assert.equal(results.length, 0);
 });

GitHub sha: 07b85670

This commit has been mentioned on Discourse Meta. There might be relevant details there: