Remove support for writing accounts from ReviewDb
Accounts have been fully migrated to NoteDb. However inside of Google we still have code that depends on the Accounts table. hence this table is dropped only later by a follow-up change. Change-Id: Ia32983e2877e3965561db7d264cf1d2b7b2e40c3 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
parent
30af94f4ce
commit
6957747c87
|
@ -116,7 +116,6 @@ public class AccountCreator {
|
|||
accountsUpdate
|
||||
.create()
|
||||
.insert(
|
||||
db,
|
||||
id,
|
||||
a -> {
|
||||
a.setFullName(fullName);
|
||||
|
|
|
@ -88,7 +88,6 @@ 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.config.AllUsersName;
|
||||
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.notedb.rebuild.ChangeRebuilderImpl;
|
||||
import com.google.gerrit.server.project.RefPattern;
|
||||
|
@ -256,32 +255,11 @@ public class AccountIT extends AbstractDaemonTest {
|
|||
Account.Id nonExistingAccountId = new Account.Id(999999);
|
||||
AtomicBoolean consumerCalled = new AtomicBoolean();
|
||||
Account account =
|
||||
accountsUpdate.create().update(db, nonExistingAccountId, a -> consumerCalled.set(true));
|
||||
accountsUpdate.create().update(nonExistingAccountId, a -> consumerCalled.set(true));
|
||||
assertThat(account).isNull();
|
||||
assertThat(consumerCalled.get()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateAccountThatIsMissingInNoteDb() throws Exception {
|
||||
String name = "bar";
|
||||
TestAccount bar = accountCreator.create(name);
|
||||
assertUserBranch(bar.getId(), name, null);
|
||||
|
||||
// delete user branch
|
||||
try (Repository repo = repoManager.openRepository(allUsers)) {
|
||||
AccountsUpdate.deleteUserBranch(
|
||||
repo, allUsers, GitReferenceUpdated.DISABLED, null, serverIdent.get(), bar.getId());
|
||||
assertThat(repo.exactRef(RefNames.refsUsers(bar.getId()))).isNull();
|
||||
}
|
||||
|
||||
String status = "OOO";
|
||||
Account account = accountsUpdate.create().update(db, bar.getId(), a -> a.setStatus(status));
|
||||
assertThat(account).isNotNull();
|
||||
assertThat(account.getFullName()).isEqualTo(name);
|
||||
assertThat(account.getStatus()).isEqualTo(status);
|
||||
assertUserBranch(bar.getId(), name, status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateAccountWithoutAccountConfigNoteDb() throws Exception {
|
||||
TestAccount anonymousCoward = accountCreator.create();
|
||||
|
@ -289,7 +267,7 @@ public class AccountIT extends AbstractDaemonTest {
|
|||
|
||||
String status = "OOO";
|
||||
Account account =
|
||||
accountsUpdate.create().update(db, anonymousCoward.getId(), a -> a.setStatus(status));
|
||||
accountsUpdate.create().update(anonymousCoward.getId(), a -> a.setStatus(status));
|
||||
assertThat(account).isNotNull();
|
||||
assertThat(account.getFullName()).isNull();
|
||||
assertThat(account.getStatus()).isEqualTo(status);
|
||||
|
@ -712,7 +690,7 @@ public class AccountIT extends AbstractDaemonTest {
|
|||
String prefix = "foo.preferred";
|
||||
String prefEmail = prefix + "@example.com";
|
||||
TestAccount foo = accountCreator.create(name("foo"));
|
||||
accountsUpdate.create().update(db, foo.id, a -> a.setPreferredEmail(prefEmail));
|
||||
accountsUpdate.create().update(foo.id, a -> a.setPreferredEmail(prefEmail));
|
||||
|
||||
// verify that the account is still found when using the preferred email to lookup the account
|
||||
ImmutableSet<Account.Id> accountsByPrefEmail = emails.getAccountFor(prefEmail);
|
||||
|
@ -1287,17 +1265,17 @@ public class AccountIT extends AbstractDaemonTest {
|
|||
// metaId is set when account is created
|
||||
AccountsUpdate au = accountsUpdate.create();
|
||||
Account.Id accountId = new Account.Id(seq.nextAccountId());
|
||||
Account account = au.insert(db, accountId, a -> {});
|
||||
Account account = au.insert(accountId, a -> {});
|
||||
assertThat(account.getMetaId()).isEqualTo(getMetaId(accountId));
|
||||
|
||||
// metaId is set when account is updated
|
||||
Account updatedAccount = au.update(db, accountId, a -> a.setFullName("foo"));
|
||||
Account updatedAccount = au.update(accountId, a -> a.setFullName("foo"));
|
||||
assertThat(account.getMetaId()).isNotEqualTo(updatedAccount.getMetaId());
|
||||
assertThat(updatedAccount.getMetaId()).isEqualTo(getMetaId(accountId));
|
||||
|
||||
// metaId is set when account is replaced
|
||||
Account newAccount = new Account(accountId, TimeUtil.nowTs());
|
||||
au.replace(db, newAccount);
|
||||
au.replace(newAccount);
|
||||
assertThat(updatedAccount.getMetaId()).isNotEqualTo(newAccount.getMetaId());
|
||||
assertThat(newAccount.getMetaId()).isEqualTo(getMetaId(accountId));
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
|
|||
public void missingOwner() throws Exception {
|
||||
TestAccount owner = accountCreator.create("missing");
|
||||
ChangeControl ctl = insertChange(owner);
|
||||
accountsUpdate.create().deleteByKey(db, owner.getId());
|
||||
accountsUpdate.create().deleteByKey(owner.getId());
|
||||
|
||||
assertProblems(ctl, null, problem("Missing change owner: " + owner.getId()));
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ public class GerritPublicKeyCheckerTest {
|
|||
schemaCreator.create(db);
|
||||
userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
|
||||
// Note: does not match any key in TestKeys.
|
||||
accountsUpdate.create().update(db, userId, a -> a.setPreferredEmail("user@example.com"));
|
||||
accountsUpdate.create().update(userId, a -> a.setPreferredEmail("user@example.com"));
|
||||
user = reloadUser();
|
||||
|
||||
requestContext.setContext(
|
||||
|
|
|
@ -17,17 +17,14 @@ package com.google.gerrit.pgm.init;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gerrit.pgm.init.api.AllUsersNameOnInitProvider;
|
||||
import com.google.gerrit.pgm.init.api.InitFlags;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.GerritPersonIdentProvider;
|
||||
import com.google.gerrit.server.account.AccountConfig;
|
||||
import com.google.gerrit.server.account.Accounts;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -62,9 +59,7 @@ public class AccountsOnInit {
|
|||
this.allUsers = allUsers.get();
|
||||
}
|
||||
|
||||
public void insert(ReviewDb db, Account account) throws OrmException, IOException {
|
||||
db.accounts().insert(ImmutableSet.of(account));
|
||||
|
||||
public void insert(Account account) throws IOException {
|
||||
File path = getPath();
|
||||
if (path != null) {
|
||||
try (Repository repo = new FileRepository(path);
|
||||
|
|
|
@ -119,7 +119,7 @@ public class InitAdminUser implements InitStep {
|
|||
Account a = new Account(id, TimeUtil.nowTs());
|
||||
a.setFullName(name);
|
||||
a.setPreferredEmail(email);
|
||||
accounts.insert(db, a);
|
||||
accounts.insert(a);
|
||||
|
||||
AccountGroup adminGroup =
|
||||
groupsOnInit.getExistingGroup(db, new AccountGroup.NameKey("Administrators"));
|
||||
|
|
|
@ -144,7 +144,7 @@ public class AccountManager {
|
|||
}
|
||||
|
||||
// return the identity to the caller.
|
||||
update(db, who, id);
|
||||
update(who, id);
|
||||
return new AuthResult(id.accountId(), who.getExternalIdKey(), false);
|
||||
}
|
||||
} catch (OrmException | ConfigInvalidException e) {
|
||||
|
@ -152,7 +152,7 @@ public class AccountManager {
|
|||
}
|
||||
}
|
||||
|
||||
private void update(ReviewDb db, AuthRequest who, ExternalId extId)
|
||||
private void update(AuthRequest who, ExternalId extId)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
IdentifiedUser user = userFactory.create(extId.accountId());
|
||||
List<Consumer<Account>> accountUpdates = new ArrayList<>();
|
||||
|
@ -188,8 +188,7 @@ public class AccountManager {
|
|||
}
|
||||
|
||||
if (!accountUpdates.isEmpty()) {
|
||||
Account account =
|
||||
accountsUpdateFactory.create().update(db, user.getAccountId(), accountUpdates);
|
||||
Account account = accountsUpdateFactory.create().update(user.getAccountId(), accountUpdates);
|
||||
if (account == null) {
|
||||
throw new OrmException("Account " + user.getAccountId() + " has been deleted");
|
||||
}
|
||||
|
@ -214,7 +213,6 @@ public class AccountManager {
|
|||
AccountsUpdate accountsUpdate = accountsUpdateFactory.create();
|
||||
account =
|
||||
accountsUpdate.insert(
|
||||
db,
|
||||
newId,
|
||||
a -> {
|
||||
a.setFullName(who.getDisplayName());
|
||||
|
@ -224,7 +222,7 @@ public class AccountManager {
|
|||
ExternalId existingExtId = externalIds.get(extId.key());
|
||||
if (existingExtId != null && !existingExtId.accountId().equals(extId.accountId())) {
|
||||
// external ID is assigned to another account, do not overwrite
|
||||
accountsUpdate.delete(db, account);
|
||||
accountsUpdate.delete(account);
|
||||
throw new AccountException(
|
||||
"Cannot assign external ID \""
|
||||
+ extId.key().get()
|
||||
|
@ -277,7 +275,7 @@ public class AccountManager {
|
|||
+ "\" to account "
|
||||
+ newId
|
||||
+ "; name already in use.";
|
||||
handleSettingUserNameFailure(db, account, extId, message, e, false);
|
||||
handleSettingUserNameFailure(account, extId, message, e, false);
|
||||
} catch (InvalidUserNameException e) {
|
||||
String message =
|
||||
"Cannot assign user name \""
|
||||
|
@ -285,10 +283,10 @@ public class AccountManager {
|
|||
+ "\" to account "
|
||||
+ newId
|
||||
+ "; name does not conform.";
|
||||
handleSettingUserNameFailure(db, account, extId, message, e, false);
|
||||
handleSettingUserNameFailure(account, extId, message, e, false);
|
||||
} catch (OrmException e) {
|
||||
String message = "Cannot assign user name";
|
||||
handleSettingUserNameFailure(db, account, extId, message, e, true);
|
||||
handleSettingUserNameFailure(account, extId, message, e, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -302,7 +300,6 @@ public class AccountManager {
|
|||
* deletes the newly created account and throws an {@link AccountUserNameException}. In any case
|
||||
* the error message is logged.
|
||||
*
|
||||
* @param db the database
|
||||
* @param account the newly created account
|
||||
* @param extId the newly created external id
|
||||
* @param errorMessage the error message
|
||||
|
@ -313,12 +310,7 @@ public class AccountManager {
|
|||
* @throws OrmException thrown if cleaning the database failed
|
||||
*/
|
||||
private void handleSettingUserNameFailure(
|
||||
ReviewDb db,
|
||||
Account account,
|
||||
ExternalId extId,
|
||||
String errorMessage,
|
||||
Exception e,
|
||||
boolean logException)
|
||||
Account account, ExternalId extId, String errorMessage, Exception e, boolean logException)
|
||||
throws AccountUserNameException, OrmException, IOException, ConfigInvalidException {
|
||||
if (logException) {
|
||||
log.error(errorMessage, e);
|
||||
|
@ -333,7 +325,7 @@ public class AccountManager {
|
|||
// such an account cannot be used for uploading changes,
|
||||
// this is why the best we can do here is to fail early and cleanup
|
||||
// the database
|
||||
accountsUpdateFactory.create().delete(db, account);
|
||||
accountsUpdateFactory.create().delete(account);
|
||||
externalIdsUpdateFactory.create().delete(extId);
|
||||
throw new AccountUserNameException(errorMessage, e);
|
||||
}
|
||||
|
@ -350,34 +342,31 @@ public class AccountManager {
|
|||
*/
|
||||
public AuthResult link(Account.Id to, AuthRequest who)
|
||||
throws AccountException, OrmException, IOException, ConfigInvalidException {
|
||||
try (ReviewDb db = schema.open()) {
|
||||
ExternalId extId = externalIds.get(who.getExternalIdKey());
|
||||
if (extId != null) {
|
||||
if (!extId.accountId().equals(to)) {
|
||||
throw new AccountException("Identity in use by another account");
|
||||
}
|
||||
update(db, who, extId);
|
||||
} else {
|
||||
externalIdsUpdateFactory
|
||||
.create()
|
||||
.insert(ExternalId.createWithEmail(who.getExternalIdKey(), to, who.getEmailAddress()));
|
||||
|
||||
if (who.getEmailAddress() != null) {
|
||||
accountsUpdateFactory
|
||||
.create()
|
||||
.update(
|
||||
db,
|
||||
to,
|
||||
a -> {
|
||||
if (a.getPreferredEmail() == null) {
|
||||
a.setPreferredEmail(who.getEmailAddress());
|
||||
}
|
||||
});
|
||||
}
|
||||
ExternalId extId = externalIds.get(who.getExternalIdKey());
|
||||
if (extId != null) {
|
||||
if (!extId.accountId().equals(to)) {
|
||||
throw new AccountException("Identity in use by another account");
|
||||
}
|
||||
update(who, extId);
|
||||
} else {
|
||||
externalIdsUpdateFactory
|
||||
.create()
|
||||
.insert(ExternalId.createWithEmail(who.getExternalIdKey(), to, who.getEmailAddress()));
|
||||
|
||||
return new AuthResult(to, who.getExternalIdKey(), false);
|
||||
if (who.getEmailAddress() != null) {
|
||||
accountsUpdateFactory
|
||||
.create()
|
||||
.update(
|
||||
to,
|
||||
a -> {
|
||||
if (a.getPreferredEmail() == null) {
|
||||
a.setPreferredEmail(who.getEmailAddress());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return new AuthResult(to, who.getExternalIdKey(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -437,40 +426,36 @@ public class AccountManager {
|
|||
return;
|
||||
}
|
||||
|
||||
try (ReviewDb db = schema.open()) {
|
||||
List<ExternalId> extIds = new ArrayList<>(extIdKeys.size());
|
||||
for (ExternalId.Key extIdKey : extIdKeys) {
|
||||
ExternalId extId = externalIds.get(extIdKey);
|
||||
if (extId != null) {
|
||||
if (!extId.accountId().equals(from)) {
|
||||
throw new AccountException(
|
||||
"Identity '" + extIdKey.get() + "' in use by another account");
|
||||
}
|
||||
extIds.add(extId);
|
||||
} else {
|
||||
throw new AccountException("Identity '" + extIdKey.get() + "' not found");
|
||||
List<ExternalId> extIds = new ArrayList<>(extIdKeys.size());
|
||||
for (ExternalId.Key extIdKey : extIdKeys) {
|
||||
ExternalId extId = externalIds.get(extIdKey);
|
||||
if (extId != null) {
|
||||
if (!extId.accountId().equals(from)) {
|
||||
throw new AccountException("Identity '" + extIdKey.get() + "' in use by another account");
|
||||
}
|
||||
extIds.add(extId);
|
||||
} else {
|
||||
throw new AccountException("Identity '" + extIdKey.get() + "' not found");
|
||||
}
|
||||
}
|
||||
|
||||
externalIdsUpdateFactory.create().delete(extIds);
|
||||
externalIdsUpdateFactory.create().delete(extIds);
|
||||
|
||||
if (extIds.stream().anyMatch(e -> e.email() != null)) {
|
||||
accountsUpdateFactory
|
||||
.create()
|
||||
.update(
|
||||
db,
|
||||
from,
|
||||
a -> {
|
||||
if (a.getPreferredEmail() != null) {
|
||||
for (ExternalId extId : extIds) {
|
||||
if (a.getPreferredEmail().equals(extId.email())) {
|
||||
a.setPreferredEmail(null);
|
||||
break;
|
||||
}
|
||||
if (extIds.stream().anyMatch(e -> e.email() != null)) {
|
||||
accountsUpdateFactory
|
||||
.create()
|
||||
.update(
|
||||
from,
|
||||
a -> {
|
||||
if (a.getPreferredEmail() != null) {
|
||||
for (ExternalId extId : extIds) {
|
||||
if (a.getPreferredEmail().equals(extId.email())) {
|
||||
a.setPreferredEmail(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,10 @@ package com.google.gerrit.server.account;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
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.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
|
@ -32,7 +30,6 @@ import com.google.gerrit.server.git.MetaDataUpdate;
|
|||
import com.google.gerrit.server.index.change.ReindexAfterRefUpdate;
|
||||
import com.google.gerrit.server.mail.send.OutgoingEmailValidator;
|
||||
import com.google.gwtorm.server.OrmDuplicateKeyException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
@ -50,7 +47,7 @@ import org.eclipse.jgit.lib.Repository;
|
|||
/**
|
||||
* Updates accounts.
|
||||
*
|
||||
* <p>The account updates are written to both ReviewDb and NoteDb.
|
||||
* <p>The account updates are written to NoteDb.
|
||||
*
|
||||
* <p>In NoteDb accounts are represented as user branches in the All-Users repository. Optionally a
|
||||
* user branch can contain a 'account.config' file that stores account properties, such as full
|
||||
|
@ -189,24 +186,19 @@ public class AccountsUpdate {
|
|||
/**
|
||||
* Inserts a new account.
|
||||
*
|
||||
* @param db ReviewDb
|
||||
* @param accountId ID of the new account
|
||||
* @param init consumer to populate the new account
|
||||
* @return the newly created account
|
||||
* @throws OrmException if updating the database fails
|
||||
* @throws OrmDuplicateKeyException if the account already exists
|
||||
* @throws IOException if updating the user branch fails
|
||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||
*/
|
||||
public Account insert(ReviewDb db, Account.Id accountId, Consumer<Account> init)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
public Account insert(Account.Id accountId, Consumer<Account> init)
|
||||
throws OrmDuplicateKeyException, IOException, ConfigInvalidException {
|
||||
AccountConfig accountConfig = read(accountId);
|
||||
Account account = accountConfig.getNewAccount();
|
||||
init.accept(account);
|
||||
|
||||
// Create in ReviewDb
|
||||
db.accounts().insert(ImmutableSet.of(account));
|
||||
|
||||
// Create in NoteDb
|
||||
commitNew(accountConfig);
|
||||
return account;
|
||||
|
@ -217,17 +209,15 @@ public class AccountsUpdate {
|
|||
*
|
||||
* <p>Changing the registration date of an account is not supported.
|
||||
*
|
||||
* @param db ReviewDb
|
||||
* @param accountId ID of the account
|
||||
* @param consumer consumer to update the account, only invoked if the account exists
|
||||
* @return the updated account, {@code null} if the account doesn't exist
|
||||
* @throws OrmException if updating the database fails
|
||||
* @throws IOException if updating the user branch fails
|
||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||
*/
|
||||
public Account update(ReviewDb db, Account.Id accountId, Consumer<Account> consumer)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
return update(db, accountId, ImmutableList.of(consumer));
|
||||
public Account update(Account.Id accountId, Consumer<Account> consumer)
|
||||
throws IOException, ConfigInvalidException {
|
||||
return update(accountId, ImmutableList.of(consumer));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,44 +225,26 @@ public class AccountsUpdate {
|
|||
*
|
||||
* <p>Changing the registration date of an account is not supported.
|
||||
*
|
||||
* @param db ReviewDb
|
||||
* @param accountId ID of the account
|
||||
* @param consumers consumers to update the account, only invoked if the account exists
|
||||
* @return the updated account, {@code null} if the account doesn't exist
|
||||
* @throws OrmException if updating the database fails
|
||||
* @throws IOException if updating the user branch fails
|
||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||
*/
|
||||
public Account update(ReviewDb db, Account.Id accountId, List<Consumer<Account>> consumers)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
public Account update(Account.Id accountId, List<Consumer<Account>> consumers)
|
||||
throws IOException, ConfigInvalidException {
|
||||
if (consumers.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Update in ReviewDb
|
||||
Account reviewDbAccount =
|
||||
db.accounts()
|
||||
.atomicUpdate(
|
||||
accountId,
|
||||
a -> {
|
||||
consumers.stream().forEach(c -> c.accept(a));
|
||||
return a;
|
||||
});
|
||||
|
||||
// Update in NoteDb
|
||||
AccountConfig accountConfig = read(accountId);
|
||||
Account account = accountConfig.getAccount();
|
||||
if (account != null) {
|
||||
consumers.stream().forEach(c -> c.accept(account));
|
||||
commit(accountConfig);
|
||||
return account;
|
||||
} else if (reviewDbAccount != null) {
|
||||
// user branch doesn't exist yet
|
||||
accountConfig.setAccount(reviewDbAccount);
|
||||
commitNew(accountConfig);
|
||||
}
|
||||
|
||||
return reviewDbAccount;
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -281,25 +253,18 @@ public class AccountsUpdate {
|
|||
* <p>The existing account with the same account ID is overwritten by the given account. Choosing
|
||||
* to overwrite an account means that any updates that were done to the account by a racing
|
||||
* request after the account was read are lost. Updates are also lost if the account was read from
|
||||
* a stale account index. This is why using {@link #update(ReviewDb,
|
||||
* com.google.gerrit.reviewdb.client.Account.Id, Consumer)} to do an atomic update is always
|
||||
* preferred.
|
||||
* a stale account index. This is why using {@link
|
||||
* #update(com.google.gerrit.reviewdb.client.Account.Id, Consumer)} to do an atomic update is
|
||||
* always preferred.
|
||||
*
|
||||
* <p>Changing the registration date of an account is not supported.
|
||||
*
|
||||
* @param db ReviewDb
|
||||
* @param account the new account
|
||||
* @throws OrmException if updating the database fails
|
||||
* @throws IOException if updating the user branch fails
|
||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||
* @see #update(ReviewDb, com.google.gerrit.reviewdb.client.Account.Id, Consumer)
|
||||
* @see #update(com.google.gerrit.reviewdb.client.Account.Id, Consumer)
|
||||
*/
|
||||
public void replace(ReviewDb db, Account account)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
// Update in ReviewDb
|
||||
db.accounts().update(ImmutableSet.of(account));
|
||||
|
||||
// Update in NoteDb
|
||||
public void replace(Account account) throws IOException, ConfigInvalidException {
|
||||
AccountConfig accountConfig = read(account.getId());
|
||||
accountConfig.setAccount(account);
|
||||
commit(accountConfig);
|
||||
|
@ -308,32 +273,20 @@ public class AccountsUpdate {
|
|||
/**
|
||||
* Deletes the account.
|
||||
*
|
||||
* @param db ReviewDb
|
||||
* @param account the account that should be deleted
|
||||
* @throws OrmException if updating the database fails
|
||||
* @throws IOException if updating the user branch fails
|
||||
*/
|
||||
public void delete(ReviewDb db, Account account) throws OrmException, IOException {
|
||||
// Delete in ReviewDb
|
||||
db.accounts().delete(ImmutableSet.of(account));
|
||||
|
||||
// Delete in NoteDb
|
||||
deleteUserBranch(account.getId());
|
||||
public void delete(Account account) throws IOException {
|
||||
deleteByKey(account.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the account.
|
||||
*
|
||||
* @param db ReviewDb
|
||||
* @param accountId the ID of the account that should be deleted
|
||||
* @throws OrmException if updating the database fails
|
||||
* @throws IOException if updating the user branch fails
|
||||
*/
|
||||
public void deleteByKey(ReviewDb db, Account.Id accountId) throws OrmException, IOException {
|
||||
// Delete in ReviewDb
|
||||
db.accounts().deleteKeys(ImmutableSet.of(accountId));
|
||||
|
||||
// Delete in NoteDb
|
||||
public void deleteByKey(Account.Id accountId) throws IOException {
|
||||
deleteUserBranch(accountId);
|
||||
}
|
||||
|
||||
|
|
|
@ -174,7 +174,6 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
|
|||
accountsUpdate
|
||||
.create()
|
||||
.insert(
|
||||
db,
|
||||
id,
|
||||
a -> {
|
||||
a.setFullName(input.name);
|
||||
|
|
|
@ -23,7 +23,6 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
|||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.PutName.Input;
|
||||
|
@ -46,7 +45,6 @@ public class PutName implements RestModifyView<AccountResource, Input> {
|
|||
private final Provider<CurrentUser> self;
|
||||
private final Realm realm;
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final AccountsUpdate.Server accountsUpdate;
|
||||
|
||||
@Inject
|
||||
|
@ -54,12 +52,10 @@ public class PutName implements RestModifyView<AccountResource, Input> {
|
|||
Provider<CurrentUser> self,
|
||||
Realm realm,
|
||||
PermissionBackend permissionBackend,
|
||||
Provider<ReviewDb> dbProvider,
|
||||
AccountsUpdate.Server accountsUpdate) {
|
||||
this.self = self;
|
||||
this.realm = realm;
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.dbProvider = dbProvider;
|
||||
this.accountsUpdate = accountsUpdate;
|
||||
}
|
||||
|
||||
|
@ -74,7 +70,7 @@ public class PutName implements RestModifyView<AccountResource, Input> {
|
|||
}
|
||||
|
||||
public Response<String> apply(IdentifiedUser user, Input input)
|
||||
throws MethodNotAllowedException, ResourceNotFoundException, OrmException, IOException,
|
||||
throws MethodNotAllowedException, ResourceNotFoundException, IOException,
|
||||
ConfigInvalidException {
|
||||
if (input == null) {
|
||||
input = new Input();
|
||||
|
@ -86,9 +82,7 @@ public class PutName implements RestModifyView<AccountResource, Input> {
|
|||
|
||||
String newName = input.name;
|
||||
Account account =
|
||||
accountsUpdate
|
||||
.create()
|
||||
.update(dbProvider.get(), user.getAccountId(), a -> a.setFullName(newName));
|
||||
accountsUpdate.create().update(user.getAccountId(), a -> a.setFullName(newName));
|
||||
if (account == null) {
|
||||
throw new ResourceNotFoundException("account not found");
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
|||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.PutPreferred.Input;
|
||||
|
@ -39,18 +38,15 @@ public class PutPreferred implements RestModifyView<AccountResource.Email, Input
|
|||
static class Input {}
|
||||
|
||||
private final Provider<CurrentUser> self;
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final AccountsUpdate.Server accountsUpdate;
|
||||
|
||||
@Inject
|
||||
PutPreferred(
|
||||
Provider<CurrentUser> self,
|
||||
Provider<ReviewDb> dbProvider,
|
||||
PermissionBackend permissionBackend,
|
||||
AccountsUpdate.Server accountsUpdate) {
|
||||
this.self = self;
|
||||
this.dbProvider = dbProvider;
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.accountsUpdate = accountsUpdate;
|
||||
}
|
||||
|
@ -66,13 +62,12 @@ public class PutPreferred implements RestModifyView<AccountResource.Email, Input
|
|||
}
|
||||
|
||||
public Response<String> apply(IdentifiedUser user, String email)
|
||||
throws ResourceNotFoundException, OrmException, IOException, ConfigInvalidException {
|
||||
throws ResourceNotFoundException, IOException, ConfigInvalidException {
|
||||
AtomicBoolean alreadyPreferred = new AtomicBoolean(false);
|
||||
Account account =
|
||||
accountsUpdate
|
||||
.create()
|
||||
.update(
|
||||
dbProvider.get(),
|
||||
user.getAccountId(),
|
||||
a -> {
|
||||
if (email.equals(a.getPreferredEmail())) {
|
||||
|
|
|
@ -21,7 +21,6 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
|||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.PutStatus.Input;
|
||||
|
@ -48,18 +47,15 @@ public class PutStatus implements RestModifyView<AccountResource, Input> {
|
|||
}
|
||||
|
||||
private final Provider<CurrentUser> self;
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final AccountsUpdate.Server accountsUpdate;
|
||||
|
||||
@Inject
|
||||
PutStatus(
|
||||
Provider<CurrentUser> self,
|
||||
Provider<ReviewDb> dbProvider,
|
||||
PermissionBackend permissionBackend,
|
||||
AccountsUpdate.Server accountsUpdate) {
|
||||
this.self = self;
|
||||
this.dbProvider = dbProvider;
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.accountsUpdate = accountsUpdate;
|
||||
}
|
||||
|
@ -75,7 +71,7 @@ public class PutStatus implements RestModifyView<AccountResource, Input> {
|
|||
}
|
||||
|
||||
public Response<String> apply(IdentifiedUser user, Input input)
|
||||
throws ResourceNotFoundException, OrmException, IOException, ConfigInvalidException {
|
||||
throws ResourceNotFoundException, IOException, ConfigInvalidException {
|
||||
if (input == null) {
|
||||
input = new Input();
|
||||
}
|
||||
|
@ -84,10 +80,7 @@ public class PutStatus implements RestModifyView<AccountResource, Input> {
|
|||
Account account =
|
||||
accountsUpdate
|
||||
.create()
|
||||
.update(
|
||||
dbProvider.get(),
|
||||
user.getAccountId(),
|
||||
a -> a.setStatus(Strings.nullToEmpty(newStatus)));
|
||||
.update(user.getAccountId(), a -> a.setStatus(Strings.nullToEmpty(newStatus)));
|
||||
if (account == null) {
|
||||
throw new ResourceNotFoundException("account not found");
|
||||
}
|
||||
|
|
|
@ -19,11 +19,8 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
|||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
@ -32,23 +29,20 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
|||
@Singleton
|
||||
public class SetInactiveFlag {
|
||||
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final AccountsUpdate.Server accountsUpdate;
|
||||
|
||||
@Inject
|
||||
SetInactiveFlag(Provider<ReviewDb> dbProvider, AccountsUpdate.Server accountsUpdate) {
|
||||
this.dbProvider = dbProvider;
|
||||
SetInactiveFlag(AccountsUpdate.Server accountsUpdate) {
|
||||
this.accountsUpdate = accountsUpdate;
|
||||
}
|
||||
|
||||
public Response<?> deactivate(IdentifiedUser user)
|
||||
throws RestApiException, OrmException, IOException, ConfigInvalidException {
|
||||
throws RestApiException, IOException, ConfigInvalidException {
|
||||
AtomicBoolean alreadyInactive = new AtomicBoolean(false);
|
||||
Account account =
|
||||
accountsUpdate
|
||||
.create()
|
||||
.update(
|
||||
dbProvider.get(),
|
||||
user.getAccountId(),
|
||||
a -> {
|
||||
if (!a.isActive()) {
|
||||
|
@ -67,13 +61,12 @@ public class SetInactiveFlag {
|
|||
}
|
||||
|
||||
public Response<String> activate(IdentifiedUser user)
|
||||
throws ResourceNotFoundException, OrmException, IOException, ConfigInvalidException {
|
||||
throws ResourceNotFoundException, IOException, ConfigInvalidException {
|
||||
AtomicBoolean alreadyActive = new AtomicBoolean(false);
|
||||
Account account =
|
||||
accountsUpdate
|
||||
.create()
|
||||
.update(
|
||||
dbProvider.get(),
|
||||
user.getAccountId(),
|
||||
a -> {
|
||||
if (a.isActive()) {
|
||||
|
|
|
@ -2726,7 +2726,6 @@ class ReceiveCommits {
|
|||
accountsUpdate
|
||||
.create()
|
||||
.update(
|
||||
db,
|
||||
user.getAccountId(),
|
||||
a -> {
|
||||
if (Strings.isNullOrEmpty(a.getFullName())) {
|
||||
|
@ -2736,7 +2735,7 @@ class ReceiveCommits {
|
|||
if (account != null && Strings.isNullOrEmpty(account.getFullName())) {
|
||||
user.getAccount().setFullName(account.getFullName());
|
||||
}
|
||||
} catch (OrmException | IOException | ConfigInvalidException e) {
|
||||
} catch (IOException | ConfigInvalidException e) {
|
||||
logWarn("Cannot default full_name", e);
|
||||
} finally {
|
||||
defaultName = false;
|
||||
|
|
|
@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import static java.util.stream.Collectors.toList;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
import com.google.gerrit.extensions.api.accounts.Accounts.QueryRequest;
|
||||
|
@ -397,14 +396,9 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
|||
public void reindex() throws Exception {
|
||||
AccountInfo user1 = newAccountWithFullName("tester", "Test Usre");
|
||||
|
||||
// update account in ReviewDb without reindex so that account index is stale
|
||||
String newName = "Test User";
|
||||
// update account without reindex so that account index is stale
|
||||
Account.Id accountId = new Account.Id(user1._accountId);
|
||||
Account account = accounts.get(accountId);
|
||||
account.setFullName(newName);
|
||||
db.accounts().update(ImmutableSet.of(account));
|
||||
|
||||
// update account in NoteDb without reindex so that account index is stale
|
||||
String newName = "Test User";
|
||||
try (Repository repo = repoManager.openRepository(allUsers)) {
|
||||
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsers, repo);
|
||||
PersonIdent ident = serverIdent.get();
|
||||
|
@ -499,7 +493,6 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
|||
accountsUpdate
|
||||
.create()
|
||||
.update(
|
||||
db,
|
||||
id,
|
||||
a -> {
|
||||
a.setFullName(fullName);
|
||||
|
|
|
@ -214,7 +214,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||
userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
|
||||
String email = "user@example.com";
|
||||
externalIdsUpdate.create().insert(ExternalId.createEmail(userId, email));
|
||||
accountsUpdate.create().update(db, userId, a -> a.setPreferredEmail(email));
|
||||
accountsUpdate.create().update(userId, a -> a.setPreferredEmail(email));
|
||||
user = userFactory.create(userId);
|
||||
requestContext.setContext(newRequestContext(userId));
|
||||
}
|
||||
|
@ -2469,7 +2469,6 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||
accountsUpdate
|
||||
.create()
|
||||
.update(
|
||||
db,
|
||||
id,
|
||||
a -> {
|
||||
a.setFullName(fullName);
|
||||
|
|
|
@ -323,7 +323,6 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
|||
accountsUpdate
|
||||
.create()
|
||||
.update(
|
||||
db,
|
||||
id,
|
||||
a -> {
|
||||
a.setFullName(fullName);
|
||||
|
|
Loading…
Reference in New Issue