diff options
Diffstat (limited to 'gerrit-server/src/main/java/com/google/gerrit/server/account/ChangeUserName.java')
-rw-r--r-- | gerrit-server/src/main/java/com/google/gerrit/server/account/ChangeUserName.java | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/ChangeUserName.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/ChangeUserName.java index 9b076f8fc3..aa6baa11bb 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/ChangeUserName.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/ChangeUserName.java @@ -14,13 +14,14 @@ package com.google.gerrit.server.account; -import static com.google.gerrit.server.account.ExternalId.SCHEME_USERNAME; -import static java.util.stream.Collectors.toSet; +import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USERNAME; import com.google.gerrit.common.Nullable; import com.google.gerrit.common.errors.NameAlreadyUsedException; -import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.IdentifiedUser; +import com.google.gerrit.server.account.externalids.ExternalId; +import com.google.gerrit.server.account.externalids.ExternalIds; +import com.google.gerrit.server.account.externalids.ExternalIdsUpdate; import com.google.gerrit.server.ssh.SshKeyCache; import com.google.gwtjsonrpc.common.VoidResult; import com.google.gwtorm.server.OrmDuplicateKeyException; @@ -42,29 +43,26 @@ public class ChangeUserName implements Callable<VoidResult> { /** Generic factory to change any user's username. */ public interface Factory { - ChangeUserName create(ReviewDb db, IdentifiedUser user, String newUsername); + ChangeUserName create(IdentifiedUser user, String newUsername); } - private final AccountCache accountCache; private final SshKeyCache sshKeyCache; + private final ExternalIds externalIds; private final ExternalIdsUpdate.Server externalIdsUpdateFactory; - private final ReviewDb db; private final IdentifiedUser user; private final String newUsername; @Inject ChangeUserName( - AccountCache accountCache, SshKeyCache sshKeyCache, + ExternalIds externalIds, ExternalIdsUpdate.Server externalIdsUpdateFactory, - @Assisted ReviewDb db, @Assisted IdentifiedUser user, @Nullable @Assisted String newUsername) { - this.accountCache = accountCache; this.sshKeyCache = sshKeyCache; + this.externalIds = externalIds; this.externalIdsUpdateFactory = externalIdsUpdateFactory; - this.db = db; this.user = user; this.newUsername = newUsername; } @@ -73,10 +71,7 @@ public class ChangeUserName implements Callable<VoidResult> { public VoidResult call() throws OrmException, NameAlreadyUsedException, InvalidUserNameException, IOException, ConfigInvalidException { - Collection<ExternalId> old = - ExternalId.from(db.accountExternalIds().byAccount(user.getAccountId()).toList()).stream() - .filter(e -> e.isScheme(SCHEME_USERNAME)) - .collect(toSet()); + Collection<ExternalId> old = externalIds.byAccount(user.getAccountId(), SCHEME_USERNAME); if (!old.isEmpty()) { log.error( "External id with scheme \"username:\" already exists for the user {}", @@ -98,13 +93,12 @@ public class ChangeUserName implements Callable<VoidResult> { password = i.password(); } } - externalIdsUpdate.insert(db, ExternalId.create(key, user.getAccountId(), null, password)); + externalIdsUpdate.insert(ExternalId.create(key, user.getAccountId(), null, password)); log.info("Created the new external Id with key: {}", key); } catch (OrmDuplicateKeyException dupeErr) { // If we are using this identity, don't report the exception. // - ExternalId other = - ExternalId.from(db.accountExternalIds().get(key.asAccountExternalIdKey())); + ExternalId other = externalIds.get(key); if (other != null && other.accountId().equals(user.getAccountId())) { return VoidResult.INSTANCE; } @@ -117,13 +111,11 @@ public class ChangeUserName implements Callable<VoidResult> { // If we have any older user names, remove them. // - externalIdsUpdate.delete(db, old); + externalIdsUpdate.delete(old); for (ExternalId extId : old) { sshKeyCache.evict(extId.key().id()); - accountCache.evictByUsername(extId.key().id()); } - accountCache.evictByUsername(newUsername); sshKeyCache.evict(newUsername); return VoidResult.INSTANCE; } |