AccountConfig: Extract parsing/writing of account properties into new class
AccountConfig reads/writes account properties, preferences and project watches, but only the parsing/writing of account properties was done in this class. Parsing/writing preferences and project watches is done in separate classes. Make this consistent and have a separate class for parsing/writing account properties too. This makes AccountConfig more readable since it's now free of parsing logic. Change-Id: I66278a65b2e583976586f9f8816d924a8fd55bdf Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -22,7 +22,7 @@ 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.server.GerritPersonIdentProvider;
|
||||
import com.google.gerrit.server.account.AccountConfig;
|
||||
import com.google.gerrit.server.account.AccountProperties;
|
||||
import com.google.gerrit.server.account.Accounts;
|
||||
import com.google.gerrit.server.account.InternalAccountUpdate;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
@@ -70,7 +70,7 @@ public class AccountsOnInit {
|
||||
new GerritPersonIdentProvider(flags.cfg).get(), account.getRegisteredOn());
|
||||
|
||||
Config accountConfig = new Config();
|
||||
AccountConfig.writeToAccountConfig(
|
||||
AccountProperties.writeToAccountConfig(
|
||||
InternalAccountUpdate.builder()
|
||||
.setActive(account.isActive())
|
||||
.setFullName(account.getFullName())
|
||||
@@ -84,7 +84,7 @@ public class AccountsOnInit {
|
||||
final ObjectId blobId =
|
||||
oi.insert(Constants.OBJ_BLOB, accountConfig.toText().getBytes(UTF_8));
|
||||
editor.add(
|
||||
new PathEdit(AccountConfig.ACCOUNT_CONFIG) {
|
||||
new PathEdit(AccountProperties.ACCOUNT_CONFIG) {
|
||||
@Override
|
||||
public void apply(DirCacheEntry ent) {
|
||||
ent.setFileMode(FileMode.REGULAR_FILE);
|
||||
|
||||
@@ -61,61 +61,33 @@ import org.eclipse.jgit.revwalk.RevSort;
|
||||
* <p>This class can read/write account properties, preferences (general, diff and edit preferences)
|
||||
* and project watches.
|
||||
*
|
||||
* <p>The account properties are stored in an 'account.config' config file. Parsing and updating it
|
||||
* is implemented in this class.
|
||||
* <p>The following files are read/written:
|
||||
*
|
||||
* <p>The 'account.config' file is a git config file that has one 'account' section with the
|
||||
* properties of the account:
|
||||
*
|
||||
* <pre>
|
||||
* [account]
|
||||
* active = false
|
||||
* fullName = John Doe
|
||||
* preferredEmail = john.doe@foo.com
|
||||
* status = Overloaded with reviews
|
||||
* </pre>
|
||||
*
|
||||
* <p>All keys are optional. This means 'account.config' may not exist on the user branch if no
|
||||
* properties are set.
|
||||
*
|
||||
* <p>Not setting a key and setting a key to an empty string are treated the same way and result in
|
||||
* a {@code null} value.
|
||||
*
|
||||
* <p>If no value for 'active' is specified, by default the account is considered as active.
|
||||
* <ul>
|
||||
* <li>'account.config': Contains the account properties. Parsing and writing it is delegated to
|
||||
* {@link AccountProperties}.
|
||||
* <li>'preferences.config': Contains the preferences. Parsing and writing it is delegated to
|
||||
* {@link Preferences}.
|
||||
* <li>'account.config': Contains the project watches. Parsing and writing it is delegated to
|
||||
* {@link ProjectWatches}.
|
||||
* </ul>
|
||||
*
|
||||
* <p>The commit date of the first commit on the user branch is used as registration date of the
|
||||
* account. The first commit may be an empty commit (if no properties were set and 'account.config'
|
||||
* doesn't exist).
|
||||
*
|
||||
* <p>The preferences are stored in a 'preferences.config' config file. Parsing and updating it is
|
||||
* implemented by {@link Preferences} and this class delegates the handling of preferences to {@link
|
||||
* Preferences}.
|
||||
*
|
||||
* <p>The project watches are stored in a 'watch.config' config file. Parsing and updating it is
|
||||
* implemented by {@link ProjectWatches} and this class delegates the handling of project watches to
|
||||
* {@link ProjectWatches}.
|
||||
* account. The first commit may be an empty commit (since all config files are optional).
|
||||
*
|
||||
* <p>By default preferences and project watches are lazily parsed on need. Eager parsing can be
|
||||
* requested by {@link #setEagerParsing(boolean)}.
|
||||
*/
|
||||
public class AccountConfig extends VersionedMetaData implements ValidationError.Sink {
|
||||
public static final String ACCOUNT_CONFIG = "account.config";
|
||||
public static final String ACCOUNT = "account";
|
||||
public static final String KEY_ACTIVE = "active";
|
||||
public static final String KEY_FULL_NAME = "fullName";
|
||||
public static final String KEY_PREFERRED_EMAIL = "preferredEmail";
|
||||
public static final String KEY_STATUS = "status";
|
||||
|
||||
private final Account.Id accountId;
|
||||
private final Repository repo;
|
||||
private final String ref;
|
||||
|
||||
private Optional<Account> loadedAccount;
|
||||
private Optional<AccountProperties> loadedAccountProperties;
|
||||
private Optional<ObjectId> externalIdsRev;
|
||||
private ProjectWatches projectWatches;
|
||||
private Preferences preferences;
|
||||
private Optional<InternalAccountUpdate> accountUpdate = Optional.empty();
|
||||
private Timestamp registeredOn;
|
||||
private boolean eagerParsing;
|
||||
private List<ValidationError> validationErrors;
|
||||
|
||||
@@ -135,7 +107,7 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
||||
* @return this AccountConfig instance for chaining
|
||||
*/
|
||||
public AccountConfig setEagerParsing(boolean eagerParsing) {
|
||||
checkState(loadedAccount == null, "Account %s already loaded", accountId.get());
|
||||
checkState(loadedAccountProperties == null, "Account %s already loaded", accountId.get());
|
||||
this.eagerParsing = eagerParsing;
|
||||
return this;
|
||||
}
|
||||
@@ -159,7 +131,7 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
||||
*/
|
||||
public Optional<Account> getLoadedAccount() {
|
||||
checkLoaded();
|
||||
return loadedAccount;
|
||||
return loadedAccountProperties.map(AccountProperties::getAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,7 +198,9 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
||||
*/
|
||||
public AccountConfig setAccount(Account account) {
|
||||
checkLoaded();
|
||||
this.loadedAccount = Optional.of(account);
|
||||
this.loadedAccountProperties =
|
||||
Optional.of(
|
||||
new AccountProperties(account.getId(), account.getRegisteredOn(), new Config(), null));
|
||||
this.accountUpdate =
|
||||
Optional.of(
|
||||
InternalAccountUpdate.builder()
|
||||
@@ -235,7 +209,6 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
||||
.setPreferredEmail(account.getPreferredEmail())
|
||||
.setStatus(account.getStatus())
|
||||
.build());
|
||||
this.registeredOn = account.getRegisteredOn();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -260,9 +233,9 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
||||
if (revision != null) {
|
||||
throw new OrmDuplicateKeyException(String.format("account %s already exists", accountId));
|
||||
}
|
||||
this.registeredOn = registeredOn;
|
||||
this.loadedAccount = Optional.of(new Account(accountId, registeredOn));
|
||||
return loadedAccount.get();
|
||||
this.loadedAccountProperties =
|
||||
Optional.of(new AccountProperties(accountId, registeredOn, new Config(), null));
|
||||
return loadedAccountProperties.map(AccountProperties::getAccount).get();
|
||||
}
|
||||
|
||||
public AccountConfig setAccountUpdate(InternalAccountUpdate accountUpdate) {
|
||||
@@ -276,10 +249,11 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
||||
rw.reset();
|
||||
rw.markStart(revision);
|
||||
rw.sort(RevSort.REVERSE);
|
||||
registeredOn = new Timestamp(rw.next().getCommitTime() * 1000L);
|
||||
Timestamp registeredOn = new Timestamp(rw.next().getCommitTime() * 1000L);
|
||||
|
||||
Config accountConfig = readConfig(ACCOUNT_CONFIG);
|
||||
loadedAccount = Optional.of(parse(accountConfig, revision.name()));
|
||||
Config accountConfig = readConfig(AccountProperties.ACCOUNT_CONFIG);
|
||||
loadedAccountProperties =
|
||||
Optional.of(new AccountProperties(accountId, registeredOn, accountConfig, revision));
|
||||
|
||||
projectWatches = new ProjectWatches(accountId, readConfig(ProjectWatches.WATCH_CONFIG), this);
|
||||
|
||||
@@ -295,7 +269,7 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
||||
preferences.parse();
|
||||
}
|
||||
} else {
|
||||
loadedAccount = Optional.empty();
|
||||
loadedAccountProperties = Optional.empty();
|
||||
|
||||
projectWatches = new ProjectWatches(accountId, new Config(), this);
|
||||
|
||||
@@ -307,23 +281,10 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
||||
externalIdsRev = Optional.ofNullable(externalIdsRef).map(Ref::getObjectId);
|
||||
}
|
||||
|
||||
private Account parse(Config cfg, String metaId) {
|
||||
Account account = new Account(accountId, registeredOn);
|
||||
account.setActive(cfg.getBoolean(ACCOUNT, null, KEY_ACTIVE, true));
|
||||
account.setFullName(get(cfg, KEY_FULL_NAME));
|
||||
|
||||
String preferredEmail = get(cfg, KEY_PREFERRED_EMAIL);
|
||||
account.setPreferredEmail(preferredEmail);
|
||||
|
||||
account.setStatus(get(cfg, KEY_STATUS));
|
||||
account.setMetaId(metaId);
|
||||
return account;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RevCommit commit(MetaDataUpdate update) throws IOException {
|
||||
RevCommit c = super.commit(update);
|
||||
loadedAccount.get().setMetaId(c.name());
|
||||
loadedAccountProperties.get().setMetaId(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -331,7 +292,7 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
||||
protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException {
|
||||
checkLoaded();
|
||||
|
||||
if (!loadedAccount.isPresent()) {
|
||||
if (!loadedAccountProperties.isPresent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -344,38 +305,26 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
||||
commit.setMessage("Create account\n");
|
||||
}
|
||||
|
||||
Timestamp registeredOn = loadedAccountProperties.get().getRegisteredOn();
|
||||
commit.setAuthor(new PersonIdent(commit.getAuthor(), registeredOn));
|
||||
commit.setCommitter(new PersonIdent(commit.getCommitter(), registeredOn));
|
||||
}
|
||||
|
||||
Config accountConfig = saveAccount();
|
||||
saveAccount();
|
||||
saveProjectWatches();
|
||||
savePreferences();
|
||||
|
||||
// metaId is set in the commit(MetaDataUpdate) method after the commit is created
|
||||
loadedAccount = Optional.of(parse(accountConfig, null));
|
||||
|
||||
accountUpdate = Optional.empty();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Config saveAccount() throws IOException, ConfigInvalidException {
|
||||
Config accountConfig = readConfig(ACCOUNT_CONFIG);
|
||||
private void saveAccount() throws IOException {
|
||||
if (accountUpdate.isPresent()) {
|
||||
writeToAccountConfig(accountUpdate.get(), accountConfig);
|
||||
saveConfig(
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
loadedAccountProperties.get().save(accountUpdate.get()));
|
||||
}
|
||||
saveConfig(ACCOUNT_CONFIG, accountConfig);
|
||||
return accountConfig;
|
||||
}
|
||||
|
||||
public static void writeToAccountConfig(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));
|
||||
}
|
||||
|
||||
private void saveProjectWatches() throws IOException {
|
||||
@@ -409,57 +358,8 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
||||
accountUpdate.get().getEditPreferences()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets/Unsets {@code account.active} in the given config.
|
||||
*
|
||||
* <p>{@code account.active} is set to {@code false} if the account is inactive.
|
||||
*
|
||||
* <p>If the account is active {@code account.active} is unset since {@code true} is the default
|
||||
* if this field is missing.
|
||||
*
|
||||
* @param cfg the config
|
||||
* @param value whether the account is active
|
||||
*/
|
||||
private static void setActive(Config cfg, boolean value) {
|
||||
if (!value) {
|
||||
cfg.setBoolean(ACCOUNT, null, KEY_ACTIVE, false);
|
||||
} else {
|
||||
cfg.unset(ACCOUNT, null, KEY_ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets/Unsets the given key in the given config.
|
||||
*
|
||||
* <p>The key unset if the value is {@code null}.
|
||||
*
|
||||
* @param cfg the config
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
private static void set(Config cfg, String key, String value) {
|
||||
if (!Strings.isNullOrEmpty(value)) {
|
||||
cfg.setString(ACCOUNT, null, key, value);
|
||||
} else {
|
||||
cfg.unset(ACCOUNT, null, key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given key from the given config.
|
||||
*
|
||||
* <p>Empty values are returned as {@code null}
|
||||
*
|
||||
* @param cfg the config
|
||||
* @param key the key
|
||||
* @return the value, {@code null} if key was not set or key was set to empty string
|
||||
*/
|
||||
private static String get(Config cfg, String key) {
|
||||
return Strings.emptyToNull(cfg.getString(ACCOUNT, null, key));
|
||||
}
|
||||
|
||||
private void checkLoaded() {
|
||||
checkState(loadedAccount != null, "Account %s not loaded yet", accountId.get());
|
||||
checkState(loadedAccountProperties != null, "Account %s not loaded yet", accountId.get());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
164
java/com/google/gerrit/server/account/AccountProperties.java
Normal file
164
java/com/google/gerrit/server/account/AccountProperties.java
Normal file
@@ -0,0 +1,164 @@
|
||||
// Copyright (C) 2018 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 License.
|
||||
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import java.sql.Timestamp;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
/**
|
||||
* Parses/writes account properties from/to a {@link Config} file.
|
||||
*
|
||||
* <p>This is a low-level API. Read/write of account properties in a user branch should be done
|
||||
* through {@link AccountsUpdate} or {@link AccountConfig}.
|
||||
*
|
||||
* <p>The config file has one 'account' section with the properties of the account:
|
||||
*
|
||||
* <pre>
|
||||
* [account]
|
||||
* active = false
|
||||
* fullName = John Doe
|
||||
* preferredEmail = john.doe@foo.com
|
||||
* status = Overloaded with reviews
|
||||
* </pre>
|
||||
*
|
||||
* <p>All keys are optional.
|
||||
*
|
||||
* <p>Not setting a key and setting a key to an empty string are treated the same way and result in
|
||||
* a {@code null} value.
|
||||
*
|
||||
* <p>If no value for 'active' is specified, by default the account is considered as active.
|
||||
*
|
||||
* <p>The account is lazily parsed.
|
||||
*/
|
||||
public class AccountProperties {
|
||||
public static final String ACCOUNT_CONFIG = "account.config";
|
||||
public static final String ACCOUNT = "account";
|
||||
public static final String KEY_ACTIVE = "active";
|
||||
public static final String KEY_FULL_NAME = "fullName";
|
||||
public static final String KEY_PREFERRED_EMAIL = "preferredEmail";
|
||||
public static final String KEY_STATUS = "status";
|
||||
|
||||
private final Account.Id accountId;
|
||||
private final Timestamp registeredOn;
|
||||
private final Config accountConfig;
|
||||
private @Nullable ObjectId metaId;
|
||||
private Account account;
|
||||
|
||||
AccountProperties(
|
||||
Account.Id accountId,
|
||||
Timestamp registeredOn,
|
||||
Config accountConfig,
|
||||
@Nullable ObjectId metaId) {
|
||||
this.accountId = accountId;
|
||||
this.registeredOn = registeredOn;
|
||||
this.accountConfig = accountConfig;
|
||||
this.metaId = metaId;
|
||||
}
|
||||
|
||||
Account getAccount() {
|
||||
if (account == null) {
|
||||
parse();
|
||||
}
|
||||
return account;
|
||||
}
|
||||
|
||||
public Timestamp getRegisteredOn() {
|
||||
return registeredOn;
|
||||
}
|
||||
|
||||
void setMetaId(@Nullable ObjectId metaId) {
|
||||
this.metaId = metaId;
|
||||
this.account = null;
|
||||
}
|
||||
|
||||
private void parse() {
|
||||
account = new Account(accountId, registeredOn);
|
||||
account.setActive(accountConfig.getBoolean(ACCOUNT, null, KEY_ACTIVE, true));
|
||||
account.setFullName(get(accountConfig, KEY_FULL_NAME));
|
||||
|
||||
String preferredEmail = get(accountConfig, KEY_PREFERRED_EMAIL);
|
||||
account.setPreferredEmail(preferredEmail);
|
||||
|
||||
account.setStatus(get(accountConfig, KEY_STATUS));
|
||||
account.setMetaId(metaId != null ? metaId.name() : null);
|
||||
}
|
||||
|
||||
Config save(InternalAccountUpdate accountUpdate) {
|
||||
writeToAccountConfig(accountUpdate, accountConfig);
|
||||
return accountConfig;
|
||||
}
|
||||
|
||||
public static void writeToAccountConfig(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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given key from the given config.
|
||||
*
|
||||
* <p>Empty values are returned as {@code null}
|
||||
*
|
||||
* @param cfg the config
|
||||
* @param key the key
|
||||
* @return the value, {@code null} if key was not set or key was set to empty string
|
||||
*/
|
||||
private static String get(Config cfg, String key) {
|
||||
return Strings.emptyToNull(cfg.getString(ACCOUNT, null, key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets/Unsets {@code account.active} in the given config.
|
||||
*
|
||||
* <p>{@code account.active} is set to {@code false} if the account is inactive.
|
||||
*
|
||||
* <p>If the account is active {@code account.active} is unset since {@code true} is the default
|
||||
* if this field is missing.
|
||||
*
|
||||
* @param cfg the config
|
||||
* @param value whether the account is active
|
||||
*/
|
||||
private static void setActive(Config cfg, boolean value) {
|
||||
if (!value) {
|
||||
cfg.setBoolean(ACCOUNT, null, KEY_ACTIVE, false);
|
||||
} else {
|
||||
cfg.unset(ACCOUNT, null, KEY_ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets/Unsets the given key in the given config.
|
||||
*
|
||||
* <p>The key unset if the value is {@code null}.
|
||||
*
|
||||
* @param cfg the config
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
private static void set(Config cfg, String key, String value) {
|
||||
if (!Strings.isNullOrEmpty(value)) {
|
||||
cfg.setString(ACCOUNT, null, key, value);
|
||||
} else {
|
||||
cfg.unset(ACCOUNT, null, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountConfig;
|
||||
import com.google.gerrit.server.account.AccountProperties;
|
||||
import com.google.gerrit.server.git.ValidationError;
|
||||
import com.google.gerrit.server.mail.send.OutgoingEmailValidator;
|
||||
import com.google.inject.Inject;
|
||||
@@ -65,7 +66,7 @@ public class AccountValidator {
|
||||
return ImmutableList.of(
|
||||
String.format(
|
||||
"commit '%s' has an invalid '%s' file for account '%s': %s",
|
||||
newId.name(), AccountConfig.ACCOUNT_CONFIG, accountId.get(), e.getMessage()));
|
||||
newId.name(), AccountProperties.ACCOUNT_CONFIG, accountId.get(), e.getMessage()));
|
||||
}
|
||||
|
||||
if (!newAccount.isPresent()) {
|
||||
|
||||
@@ -28,7 +28,7 @@ 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.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountConfig;
|
||||
import com.google.gerrit.server.account.AccountProperties;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
import com.google.gerrit.server.config.PluginConfig;
|
||||
@@ -276,7 +276,7 @@ public class MergeValidators {
|
||||
changeDataFactory.create(
|
||||
dbProvider.get(), destProject.getProject().getNameKey(), patchSetId.getParentKey());
|
||||
try {
|
||||
if (!cd.currentFilePaths().contains(AccountConfig.ACCOUNT_CONFIG)) {
|
||||
if (!cd.currentFilePaths().contains(AccountProperties.ACCOUNT_CONFIG)) {
|
||||
return;
|
||||
}
|
||||
} catch (IOException | OrmException e) {
|
||||
|
||||
@@ -90,7 +90,7 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.server.Sequences;
|
||||
import com.google.gerrit.server.account.AccountConfig;
|
||||
import com.google.gerrit.server.account.AccountProperties;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.account.AccountsUpdate;
|
||||
import com.google.gerrit.server.account.Emails;
|
||||
@@ -447,14 +447,15 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
assertThat(timestampDiffMs).isAtMost(ChangeRebuilderImpl.MAX_WINDOW_MS);
|
||||
|
||||
// Check the 'account.config' file.
|
||||
try (TreeWalk tw = TreeWalk.forPath(or, AccountConfig.ACCOUNT_CONFIG, c.getTree())) {
|
||||
try (TreeWalk tw = TreeWalk.forPath(or, AccountProperties.ACCOUNT_CONFIG, c.getTree())) {
|
||||
if (name != null || status != null) {
|
||||
assertThat(tw).isNotNull();
|
||||
Config cfg = new Config();
|
||||
cfg.fromText(new String(or.open(tw.getObjectId(0), OBJ_BLOB).getBytes(), UTF_8));
|
||||
assertThat(cfg.getString(AccountConfig.ACCOUNT, null, AccountConfig.KEY_FULL_NAME))
|
||||
assertThat(
|
||||
cfg.getString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_FULL_NAME))
|
||||
.isEqualTo(name);
|
||||
assertThat(cfg.getString(AccountConfig.ACCOUNT, null, AccountConfig.KEY_STATUS))
|
||||
assertThat(cfg.getString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_STATUS))
|
||||
.isEqualTo(status);
|
||||
} else {
|
||||
// No account properties were set, hence an 'account.config' file was not created.
|
||||
@@ -1105,7 +1106,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
allUsersRepo.reset("userRef");
|
||||
|
||||
Config ac = getAccountConfig(allUsersRepo);
|
||||
ac.setString(AccountConfig.ACCOUNT, null, AccountConfig.KEY_STATUS, "out-of-office");
|
||||
ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_STATUS, "out-of-office");
|
||||
|
||||
PushOneCommit.Result r =
|
||||
pushFactory
|
||||
@@ -1114,7 +1115,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
admin.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
ac.toText())
|
||||
.to(MagicBranch.NEW_CHANGE + userRef);
|
||||
r.assertOkStatus();
|
||||
@@ -1144,7 +1145,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
|
||||
String email = "some.email@example.com";
|
||||
Config ac = getAccountConfig(allUsersRepo);
|
||||
ac.setString(AccountConfig.ACCOUNT, null, AccountConfig.KEY_PREFERRED_EMAIL, email);
|
||||
ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_PREFERRED_EMAIL, email);
|
||||
|
||||
PushOneCommit.Result r =
|
||||
pushFactory
|
||||
@@ -1153,7 +1154,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
foo.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
ac.toText())
|
||||
.to(MagicBranch.NEW_CHANGE + userRef);
|
||||
r.assertOkStatus();
|
||||
@@ -1186,7 +1187,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
admin.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
"invalid config")
|
||||
.to(MagicBranch.NEW_CHANGE + userRef);
|
||||
r.assertOkStatus();
|
||||
@@ -1200,9 +1201,9 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
"invalid account configuration: commit '%s' has an invalid '%s' file for account '%s':"
|
||||
+ " Invalid config file %s in commit %s",
|
||||
r.getCommit().name(),
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
admin.id,
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
r.getCommit().name()));
|
||||
gApi.changes().id(r.getChangeId()).current().submit();
|
||||
}
|
||||
@@ -1217,7 +1218,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
|
||||
String noEmail = "no.email";
|
||||
Config ac = getAccountConfig(allUsersRepo);
|
||||
ac.setString(AccountConfig.ACCOUNT, null, AccountConfig.KEY_PREFERRED_EMAIL, noEmail);
|
||||
ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_PREFERRED_EMAIL, noEmail);
|
||||
|
||||
PushOneCommit.Result r =
|
||||
pushFactory
|
||||
@@ -1226,7 +1227,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
admin.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
ac.toText())
|
||||
.to(MagicBranch.NEW_CHANGE + userRef);
|
||||
r.assertOkStatus();
|
||||
@@ -1251,7 +1252,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
allUsersRepo.reset("userRef");
|
||||
|
||||
Config ac = getAccountConfig(allUsersRepo);
|
||||
ac.setBoolean(AccountConfig.ACCOUNT, null, AccountConfig.KEY_ACTIVE, false);
|
||||
ac.setBoolean(AccountProperties.ACCOUNT, null, AccountProperties.KEY_ACTIVE, false);
|
||||
|
||||
PushOneCommit.Result r =
|
||||
pushFactory
|
||||
@@ -1260,7 +1261,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
admin.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
ac.toText())
|
||||
.to(MagicBranch.NEW_CHANGE + userRef);
|
||||
r.assertOkStatus();
|
||||
@@ -1291,7 +1292,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
allUsersRepo.reset("userRef");
|
||||
|
||||
Config ac = getAccountConfig(allUsersRepo);
|
||||
ac.setBoolean(AccountConfig.ACCOUNT, null, AccountConfig.KEY_ACTIVE, false);
|
||||
ac.setBoolean(AccountProperties.ACCOUNT, null, AccountProperties.KEY_ACTIVE, false);
|
||||
|
||||
PushOneCommit.Result r =
|
||||
pushFactory
|
||||
@@ -1300,7 +1301,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
admin.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
ac.toText())
|
||||
.to(MagicBranch.NEW_CHANGE + userRef);
|
||||
r.assertOkStatus();
|
||||
@@ -1367,7 +1368,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
allUsersRepo.reset("userRef");
|
||||
|
||||
Config ac = getAccountConfig(allUsersRepo);
|
||||
ac.setString(AccountConfig.ACCOUNT, null, AccountConfig.KEY_STATUS, "out-of-office");
|
||||
ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_STATUS, "out-of-office");
|
||||
|
||||
accountIndexedCounter.clear();
|
||||
pushFactory
|
||||
@@ -1376,7 +1377,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
oooUser.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
ac.toText())
|
||||
.to(RefNames.refsUsers(oooUser.id))
|
||||
.assertOkStatus();
|
||||
@@ -1402,7 +1403,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
admin.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
"invalid config")
|
||||
.to(RefNames.REFS_USERS_SELF);
|
||||
r.assertErrorStatus("invalid account configuration");
|
||||
@@ -1411,9 +1412,9 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
"commit '%s' has an invalid '%s' file for account '%s':"
|
||||
+ " Invalid config file %s in commit %s",
|
||||
r.getCommit().name(),
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
admin.id,
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
r.getCommit().name()));
|
||||
accountIndexedCounter.assertNoReindex();
|
||||
}
|
||||
@@ -1426,7 +1427,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
|
||||
String noEmail = "no.email";
|
||||
Config ac = getAccountConfig(allUsersRepo);
|
||||
ac.setString(AccountConfig.ACCOUNT, null, AccountConfig.KEY_PREFERRED_EMAIL, noEmail);
|
||||
ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_PREFERRED_EMAIL, noEmail);
|
||||
|
||||
PushOneCommit.Result r =
|
||||
pushFactory
|
||||
@@ -1435,7 +1436,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
admin.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
ac.toText())
|
||||
.to(RefNames.REFS_USERS_SELF);
|
||||
r.assertErrorStatus("invalid account configuration");
|
||||
@@ -1462,7 +1463,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
|
||||
String status = "in vacation";
|
||||
Config ac = getAccountConfig(allUsersRepo);
|
||||
ac.setString(AccountConfig.ACCOUNT, null, AccountConfig.KEY_STATUS, status);
|
||||
ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_STATUS, status);
|
||||
|
||||
pushFactory
|
||||
.create(
|
||||
@@ -1470,7 +1471,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
foo.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
ac.toText())
|
||||
.to(userRef)
|
||||
.assertOkStatus();
|
||||
@@ -1496,7 +1497,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
|
||||
String email = "some.email@example.com";
|
||||
Config ac = getAccountConfig(allUsersRepo);
|
||||
ac.setString(AccountConfig.ACCOUNT, null, AccountConfig.KEY_PREFERRED_EMAIL, email);
|
||||
ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_PREFERRED_EMAIL, email);
|
||||
|
||||
pushFactory
|
||||
.create(
|
||||
@@ -1504,7 +1505,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
foo.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
ac.toText())
|
||||
.to(userRef)
|
||||
.assertOkStatus();
|
||||
@@ -1522,7 +1523,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
allUsersRepo.reset("userRef");
|
||||
|
||||
Config ac = getAccountConfig(allUsersRepo);
|
||||
ac.setBoolean(AccountConfig.ACCOUNT, null, AccountConfig.KEY_ACTIVE, false);
|
||||
ac.setBoolean(AccountProperties.ACCOUNT, null, AccountProperties.KEY_ACTIVE, false);
|
||||
|
||||
PushOneCommit.Result r =
|
||||
pushFactory
|
||||
@@ -1531,7 +1532,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
admin.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
ac.toText())
|
||||
.to(RefNames.REFS_USERS_SELF);
|
||||
r.assertErrorStatus("invalid account configuration");
|
||||
@@ -1555,7 +1556,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
allUsersRepo.reset("userRef");
|
||||
|
||||
Config ac = getAccountConfig(allUsersRepo);
|
||||
ac.setBoolean(AccountConfig.ACCOUNT, null, AccountConfig.KEY_ACTIVE, false);
|
||||
ac.setBoolean(AccountProperties.ACCOUNT, null, AccountProperties.KEY_ACTIVE, false);
|
||||
|
||||
pushFactory
|
||||
.create(
|
||||
@@ -1563,7 +1564,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
admin.getIdent(),
|
||||
allUsersRepo,
|
||||
"Update account config",
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
ac.toText())
|
||||
.to(userRef)
|
||||
.assertOkStatus();
|
||||
@@ -2507,7 +2508,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
try (TreeWalk tw =
|
||||
TreeWalk.forPath(
|
||||
allUsersRepo.getRepository(),
|
||||
AccountConfig.ACCOUNT_CONFIG,
|
||||
AccountProperties.ACCOUNT_CONFIG,
|
||||
getHead(allUsersRepo.getRepository()).getTree())) {
|
||||
assertThat(tw).isNotNull();
|
||||
ac.fromText(
|
||||
|
||||
Reference in New Issue
Block a user