diff options
author | Saša Živkov <sasa.zivkov@sap.com> | 2015-07-17 13:00:59 +0200 |
---|---|---|
committer | Saša Živkov <sasa.zivkov@sap.com> | 2015-07-21 10:16:30 +0200 |
commit | 0575d27ca7fb8db31ae325cef6dfd3680cf2fed6 (patch) | |
tree | 9c5dd7a2e8a7dc9bf8f0322b836598c71317e2dd | |
parent | 84694cba7d71f03c16bf8f99591eaf9e0be7f210 (diff) |
Don't suggest inactive accounts
When, for example, adding accounts to a group the drop down list would
also suggest inactive accounts. Exclude the inactive accounts from the
suggestion.
NOTE: suggesting of reviewers doesn't have this issue as this is a
different code. Ideally, suggesting accounts and suggesting reviewers
should be refactored to use the same suggestion algorithm. However,
this would be a larger change and better suited for the master branch.
Change-Id: I6bd22739c326a77dbf6fc3f36ee245d9e6939e34
-rw-r--r-- | gerrit-server/src/main/java/com/google/gerrit/server/account/SuggestAccounts.java | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/SuggestAccounts.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/SuggestAccounts.java index 07936d9f60..5cb05e0a3d 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/SuggestAccounts.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/SuggestAccounts.java @@ -45,6 +45,7 @@ class SuggestAccounts implements RestReadView<TopLevelResource> { private final AccountControl accountControl; private final AccountLoader accountLoader; + private final AccountCache accountCache; private final ReviewDb db; private final boolean suggest; private final int suggestFrom; @@ -68,10 +69,12 @@ class SuggestAccounts implements RestReadView<TopLevelResource> { @Inject SuggestAccounts(AccountControl.Factory accountControlFactory, AccountLoader.Factory accountLoaderFactory, + AccountCache accountCache, ReviewDb db, @GerritServerConfig Config cfg) { accountControl = accountControlFactory.get(); accountLoader = accountLoaderFactory.create(true); + this.accountCache = accountCache; this.db = db; this.suggestFrom = cfg.getInt("suggest", null, "from", 0); @@ -108,12 +111,12 @@ class SuggestAccounts implements RestReadView<TopLevelResource> { Map<Account.Id, String> queryEmail = new HashMap<>(); for (Account p : db.accounts().suggestByFullName(a, b, limit)) { - addSuggestion(matches, p.getId()); + addSuggestion(matches, p); } if (matches.size() < limit) { for (Account p : db.accounts() .suggestByPreferredEmail(a, b, limit - matches.size())) { - addSuggestion(matches, p.getId()); + addSuggestion(matches, p); } } if (matches.size() < limit) { @@ -146,11 +149,20 @@ class SuggestAccounts implements RestReadView<TopLevelResource> { return m; } - private boolean addSuggestion(Map<Account.Id, AccountInfo> map, Account.Id id) { + private boolean addSuggestion(Map<Account.Id, AccountInfo> map, Account a) { + if (!a.isActive()) { + return false; + } + Account.Id id = a.getId(); if (!map.containsKey(id) && accountControl.canSee(id)) { map.put(id, accountLoader.get(id)); return true; } return false; } + + private boolean addSuggestion(Map<Account.Id, AccountInfo> map, Account.Id id) { + Account a = accountCache.get(id).getAccount(); + return addSuggestion(map, a); + } } |