Make Git history of user branches more useful by specific commit messages
At the moment the Git history of a user branch is not very useful since it always reads as "Create account", "Update account", "Update account", "Update account" etc. Make the commit messages more specific to the actual update. For this callers of AccountsUpdate are now required to provide a commit message for account creations and account updates. Having specific commit message also makes debugging easier. E.g. if there is bad account update it is easier to identify the code that was doing it. Change-Id: Ifca4479d1c61b4231c1d78d0eecb4a77a01a464a Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -117,7 +117,9 @@ public class AccountCreator {
|
|||||||
}
|
}
|
||||||
externalIdsUpdate.create().insert(extIds);
|
externalIdsUpdate.create().insert(extIds);
|
||||||
|
|
||||||
accountsUpdate.create().insert(id, u -> u.setFullName(fullName).setPreferredEmail(email));
|
accountsUpdate
|
||||||
|
.create()
|
||||||
|
.insert("Create Test Account", id, u -> u.setFullName(fullName).setPreferredEmail(email));
|
||||||
|
|
||||||
if (groupNames != null) {
|
if (groupNames != null) {
|
||||||
for (String n : groupNames) {
|
for (String n : groupNames) {
|
||||||
|
|||||||
@@ -199,9 +199,14 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (revision != null) {
|
if (revision != null) {
|
||||||
commit.setMessage("Update account\n");
|
if (Strings.isNullOrEmpty(commit.getMessage())) {
|
||||||
|
commit.setMessage("Update account\n");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
commit.setMessage("Create account\n");
|
if (Strings.isNullOrEmpty(commit.getMessage())) {
|
||||||
|
commit.setMessage("Create account\n");
|
||||||
|
}
|
||||||
|
|
||||||
commit.setAuthor(new PersonIdent(commit.getAuthor(), registeredOn));
|
commit.setAuthor(new PersonIdent(commit.getAuthor(), registeredOn));
|
||||||
commit.setCommitter(new PersonIdent(commit.getCommitter(), registeredOn));
|
commit.setCommitter(new PersonIdent(commit.getCommitter(), registeredOn));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,7 +240,10 @@ public class AccountManager {
|
|||||||
Account account =
|
Account account =
|
||||||
accountsUpdateFactory
|
accountsUpdateFactory
|
||||||
.create()
|
.create()
|
||||||
.update(user.getAccountId(), AccountUpdater.joinConsumers(accountUpdates));
|
.update(
|
||||||
|
"Update Account on Login",
|
||||||
|
user.getAccountId(),
|
||||||
|
AccountUpdater.joinConsumers(accountUpdates));
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
throw new OrmException("Account " + user.getAccountId() + " has been deleted");
|
throw new OrmException("Account " + user.getAccountId() + " has been deleted");
|
||||||
}
|
}
|
||||||
@@ -265,7 +268,9 @@ public class AccountManager {
|
|||||||
AccountsUpdate accountsUpdate = accountsUpdateFactory.create();
|
AccountsUpdate accountsUpdate = accountsUpdateFactory.create();
|
||||||
account =
|
account =
|
||||||
accountsUpdate.insert(
|
accountsUpdate.insert(
|
||||||
newId, u -> u.setFullName(who.getDisplayName()).setPreferredEmail(extId.email()));
|
"Create Account on First Login",
|
||||||
|
newId,
|
||||||
|
u -> u.setFullName(who.getDisplayName()).setPreferredEmail(extId.email()));
|
||||||
|
|
||||||
ExternalId existingExtId = externalIds.get(extId.key());
|
ExternalId existingExtId = externalIds.get(extId.key());
|
||||||
if (existingExtId != null && !existingExtId.accountId().equals(extId.accountId())) {
|
if (existingExtId != null && !existingExtId.accountId().equals(extId.accountId())) {
|
||||||
@@ -415,6 +420,10 @@ public class AccountManager {
|
|||||||
accountsUpdateFactory
|
accountsUpdateFactory
|
||||||
.create()
|
.create()
|
||||||
.update(
|
.update(
|
||||||
|
"Set Preferred Email on Linking External ID\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "An external ID with email was added and the account didn't have a\n"
|
||||||
|
+ "preferred email yet.",
|
||||||
to,
|
to,
|
||||||
(a, u) -> {
|
(a, u) -> {
|
||||||
if (a.getPreferredEmail() == null) {
|
if (a.getPreferredEmail() == null) {
|
||||||
@@ -423,7 +432,6 @@ public class AccountManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AuthResult(to, who.getExternalIdKey(), false);
|
return new AuthResult(to, who.getExternalIdKey(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,6 +511,10 @@ public class AccountManager {
|
|||||||
accountsUpdateFactory
|
accountsUpdateFactory
|
||||||
.create()
|
.create()
|
||||||
.update(
|
.update(
|
||||||
|
"Clear Preferred Email on Unlinking External ID\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "The preferred email is cleared because the corresponding external ID\n"
|
||||||
|
+ "was removed.",
|
||||||
from,
|
from,
|
||||||
(a, u) -> {
|
(a, u) -> {
|
||||||
if (a.getPreferredEmail() != null) {
|
if (a.getPreferredEmail() != null) {
|
||||||
|
|||||||
@@ -15,8 +15,10 @@
|
|||||||
package com.google.gerrit.server.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.util.concurrent.Runnables;
|
import com.google.common.util.concurrent.Runnables;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
@@ -270,6 +272,7 @@ public class AccountsUpdate {
|
|||||||
/**
|
/**
|
||||||
* Inserts a new account.
|
* Inserts a new account.
|
||||||
*
|
*
|
||||||
|
* @param message commit message for the account creation, must not be {@code null or empty}
|
||||||
* @param accountId ID of the new account
|
* @param accountId ID of the new account
|
||||||
* @param init consumer to populate the new account
|
* @param init consumer to populate the new account
|
||||||
* @return the newly created account
|
* @return the newly created account
|
||||||
@@ -278,14 +281,16 @@ public class AccountsUpdate {
|
|||||||
* @throws OrmException if creating the user branch fails
|
* @throws OrmException if creating the user branch fails
|
||||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||||
*/
|
*/
|
||||||
public Account insert(Account.Id accountId, Consumer<InternalAccountUpdate.Builder> init)
|
public Account insert(
|
||||||
|
String message, Account.Id accountId, Consumer<InternalAccountUpdate.Builder> init)
|
||||||
throws OrmException, IOException, ConfigInvalidException {
|
throws OrmException, IOException, ConfigInvalidException {
|
||||||
return insert(accountId, AccountUpdater.fromConsumer(init));
|
return insert(message, accountId, AccountUpdater.fromConsumer(init));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a new account.
|
* Inserts a new account.
|
||||||
*
|
*
|
||||||
|
* @param message commit message for the account creation, must not be {@code null or empty}
|
||||||
* @param accountId ID of the new account
|
* @param accountId ID of the new account
|
||||||
* @param updater updater to populate the new account
|
* @param updater updater to populate the new account
|
||||||
* @return the newly created account
|
* @return the newly created account
|
||||||
@@ -294,7 +299,7 @@ public class AccountsUpdate {
|
|||||||
* @throws OrmException if creating the user branch fails
|
* @throws OrmException if creating the user branch fails
|
||||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||||
*/
|
*/
|
||||||
public Account insert(Account.Id accountId, AccountUpdater updater)
|
public Account insert(String message, Account.Id accountId, AccountUpdater updater)
|
||||||
throws OrmException, IOException, ConfigInvalidException {
|
throws OrmException, IOException, ConfigInvalidException {
|
||||||
return updateAccount(
|
return updateAccount(
|
||||||
r -> {
|
r -> {
|
||||||
@@ -304,7 +309,7 @@ public class AccountsUpdate {
|
|||||||
updater.update(account, updateBuilder);
|
updater.update(account, updateBuilder);
|
||||||
accountConfig.setAccountUpdate(updateBuilder.build());
|
accountConfig.setAccountUpdate(updateBuilder.build());
|
||||||
|
|
||||||
UpdatedAccount updatedAccounts = new UpdatedAccount(accountConfig);
|
UpdatedAccount updatedAccounts = new UpdatedAccount(message, accountConfig);
|
||||||
updatedAccounts.setCreated(true);
|
updatedAccounts.setCreated(true);
|
||||||
return updatedAccounts;
|
return updatedAccounts;
|
||||||
});
|
});
|
||||||
@@ -315,6 +320,7 @@ public class AccountsUpdate {
|
|||||||
*
|
*
|
||||||
* <p>Changing the registration date of an account is not supported.
|
* <p>Changing the registration date of an account is not supported.
|
||||||
*
|
*
|
||||||
|
* @param message commit message for the account update, must not be {@code null or empty}
|
||||||
* @param accountId ID of the account
|
* @param accountId ID of the account
|
||||||
* @param update 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
|
* @return the updated account, {@code null} if the account doesn't exist
|
||||||
@@ -322,9 +328,10 @@ public class AccountsUpdate {
|
|||||||
* @throws OrmException if updating the user branch fails
|
* @throws OrmException if updating the user branch fails
|
||||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||||
*/
|
*/
|
||||||
public Account update(Account.Id accountId, Consumer<InternalAccountUpdate.Builder> update)
|
public Account update(
|
||||||
|
String message, Account.Id accountId, Consumer<InternalAccountUpdate.Builder> update)
|
||||||
throws OrmException, IOException, ConfigInvalidException {
|
throws OrmException, IOException, ConfigInvalidException {
|
||||||
return update(accountId, AccountUpdater.fromConsumer(update));
|
return update(message, accountId, AccountUpdater.fromConsumer(update));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -332,6 +339,7 @@ public class AccountsUpdate {
|
|||||||
*
|
*
|
||||||
* <p>Changing the registration date of an account is not supported.
|
* <p>Changing the registration date of an account is not supported.
|
||||||
*
|
*
|
||||||
|
* @param message commit message for the account update, must not be {@code null or empty}
|
||||||
* @param accountId ID of the account
|
* @param accountId ID of the account
|
||||||
* @param updater updater 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
|
* @return the updated account, {@code null} if the account doesn't exist
|
||||||
@@ -340,7 +348,7 @@ public class AccountsUpdate {
|
|||||||
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
* @throws ConfigInvalidException if any of the account fields has an invalid value
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Account update(Account.Id accountId, AccountUpdater updater)
|
public Account update(String message, Account.Id accountId, AccountUpdater updater)
|
||||||
throws OrmException, IOException, ConfigInvalidException {
|
throws OrmException, IOException, ConfigInvalidException {
|
||||||
return updateAccount(
|
return updateAccount(
|
||||||
r -> {
|
r -> {
|
||||||
@@ -353,7 +361,7 @@ public class AccountsUpdate {
|
|||||||
InternalAccountUpdate.Builder updateBuilder = InternalAccountUpdate.builder();
|
InternalAccountUpdate.Builder updateBuilder = InternalAccountUpdate.builder();
|
||||||
updater.update(account.get(), updateBuilder);
|
updater.update(account.get(), updateBuilder);
|
||||||
accountConfig.setAccountUpdate(updateBuilder.build());
|
accountConfig.setAccountUpdate(updateBuilder.build());
|
||||||
UpdatedAccount updatedAccounts = new UpdatedAccount(accountConfig);
|
UpdatedAccount updatedAccounts = new UpdatedAccount(message, accountConfig);
|
||||||
return updatedAccounts;
|
return updatedAccounts;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -454,9 +462,17 @@ public class AccountsUpdate {
|
|||||||
private void commit(Repository allUsersRepo, UpdatedAccount updatedAccount) throws IOException {
|
private void commit(Repository allUsersRepo, UpdatedAccount updatedAccount) throws IOException {
|
||||||
BatchRefUpdate batchRefUpdate = allUsersRepo.getRefDatabase().newBatchUpdate();
|
BatchRefUpdate batchRefUpdate = allUsersRepo.getRefDatabase().newBatchUpdate();
|
||||||
if (updatedAccount.isCreated()) {
|
if (updatedAccount.isCreated()) {
|
||||||
commitNewAccountConfig(allUsersRepo, batchRefUpdate, updatedAccount.getAccountConfig());
|
commitNewAccountConfig(
|
||||||
|
updatedAccount.getMessage(),
|
||||||
|
allUsersRepo,
|
||||||
|
batchRefUpdate,
|
||||||
|
updatedAccount.getAccountConfig());
|
||||||
} else {
|
} else {
|
||||||
commitAccountConfig(allUsersRepo, batchRefUpdate, updatedAccount.getAccountConfig());
|
commitAccountConfig(
|
||||||
|
updatedAccount.getMessage(),
|
||||||
|
allUsersRepo,
|
||||||
|
batchRefUpdate,
|
||||||
|
updatedAccount.getAccountConfig());
|
||||||
}
|
}
|
||||||
RefUpdateUtil.executeChecked(batchRefUpdate, allUsersRepo);
|
RefUpdateUtil.executeChecked(batchRefUpdate, allUsersRepo);
|
||||||
gitRefUpdated.fire(
|
gitRefUpdated.fire(
|
||||||
@@ -464,36 +480,48 @@ public class AccountsUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void commitNewAccountConfig(
|
private void commitNewAccountConfig(
|
||||||
Repository allUsersRepo, BatchRefUpdate batchRefUpdate, AccountConfig accountConfig)
|
String message,
|
||||||
|
Repository allUsersRepo,
|
||||||
|
BatchRefUpdate batchRefUpdate,
|
||||||
|
AccountConfig accountConfig)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
// When creating a new account we must allow empty commits so that the user branch gets created
|
// When creating a new account we must allow empty commits so that the user branch gets created
|
||||||
// with an empty commit when no account properties are set and hence no 'account.config' file
|
// with an empty commit when no account properties are set and hence no 'account.config' file
|
||||||
// will be created.
|
// will be created.
|
||||||
commitAccountConfig(allUsersRepo, batchRefUpdate, accountConfig, true);
|
commitAccountConfig(message, allUsersRepo, batchRefUpdate, accountConfig, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void commitAccountConfig(
|
private void commitAccountConfig(
|
||||||
Repository allUsersRepo, BatchRefUpdate batchRefUpdate, AccountConfig accountConfig)
|
String message,
|
||||||
|
Repository allUsersRepo,
|
||||||
|
BatchRefUpdate batchRefUpdate,
|
||||||
|
AccountConfig accountConfig)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
commitAccountConfig(allUsersRepo, batchRefUpdate, accountConfig, false);
|
commitAccountConfig(message, allUsersRepo, batchRefUpdate, accountConfig, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void commitAccountConfig(
|
private void commitAccountConfig(
|
||||||
|
String message,
|
||||||
Repository allUsersRepo,
|
Repository allUsersRepo,
|
||||||
BatchRefUpdate batchRefUpdate,
|
BatchRefUpdate batchRefUpdate,
|
||||||
AccountConfig accountConfig,
|
AccountConfig accountConfig,
|
||||||
boolean allowEmptyCommit)
|
boolean allowEmptyCommit)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
try (MetaDataUpdate md = createMetaDataUpdate(allUsersRepo, batchRefUpdate)) {
|
try (MetaDataUpdate md = createMetaDataUpdate(message, allUsersRepo, batchRefUpdate)) {
|
||||||
md.setAllowEmpty(allowEmptyCommit);
|
md.setAllowEmpty(allowEmptyCommit);
|
||||||
accountConfig.commit(md);
|
accountConfig.commit(md);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MetaDataUpdate createMetaDataUpdate(
|
private MetaDataUpdate createMetaDataUpdate(
|
||||||
Repository allUsersRepo, BatchRefUpdate batchRefUpdate) {
|
String message, Repository allUsersRepo, BatchRefUpdate batchRefUpdate) {
|
||||||
MetaDataUpdate metaDataUpdate =
|
MetaDataUpdate metaDataUpdate =
|
||||||
metaDataUpdateInternalFactory.get().create(allUsersName, allUsersRepo, batchRefUpdate);
|
metaDataUpdateInternalFactory.get().create(allUsersName, allUsersRepo, batchRefUpdate);
|
||||||
|
if (!message.endsWith("\n")) {
|
||||||
|
message = message + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
metaDataUpdate.getCommitBuilder().setMessage(message);
|
||||||
metaDataUpdate.getCommitBuilder().setCommitter(committerIdent);
|
metaDataUpdate.getCommitBuilder().setCommitter(committerIdent);
|
||||||
metaDataUpdate.getCommitBuilder().setAuthor(authorIdent);
|
metaDataUpdate.getCommitBuilder().setAuthor(authorIdent);
|
||||||
return metaDataUpdate;
|
return metaDataUpdate;
|
||||||
@@ -506,19 +534,18 @@ public class AccountsUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class UpdatedAccount {
|
private static class UpdatedAccount {
|
||||||
|
private final String message;
|
||||||
private final AccountConfig accountConfig;
|
private final AccountConfig accountConfig;
|
||||||
private boolean created;
|
private boolean created;
|
||||||
|
|
||||||
private UpdatedAccount(AccountConfig accountConfig) {
|
private UpdatedAccount(String message, AccountConfig accountConfig) {
|
||||||
|
checkState(!Strings.isNullOrEmpty(message), "message for account update must be set");
|
||||||
|
this.message = checkNotNull(message);
|
||||||
this.accountConfig = checkNotNull(accountConfig);
|
this.accountConfig = checkNotNull(accountConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreated(boolean created) {
|
public String getMessage() {
|
||||||
this.created = created;
|
return message;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCreated() {
|
|
||||||
return created;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountConfig getAccountConfig() {
|
public AccountConfig getAccountConfig() {
|
||||||
@@ -528,5 +555,13 @@ public class AccountsUpdate {
|
|||||||
public Account getAccount() {
|
public Account getAccount() {
|
||||||
return accountConfig.getLoadedAccount().get();
|
return accountConfig.getLoadedAccount().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCreated(boolean created) {
|
||||||
|
this.created = created;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCreated() {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,7 +172,10 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
|
|||||||
|
|
||||||
accountsUpdate
|
accountsUpdate
|
||||||
.create()
|
.create()
|
||||||
.insert(id, u -> u.setFullName(input.name).setPreferredEmail(input.email));
|
.insert(
|
||||||
|
"Create Account via API",
|
||||||
|
id,
|
||||||
|
u -> u.setFullName(input.name).setPreferredEmail(input.email));
|
||||||
|
|
||||||
for (AccountGroup.UUID groupUuid : groups) {
|
for (AccountGroup.UUID groupUuid : groups) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -77,7 +77,9 @@ public class PutName implements RestModifyView<AccountResource, NameInput> {
|
|||||||
|
|
||||||
String newName = input.name;
|
String newName = input.name;
|
||||||
Account account =
|
Account account =
|
||||||
accountsUpdate.create().update(user.getAccountId(), u -> u.setFullName(newName));
|
accountsUpdate
|
||||||
|
.create()
|
||||||
|
.update("Set Full Name via API", user.getAccountId(), u -> u.setFullName(newName));
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
throw new ResourceNotFoundException("account not found");
|
throw new ResourceNotFoundException("account not found");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ public class PutPreferred implements RestModifyView<AccountResource.Email, Input
|
|||||||
accountsUpdate
|
accountsUpdate
|
||||||
.create()
|
.create()
|
||||||
.update(
|
.update(
|
||||||
|
"Set Preferred Email via API",
|
||||||
user.getAccountId(),
|
user.getAccountId(),
|
||||||
(a, u) -> {
|
(a, u) -> {
|
||||||
if (email.equals(a.getPreferredEmail())) {
|
if (email.equals(a.getPreferredEmail())) {
|
||||||
|
|||||||
@@ -67,7 +67,9 @@ public class PutStatus implements RestModifyView<AccountResource, StatusInput> {
|
|||||||
|
|
||||||
String newStatus = input.status;
|
String newStatus = input.status;
|
||||||
Account account =
|
Account account =
|
||||||
accountsUpdate.create().update(user.getAccountId(), u -> u.setStatus(newStatus));
|
accountsUpdate
|
||||||
|
.create()
|
||||||
|
.update("Set Status via API", user.getAccountId(), u -> u.setStatus(newStatus));
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
throw new ResourceNotFoundException("account not found");
|
throw new ResourceNotFoundException("account not found");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public class SetInactiveFlag {
|
|||||||
accountsUpdate
|
accountsUpdate
|
||||||
.create()
|
.create()
|
||||||
.update(
|
.update(
|
||||||
|
"Deactivate Account via API",
|
||||||
accountId,
|
accountId,
|
||||||
(a, u) -> {
|
(a, u) -> {
|
||||||
if (!a.isActive()) {
|
if (!a.isActive()) {
|
||||||
@@ -67,6 +68,7 @@ public class SetInactiveFlag {
|
|||||||
accountsUpdate
|
accountsUpdate
|
||||||
.create()
|
.create()
|
||||||
.update(
|
.update(
|
||||||
|
"Activate Account via API",
|
||||||
accountId,
|
accountId,
|
||||||
(a, u) -> {
|
(a, u) -> {
|
||||||
if (a.isActive()) {
|
if (a.isActive()) {
|
||||||
|
|||||||
@@ -2932,6 +2932,7 @@ class ReceiveCommits {
|
|||||||
accountsUpdate
|
accountsUpdate
|
||||||
.create()
|
.create()
|
||||||
.update(
|
.update(
|
||||||
|
"Set Full Name on Receive Commits",
|
||||||
user.getAccountId(),
|
user.getAccountId(),
|
||||||
(a, u) -> {
|
(a, u) -> {
|
||||||
if (Strings.isNullOrEmpty(a.getFullName())) {
|
if (Strings.isNullOrEmpty(a.getFullName())) {
|
||||||
|
|||||||
@@ -324,12 +324,36 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
assertUserBranchWithoutAccountConfig(anonymousCoward.getId());
|
assertUserBranchWithoutAccountConfig(anonymousCoward.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void commitMessageOnAccountUpdates() throws Exception {
|
||||||
|
AccountsUpdate au = accountsUpdate.create();
|
||||||
|
Account.Id accountId = new Account.Id(seq.nextAccountId());
|
||||||
|
au.insert("Create Test Account", accountId, u -> {});
|
||||||
|
assertLastCommitMessageOfUserBranch(accountId, "Create Test Account");
|
||||||
|
|
||||||
|
au.update("Set Status", accountId, u -> u.setStatus("Foo"));
|
||||||
|
assertLastCommitMessageOfUserBranch(accountId, "Set Status");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertLastCommitMessageOfUserBranch(Account.Id accountId, String expectedMessage)
|
||||||
|
throws Exception {
|
||||||
|
try (Repository repo = repoManager.openRepository(allUsers);
|
||||||
|
RevWalk rw = new RevWalk(repo)) {
|
||||||
|
Ref exactRef = repo.exactRef(RefNames.refsUsers(accountId));
|
||||||
|
assertThat(rw.parseCommit(exactRef.getObjectId()).getShortMessage())
|
||||||
|
.isEqualTo(expectedMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateNonExistingAccount() throws Exception {
|
public void updateNonExistingAccount() throws Exception {
|
||||||
Account.Id nonExistingAccountId = new Account.Id(999999);
|
Account.Id nonExistingAccountId = new Account.Id(999999);
|
||||||
AtomicBoolean consumerCalled = new AtomicBoolean();
|
AtomicBoolean consumerCalled = new AtomicBoolean();
|
||||||
Account account =
|
Account account =
|
||||||
accountsUpdate.create().update(nonExistingAccountId, a -> consumerCalled.set(true));
|
accountsUpdate
|
||||||
|
.create()
|
||||||
|
.update(
|
||||||
|
"Update Non-Existing Account", nonExistingAccountId, a -> consumerCalled.set(true));
|
||||||
assertThat(account).isNull();
|
assertThat(account).isNull();
|
||||||
assertThat(consumerCalled.get()).isFalse();
|
assertThat(consumerCalled.get()).isFalse();
|
||||||
}
|
}
|
||||||
@@ -341,7 +365,9 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
String status = "OOO";
|
String status = "OOO";
|
||||||
Account account =
|
Account account =
|
||||||
accountsUpdate.create().update(anonymousCoward.getId(), u -> u.setStatus(status));
|
accountsUpdate
|
||||||
|
.create()
|
||||||
|
.update("Set status", anonymousCoward.getId(), u -> u.setStatus(status));
|
||||||
assertThat(account).isNotNull();
|
assertThat(account).isNotNull();
|
||||||
assertThat(account.getFullName()).isNull();
|
assertThat(account.getFullName()).isNull();
|
||||||
assertThat(account.getStatus()).isEqualTo(status);
|
assertThat(account.getStatus()).isEqualTo(status);
|
||||||
@@ -871,7 +897,9 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
String prefix = "foo.preferred";
|
String prefix = "foo.preferred";
|
||||||
String prefEmail = prefix + "@example.com";
|
String prefEmail = prefix + "@example.com";
|
||||||
TestAccount foo = accountCreator.create(name("foo"));
|
TestAccount foo = accountCreator.create(name("foo"));
|
||||||
accountsUpdate.create().update(foo.id, u -> u.setPreferredEmail(prefEmail));
|
accountsUpdate
|
||||||
|
.create()
|
||||||
|
.update("Set Preferred Email", foo.id, u -> u.setPreferredEmail(prefEmail));
|
||||||
|
|
||||||
// verify that the account is still found when using the preferred email to lookup the account
|
// verify that the account is still found when using the preferred email to lookup the account
|
||||||
ImmutableSet<Account.Id> accountsByPrefEmail = emails.getAccountFor(prefEmail);
|
ImmutableSet<Account.Id> accountsByPrefEmail = emails.getAccountFor(prefEmail);
|
||||||
@@ -1347,7 +1375,9 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
String userRef = RefNames.refsUsers(foo.id);
|
String userRef = RefNames.refsUsers(foo.id);
|
||||||
|
|
||||||
String noEmail = "no.email";
|
String noEmail = "no.email";
|
||||||
accountsUpdate.create().update(foo.id, u -> u.setPreferredEmail(noEmail));
|
accountsUpdate
|
||||||
|
.create()
|
||||||
|
.update("Set Preferred Email", foo.id, u -> u.setPreferredEmail(noEmail));
|
||||||
accountIndexedCounter.clear();
|
accountIndexedCounter.clear();
|
||||||
|
|
||||||
grant(allUsers, userRef, Permission.PUSH, false, REGISTERED_USERS);
|
grant(allUsers, userRef, Permission.PUSH, false, REGISTERED_USERS);
|
||||||
@@ -1829,11 +1859,11 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
// metaId is set when account is created
|
// metaId is set when account is created
|
||||||
AccountsUpdate au = accountsUpdate.create();
|
AccountsUpdate au = accountsUpdate.create();
|
||||||
Account.Id accountId = new Account.Id(seq.nextAccountId());
|
Account.Id accountId = new Account.Id(seq.nextAccountId());
|
||||||
Account account = au.insert(accountId, u -> {});
|
Account account = au.insert("Create Test Account", accountId, u -> {});
|
||||||
assertThat(account.getMetaId()).isEqualTo(getMetaId(accountId));
|
assertThat(account.getMetaId()).isEqualTo(getMetaId(accountId));
|
||||||
|
|
||||||
// metaId is set when account is updated
|
// metaId is set when account is updated
|
||||||
Account updatedAccount = au.update(accountId, u -> u.setFullName("foo"));
|
Account updatedAccount = au.update("Set Full Name", accountId, u -> u.setFullName("foo"));
|
||||||
assertThat(account.getMetaId()).isNotEqualTo(updatedAccount.getMetaId());
|
assertThat(account.getMetaId()).isNotEqualTo(updatedAccount.getMetaId());
|
||||||
assertThat(updatedAccount.getMetaId()).isEqualTo(getMetaId(accountId));
|
assertThat(updatedAccount.getMetaId()).isEqualTo(getMetaId(accountId));
|
||||||
}
|
}
|
||||||
@@ -1923,7 +1953,7 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
() -> {
|
() -> {
|
||||||
if (!doneBgUpdate.getAndSet(true)) {
|
if (!doneBgUpdate.getAndSet(true)) {
|
||||||
try {
|
try {
|
||||||
accountsUpdate.create().update(admin.id, u -> u.setStatus(status));
|
accountsUpdate.create().update("Set Status", admin.id, u -> u.setStatus(status));
|
||||||
} catch (IOException | ConfigInvalidException | OrmException e) {
|
} catch (IOException | ConfigInvalidException | OrmException e) {
|
||||||
// Ignore, the successful update of the account is asserted later
|
// Ignore, the successful update of the account is asserted later
|
||||||
}
|
}
|
||||||
@@ -1934,7 +1964,7 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
assertThat(accountInfo.status).isNull();
|
assertThat(accountInfo.status).isNull();
|
||||||
assertThat(accountInfo.name).isNotEqualTo(fullName);
|
assertThat(accountInfo.name).isNotEqualTo(fullName);
|
||||||
|
|
||||||
Account updatedAccount = update.update(admin.id, u -> u.setFullName(fullName));
|
Account updatedAccount = update.update("Set Full Name", admin.id, u -> u.setFullName(fullName));
|
||||||
assertThat(doneBgUpdate.get()).isTrue();
|
assertThat(doneBgUpdate.get()).isTrue();
|
||||||
|
|
||||||
assertThat(updatedAccount.getStatus()).isEqualTo(status);
|
assertThat(updatedAccount.getStatus()).isEqualTo(status);
|
||||||
@@ -1974,7 +2004,10 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
try {
|
try {
|
||||||
accountsUpdate
|
accountsUpdate
|
||||||
.create()
|
.create()
|
||||||
.update(admin.id, u -> u.setStatus(status.get(bgCounter.getAndAdd(1))));
|
.update(
|
||||||
|
"Set Status",
|
||||||
|
admin.id,
|
||||||
|
u -> u.setStatus(status.get(bgCounter.getAndAdd(1))));
|
||||||
} catch (IOException | ConfigInvalidException | OrmException e) {
|
} catch (IOException | ConfigInvalidException | OrmException e) {
|
||||||
// Ignore, the expected exception is asserted later
|
// Ignore, the expected exception is asserted later
|
||||||
}
|
}
|
||||||
@@ -1985,7 +2018,7 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
assertThat(accountInfo.name).isNotEqualTo(fullName);
|
assertThat(accountInfo.name).isNotEqualTo(fullName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
update.update(admin.id, u -> u.setFullName(fullName));
|
update.update("Set Full Name", admin.id, u -> u.setFullName(fullName));
|
||||||
fail("expected LockFailureException");
|
fail("expected LockFailureException");
|
||||||
} catch (LockFailureException e) {
|
} catch (LockFailureException e) {
|
||||||
// Ignore, expected
|
// Ignore, expected
|
||||||
|
|||||||
@@ -116,7 +116,9 @@ public class GerritPublicKeyCheckerTest {
|
|||||||
schemaCreator.create(db);
|
schemaCreator.create(db);
|
||||||
userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
|
userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
|
||||||
// Note: does not match any key in TestKeys.
|
// Note: does not match any key in TestKeys.
|
||||||
accountsUpdate.create().update(userId, u -> u.setPreferredEmail("user@example.com"));
|
accountsUpdate
|
||||||
|
.create()
|
||||||
|
.update("Set Preferred Email", userId, u -> u.setPreferredEmail("user@example.com"));
|
||||||
user = reloadUser();
|
user = reloadUser();
|
||||||
|
|
||||||
requestContext.setContext(
|
requestContext.setContext(
|
||||||
|
|||||||
@@ -542,6 +542,7 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
|||||||
accountsUpdate
|
accountsUpdate
|
||||||
.create()
|
.create()
|
||||||
.update(
|
.update(
|
||||||
|
"Update Test Account",
|
||||||
id,
|
id,
|
||||||
u -> {
|
u -> {
|
||||||
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
|
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
|
userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
|
||||||
String email = "user@example.com";
|
String email = "user@example.com";
|
||||||
externalIdsUpdate.create().insert(ExternalId.createEmail(userId, email));
|
externalIdsUpdate.create().insert(ExternalId.createEmail(userId, email));
|
||||||
accountsUpdate.create().update(userId, u -> u.setPreferredEmail(email));
|
accountsUpdate.create().update("Set Preferred Email", userId, u -> u.setPreferredEmail(email));
|
||||||
user = userFactory.create(userId);
|
user = userFactory.create(userId);
|
||||||
requestContext.setContext(newRequestContext(userId));
|
requestContext.setContext(newRequestContext(userId));
|
||||||
}
|
}
|
||||||
@@ -2729,6 +2729,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
accountsUpdate
|
accountsUpdate
|
||||||
.create()
|
.create()
|
||||||
.update(
|
.update(
|
||||||
|
"Update Test Account",
|
||||||
id,
|
id,
|
||||||
u -> {
|
u -> {
|
||||||
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
|
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
|
||||||
|
|||||||
@@ -409,6 +409,7 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
|||||||
accountsUpdate
|
accountsUpdate
|
||||||
.create()
|
.create()
|
||||||
.update(
|
.update(
|
||||||
|
"Update Test Account",
|
||||||
id,
|
id,
|
||||||
u -> {
|
u -> {
|
||||||
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
|
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
|
||||||
|
|||||||
@@ -264,6 +264,7 @@ public abstract class AbstractQueryProjectsTest extends GerritServerTests {
|
|||||||
accountsUpdate
|
accountsUpdate
|
||||||
.create()
|
.create()
|
||||||
.update(
|
.update(
|
||||||
|
"Update Test Account",
|
||||||
id,
|
id,
|
||||||
u -> {
|
u -> {
|
||||||
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
|
u.setFullName(fullName).setPreferredEmail(email).setActive(active);
|
||||||
|
|||||||
Reference in New Issue
Block a user