Add an InternalAccountUpdate class to prepare updates to accounts

Instead of doing account updates directly on the Account instance have
an InternalAccountUpdate class with a builder for preparing account
updates.

This is done for the following reasons:

1. More consistency with how group updates are done (group updates are
   prepared with an InternalGroupUpdate class).

2. It's a preparation to make updates of different account data types
   atomic (e.g. update of account properties and external IDs should
   become atomic).

3. This change will allow us to replace the Account entity class from
   ReviewDb times with an AutoValue type (similar to how groups are
   represented by the InternalGroup AutoValue type).

To achieve 2. the new InternalAccountUpdate class can be extended to
host updates for further account data like external IDs, preferences
etc. Since all account data is stored in the All-Users repository the
updates in NoteDb can be atomic across different account data types.
In particular this will simplify the account creation which first
creates the external ID and then inserts the account, but then has to
rollback the external ID creation if the account insertion fails.

In contrast to GroupsUpdate AccountsUpdate continues to require a
consumer for updates (instead of an InternalAccountUpdate instance).
This is because some callers of the AccountsUpdate class need to have
access to the loaded account to decide which updates should be done
(e.g. ReceiveCommits wants to set a full name only if a full name wasn't
set yet). This is why the consumer is invoked with a new AccountUpdate
that provides both, access to the current account (for reading) and
access to the InternalAccountUpdate builder (for updates).

Change-Id: I057361b9ca4d3a61475c77a6ff06f40ebedaec0f
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2017-12-08 13:57:26 +01:00
parent 350e3e263f
commit d741a4afb7
18 changed files with 334 additions and 83 deletions

View File

