Always fall back to email address if account.name is not set

The goal of this change is just make computing the user name and display
name simpler and more consistent across the app. Usage of the display
name utils is low. And for default display names and first names coming
up we need to make these methods easier to refactor and change.

Change-Id: I4e5876ed6ea1909796b47484fb973228984dc1ce
diff --git a/polygerrit-ui/app/behaviors/gr-display-name-behavior/gr-display-name-behavior.js b/polygerrit-ui/app/behaviors/gr-display-name-behavior/gr-display-name-behavior.js
index 1ba8fd9..2e7f5d4 100644
--- a/polygerrit-ui/app/behaviors/gr-display-name-behavior/gr-display-name-behavior.js
+++ b/polygerrit-ui/app/behaviors/gr-display-name-behavior/gr-display-name-behavior.js
@@ -25,12 +25,8 @@
   Gerrit.DisplayNameBehavior = {
     // TODO(dmfilippov) replace DisplayNameBehavior with GrDisplayNameUtils
 
-    /**
-     * enableEmail when true enables to fallback to using email if
-     * the account name is not avilable.
-     */
-    getUserName(config, account, enableEmail) {
-      return GrDisplayNameUtils.getUserName(config, account, enableEmail);
+    getUserName(config, account) {
+      return GrDisplayNameUtils.getUserName(config, account);
     },
 
     getGroupDisplayName(group) {
diff --git a/polygerrit-ui/app/behaviors/gr-display-name-behavior/gr-display-name-behavior_test.html b/polygerrit-ui/app/behaviors/gr-display-name-behavior/gr-display-name-behavior_test.html
index 863f708..26022c4 100644
--- a/polygerrit-ui/app/behaviors/gr-display-name-behavior/gr-display-name-behavior_test.html
+++ b/polygerrit-ui/app/behaviors/gr-display-name-behavior/gr-display-name-behavior_test.html
@@ -65,26 +65,26 @@
     const account = {
       name: 'test-name',
     };
-    assert.deepEqual(element.getUserName(config, account, true), 'test-name');
+    assert.equal(element.getUserName(config, account), 'test-name');
   });
 
   test('getUserName username only', () => {
     const account = {
       username: 'test-user',
     };
-    assert.deepEqual(element.getUserName(config, account, true), 'test-user');
+    assert.equal(element.getUserName(config, account), 'test-user');
   });
 
   test('getUserName email only', () => {
     const account = {
       email: 'test-user@test-url.com',
     };
-    assert.deepEqual(element.getUserName(config, account, true),
+    assert.equal(element.getUserName(config, account),
         'test-user@test-url.com');
   });
 
   test('getUserName returns not Anonymous Coward as the anon name', () => {
-    assert.deepEqual(element.getUserName(config, null, true), 'Anonymous');
+    assert.equal(element.getUserName(config, null), 'Anonymous');
   });
 
   test('getUserName for the config returning the anon name', () => {
@@ -93,7 +93,7 @@
         anonymous_coward_name: 'Test Anon',
       },
     };
-    assert.deepEqual(element.getUserName(config, null, true), 'Test Anon');
+    assert.equal(element.getUserName(config, null), 'Test Anon');
   });
 
   test('getGroupDisplayName', () => {
diff --git a/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.js b/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.js
index 6d9f9d7..444986b 100644
--- a/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.js
+++ b/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.js
@@ -124,7 +124,7 @@
   }
 
   _accountName(account) {
-    return this.getUserName(this.config, account, true);
+    return this.getUserName(this.config, account);
   }
 }
 
