ExternalIdCache: Add method to get external IDs by account ID + scheme
Change-Id: I800c41923facbfe9194ce47716ed2d23d0ffd70a Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -210,8 +210,8 @@ public class GpgKeys implements
|
||||
@VisibleForTesting
|
||||
public static FluentIterable<AccountExternalId> getGpgExtIds(
|
||||
ExternalIdCache externalIdCache, Account.Id accountId) {
|
||||
return FluentIterable.from(externalIdCache.byAccount(accountId))
|
||||
.filter(in -> in.isScheme(SCHEME_GPGKEY));
|
||||
return FluentIterable.from(
|
||||
externalIdCache.byAccount(accountId, SCHEME_GPGKEY));
|
||||
}
|
||||
|
||||
private Iterable<AccountExternalId> getGpgExtIds(AccountResource rsrc) {
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -76,7 +75,8 @@ public class ChangeUserName implements Callable<VoidResult> {
|
||||
@Override
|
||||
public VoidResult call() throws OrmException, NameAlreadyUsedException,
|
||||
InvalidUserNameException, IOException {
|
||||
final Collection<AccountExternalId> old = old();
|
||||
Collection<AccountExternalId> old =
|
||||
externalIdCache.byAccount(user.getAccountId(), SCHEME_USERNAME);
|
||||
if (!old.isEmpty()) {
|
||||
throw new IllegalStateException(USERNAME_CANNOT_BE_CHANGED);
|
||||
}
|
||||
@@ -128,15 +128,4 @@ public class ChangeUserName implements Callable<VoidResult> {
|
||||
sshKeyCache.evict(newUsername);
|
||||
return VoidResult.INSTANCE;
|
||||
}
|
||||
|
||||
private Collection<AccountExternalId> old() {
|
||||
final Collection<AccountExternalId> r = new ArrayList<>(1);
|
||||
for (AccountExternalId i : externalIdCache.byAccount(
|
||||
user.getAccountId())) {
|
||||
if (i.isScheme(SCHEME_USERNAME)) {
|
||||
r.add(i);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,14 @@
|
||||
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountExternalId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/** Caches external ids of all accounts */
|
||||
public interface ExternalIdCache {
|
||||
@@ -40,4 +43,10 @@ public interface ExternalIdCache {
|
||||
default void onRemove(Account.Id accountId, AccountExternalId.Key extIdKey) {
|
||||
onRemove(accountId, Collections.singleton(extIdKey));
|
||||
}
|
||||
|
||||
default Set<AccountExternalId> byAccount(Account.Id accountId,
|
||||
String scheme) {
|
||||
return byAccount(accountId).stream().filter(e -> e.isScheme(scheme))
|
||||
.collect(toSet());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user