@@ -117,14 +117,7 @@ public class AccountCreator {
}
externalIdsUpdate.create().insert(extIds);
accountsUpdate
.create()
.insert(
id,
a -> {
a.setFullName(fullName);
a.setPreferredEmail(email);
});
accountsUpdate.create().insert(id, u -> u.setFullName(fullName).setPreferredEmail(email));
if (groupNames != null) {
for (String n : groupNames) {

View File

@@ -24,6 +24,7 @@ import com.google.gerrit.reviewdb.client.RefNames;
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.account.InternalAccountUpdate;
import com.google.gerrit.server.config.SitePaths;
import com.google.inject.Inject;
import java.io.File;
@@ -69,7 +70,14 @@ public class AccountsOnInit {
new GerritPersonIdentProvider(flags.cfg).get(), account.getRegisteredOn());
Config accountConfig = new Config();
AccountConfig.writeToConfig(account, accountConfig);
AccountConfig.writeToConfig(
InternalAccountUpdate.builder()
.setActive(account.isActive())
.setFullName(account.getFullName())
.setPreferredEmail(account.getPreferredEmail())
.setStatus(account.getStatus())
.build(),
accountConfig);
DirCache newTree = DirCache.newInCore();
DirCacheEditor editor = newTree.editor();

View File

@@ -80,6 +80,7 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
private final String ref;
private Optional<Account> loadedAccount;
private Optional<InternalAccountUpdate> accountUpdate = Optional.empty();
private Timestamp registeredOn;
private List<ValidationError> validationErrors;
@@ -117,6 +118,14 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
public void setAccount(Account account) {
checkLoaded();
this.loadedAccount = Optional.of(account);
this.accountUpdate =
Optional.of(
InternalAccountUpdate.builder()
.setActive(account.isActive())
.setFullName(account.getFullName())
.setPreferredEmail(account.getPreferredEmail())
.setStatus(account.getStatus())
.build());
this.registeredOn = account.getRegisteredOn();
}
@@ -136,6 +145,10 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
return loadedAccount.get();
}
public void setAccountUpdate(InternalAccountUpdate accountUpdate) {
this.accountUpdate = Optional.of(accountUpdate);
}
@Override
protected void onLoad() throws IOException, ConfigInvalidException {
if (revision != null) {
@@ -194,16 +207,26 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
}
Config cfg = readConfig(ACCOUNT_CONFIG);
writeToConfig(loadedAccount.get(), cfg);
if (accountUpdate.isPresent()) {
writeToConfig(accountUpdate.get(), cfg);
}
saveConfig(ACCOUNT_CONFIG, cfg);
// metaId is set in the commit(MetaDataUpdate) method after the commit is created
loadedAccount = Optional.of(parse(cfg, null));
accountUpdate = Optional.empty();
return true;
}
public static void writeToConfig(Account account, Config cfg) {
setActive(cfg, account.isActive());
set(cfg, KEY_FULL_NAME, account.getFullName());
set(cfg, KEY_PREFERRED_EMAIL, account.getPreferredEmail());
set(cfg, KEY_STATUS, account.getStatus());
public static void writeToConfig(InternalAccountUpdate accountUpdate, Config cfg) {
accountUpdate.getActive().ifPresent(active -> setActive(cfg, active));
accountUpdate.getFullName().ifPresent(fullName -> set(cfg, KEY_FULL_NAME, fullName));
accountUpdate
.getPreferredEmail()
.ifPresent(preferredEmail -> set(cfg, KEY_PREFERRED_EMAIL, preferredEmail));
accountUpdate.getStatus().ifPresent(status -> set(cfg, KEY_STATUS, status));
}
/**

View File

@@ -29,6 +29,7 @@ import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.Sequences;
import com.google.gerrit.server.account.AccountsUpdate.AccountUpdater;
import com.google.gerrit.server.account.externalids.ExternalId;
import com.google.gerrit.server.account.externalids.ExternalIds;
import com.google.gerrit.server.account.externalids.ExternalIdsUpdate;
@@ -203,7 +204,7 @@ public class AccountManager {
private void update(AuthRequest who, ExternalId extId)
throws OrmException, IOException, ConfigInvalidException {
IdentifiedUser user = userFactory.create(extId.accountId());
List<Consumer<Account>> accountUpdates = new ArrayList<>();
List<Consumer<InternalAccountUpdate.Builder>> accountUpdates = new ArrayList<>();
// If the email address was modified by the authentication provider,
// update our records to match the changed email.
@@ -212,7 +213,7 @@ public class AccountManager {
String oldEmail = extId.email();
if (newEmail != null && !newEmail.equals(oldEmail)) {
if (oldEmail != null && oldEmail.equals(user.getAccount().getPreferredEmail())) {
accountUpdates.add(a -> a.setPreferredEmail(newEmail));
accountUpdates.add(u -> u.setPreferredEmail(newEmail));
}
externalIdsUpdateFactory
@@ -224,7 +225,7 @@ public class AccountManager {
if (!realm.allowsEdit(AccountFieldName.FULL_NAME)
&& !Strings.isNullOrEmpty(who.getDisplayName())
&& !eq(user.getAccount().getFullName(), who.getDisplayName())) {
accountUpdates.add(a -> a.setFullName(who.getDisplayName()));
accountUpdates.add(u -> u.setFullName(who.getDisplayName()));
}
if (!realm.allowsEdit(AccountFieldName.USER_NAME)
@@ -236,7 +237,10 @@ public class AccountManager {
}
if (!accountUpdates.isEmpty()) {
Account account = accountsUpdateFactory.create().update(user.getAccountId(), accountUpdates);
Account account =
accountsUpdateFactory
.create()
.update(user.getAccountId(), AccountUpdater.joinConsumers(accountUpdates));
if (account == null) {
throw new OrmException("Account " + user.getAccountId() + " has been deleted");
}
@@ -261,11 +265,7 @@ public class AccountManager {
AccountsUpdate accountsUpdate = accountsUpdateFactory.create();
account =
accountsUpdate.insert(
newId,
a -> {
a.setFullName(who.getDisplayName());
a.setPreferredEmail(extId.email());
});
newId, u -> u.setFullName(who.getDisplayName()).setPreferredEmail(extId.email()));
ExternalId existingExtId = externalIds.get(extId.key());
if (existingExtId != null && !existingExtId.accountId().equals(extId.accountId())) {
@@ -416,9 +416,9 @@ public class AccountManager {
.create()
.update(
to,
a -> {
(a, u) -> {
if (a.getPreferredEmail() == null) {
a.setPreferredEmail(who.getEmailAddress());
u.setPreferredEmail(who.getEmailAddress());
}
});
}
@@ -504,11 +504,11 @@ public class AccountManager {
.create()
.update(
from,
a -> {
(a, u) -> {
if (a.getPreferredEmail() != null) {
for (ExternalId extId : extIds) {
if (a.getPreferredEmail().equals(extId.email())) {
a.setPreferredEmail(null);
u.setPreferredEmail(null);
break;
}
}

View File

@@ -16,7 +16,7 @@ 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.Lists;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Project;
@@ -63,6 +63,38 @@ import org.eclipse.jgit.lib.Repository;
*/
@Singleton
public class AccountsUpdate {
/**
* Updater for an account.
*
* <p>Allows to read the current state of an account and to prepare updates to it.
*/
@FunctionalInterface
public static interface AccountUpdater {
/**
* Prepare updates to an account.
*
* <p>Use the provided account only to read the current state of the account. Don't do updates
* to the account. For updates use the provided account update builder.
*
* @param account the account that is being updated
* @param update account update builder
*/
void update(Account account, InternalAccountUpdate.Builder update);
public static AccountUpdater join(List<AccountUpdater> updaters) {
return (a, u) -> updaters.stream().forEach(updater -> updater.update(a, u));
}
public static AccountUpdater joinConsumers(
List<Consumer<InternalAccountUpdate.Builder>> consumers) {
return join(Lists.transform(consumers, AccountUpdater::fromConsumer));
}
static AccountUpdater fromConsumer(Consumer<InternalAccountUpdate.Builder> consumer) {
return (a, u) -> consumer.accept(u);
}
}
/**
* Factory to create an AccountsUpdate instance for updating accounts by the Gerrit server.
*
@@ -194,15 +226,30 @@ public class AccountsUpdate {
* @throws IOException if updating the user branch fails
* @throws ConfigInvalidException if any of the account fields has an invalid value
*/
public Account insert(Account.Id accountId, Consumer<Account> init)
public Account insert(Account.Id accountId, Consumer<InternalAccountUpdate.Builder> init)
throws OrmDuplicateKeyException, IOException, ConfigInvalidException {
return insert(accountId, AccountUpdater.fromConsumer(init));
}
/**
* Inserts a new account.
*
* @param accountId ID of the new account
* @param updater updater to populate the new account
* @return the newly created account
* @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(Account.Id accountId, AccountUpdater updater)
throws OrmDuplicateKeyException, IOException, ConfigInvalidException {
AccountConfig accountConfig = read(accountId);
Account account = accountConfig.getNewAccount();
init.accept(account);
// Create in NoteDb
InternalAccountUpdate.Builder updateBuilder = InternalAccountUpdate.builder();
updater.update(account, updateBuilder);
accountConfig.setAccountUpdate(updateBuilder.build());
commitNew(accountConfig);
return account;
return accountConfig.getLoadedAccount().get();
}
/**
@@ -211,14 +258,14 @@ public class AccountsUpdate {
* <p>Changing the registration date of an account is not supported.
*
* @param accountId ID of the account
* @param consumer consumer to update the account, only invoked if the account exists
* @param update consumer to update the account, only invoked if the account exists
* @return the updated account, {@code null} if the account doesn't exist
* @throws IOException if updating the user branch fails
* @throws ConfigInvalidException if any of the account fields has an invalid value
*/
public Account update(Account.Id accountId, Consumer<Account> consumer)
public Account update(Account.Id accountId, Consumer<InternalAccountUpdate.Builder> update)
throws IOException, ConfigInvalidException {
return update(accountId, ImmutableList.of(consumer));
return update(accountId, AccountUpdater.fromConsumer(update));
}
/**
@@ -227,13 +274,13 @@ public class AccountsUpdate {
* <p>Changing the registration date of an account is not supported.
*
* @param accountId ID of the account
* @param consumers consumers to update the account, only invoked if the account exists
* @param updater updater to update the account, only invoked if the account exists
* @return the updated account, {@code null} if the account doesn't exist
* @throws IOException if updating the user branch fails
* @throws ConfigInvalidException if any of the account fields has an invalid value
*/
@Nullable
public Account update(Account.Id accountId, List<Consumer<Account>> consumers)
public Account update(Account.Id accountId, AccountUpdater updater)
throws IOException, ConfigInvalidException {
AccountConfig accountConfig = read(accountId);
Optional<Account> account = accountConfig.getLoadedAccount();
@@ -241,9 +288,11 @@ public class AccountsUpdate {
return null;
}
consumers.stream().forEach(c -> c.accept(account.get()));
InternalAccountUpdate.Builder updateBuilder = InternalAccountUpdate.builder();
updater.update(account.get(), updateBuilder);
accountConfig.setAccountUpdate(updateBuilder.build());
commit(accountConfig);
return account.get();
return accountConfig.getLoadedAccount().orElse(null);
}
/**

View File

@@ -172,12 +172,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
accountsUpdate
.create()
.insert(
id,
a -> {
a.setFullName(input.name);
a.setPreferredEmail(input.email);
});
.insert(id, u -> u.setFullName(input.name).setPreferredEmail(input.email));
for (AccountGroup.UUID groupUuid : groups) {
try {

View File

@@ -0,0 +1,192 @@
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the Licens
package com.google.gerrit.server.account;
import com.google.auto.value.AutoValue;
import com.google.common.base.Strings;
import com.google.gerrit.reviewdb.client.Account;
import java.util.Optional;
/**
* Class to prepare updates to an account.
*
* <p>The getters in this class and the setters in the {@link Builder} correspond to fields in
* {@link Account}. The account ID and the registration date cannot be updated.
*/
@AutoValue
public abstract class InternalAccountUpdate {
public static Builder builder() {
return new Builder.WrapperThatConvertsNullStringArgsToEmptyStrings(
new AutoValue_InternalAccountUpdate.Builder());
}
/**
* Returns the new value for the full name.
*
* @return the new value for the full name, {@code Optional#empty()} if the full name is not being
* updated, {@code Optional#of("")} if the full name is unset, the wrapped value is never
* {@code null}
*/
public abstract Optional<String> getFullName();
/**
* Returns the new value for the preferred email.
*
* @return the new value for the preferred email, {@code Optional#empty()} if the preferred email
* is not being updated, {@code Optional#of("")} if the preferred email is unset, the wrapped
* value is never {@code null}
*/
public abstract Optional<String> getPreferredEmail();
/**
* Returns the new value for the active flag.
*
* @return the new value for the active flag, {@code Optional#empty()} if the active flag is not
* being updated, the wrapped value is never {@code null}
*/
public abstract Optional<Boolean> getActive();
/**
* Returns the new value for the status.
*
* @return the new value for the status, {@code Optional#empty()} if the status is not being
* updated, {@code Optional#of("")} if the status is unset, the wrapped value is never {@code
* null}
*/
public abstract Optional<String> getStatus();
/**
* Class to build an account update.
*
* <p>Account data is only updated if the corresponding setter is invoked. If a setter is not
* invoked the corresponding data stays unchanged. To unset string values the setter can be
* invoked with either {@code null} or an empty string ({@code null} is converted to an empty
* string by using the {@link WrapperThatConvertsNullStringArgsToEmptyStrings} wrapper, see {@link
* InternalAccountUpdate#builder()}).
*/
@AutoValue.Builder
public abstract static class Builder {
/**
* Sets a new full name for the account.
*
* @param fullName the new full name, if {@code null} or empty string the full name is unset
* @return the builder
*/
public abstract Builder setFullName(String fullName);
/**
* Sets a new preferred email for the account.
*
* @param preferredEmail the new preferred email, if {@code null} or empty string the preferred
* email is unset
* @return the builder
*/
public abstract Builder setPreferredEmail(String preferredEmail);
/**
* Sets the active flag for the account.
*
* @param active {@code true} if the account should be set to active, {@code false} if the
* account should be set to inactive
* @return the builder
*/
public abstract Builder setActive(boolean active);
/**
* Sets a new status for the account.
*
* @param status the new status, if {@code null} or empty string the status is unset
* @return the builder
*/
public abstract Builder setStatus(String status);
/**
* Builds the account update.
*
* @return the account update
*/
public abstract InternalAccountUpdate build();
/**
* Wrapper for {@link Builder} that converts {@code null} string arguments to empty strings for
* all setter methods. This allows us to treat setter invocations with a {@code null} string
* argument as signal to unset the corresponding field. E.g. for a builder method {@code
* setX(String)} the following semantics apply:
*
* <ul>
* <li>Method is not invoked: X stays unchanged, X is stored as {@code Optional.empty()}.
* <li>Argument is a non-empty string Y: X is updated to the Y, X is stored as {@code
* Optional.of(Y)}.
* <li>Argument is an empty string: X is unset, X is stored as {@code Optional.of("")}
* <li>Argument is {@code null}: X is unset, X is stored as {@code Optional.of("")} (since the
* wrapper converts {@code null} to an empty string)
* </ul>
*
* Without the wrapper calling {@code setX(null)} would fail with a {@link
* NullPointerException}. Hence all callers would need to take care to call {@link
* Strings#nullToEmpty(String)} for all string arguments and likely it would be forgotten in
* some places.
*
* <p>This means the stored values are interpreted like this:
*
* <ul>
* <li>{@code Optional.empty()}: property stays unchanged
* <li>{@code Optional.of(<non-empty-string>)}: property is updated
* <li>{@code Optional.of("")}: property is unset
* </ul>
*
* This wrapper forwards all method invocations to the wrapped {@link Builder} instance that was
* created by AutoValue. For methods that return the AutoValue {@link Builder} instance the
* return value is replaced with the wrapper instance so that all chained calls go through the
* wrapper.
*/
private static class WrapperThatConvertsNullStringArgsToEmptyStrings extends Builder {
private final Builder delegate;
private WrapperThatConvertsNullStringArgsToEmptyStrings(Builder delegate) {
this.delegate = delegate;
}
@Override
public Builder setFullName(String fullName) {
delegate.setFullName(Strings.nullToEmpty(fullName));
return this;
}
@Override
public Builder setPreferredEmail(String preferredEmail) {
delegate.setPreferredEmail(Strings.nullToEmpty(preferredEmail));
return this;
}
@Override
public Builder setActive(boolean active) {
delegate.setActive(active);
return this;
}
@Override
public Builder setStatus(String status) {
delegate.setStatus(Strings.nullToEmpty(status));
return this;
}
@Override
public InternalAccountUpdate build() {
return delegate.build();
}
}
}
}

View File

@@ -77,7 +77,7 @@ public class PutName implements RestModifyView<AccountResource, NameInput> {
String newName = input.name;
Account account =
accountsUpdate.create().update(user.getAccountId(), a -> a.setFullName(newName));
accountsUpdate.create().update(user.getAccountId(), u -> u.setFullName(newName));
if (account == null) {
throw new ResourceNotFoundException("account not found");
}

View File

@@ -68,11 +68,11 @@ public class PutPreferred implements RestModifyView<AccountResource.Email, Input
.create()
.update(
user.getAccountId(),
a -> {
(a, u) -> {
if (email.equals(a.getPreferredEmail())) {
alreadyPreferred.set(true);
} else {
a.setPreferredEmail(email);
u.setPreferredEmail(email);
}
});
if (account == null) {

View File

@@ -67,9 +67,7 @@ public class PutStatus implements RestModifyView<AccountResource, StatusInput> {
String newStatus = input.status;
Account account =
accountsUpdate
.create()
.update(user.getAccountId(), a -> a.setStatus(Strings.nullToEmpty(newStatus)));
accountsUpdate.create().update(user.getAccountId(), u -> u.setStatus(newStatus));
if (account == null) {
throw new ResourceNotFoundException("account not found");
}

View File

@@ -43,11 +43,11 @@ public class SetInactiveFlag {
.create()
.update(
accountId,
a -> {
(a, u) -> {
if (!a.isActive()) {
alreadyInactive.set(true);
} else {
a.setActive(false);
u.setActive(false);
}
});
if (account == null) {
@@ -67,11 +67,11 @@ public class SetInactiveFlag {
.create()
.update(
accountId,
a -> {
(a, u) -> {
if (a.isActive()) {
alreadyActive.set(true);
} else {
a.setActive(true);
u.setActive(true);
}
});
if (account == null) {

View File

@@ -2933,9 +2933,9 @@ class ReceiveCommits {
.create()
.update(
user.getAccountId(),
a -> {
(a, u) -> {
if (Strings.isNullOrEmpty(a.getFullName())) {
a.setFullName(setFullNameTo);
u.setFullName(setFullNameTo);
}
});
if (account != null) {

View File

@@ -324,7 +324,7 @@ public class AccountIT extends AbstractDaemonTest {
String status = "OOO";
Account account =
accountsUpdate.create().update(anonymousCoward.getId(), a -> a.setStatus(status));
accountsUpdate.create().update(anonymousCoward.getId(), u -> u.setStatus(status));
assertThat(account).isNotNull();
assertThat(account.getFullName()).isNull();
assertThat(account.getStatus()).isEqualTo(status);
@@ -854,7 +854,7 @@ public class AccountIT extends AbstractDaemonTest {
String prefix = "foo.preferred";
String prefEmail = prefix + "@example.com";
TestAccount foo = accountCreator.create(name("foo"));
accountsUpdate.create().update(foo.id, a -> a.setPreferredEmail(prefEmail));
accountsUpdate.create().update(foo.id, u -> u.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);
@@ -1330,7 +1330,7 @@ public class AccountIT extends AbstractDaemonTest {
String userRef = RefNames.refsUsers(foo.id);
String noEmail = "no.email";
accountsUpdate.create().update(foo.id, a -> a.setPreferredEmail(noEmail));
accountsUpdate.create().update(foo.id, u -> u.setPreferredEmail(noEmail));
accountIndexedCounter.clear();
grant(allUsers, userRef, Permission.PUSH, false, REGISTERED_USERS);
@@ -1812,11 +1812,11 @@ 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(accountId, a -> {});
Account account = au.insert(accountId, u -> {});
assertThat(account.getMetaId()).isEqualTo(getMetaId(accountId));
// metaId is set when account is updated
Account updatedAccount = au.update(accountId, a -> a.setFullName("foo"));
Account updatedAccount = au.update(accountId, u -> u.setFullName("foo"));
assertThat(account.getMetaId()).isNotEqualTo(updatedAccount.getMetaId());
assertThat(updatedAccount.getMetaId()).isEqualTo(getMetaId(accountId));
}

View File

@@ -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(userId, a -> a.setPreferredEmail("user@example.com"));
accountsUpdate.create().update(userId, u -> u.setPreferredEmail("user@example.com"));
user = reloadUser();
requestContext.setContext(

View File

@@ -46,6 +46,7 @@ import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.account.Accounts;
import com.google.gerrit.server.account.AccountsUpdate;
import com.google.gerrit.server.account.AuthRequest;
import com.google.gerrit.server.account.InternalAccountUpdate;
import com.google.gerrit.server.account.externalids.ExternalId;
import com.google.gerrit.server.account.externalids.ExternalIds;
import com.google.gerrit.server.config.AllProjectsName;
@@ -417,7 +418,7 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
md.getCommitBuilder().setCommitter(ident);
AccountConfig accountConfig = new AccountConfig(null, accountId);
accountConfig.load(repo);
accountConfig.getLoadedAccount().get().setFullName(newName);
accountConfig.setAccountUpdate(InternalAccountUpdate.builder().setFullName(newName).build());
accountConfig.commit(md);
}
@@ -542,10 +543,8 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
.create()
.update(
id,
a -> {
a.setFullName(fullName);
a.setPreferredEmail(email);
a.setActive(active);
u -> {
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
});
return id;
}

View File

@@ -224,7 +224,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(userId, a -> a.setPreferredEmail(email));
accountsUpdate.create().update(userId, u -> u.setPreferredEmail(email));
user = userFactory.create(userId);
requestContext.setContext(newRequestContext(userId));
}
@@ -2730,10 +2730,8 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
.create()
.update(
id,
a -> {
a.setFullName(fullName);
a.setPreferredEmail(email);
a.setActive(active);
u -> {
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
});
return id;
}

View File

@@ -410,10 +410,8 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
.create()
.update(
id,
a -> {
a.setFullName(fullName);
a.setPreferredEmail(email);
a.setActive(active);
u -> {
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
});
return id;
}

View File

@@ -265,10 +265,8 @@ public abstract class AbstractQueryProjectsTest extends GerritServerTests {
.create()
.update(
id,
a -> {
a.setFullName(fullName);
a.setPreferredEmail(email);
a.setActive(active);
u -> {
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
});
return id;
}