diff --git a/polygerrit-ui/app/elements/core/gr-smart-search/gr-smart-search.js b/polygerrit-ui/app/elements/core/gr-smart-search/gr-smart-search.js
index a93c139..b27adf7 100644
--- a/polygerrit-ui/app/elements/core/gr-smart-search/gr-smart-search.js
+++ b/polygerrit-ui/app/elements/core/gr-smart-search/gr-smart-search.js
@@ -161,7 +161,7 @@
 
   _mapAccountsHelper(accounts, predicate) {
     return accounts.map(account => {
-      const userName = this.getUserName(this._serverConfig, account, false);
+      const userName = this.getUserName(this._serverConfig, account);
       return {
         label: account.name || '',
         text: account.email ?
diff --git a/polygerrit-ui/app/elements/shared/gr-account-label/gr-account-label.js b/polygerrit-ui/app/elements/shared/gr-account-label/gr-account-label.js
index 5675f0b..d279563 100644
--- a/polygerrit-ui/app/elements/shared/gr-account-label/gr-account-label.js
+++ b/polygerrit-ui/app/elements/shared/gr-account-label/gr-account-label.js
@@ -69,7 +69,7 @@
   }
 
   _computeName(account, config) {
-    return this.getUserName(config, account, /* enableEmail */ true);
+    return this.getUserName(config, account);
   }
 }
 
diff --git a/polygerrit-ui/app/scripts/gr-display-name-utils/gr-display-name-utils.js b/polygerrit-ui/app/scripts/gr-display-name-utils/gr-display-name-utils.js
index f0d0e7f..cefd254 100644
--- a/polygerrit-ui/app/scripts/gr-display-name-utils/gr-display-name-utils.js
+++ b/polygerrit-ui/app/scripts/gr-display-name-utils/gr-display-name-utils.js
@@ -24,16 +24,12 @@
   const ANONYMOUS_NAME = 'Anonymous';
 
   class GrDisplayNameUtils {
-    /**
-     * enableEmail when true enables to fallback to using email if
-     * the account name is not avilable.
-     */
-    static getUserName(config, account, enableEmail) {
+    static getUserName(config, account) {
       if (account && account.name) {
         return account.name;
       } else if (account && account.username) {
         return account.username;
-      } else if (enableEmail && account && account.email) {
+      } else if (account && account.email) {
         return account.email;
       } else if (config && config.user &&
           config.user.anonymous_coward_name !== 'Anonymous Coward') {
@@ -43,8 +39,8 @@
       return ANONYMOUS_NAME;
     }
 
-    static getAccountDisplayName(config, account, enableEmail) {
-      const reviewerName = this.getUserName(config, account, !!enableEmail);
+    static getAccountDisplayName(config, account) {
+      const reviewerName = this.getUserName(config, account);
       const reviewerEmail = this._accountEmail(account.email);
       const reviewerStatus = account.status ? '(' + account.status + ')' : '';
       return [reviewerName, reviewerEmail, reviewerStatus]
diff --git a/polygerrit-ui/app/scripts/gr-display-name-utils/gr-display-name-utils_test.html b/polygerrit-ui/app/scripts/gr-display-name-utils/gr-display-name-utils_test.html
index b9ddac62..7ef5250 100644
--- a/polygerrit-ui/app/scripts/gr-display-name-utils/gr-display-name-utils_test.html
+++ b/polygerrit-ui/app/scripts/gr-display-name-utils/gr-display-name-utils_test.html
@@ -43,7 +43,7 @@
     const account = {
       name: 'test-name',
     };
-    assert.deepEqual(GrDisplayNameUtils.getUserName(config, account, true),
+    assert.deepEqual(GrDisplayNameUtils.getUserName(config, account),
         'test-name');
   });
 
@@ -51,7 +51,7 @@
     const account = {
       username: 'test-user',
     };
-    assert.deepEqual(GrDisplayNameUtils.getUserName(config, account, true),
+    assert.deepEqual(GrDisplayNameUtils.getUserName(config, account),
         'test-user');
   });
 
@@ -59,12 +59,12 @@
     const account = {
       email: 'test-user@test-url.com',
     };
-    assert.deepEqual(GrDisplayNameUtils.getUserName(config, account, true),
+    assert.deepEqual(GrDisplayNameUtils.getUserName(config, account),
         'test-user@test-url.com');
   });
 
   test('getUserName returns not Anonymous Coward as the anon name', () => {
-    assert.deepEqual(GrDisplayNameUtils.getUserName(config, null, true),
+    assert.deepEqual(GrDisplayNameUtils.getUserName(config, null),
         'Anonymous');
   });
 
@@ -74,7 +74,7 @@
         anonymous_coward_name: 'Test Anon',
       },
     };
-    assert.deepEqual(GrDisplayNameUtils.getUserName(config, null, true),
+    assert.deepEqual(GrDisplayNameUtils.getUserName(config, null),
         'Test Anon');
   });
 
@@ -89,13 +89,6 @@
     assert.equal(
         GrDisplayNameUtils.getAccountDisplayName(config,
             {email: 'my@example.com'}),
-        'Anonymous <my@example.com>');
-  });
-
-  test('getAccountDisplayName - account with email only - allowEmail', () => {
-    assert.equal(
-        GrDisplayNameUtils.getAccountDisplayName(config,
-            {email: 'my@example.com'}, true),
         'my@example.com <my@example.com>');
   });
 
diff --git a/polygerrit-ui/app/scripts/gr-email-suggestions-provider/gr-email-suggestions-provider.js b/polygerrit-ui/app/scripts/gr-email-suggestions-provider/gr-email-suggestions-provider.js
index 67001d2..a1fd94a 100644
--- a/polygerrit-ui/app/scripts/gr-email-suggestions-provider/gr-email-suggestions-provider.js
+++ b/polygerrit-ui/app/scripts/gr-email-suggestions-provider/gr-email-suggestions-provider.js
@@ -36,7 +36,7 @@
 
     makeSuggestionItem(account) {
       return {
-        name: GrDisplayNameUtils.getAccountDisplayName(null, account, true),
+        name: GrDisplayNameUtils.getAccountDisplayName(null, account),
         value: {account, count: 1},
       };
     }
diff --git a/polygerrit-ui/app/scripts/gr-reviewer-suggestions-provider/gr-reviewer-suggestions-provider.js b/polygerrit-ui/app/scripts/gr-reviewer-suggestions-provider/gr-reviewer-suggestions-provider.js
index fecf75aa..a47eb72 100644
--- a/polygerrit-ui/app/scripts/gr-reviewer-suggestions-provider/gr-reviewer-suggestions-provider.js
+++ b/polygerrit-ui/app/scripts/gr-reviewer-suggestions-provider/gr-reviewer-suggestions-provider.js
@@ -87,7 +87,7 @@
         // Reviewer is an account suggestion from getChangeSuggestedReviewers.
         return {
           name: GrDisplayNameUtils.getAccountDisplayName(this._config,
-              suggestion.account, false),
+              suggestion.account),
           value: suggestion,
         };
       }
@@ -104,7 +104,7 @@
         // Reviewer is an account suggestion from getSuggestedAccounts.
         return {
           name: GrDisplayNameUtils.getAccountDisplayName(this._config,
-              suggestion, false),
+              suggestion),
           value: {account: suggestion, count: 1},
         };
       }