GroupMembers: Filter out members for which an account doesn't exist

None of the callers is interested in members that don't exist as account
in Gerrit.

Change-Id: I3866e85181d200c078c40bfab7f2937459902fb1
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-01-26 11:47:30 +01:00
parent 0ebe2b7daf
commit 3df5a5d13d

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.account;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
@@ -56,6 +57,8 @@ public class GroupMembers {
/**
* Recursively enumerate the members of the given group. Should not be used with the
* PROJECT_OWNERS magical group.
*
* <p>Group members for which an account doesn't exist are filtered out.
*/
public Set<Account> listAccounts(AccountGroup.UUID groupUUID) throws IOException {
if (SystemGroupBackend.PROJECT_OWNERS.equals(groupUUID)) {
@@ -71,6 +74,8 @@ public class GroupMembers {
/**
* Recursively enumerate the members of the given group. The project should be specified so the
* PROJECT_OWNERS magical group can be expanded.
*
* <p>Group members for which an account doesn't exist are filtered out.
*/
public Set<Account> listAccounts(AccountGroup.UUID groupUUID, Project.NameKey project)
throws NoSuchProjectException, IOException {
@@ -124,7 +129,8 @@ public class GroupMembers {
.getMembers()
.stream()
.filter(groupControl::canSeeMember)
.map(accountCache::get)
.map(accountCache::maybeGet)
.flatMap(Streams::stream)
.map(AccountState::getAccount)
.collect(toImmutableSet());