use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class ThreadLocalRequestContext method module.
public static Module module() {
return new AbstractModule() {
@Override
protected void configure() {
bind(ThreadLocalRequestContext.class);
bind(RequestContext.class).annotatedWith(Names.named(FALLBACK)).to(FallbackRequestContext.class);
}
@Provides
RequestContext provideRequestContext(@Named(FALLBACK) RequestContext fallback) {
return MoreObjects.firstNonNull(local.get(), fallback);
}
@Provides
CurrentUser provideCurrentUser(RequestContext ctx) {
return ctx.getUser();
}
@Provides
IdentifiedUser provideCurrentUser(CurrentUser user) {
if (user.isIdentifiedUser()) {
return user.asIdentifiedUser();
}
throw new ProvisionException(NotSignedInException.MESSAGE, new NotSignedInException());
}
};
}
use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class ChangeNotesTest method copiedApprovals_withRealUserAndTag_keepsUUID.
@Test
public void copiedApprovals_withRealUserAndTag_keepsUUID() throws Exception {
ImmutableList<String> strangeTags = ImmutableList.of(", ", ":\"", ",", "!@#$%^\0&*):\" \n: \r\"#$@,. :");
for (String strangeTag : strangeTags) {
Change c = newChange();
CurrentUser otherUserAsOwner = userFactory.runAs(null, changeOwner.getAccountId(), otherUser);
ChangeUpdate update = newUpdate(c, otherUserAsOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) 2);
update.setTag(strangeTag);
update.commit();
ChangeNotes notes = newNotes(c);
PatchSetApproval originalPsa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
assertThat(originalPsa.accountId()).isEqualTo(changeOwner.getAccountId());
assertThat(originalPsa.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(originalPsa.value()).isEqualTo(2);
assertThat(originalPsa.tag()).hasValue(NoteDbUtil.sanitizeFooter(strangeTag));
assertThat(originalPsa.realAccountId()).isEqualTo(otherUserId);
assertParsedUuid(originalPsa);
// Copied approvals are persisted at the patch set upload, add new patch set
incrementPatchSet(c);
addCopiedApproval(c, changeOwner, originalPsa);
notes = newNotes(c);
assertThat(notes.getApprovalsWithCopied().keySet()).hasSize(2);
PatchSetApproval copiedApproval = Iterables.getOnlyElement(notes.getApprovalsWithCopied().get(c.currentPatchSetId()).stream().filter(a -> a.copied()).collect(toImmutableList()));
PatchSetApproval nonCopiedApproval = Iterables.getOnlyElement(notes.getApprovalsWithCopied().get(originalPsa.patchSetId()).stream().filter(a -> !a.copied()).collect(toImmutableList()));
// Still same original PSA is returned
assertThat(nonCopiedApproval).isEqualTo(originalPsa);
// The copied approval matches the original approval, including UUID
assertCopiedApproval(originalPsa, copiedApproval);
}
}
use of com.google.gerrit.server.CurrentUser in project gerrit by GerritCodeReview.
the class ChangeNotesTest method realUser.
@Test
public void realUser() throws Exception {
Change c = newChange();
CurrentUser ownerAsOtherUser = userFactory.runAs(null, otherUserId, changeOwner);
ChangeUpdate update = newUpdate(c, ownerAsOtherUser);
update.setChangeMessage("Message on behalf of other user");
update.commit();
ChangeMessage msg = Iterables.getLast(newNotes(c).getChangeMessages());
assertThat(msg.getMessage()).isEqualTo("Message on behalf of other user");
assertThat(msg.getAuthor()).isEqualTo(otherUserId);
assertThat(msg.getRealAuthor()).isEqualTo(changeOwner.getAccountId());
}
Aggregations