Don't store username in Account but in AccountState
The username is just an external ID and all other external IDs are kept in AccountState. It is more consistent if the username is kept in AccountState alongside the other external IDs. This is also a preparation to make Account an AutoValue class. Then account will be non-mutable and hence a username can no longer be set on it after it was created. Change-Id: Ia7ad7b43326caea356812e48ecee9dd92da596ab Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -160,20 +160,21 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
Element userlistElement = HtmlDomUtil.find(doc, "userlist");
|
||||
try (ReviewDb db = schema.open()) {
|
||||
for (Account.Id accountId : accounts.firstNIds(100)) {
|
||||
Account a = accountCache.get(accountId).getAccount();
|
||||
AccountState accountState = accountCache.get(accountId);
|
||||
Account account = accountState.getAccount();
|
||||
String displayName;
|
||||
if (a.getUserName() != null) {
|
||||
displayName = a.getUserName();
|
||||
} else if (a.getFullName() != null && !a.getFullName().isEmpty()) {
|
||||
displayName = a.getFullName();
|
||||
} else if (a.getPreferredEmail() != null) {
|
||||
displayName = a.getPreferredEmail();
|
||||
if (accountState.getUserName() != null) {
|
||||
displayName = accountState.getUserName();
|
||||
} else if (account.getFullName() != null && !account.getFullName().isEmpty()) {
|
||||
displayName = account.getFullName();
|
||||
} else if (account.getPreferredEmail() != null) {
|
||||
displayName = account.getPreferredEmail();
|
||||
} else {
|
||||
displayName = accountId.toString();
|
||||
}
|
||||
|
||||
Element linkElement = doc.createElement("a");
|
||||
linkElement.setAttribute("href", "?account_id=" + a.getId().toString());
|
||||
linkElement.setAttribute("href", "?account_id=" + account.getId().toString());
|
||||
linkElement.setTextContent(displayName);
|
||||
userlistElement.appendChild(linkElement);
|
||||
userlistElement.appendChild(doc.createElement("br"));
|
||||
|
||||
@@ -106,7 +106,7 @@ class ChangeProjectAccess extends ProjectAccessHandler<ProjectAccess> {
|
||||
RefNames.REFS_CONFIG,
|
||||
base,
|
||||
commit.getId(),
|
||||
user.asIdentifiedUser().getAccount());
|
||||
user.asIdentifiedUser().state());
|
||||
|
||||
projectCache.evict(config.getProject());
|
||||
createGroupPermissionSyncer.syncIfNeeded();
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class Account {
|
||||
public static final String USER_NAME_PATTERN_REST = "[a-zA-Z0-9._@-]";
|
||||
public static final String USER_NAME_PATTERN_LAST = "[a-zA-Z0-9]";
|
||||
|
||||
/** Regular expression that {@link #userName} must match. */
|
||||
/** Regular expression that a username must match. */
|
||||
public static final String USER_NAME_PATTERN =
|
||||
"^"
|
||||
+ //
|
||||
@@ -176,9 +176,6 @@ public final class Account {
|
||||
@Column(id = 8, notNull = false)
|
||||
protected String status;
|
||||
|
||||
/** <i>computed</i> the username selected from the identities. */
|
||||
protected String userName;
|
||||
|
||||
/**
|
||||
* ID of the user branch from which the account was read, {@code null} if the account was read
|
||||
* from ReviewDb.
|
||||
@@ -306,16 +303,6 @@ public final class Account {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/** @return the computed user name for this account */
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
/** Update the computed user name property. */
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Account && ((Account) o).getId().equals(getId());
|
||||
|
||||
@@ -157,6 +157,7 @@ public class AccountState {
|
||||
private final AllUsersName allUsersName;
|
||||
private final Account account;
|
||||
private final ImmutableSet<ExternalId> externalIds;
|
||||
private final Optional<String> userName;
|
||||
private final Supplier<ImmutableMap<ProjectWatchKey, ImmutableSet<NotifyType>>> projectWatches;
|
||||
private final Supplier<GeneralPreferencesInfo> generalPreferences;
|
||||
private final Supplier<DiffPreferencesInfo> diffPreferences;
|
||||
@@ -174,11 +175,11 @@ public class AccountState {
|
||||
this.allUsersName = allUsersName;
|
||||
this.account = account;
|
||||
this.externalIds = externalIds;
|
||||
this.userName = ExternalId.getUserName(externalIds);
|
||||
this.projectWatches = projectWatches;
|
||||
this.generalPreferences = generalPreferences;
|
||||
this.diffPreferences = diffPreferences;
|
||||
this.editPreferences = editPreferences;
|
||||
this.account.setUserName(ExternalId.getUserName(externalIds).orElse(null));
|
||||
}
|
||||
|
||||
public AllUsersName getAllUsersNameForIndexing() {
|
||||
@@ -195,8 +196,9 @@ public class AccountState {
|
||||
*
|
||||
* <p>The username is the {@link ExternalId} using the scheme {@link ExternalId#SCHEME_USERNAME}.
|
||||
*/
|
||||
@Nullable
|
||||
public String getUserName() {
|
||||
return account.getUserName();
|
||||
return userName.orElse(null);
|
||||
}
|
||||
|
||||
public boolean checkPassword(String password, String username) {
|
||||
|
||||
@@ -560,7 +560,7 @@ public class AccountsUpdate {
|
||||
RefUpdateUtil.executeChecked(batchRefUpdate, allUsersRepo);
|
||||
updatedAccount.getExternalIdNotes().updateCaches();
|
||||
gitRefUpdated.fire(
|
||||
allUsersName, batchRefUpdate, currentUser != null ? currentUser.getAccount() : null);
|
||||
allUsersName, batchRefUpdate, currentUser != null ? currentUser.state() : null);
|
||||
}
|
||||
|
||||
private void commitNewAccountConfig(
|
||||
|
||||
@@ -69,15 +69,16 @@ public class InternalAccountDirectory extends AccountDirectory {
|
||||
for (AccountInfo info : in) {
|
||||
Account.Id id = new Account.Id(info._accountId);
|
||||
AccountState state = accountCache.get(id);
|
||||
fill(info, state.getAccount(), state.getExternalIds(), options);
|
||||
fill(info, state, state.getExternalIds(), options);
|
||||
}
|
||||
}
|
||||
|
||||
private void fill(
|
||||
AccountInfo info,
|
||||
Account account,
|
||||
AccountState accountState,
|
||||
@Nullable Collection<ExternalId> externalIds,
|
||||
Set<FillOptions> options) {
|
||||
Account account = accountState.getAccount();
|
||||
if (options.contains(FillOptions.ID)) {
|
||||
info._accountId = account.getId().get();
|
||||
} else {
|
||||
@@ -87,7 +88,7 @@ public class InternalAccountDirectory extends AccountDirectory {
|
||||
if (options.contains(FillOptions.NAME)) {
|
||||
info.name = Strings.emptyToNull(account.getFullName());
|
||||
if (info.name == null) {
|
||||
info.name = account.getUserName();
|
||||
info.name = accountState.getUserName();
|
||||
}
|
||||
}
|
||||
if (options.contains(FillOptions.EMAIL)) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.PatchSetUtil;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.extensions.events.ChangeAbandoned;
|
||||
import com.google.gerrit.server.mail.send.AbandonedSender;
|
||||
import com.google.gerrit.server.mail.send.ReplyToChangeSender;
|
||||
@@ -51,7 +52,7 @@ public class AbandonOp implements BatchUpdateOp {
|
||||
private final String msgTxt;
|
||||
private final NotifyHandling notifyHandling;
|
||||
private final ListMultimap<RecipientType, Account.Id> accountsToNotify;
|
||||
private final Account account;
|
||||
private final AccountState accountState;
|
||||
|
||||
private Change change;
|
||||
private PatchSet patchSet;
|
||||
@@ -59,7 +60,7 @@ public class AbandonOp implements BatchUpdateOp {
|
||||
|
||||
public interface Factory {
|
||||
AbandonOp create(
|
||||
@Assisted @Nullable Account account,
|
||||
@Assisted @Nullable AccountState accountState,
|
||||
@Assisted @Nullable String msgTxt,
|
||||
@Assisted NotifyHandling notifyHandling,
|
||||
@Assisted ListMultimap<RecipientType, Account.Id> accountsToNotify);
|
||||
@@ -71,7 +72,7 @@ public class AbandonOp implements BatchUpdateOp {
|
||||
ChangeMessagesUtil cmUtil,
|
||||
PatchSetUtil psUtil,
|
||||
ChangeAbandoned changeAbandoned,
|
||||
@Assisted @Nullable Account account,
|
||||
@Assisted @Nullable AccountState accountState,
|
||||
@Assisted @Nullable String msgTxt,
|
||||
@Assisted NotifyHandling notifyHandling,
|
||||
@Assisted ListMultimap<RecipientType, Account.Id> accountsToNotify) {
|
||||
@@ -80,7 +81,7 @@ public class AbandonOp implements BatchUpdateOp {
|
||||
this.psUtil = psUtil;
|
||||
this.changeAbandoned = changeAbandoned;
|
||||
|
||||
this.account = account;
|
||||
this.accountState = accountState;
|
||||
this.msgTxt = Strings.nullToEmpty(msgTxt);
|
||||
this.notifyHandling = notifyHandling;
|
||||
this.accountsToNotify = accountsToNotify;
|
||||
@@ -124,8 +125,8 @@ public class AbandonOp implements BatchUpdateOp {
|
||||
public void postUpdate(Context ctx) throws OrmException {
|
||||
try {
|
||||
ReplyToChangeSender cm = abandonedSenderFactory.create(ctx.getProject(), change.getId());
|
||||
if (account != null) {
|
||||
cm.setFrom(account.getId());
|
||||
if (accountState != null) {
|
||||
cm.setFrom(accountState.getAccount().getId());
|
||||
}
|
||||
cm.setChangeMessage(message.getMessage(), ctx.getWhen());
|
||||
cm.setNotify(notifyHandling);
|
||||
@@ -134,6 +135,6 @@ public class AbandonOp implements BatchUpdateOp {
|
||||
} catch (Exception e) {
|
||||
log.error("Cannot email update for change " + change.getId(), e);
|
||||
}
|
||||
changeAbandoned.fire(change, patchSet, account, msgTxt, ctx.getWhen(), notifyHandling);
|
||||
changeAbandoned.fire(change, patchSet, accountState, msgTxt, ctx.getWhen(), notifyHandling);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.update.BatchUpdate;
|
||||
import com.google.gerrit.server.update.UpdateException;
|
||||
@@ -63,7 +64,7 @@ public class BatchAbandon {
|
||||
if (changes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Account account = user.isIdentifiedUser() ? user.asIdentifiedUser().getAccount() : null;
|
||||
AccountState accountState = user.isIdentifiedUser() ? user.asIdentifiedUser().state() : null;
|
||||
try (BatchUpdate u = updateFactory.create(dbProvider.get(), project, user, TimeUtil.nowTs())) {
|
||||
for (ChangeData change : changes) {
|
||||
if (!project.equals(change.project())) {
|
||||
@@ -74,7 +75,7 @@ public class BatchAbandon {
|
||||
}
|
||||
u.addOp(
|
||||
change.getId(),
|
||||
abandonOpFactory.create(account, msgTxt, notifyHandling, accountsToNotify));
|
||||
abandonOpFactory.create(accountState, msgTxt, notifyHandling, accountsToNotify));
|
||||
}
|
||||
u.execute();
|
||||
}
|
||||
|
||||
@@ -130,9 +130,6 @@ public class SetAssigneeOp implements BatchUpdateOp {
|
||||
log.error("Cannot send email to new assignee of change " + change.getId(), err);
|
||||
}
|
||||
assigneeChanged.fire(
|
||||
change,
|
||||
ctx.getAccount(),
|
||||
oldAssignee != null ? oldAssignee.getAccount() : null,
|
||||
ctx.getWhen());
|
||||
change, ctx.getAccount(), oldAssignee != null ? oldAssignee.state() : null, ctx.getWhen());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ApprovalsUtil;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.account.Emails;
|
||||
import com.google.gerrit.server.change.ChangeKindCache;
|
||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||
@@ -245,8 +246,8 @@ public class EventFactory {
|
||||
la.label = lbl.label;
|
||||
la.status = lbl.status.name();
|
||||
if (lbl.appliedBy != null) {
|
||||
Account a = accountCache.get(lbl.appliedBy).getAccount();
|
||||
la.by = asAccountAttribute(a);
|
||||
AccountState accountState = accountCache.get(lbl.appliedBy);
|
||||
la.by = asAccountAttribute(accountState);
|
||||
}
|
||||
sa.labels.add(la);
|
||||
}
|
||||
@@ -572,24 +573,24 @@ public class EventFactory {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
return asAccountAttribute(accountCache.get(id).getAccount());
|
||||
return asAccountAttribute(accountCache.get(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an AuthorAttribute for the given account suitable for serialization to JSON.
|
||||
*
|
||||
* @param account
|
||||
* @param accountState the account state
|
||||
* @return object suitable for serialization to JSON
|
||||
*/
|
||||
public AccountAttribute asAccountAttribute(Account account) {
|
||||
if (account == null) {
|
||||
public AccountAttribute asAccountAttribute(AccountState accountState) {
|
||||
if (accountState == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AccountAttribute who = new AccountAttribute();
|
||||
who.name = account.getFullName();
|
||||
who.email = account.getPreferredEmail();
|
||||
who.username = account.getUserName();
|
||||
who.name = accountState.getAccount().getFullName();
|
||||
who.email = accountState.getAccount().getPreferredEmail();
|
||||
who.username = accountState.getUserName();
|
||||
return who;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.google.gerrit.server.extensions.events;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.events.AgreementSignupListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class AgreementSignup {
|
||||
@@ -30,11 +30,11 @@ public class AgreementSignup {
|
||||
this.util = util;
|
||||
}
|
||||
|
||||
public void fire(Account account, String agreementName) {
|
||||
public void fire(AccountState accountState, String agreementName) {
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
Event event = new Event(util.accountInfo(account), agreementName);
|
||||
Event event = new Event(util.accountInfo(accountState), agreementName);
|
||||
for (AgreementSignupListener l : listeners) {
|
||||
try {
|
||||
l.onAgreementSignup(event);
|
||||
|
||||
@@ -19,8 +19,8 @@ import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.events.AssigneeChangedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import java.sql.Timestamp;
|
||||
@@ -39,7 +39,8 @@ public class AssigneeChanged {
|
||||
this.util = util;
|
||||
}
|
||||
|
||||
public void fire(Change change, Account account, Account oldAssignee, Timestamp when) {
|
||||
public void fire(
|
||||
Change change, AccountState accountState, AccountState oldAssignee, Timestamp when) {
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
@@ -47,7 +48,7 @@ public class AssigneeChanged {
|
||||
Event event =
|
||||
new Event(
|
||||
util.changeInfo(change),
|
||||
util.accountInfo(account),
|
||||
util.accountInfo(accountState),
|
||||
util.accountInfo(oldAssignee),
|
||||
when);
|
||||
for (AssigneeChangedListener l : listeners) {
|
||||
|
||||
@@ -20,10 +20,10 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||
import com.google.gerrit.extensions.events.ChangeAbandonedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -49,7 +49,7 @@ public class ChangeAbandoned {
|
||||
public void fire(
|
||||
Change change,
|
||||
PatchSet ps,
|
||||
Account abandoner,
|
||||
AccountState abandoner,
|
||||
String reason,
|
||||
Timestamp when,
|
||||
NotifyHandling notifyHandling) {
|
||||
|
||||
@@ -20,10 +20,10 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||
import com.google.gerrit.extensions.events.ChangeMergedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -47,7 +47,7 @@ public class ChangeMerged {
|
||||
}
|
||||
|
||||
public void fire(
|
||||
Change change, PatchSet ps, Account merger, String newRevisionId, Timestamp when) {
|
||||
Change change, PatchSet ps, AccountState merger, String newRevisionId, Timestamp when) {
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||
import com.google.gerrit.extensions.events.ChangeRestoredListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -46,7 +46,8 @@ public class ChangeRestored {
|
||||
this.util = util;
|
||||
}
|
||||
|
||||
public void fire(Change change, PatchSet ps, Account restorer, String reason, Timestamp when) {
|
||||
public void fire(
|
||||
Change change, PatchSet ps, AccountState restorer, String reason, Timestamp when) {
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||
import com.google.gerrit.extensions.events.CommentAddedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -51,7 +51,7 @@ public class CommentAdded {
|
||||
public void fire(
|
||||
Change change,
|
||||
PatchSet ps,
|
||||
Account author,
|
||||
AccountState author,
|
||||
String comment,
|
||||
Map<String, Short> approvals,
|
||||
Map<String, Short> oldApprovals,
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.change.ChangeJson;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -93,23 +94,26 @@ public class EventUtil {
|
||||
return changeJson.getRevisionInfo(cd, ps);
|
||||
}
|
||||
|
||||
public AccountInfo accountInfo(Account a) {
|
||||
if (a == null || a.getId() == null) {
|
||||
public AccountInfo accountInfo(AccountState accountState) {
|
||||
if (accountState == null || accountState.getAccount().getId() == null) {
|
||||
return null;
|
||||
}
|
||||
AccountInfo accountInfo = new AccountInfo(a.getId().get());
|
||||
accountInfo.email = a.getPreferredEmail();
|
||||
accountInfo.name = a.getFullName();
|
||||
accountInfo.username = a.getUserName();
|
||||
Account account = accountState.getAccount();
|
||||
AccountInfo accountInfo = new AccountInfo(account.getId().get());
|
||||
accountInfo.email = account.getPreferredEmail();
|
||||
accountInfo.name = account.getFullName();
|
||||
accountInfo.username = accountState.getUserName();
|
||||
return accountInfo;
|
||||
}
|
||||
|
||||
public Map<String, ApprovalInfo> approvals(
|
||||
Account a, Map<String, Short> approvals, Timestamp ts) {
|
||||
AccountState accountState, Map<String, Short> approvals, Timestamp ts) {
|
||||
Map<String, ApprovalInfo> result = new HashMap<>();
|
||||
for (Map.Entry<String, Short> e : approvals.entrySet()) {
|
||||
Integer value = e.getValue() != null ? Integer.valueOf(e.getValue()) : null;
|
||||
result.put(e.getKey(), ChangeJson.getApprovalInfo(a.getId(), value, null, null, ts));
|
||||
result.put(
|
||||
e.getKey(),
|
||||
ChangeJson.getApprovalInfo(accountState.getAccount().getId(), value, null, null, ts));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.events.GitReferenceUpdatedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.inject.Inject;
|
||||
import org.eclipse.jgit.lib.BatchRefUpdate;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -34,10 +34,10 @@ public class GitReferenceUpdated {
|
||||
Project.NameKey project,
|
||||
RefUpdate refUpdate,
|
||||
ReceiveCommand.Type type,
|
||||
Account updater) {}
|
||||
AccountState updater) {}
|
||||
|
||||
@Override
|
||||
public void fire(Project.NameKey project, RefUpdate refUpdate, Account updater) {}
|
||||
public void fire(Project.NameKey project, RefUpdate refUpdate, AccountState updater) {}
|
||||
|
||||
@Override
|
||||
public void fire(
|
||||
@@ -45,13 +45,14 @@ public class GitReferenceUpdated {
|
||||
String ref,
|
||||
ObjectId oldObjectId,
|
||||
ObjectId newObjectId,
|
||||
Account updater) {}
|
||||
AccountState updater) {}
|
||||
|
||||
@Override
|
||||
public void fire(Project.NameKey project, ReceiveCommand cmd, Account updater) {}
|
||||
public void fire(Project.NameKey project, ReceiveCommand cmd, AccountState updater) {}
|
||||
|
||||
@Override
|
||||
public void fire(Project.NameKey project, BatchRefUpdate batchRefUpdate, Account updater) {}
|
||||
public void fire(
|
||||
Project.NameKey project, BatchRefUpdate batchRefUpdate, AccountState updater) {}
|
||||
};
|
||||
|
||||
private final DynamicSet<GitReferenceUpdatedListener> listeners;
|
||||
@@ -69,7 +70,10 @@ public class GitReferenceUpdated {
|
||||
}
|
||||
|
||||
public void fire(
|
||||
Project.NameKey project, RefUpdate refUpdate, ReceiveCommand.Type type, Account updater) {
|
||||
Project.NameKey project,
|
||||
RefUpdate refUpdate,
|
||||
ReceiveCommand.Type type,
|
||||
AccountState updater) {
|
||||
fire(
|
||||
project,
|
||||
refUpdate.getName(),
|
||||
@@ -79,7 +83,7 @@ public class GitReferenceUpdated {
|
||||
util.accountInfo(updater));
|
||||
}
|
||||
|
||||
public void fire(Project.NameKey project, RefUpdate refUpdate, Account updater) {
|
||||
public void fire(Project.NameKey project, RefUpdate refUpdate, AccountState updater) {
|
||||
fire(
|
||||
project,
|
||||
refUpdate.getName(),
|
||||
@@ -94,7 +98,7 @@ public class GitReferenceUpdated {
|
||||
String ref,
|
||||
ObjectId oldObjectId,
|
||||
ObjectId newObjectId,
|
||||
Account updater) {
|
||||
AccountState updater) {
|
||||
fire(
|
||||
project,
|
||||
ref,
|
||||
@@ -104,7 +108,7 @@ public class GitReferenceUpdated {
|
||||
util.accountInfo(updater));
|
||||
}
|
||||
|
||||
public void fire(Project.NameKey project, ReceiveCommand cmd, Account updater) {
|
||||
public void fire(Project.NameKey project, ReceiveCommand cmd, AccountState updater) {
|
||||
fire(
|
||||
project,
|
||||
cmd.getRefName(),
|
||||
@@ -114,7 +118,7 @@ public class GitReferenceUpdated {
|
||||
util.accountInfo(updater));
|
||||
}
|
||||
|
||||
public void fire(Project.NameKey project, BatchRefUpdate batchRefUpdate, Account updater) {
|
||||
public void fire(Project.NameKey project, BatchRefUpdate batchRefUpdate, AccountState updater) {
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.events.HashtagsEditedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import java.sql.Timestamp;
|
||||
@@ -44,7 +44,7 @@ public class HashtagsEdited {
|
||||
|
||||
public void fire(
|
||||
Change change,
|
||||
Account editor,
|
||||
AccountState editor,
|
||||
ImmutableSortedSet<String> hashtags,
|
||||
Set<String> added,
|
||||
Set<String> removed,
|
||||
|
||||
@@ -19,8 +19,8 @@ import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.events.PrivateStateChangedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import java.sql.Timestamp;
|
||||
@@ -39,8 +39,7 @@ public class PrivateStateChanged {
|
||||
this.util = util;
|
||||
}
|
||||
|
||||
public void fire(Change change, Account account, Timestamp when) {
|
||||
|
||||
public void fire(Change change, AccountState account, Timestamp when) {
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||
import com.google.gerrit.extensions.events.ReviewerAddedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -49,7 +49,11 @@ public class ReviewerAdded {
|
||||
}
|
||||
|
||||
public void fire(
|
||||
Change change, PatchSet patchSet, List<Account> reviewers, Account adder, Timestamp when) {
|
||||
Change change,
|
||||
PatchSet patchSet,
|
||||
List<AccountState> reviewers,
|
||||
AccountState adder,
|
||||
Timestamp when) {
|
||||
if (!listeners.iterator().hasNext() || reviewers.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||
import com.google.gerrit.extensions.events.ReviewerDeletedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -51,8 +51,8 @@ public class ReviewerDeleted {
|
||||
public void fire(
|
||||
Change change,
|
||||
PatchSet patchSet,
|
||||
Account reviewer,
|
||||
Account remover,
|
||||
AccountState reviewer,
|
||||
AccountState remover,
|
||||
String message,
|
||||
Map<String, Short> newApprovals,
|
||||
Map<String, Short> oldApprovals,
|
||||
|
||||
@@ -20,10 +20,10 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||
import com.google.gerrit.extensions.events.RevisionCreatedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -47,7 +47,11 @@ public class RevisionCreated {
|
||||
}
|
||||
|
||||
public void fire(
|
||||
Change change, PatchSet patchSet, Account uploader, Timestamp when, NotifyHandling notify) {
|
||||
Change change,
|
||||
PatchSet patchSet,
|
||||
AccountState uploader,
|
||||
Timestamp when,
|
||||
NotifyHandling notify) {
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.events.TopicEditedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import java.sql.Timestamp;
|
||||
@@ -39,7 +39,7 @@ public class TopicEdited {
|
||||
this.util = util;
|
||||
}
|
||||
|
||||
public void fire(Change change, Account account, String oldTopicName, Timestamp when) {
|
||||
public void fire(Change change, AccountState account, String oldTopicName, Timestamp when) {
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||
import com.google.gerrit.extensions.events.VoteDeletedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.GpgException;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -51,12 +51,12 @@ public class VoteDeleted {
|
||||
public void fire(
|
||||
Change change,
|
||||
PatchSet ps,
|
||||
Account reviewer,
|
||||
AccountState reviewer,
|
||||
Map<String, Short> approvals,
|
||||
Map<String, Short> oldApprovals,
|
||||
NotifyHandling notify,
|
||||
String message,
|
||||
Account remover,
|
||||
AccountState remover,
|
||||
Timestamp when) {
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
|
||||
@@ -19,8 +19,8 @@ import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.events.WorkInProgressStateChangedListener;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import java.sql.Timestamp;
|
||||
@@ -40,8 +40,7 @@ public class WorkInProgressStateChanged {
|
||||
this.util = util;
|
||||
}
|
||||
|
||||
public void fire(Change change, Account account, Timestamp when) {
|
||||
|
||||
public void fire(Change change, AccountState account, Timestamp when) {
|
||||
if (!listeners.iterator().hasNext()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -262,6 +262,6 @@ public class MetaDataUpdate implements AutoCloseable {
|
||||
}
|
||||
|
||||
protected void fireGitRefUpdatedEvent(RefUpdate ru) {
|
||||
gitRefUpdated.fire(projectName, ru, author == null ? null : author.getAccount());
|
||||
gitRefUpdated.fire(projectName, ru, author == null ? null : author.state());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,7 +497,7 @@ public class ReplaceOp implements BatchUpdateOp {
|
||||
try {
|
||||
ReplacePatchSetSender cm =
|
||||
replacePatchSetFactory.create(projectState.getNameKey(), notes.getChangeId());
|
||||
cm.setFrom(ctx.getAccount().getId());
|
||||
cm.setFrom(ctx.getAccount().getAccount().getId());
|
||||
cm.setPatchSet(newPatchSet, info);
|
||||
cm.setChangeMessage(msg.getMessage(), ctx.getWhen());
|
||||
if (magicBranch != null) {
|
||||
|
||||
@@ -553,7 +553,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
|
||||
args.changeMerged.fire(
|
||||
updatedChange,
|
||||
mergedPatchSet,
|
||||
args.accountCache.get(submitter.getAccountId()).getAccount(),
|
||||
args.accountCache.get(submitter.getAccountId()),
|
||||
args.mergeTip.getCurrentTip().name(),
|
||||
ctx.getWhen());
|
||||
}
|
||||
|
||||
@@ -612,7 +612,7 @@ public class GroupsUpdate {
|
||||
|
||||
RefUpdateUtil.executeChecked(batchRefUpdate, allUsersRepo);
|
||||
gitRefUpdated.fire(
|
||||
allUsersName, batchRefUpdate, currentUser != null ? currentUser.getAccount() : null);
|
||||
allUsersName, batchRefUpdate, currentUser != null ? currentUser.state() : null);
|
||||
}
|
||||
|
||||
private void updateCachesOnGroupCreation(InternalGroup createdGroup) throws IOException {
|
||||
|
||||
@@ -18,7 +18,6 @@ import com.google.gerrit.extensions.auth.oauth.OAuthToken;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import com.google.gerrit.server.auth.oauth.OAuthTokenCache;
|
||||
@@ -57,13 +56,12 @@ class GetOAuthToken implements RestReadView<AccountResource> {
|
||||
if (self.get() != rsrc.getUser()) {
|
||||
throw new AuthException("not allowed to get access token");
|
||||
}
|
||||
Account a = rsrc.getUser().getAccount();
|
||||
OAuthToken accessToken = tokenCache.get(a.getId());
|
||||
OAuthToken accessToken = tokenCache.get(rsrc.getUser().getAccountId());
|
||||
if (accessToken == null) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
OAuthTokenInfo accessTokenInfo = new OAuthTokenInfo();
|
||||
accessTokenInfo.username = a.getUserName();
|
||||
accessTokenInfo.username = rsrc.getUser().state().getUserName();
|
||||
accessTokenInfo.resourceHost = getHostName(canonicalWebUrlProvider.get());
|
||||
accessTokenInfo.accessToken = accessToken.getToken();
|
||||
accessTokenInfo.providerId = accessToken.getProviderId();
|
||||
|
||||
@@ -28,7 +28,7 @@ public class GetUsername implements RestReadView<AccountResource> {
|
||||
|
||||
@Override
|
||||
public String apply(AccountResource rsrc) throws AuthException, ResourceNotFoundException {
|
||||
String username = rsrc.getUser().getAccount().getUserName();
|
||||
String username = rsrc.getUser().state().getUserName();
|
||||
if (username == null) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.extensions.events.AgreementSignup;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
@@ -92,13 +92,13 @@ public class PutAgreement implements RestModifyView<AccountResource, AgreementIn
|
||||
throw new ResourceConflictException("autoverify group uuid not found");
|
||||
}
|
||||
|
||||
Account account = self.get().getAccount();
|
||||
AccountState accountState = self.get().state();
|
||||
try {
|
||||
addMembers.addMembers(uuid, ImmutableSet.of(account.getId()));
|
||||
addMembers.addMembers(uuid, ImmutableSet.of(accountState.getAccount().getId()));
|
||||
} catch (NoSuchGroupException e) {
|
||||
throw new ResourceConflictException("autoverify group not found");
|
||||
}
|
||||
agreementSignup.fire(account, agreementName);
|
||||
agreementSignup.fire(accountState, agreementName);
|
||||
|
||||
return Response.ok(agreementName);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.change.AbandonOp;
|
||||
import com.google.gerrit.server.change.ChangeJson;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
@@ -123,8 +124,8 @@ public class Abandon extends RetryingRestModifyView<ChangeResource, AbandonInput
|
||||
NotifyHandling notifyHandling,
|
||||
ListMultimap<RecipientType, Account.Id> accountsToNotify)
|
||||
throws RestApiException, UpdateException {
|
||||
Account account = user.isIdentifiedUser() ? user.asIdentifiedUser().getAccount() : null;
|
||||
AbandonOp op = abandonOpFactory.create(account, msgTxt, notifyHandling, accountsToNotify);
|
||||
AccountState accountState = user.isIdentifiedUser() ? user.asIdentifiedUser().state() : null;
|
||||
AbandonOp op = abandonOpFactory.create(accountState, msgTxt, notifyHandling, accountsToNotify);
|
||||
try (BatchUpdate u =
|
||||
updateFactory.create(dbProvider.get(), notes.getProjectName(), user, TimeUtil.nowTs())) {
|
||||
u.addOp(notes.getChangeId(), op).execute();
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountLoader;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.extensions.events.AssigneeChanged;
|
||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||
@@ -89,7 +90,7 @@ public class DeleteAssignee
|
||||
|
||||
private class Op implements BatchUpdateOp {
|
||||
private Change change;
|
||||
private Account deletedAssignee;
|
||||
private AccountState deletedAssignee;
|
||||
|
||||
@Override
|
||||
public boolean updateChange(ChangeContext ctx) throws RestApiException, OrmException {
|
||||
@@ -100,7 +101,7 @@ public class DeleteAssignee
|
||||
return false;
|
||||
}
|
||||
IdentifiedUser deletedAssigneeUser = userFactory.create(currentAssigneeId);
|
||||
deletedAssignee = deletedAssigneeUser.getAccount();
|
||||
deletedAssignee = deletedAssigneeUser.state();
|
||||
// noteDb
|
||||
update.removeAssignee();
|
||||
// reviewDb
|
||||
@@ -110,7 +111,7 @@ public class DeleteAssignee
|
||||
}
|
||||
|
||||
public Account.Id getDeletedAssignee() {
|
||||
return deletedAssignee != null ? deletedAssignee.getId() : null;
|
||||
return deletedAssignee != null ? deletedAssignee.getAccount().getId() : null;
|
||||
}
|
||||
|
||||
private void addMessage(ChangeContext ctx, ChangeUpdate update, IdentifiedUser deletedAssignee)
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DeleteReviewer
|
||||
if (rsrc.isByEmail()) {
|
||||
op = deleteReviewerByEmailOpFactory.create(rsrc.getReviewerByEmail(), input);
|
||||
} else {
|
||||
op = deleteReviewerOpFactory.create(rsrc.getReviewerUser().getAccount(), input);
|
||||
op = deleteReviewerOpFactory.create(rsrc.getReviewerUser().state(), input);
|
||||
}
|
||||
bu.addOp(rsrc.getChange().getId(), op);
|
||||
bu.execute();
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.google.gerrit.server.ApprovalsUtil;
|
||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.PatchSetUtil;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.change.NotifyUtil;
|
||||
import com.google.gerrit.server.extensions.events.ReviewerDeleted;
|
||||
import com.google.gerrit.server.mail.send.DeleteReviewerSender;
|
||||
@@ -63,7 +64,7 @@ public class DeleteReviewerOp implements BatchUpdateOp {
|
||||
private static final Logger log = LoggerFactory.getLogger(DeleteReviewerOp.class);
|
||||
|
||||
public interface Factory {
|
||||
DeleteReviewerOp create(Account reviewerAccount, DeleteReviewerInput input);
|
||||
DeleteReviewerOp create(AccountState reviewerAccount, DeleteReviewerInput input);
|
||||
}
|
||||
|
||||
private final ApprovalsUtil approvalsUtil;
|
||||
@@ -78,7 +79,7 @@ public class DeleteReviewerOp implements BatchUpdateOp {
|
||||
private final RemoveReviewerControl removeReviewerControl;
|
||||
private final ProjectCache projectCache;
|
||||
|
||||
private final Account reviewer;
|
||||
private final AccountState reviewer;
|
||||
private final DeleteReviewerInput input;
|
||||
|
||||
ChangeMessage changeMessage;
|
||||
@@ -100,7 +101,7 @@ public class DeleteReviewerOp implements BatchUpdateOp {
|
||||
NotifyUtil notifyUtil,
|
||||
RemoveReviewerControl removeReviewerControl,
|
||||
ProjectCache projectCache,
|
||||
@Assisted Account reviewerAccount,
|
||||
@Assisted AccountState reviewerAccount,
|
||||
@Assisted DeleteReviewerInput input) {
|
||||
this.approvalsUtil = approvalsUtil;
|
||||
this.psUtil = psUtil;
|
||||
@@ -121,7 +122,7 @@ public class DeleteReviewerOp implements BatchUpdateOp {
|
||||
public boolean updateChange(ChangeContext ctx)
|
||||
throws AuthException, ResourceNotFoundException, OrmException, PermissionBackendException,
|
||||
IOException {
|
||||
Account.Id reviewerId = reviewer.getId();
|
||||
Account.Id reviewerId = reviewer.getAccount().getId();
|
||||
// Check of removing this reviewer (even if there is no vote processed by the loop below) is OK
|
||||
removeReviewerControl.checkRemoveReviewer(ctx.getNotes(), ctx.getUser(), reviewerId);
|
||||
|
||||
@@ -139,7 +140,7 @@ public class DeleteReviewerOp implements BatchUpdateOp {
|
||||
}
|
||||
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Removed reviewer " + reviewer.getFullName());
|
||||
msg.append("Removed reviewer " + reviewer.getAccount().getFullName());
|
||||
StringBuilder removedVotesMsg = new StringBuilder();
|
||||
removedVotesMsg.append(" with the following votes:\n\n");
|
||||
List<PatchSetApproval> del = new ArrayList<>();
|
||||
@@ -234,14 +235,14 @@ public class DeleteReviewerOp implements BatchUpdateOp {
|
||||
private void emailReviewers(
|
||||
Project.NameKey projectName, Change change, ChangeMessage changeMessage) {
|
||||
Account.Id userId = user.get().getAccountId();
|
||||
if (userId.equals(reviewer.getId())) {
|
||||
if (userId.equals(reviewer.getAccount().getId())) {
|
||||
// The user knows they removed themselves, don't bother emailing them.
|
||||
return;
|
||||
}
|
||||
try {
|
||||
DeleteReviewerSender cm = deleteReviewerSenderFactory.create(projectName, change.getId());
|
||||
cm.setFrom(userId);
|
||||
cm.addReviewers(Collections.singleton(reviewer.getId()));
|
||||
cm.addReviewers(Collections.singleton(reviewer.getAccount().getId()));
|
||||
cm.setChangeMessage(changeMessage.getMessage(), changeMessage.getWrittenOn());
|
||||
cm.setNotify(input.notify);
|
||||
cm.setAccountsToNotify(notifyUtil.resolveAccounts(input.notifyDetails));
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.google.gerrit.server.ApprovalsUtil;
|
||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.PatchSetUtil;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.change.NotifyUtil;
|
||||
import com.google.gerrit.server.change.ReviewerResource;
|
||||
import com.google.gerrit.server.change.VoteResource;
|
||||
@@ -134,7 +135,7 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
|
||||
change.getId(),
|
||||
new Op(
|
||||
projectCache.checkedGet(r.getChange().getProject()),
|
||||
r.getReviewerUser().getAccount(),
|
||||
r.getReviewerUser().state(),
|
||||
rsrc.getLabel(),
|
||||
input));
|
||||
bu.execute();
|
||||
@@ -145,7 +146,7 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
|
||||
|
||||
private class Op implements BatchUpdateOp {
|
||||
private final ProjectState projectState;
|
||||
private final Account account;
|
||||
private final AccountState accountState;
|
||||
private final String label;
|
||||
private final DeleteVoteInput input;
|
||||
|
||||
@@ -155,9 +156,10 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
|
||||
private Map<String, Short> newApprovals = new HashMap<>();
|
||||
private Map<String, Short> oldApprovals = new HashMap<>();
|
||||
|
||||
private Op(ProjectState projectState, Account account, String label, DeleteVoteInput input) {
|
||||
private Op(
|
||||
ProjectState projectState, AccountState accountState, String label, DeleteVoteInput input) {
|
||||
this.projectState = projectState;
|
||||
this.account = account;
|
||||
this.accountState = accountState;
|
||||
this.label = label;
|
||||
this.input = input;
|
||||
}
|
||||
@@ -173,13 +175,15 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
|
||||
boolean found = false;
|
||||
LabelTypes labelTypes = projectState.getLabelTypes(ctx.getNotes(), ctx.getUser());
|
||||
|
||||
Account.Id accountId = accountState.getAccount().getId();
|
||||
|
||||
for (PatchSetApproval a :
|
||||
approvalsUtil.byPatchSetUser(
|
||||
ctx.getDb(),
|
||||
ctx.getNotes(),
|
||||
ctx.getUser(),
|
||||
psId,
|
||||
account.getId(),
|
||||
accountId,
|
||||
ctx.getRevWalk(),
|
||||
ctx.getRepoView().getConfig())) {
|
||||
if (labelTypes.byLabel(a.getLabelId()) == null) {
|
||||
@@ -207,13 +211,13 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
ctx.getUpdate(psId).removeApprovalFor(account.getId(), label);
|
||||
ctx.getUpdate(psId).removeApprovalFor(accountId, label);
|
||||
ctx.getDb().patchSetApprovals().upsert(Collections.singleton(deletedApproval(ctx)));
|
||||
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Removed ");
|
||||
LabelVote.appendTo(msg, label, checkNotNull(oldApprovals.get(label)));
|
||||
msg.append(" by ").append(userFactory.create(account.getId()).getNameEmail()).append("\n");
|
||||
msg.append(" by ").append(userFactory.create(accountId).getNameEmail()).append("\n");
|
||||
changeMessage =
|
||||
ChangeMessagesUtil.newMessage(ctx, msg.toString(), ChangeMessagesUtil.TAG_DELETE_VOTE);
|
||||
cmUtil.addChangeMessage(ctx.getDb(), ctx.getUpdate(psId), changeMessage);
|
||||
@@ -226,7 +230,8 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
|
||||
// set the real user; this preserves the calling user as the NoteDb
|
||||
// committer.
|
||||
return new PatchSetApproval(
|
||||
new PatchSetApproval.Key(ps.getId(), account.getId(), new LabelId(label)),
|
||||
new PatchSetApproval.Key(
|
||||
ps.getId(), accountState.getAccount().getId(), new LabelId(label)),
|
||||
(short) 0,
|
||||
ctx.getWhen());
|
||||
}
|
||||
@@ -254,12 +259,12 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
|
||||
voteDeleted.fire(
|
||||
change,
|
||||
ps,
|
||||
account,
|
||||
accountState,
|
||||
newApprovals,
|
||||
oldApprovals,
|
||||
input.notify,
|
||||
changeMessage.getMessage(),
|
||||
user.getAccount(),
|
||||
user.state(),
|
||||
ctx.getWhen());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -873,7 +873,7 @@ public class PostReview
|
||||
commentAdded.fire(
|
||||
notes.getChange(),
|
||||
ps,
|
||||
user.getAccount(),
|
||||
user.state(),
|
||||
message.getMessage(),
|
||||
approvals,
|
||||
oldApprovals,
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.google.gerrit.server.ApprovalsUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.PatchSetUtil;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.extensions.events.ReviewerAdded;
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
@@ -202,11 +203,8 @@ public class PostReviewersOp implements BatchUpdateOp {
|
||||
notify,
|
||||
accountsToNotify);
|
||||
if (!addedReviewers.isEmpty()) {
|
||||
List<Account> reviewers =
|
||||
addedReviewers
|
||||
.stream()
|
||||
.map(r -> accountCache.get(r.getAccountId()).getAccount())
|
||||
.collect(toList());
|
||||
List<AccountState> reviewers =
|
||||
addedReviewers.stream().map(r -> accountCache.get(r.getAccountId())).collect(toList());
|
||||
reviewerAdded.fire(rsrc.getChange(), patchSet, reviewers, ctx.getAccount(), ctx.getWhen());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,10 +141,7 @@ public class CreateBranch implements RestModifyView<ProjectResource, BranchInput
|
||||
case NEW:
|
||||
case NO_CHANGE:
|
||||
referenceUpdated.fire(
|
||||
name.getParentKey(),
|
||||
u,
|
||||
ReceiveCommand.Type.CREATE,
|
||||
identifiedUser.get().getAccount());
|
||||
name.getParentKey(), u, ReceiveCommand.Type.CREATE, identifiedUser.get().state());
|
||||
break;
|
||||
case LOCK_FAILURE:
|
||||
if (repo.getRefDatabase().exactRef(ref) != null) {
|
||||
|
||||
@@ -350,7 +350,7 @@ public class CreateProject implements RestModifyView<TopLevelResource, ProjectIn
|
||||
switch (result) {
|
||||
case NEW:
|
||||
referenceUpdated.fire(
|
||||
project, ru, ReceiveCommand.Type.CREATE, identifiedUser.get().getAccount());
|
||||
project, ru, ReceiveCommand.Type.CREATE, identifiedUser.get().state());
|
||||
break;
|
||||
case FAST_FORWARD:
|
||||
case FORCED:
|
||||
|
||||
@@ -145,7 +145,7 @@ public class CreateTag implements RestModifyView<ProjectResource, TagInput> {
|
||||
ref,
|
||||
ObjectId.zeroId(),
|
||||
result.getObjectId(),
|
||||
identifiedUser.get().getAccount());
|
||||
identifiedUser.get().state());
|
||||
try (RevWalk w = new RevWalk(repo)) {
|
||||
return ListTags.createTagInfo(perm, result, w, resource.getProjectState(), links);
|
||||
}
|
||||
|
||||
@@ -157,10 +157,7 @@ public class DeleteRef {
|
||||
case FAST_FORWARD:
|
||||
case FORCED:
|
||||
referenceUpdated.fire(
|
||||
resource.getNameKey(),
|
||||
u,
|
||||
ReceiveCommand.Type.DELETE,
|
||||
identifiedUser.get().getAccount());
|
||||
resource.getNameKey(), u, ReceiveCommand.Type.DELETE, identifiedUser.get().state());
|
||||
break;
|
||||
|
||||
case REJECTED_CURRENT_BRANCH:
|
||||
@@ -280,6 +277,6 @@ public class DeleteRef {
|
||||
}
|
||||
|
||||
private void postDeletion(ProjectResource project, ReceiveCommand cmd) {
|
||||
referenceUpdated.fire(project.getNameKey(), cmd, identifiedUser.get().getAccount());
|
||||
referenceUpdated.fire(project.getNameKey(), cmd, identifiedUser.get().state());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ import com.google.gerrit.extensions.config.FactoryModule;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.validators.OnSubmitValidators;
|
||||
import com.google.gerrit.server.notedb.NotesMigration;
|
||||
@@ -347,9 +347,9 @@ public abstract class BatchUpdate implements AutoCloseable {
|
||||
return user;
|
||||
}
|
||||
|
||||
protected Optional<Account> getAccount() {
|
||||
protected Optional<AccountState> getAccount() {
|
||||
return user.isIdentifiedUser()
|
||||
? Optional.of(user.asIdentifiedUser().getAccount())
|
||||
? Optional.of(user.asIdentifiedUser().state())
|
||||
: Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.TimeZone;
|
||||
@@ -122,8 +123,8 @@ public interface Context {
|
||||
* @see CurrentUser#asIdentifiedUser()
|
||||
* @return account.
|
||||
*/
|
||||
default Account getAccount() {
|
||||
return getIdentifiedUser().getAccount();
|
||||
default AccountState getAccount() {
|
||||
return getIdentifiedUser().state();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -320,7 +320,7 @@ public abstract class BaseCommand implements Command {
|
||||
if (user.isIdentifiedUser()) {
|
||||
final IdentifiedUser u = user.asIdentifiedUser();
|
||||
m.append(" (user ");
|
||||
m.append(u.getAccount().getUserName());
|
||||
m.append(u.state().getUserName());
|
||||
m.append(" account ");
|
||||
m.append(u.getAccountId());
|
||||
m.append(")");
|
||||
@@ -381,7 +381,7 @@ public abstract class BaseCommand implements Command {
|
||||
m.append(getTaskDescription());
|
||||
if (user.isIdentifiedUser()) {
|
||||
IdentifiedUser u = user.asIdentifiedUser();
|
||||
m.append(" (").append(u.getAccount().getUserName()).append(")");
|
||||
m.append(" (").append(u.state().getUserName()).append(")");
|
||||
}
|
||||
return m.toString();
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ class SshLog implements LifecycleListener {
|
||||
|
||||
if (user != null && user.isIdentifiedUser()) {
|
||||
IdentifiedUser u = user.asIdentifiedUser();
|
||||
userName = u.getAccount().getUserName();
|
||||
userName = u.state().getUserName();
|
||||
accountId = "a/" + u.getAccountId().toString();
|
||||
|
||||
} else if (user instanceof PeerDaemonUser) {
|
||||
|
||||
@@ -116,7 +116,7 @@ final class Receive extends AbstractGitCommand {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Receive error on project \"").append(projectState.getName()).append("\"");
|
||||
msg.append(" (user ");
|
||||
msg.append(currentUser.getAccount().getUserName());
|
||||
msg.append(currentUser.state().getUserName());
|
||||
msg.append(" account ");
|
||||
msg.append(currentUser.getAccountId());
|
||||
msg.append("): ");
|
||||
|
||||
@@ -203,7 +203,7 @@ final class ShowConnections extends SshCommand {
|
||||
IdentifiedUser u = user.asIdentifiedUser();
|
||||
|
||||
if (!numeric) {
|
||||
String name = u.getAccount().getUserName();
|
||||
String name = u.state().getUserName();
|
||||
if (name != null && !name.isEmpty()) {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ final class StreamEvents extends BaseCommand {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Stream Events (" + currentUser.getAccount().getUserName() + ")";
|
||||
return "Stream Events (" + currentUser.state().getUserName() + ")";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -28,11 +28,9 @@ import java.util.Optional;
|
||||
/** Fake implementation of {@link AccountCache} for testing. */
|
||||
public class FakeAccountCache implements AccountCache {
|
||||
private final Map<Account.Id, AccountState> byId;
|
||||
private final Map<String, AccountState> byUsername;
|
||||
|
||||
public FakeAccountCache() {
|
||||
byId = new HashMap<>();
|
||||
byUsername = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,7 +49,7 @@ public class FakeAccountCache implements AccountCache {
|
||||
|
||||
@Override
|
||||
public synchronized Optional<AccountState> getByUsername(String username) {
|
||||
return Optional.ofNullable(byUsername.get(username));
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,15 +62,11 @@ public class FakeAccountCache implements AccountCache {
|
||||
@Override
|
||||
public synchronized void evictAllNoReindex() {
|
||||
byId.clear();
|
||||
byUsername.clear();
|
||||
}
|
||||
|
||||
public synchronized void put(Account account) {
|
||||
AccountState state = newState(account);
|
||||
byId.put(account.getId(), state);
|
||||
if (account.getUserName() != null) {
|
||||
byUsername.put(account.getUserName(), state);
|
||||
}
|
||||
}
|
||||
|
||||
private static AccountState newState(Account account) {
|
||||
|
||||
Reference in New Issue
Block a user