Add realAuthor to ChangeMessageInfo
Currently, change messages posted on behalf of another user lead to confusion when they are displayed in the UI. One example is that the CI removes a user's vote on behalf of them. This makes it look like they removed it themselves which is not intended. The new realAuthor field will let the UI display this in a more understandable way for the user. Change-Id: I9080ae3ed7aaa9b61501c093cee3dd7f02768d49
This commit is contained in:
parent
0f839a42f8
commit
9221ef1a3e
@ -5300,6 +5300,10 @@ attached to a change.
|
||||
Author of the message as an
|
||||
link:rest-api-accounts.html#account-info[AccountInfo] entity. +
|
||||
Unset if written by the Gerrit system.
|
||||
|`real_author` |optional|
|
||||
Real author of the message as an
|
||||
link:rest-api-accounts.html#account-info[AccountInfo] entity. +
|
||||
Set if the message was posted on behalf of another user.
|
||||
|`date` ||
|
||||
The link:rest-api.html#timestamp[timestamp] this message was posted.
|
||||
|`message` ||The text left by the user.
|
||||
|
@ -39,8 +39,10 @@ import com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput;
|
||||
import com.google.gerrit.extensions.api.changes.RevisionApi;
|
||||
import com.google.gerrit.extensions.api.changes.SubmitInput;
|
||||
import com.google.gerrit.extensions.api.groups.GroupInput;
|
||||
import com.google.gerrit.extensions.client.ListChangesOption;
|
||||
import com.google.gerrit.extensions.client.Side;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeMessageInfo;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.common.GroupInfo;
|
||||
@ -62,6 +64,7 @@ import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.project.Util;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.EnumSet;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.junit.After;
|
||||
@ -529,6 +532,28 @@ public class ImpersonationIT extends AbstractDaemonTest {
|
||||
assertThat(m.getRealAuthor()).isEqualTo(admin.id); // not user2
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeMessageCreatedOnBehalfOfHasRealUser() throws Exception {
|
||||
allowCodeReviewOnBehalfOf();
|
||||
|
||||
PushOneCommit.Result r = createChange();
|
||||
ReviewInput in = new ReviewInput();
|
||||
in.onBehalfOf = user.id.toString();
|
||||
in.message = "Message on behalf of";
|
||||
in.label("Code-Review", 1);
|
||||
|
||||
setApiUser(accounts.user2());
|
||||
gApi.changes().id(r.getChangeId()).revision(r.getPatchSetId().getId()).review(in);
|
||||
|
||||
ChangeInfo info =
|
||||
gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.MESSAGES));
|
||||
assertThat(info.messages).hasSize(2);
|
||||
|
||||
ChangeMessageInfo changeMessageInfo = Iterables.getLast(info.messages);
|
||||
assertThat(changeMessageInfo.realAuthor).isNotNull();
|
||||
assertThat(changeMessageInfo.realAuthor._accountId).isEqualTo(accounts.user2().id.get());
|
||||
}
|
||||
|
||||
private void allowCodeReviewOnBehalfOf() throws Exception {
|
||||
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
|
||||
LabelType codeReviewType = Util.codeReview();
|
||||
|
@ -20,6 +20,7 @@ public class ChangeMessageInfo {
|
||||
public String id;
|
||||
public String tag;
|
||||
public AccountInfo author;
|
||||
public AccountInfo realAuthor;
|
||||
public Timestamp date;
|
||||
public String message;
|
||||
public Integer _revisionNumber;
|
||||
|
@ -1030,6 +1030,10 @@ public class ChangeJson {
|
||||
cmi.message = message.getMessage();
|
||||
cmi.tag = message.getTag();
|
||||
cmi._revisionNumber = patchNum != null ? patchNum.get() : null;
|
||||
Account.Id realAuthor = message.getRealAuthor();
|
||||
if (realAuthor != null) {
|
||||
cmi.realAuthor = accountLoader.get(realAuthor);
|
||||
}
|
||||
result.add(cmi);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user