AccountsUpdate: Remove methods to delete account
Gerrit doesn't support deletion of accounts. AccountsUpdate only supported the deletion of user branches to do a rollback if there was an error during account creation. Since the account creation is now done atomically we no longer need to manually rollback the creation of user branches. Hence the delete methods from AccountsUpdate can be removed. The last remaining callers of these methods were a test and a schema migration in which the needed functionality can be inlined. Change-Id: I58d591dba50aa70d5423f1d79b8e9af47bf55281 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -24,8 +24,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.Runnables;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.externalids.ExternalIdNotes;
|
||||
@@ -51,11 +49,7 @@ import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.BatchRefUpdate;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.RefUpdate;
|
||||
import org.eclipse.jgit.lib.RefUpdate.Result;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
/**
|
||||
@@ -446,74 +440,6 @@ public class AccountsUpdate {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the account.
|
||||
*
|
||||
* @param account the account that should be deleted
|
||||
* @throws IOException if deleting the user branch fails due to an IO error
|
||||
* @throws OrmException if deleting the user branch fails
|
||||
* @throws ConfigInvalidException
|
||||
*/
|
||||
public void delete(Account account) throws IOException, OrmException, ConfigInvalidException {
|
||||
deleteByKey(account.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the account.
|
||||
*
|
||||
* @param accountId the ID of the account that should be deleted
|
||||
* @throws IOException if deleting the user branch fails due to an IO error
|
||||
* @throws OrmException if deleting the user branch fails
|
||||
* @throws ConfigInvalidException
|
||||
*/
|
||||
public void deleteByKey(Account.Id accountId)
|
||||
throws IOException, OrmException, ConfigInvalidException {
|
||||
deleteAccount(accountId);
|
||||
}
|
||||
|
||||
private Account deleteAccount(Account.Id accountId)
|
||||
throws IOException, OrmException, ConfigInvalidException {
|
||||
return retryHelper.execute(
|
||||
ActionType.ACCOUNT_UPDATE,
|
||||
() -> {
|
||||
deleteUserBranch(accountId);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteUserBranch(Account.Id accountId) throws IOException {
|
||||
try (Repository repo = repoManager.openRepository(allUsersName)) {
|
||||
deleteUserBranch(repo, allUsersName, gitRefUpdated, currentUser, authorIdent, accountId);
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteUserBranch(
|
||||
Repository repo,
|
||||
Project.NameKey project,
|
||||
GitReferenceUpdated gitRefUpdated,
|
||||
@Nullable IdentifiedUser user,
|
||||
PersonIdent refLogIdent,
|
||||
Account.Id accountId)
|
||||
throws IOException {
|
||||
String refName = RefNames.refsUsers(accountId);
|
||||
Ref ref = repo.exactRef(refName);
|
||||
if (ref == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefUpdate ru = repo.updateRef(refName);
|
||||
ru.setExpectedOldObjectId(ref.getObjectId());
|
||||
ru.setNewObjectId(ObjectId.zeroId());
|
||||
ru.setForceUpdate(true);
|
||||
ru.setRefLogIdent(refLogIdent);
|
||||
ru.setRefLogMessage("Delete Account", true);
|
||||
Result result = ru.delete();
|
||||
if (result != Result.FORCED) {
|
||||
throw new IOException(String.format("Failed to delete ref %s: %s", refName, result.name()));
|
||||
}
|
||||
gitRefUpdated.fire(project, ru, user != null ? user.getAccount() : null);
|
||||
}
|
||||
|
||||
private AccountConfig read(Repository allUsersRepo, Account.Id accountId)
|
||||
throws IOException, ConfigInvalidException {
|
||||
AccountConfig accountConfig = new AccountConfig(emailValidator, accountId);
|
||||
|
Reference in New Issue
Block a user