use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class AbstractChangeNotesTest method setUpTestEnvironment.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Before
public void setUpTestEnvironment() throws Exception {
setTimeForTesting();
serverIdent = new PersonIdent("Gerrit Server", "noreply@gerrit.com", Date.from(TimeUtil.now()), TZ);
project = Project.nameKey("test-project");
repoManager = new InMemoryRepositoryManager();
repo = repoManager.createRepository(project);
tr = new TestRepository<>(repo);
rw = tr.getRevWalk();
accountCache = new FakeAccountCache();
Account.Builder co = Account.builder(Account.id(1), TimeUtil.now());
co.setFullName("Change Owner");
co.setPreferredEmail("change@owner.com");
accountCache.put(co.build());
Account.Builder ou = Account.builder(Account.id(2), TimeUtil.now());
ou.setFullName("Other Account");
ou.setPreferredEmail("other@account.com");
accountCache.put(ou.build());
assertableFanOutExecutor = new AssertableExecutorService();
injector = Guice.createInjector(new FactoryModule() {
@Override
public void configure() {
install(new GitModule());
install(new DefaultUrlFormatterModule());
install(NoteDbModule.forTest());
bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
bind(String.class).annotatedWith(GerritServerId.class).toInstance("gerrit");
bind(GitRepositoryManager.class).toInstance(repoManager);
bind(ProjectCache.class).to(NullProjectCache.class);
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(testConfig);
bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
bind(String.class).annotatedWith(CanonicalWebUrl.class).toInstance("http://localhost:8080/");
bind(Boolean.class).annotatedWith(EnablePeerIPInReflogRecord.class).toInstance(Boolean.FALSE);
bind(Realm.class).to(FakeRealm.class);
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
bind(AccountCache.class).toInstance(accountCache);
bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toInstance(serverIdent);
bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
bind(MetricMaker.class).to(DisabledMetricMaker.class);
bind(ExecutorService.class).annotatedWith(FanOutExecutor.class).toInstance(assertableFanOutExecutor);
bind(ServiceUserClassifier.class).to(ServiceUserClassifier.NoOp.class);
bind(InternalChangeQuery.class).toProvider(() -> {
throw new UnsupportedOperationException();
});
bind(PatchSetApprovalUuidGenerator.class).to(TestPatchSetApprovalUuidGenerator.class);
}
});
injector.injectMembers(this);
repoManager.createRepository(allUsers);
changeOwner = userFactory.create(co.id());
otherUser = userFactory.create(ou.id());
otherUserId = otherUser.getAccountId();
internalUser = new InternalUser();
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class ChangeNotesTest method patchLineCommentNotesFormatWeirdUser.
@Test
public void patchLineCommentNotesFormatWeirdUser() throws Exception {
Account.Builder account = Account.builder(Account.id(3), TimeUtil.now());
account.setFullName("Weird\n\u0002<User>\n");
account.setPreferredEmail(" we\r\nird@ex>ample<.com");
accountCache.put(account.build());
IdentifiedUser user = userFactory.create(Account.id(3));
Change c = newChange();
ChangeUpdate update = newUpdate(c, user);
String uuid = "uuid";
CommentRange range = new CommentRange(1, 1, 2, 1);
Instant time = TimeUtil.now();
PatchSet.Id psId = c.currentPatchSetId();
HumanComment comment = newComment(psId, "file1", uuid, range, range.getEndLine(), user, null, time, "comment", (short) 1, ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"), false);
update.setPatchSetId(psId);
update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit();
ChangeNotes notes = newNotes(c);
assertThat(notes.getHumanComments()).isEqualTo(ImmutableListMultimap.of(comment.getCommitId(), comment));
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class ChangeUpdate method updateAttentionSet.
/**
* Any updates to the attention set must be done in {@link #addToPlannedAttentionSetUpdates}. This
* method is called after all the updates are finished to do the updates once and for real.
*
* <p>Changing the behaviour of this method might affect the way a ChangeUpdate is considered to
* be an "Attention Set Change Only". Make sure the {@link #isAttentionSetChangeOnly} logic is
* amended as well if needed.
*/
private void updateAttentionSet(StringBuilder msg) {
if (plannedAttentionSetUpdates == null) {
plannedAttentionSetUpdates = new HashMap<>();
}
Set<Account.Id> currentUsersInAttentionSet = AttentionSetUtil.additionsOnly(getNotes().getAttentionSet()).stream().map(AttentionSetUpdate::account).collect(Collectors.toSet());
// Current reviewers/ccs are the reviewers/ccs before the update + the new reviewers/ccs - the
// deleted reviewers/ccs.
Set<Account.Id> currentReviewers = Stream.concat(getNotes().getReviewers().all().stream(), reviewers.entrySet().stream().filter(r -> r.getValue().asReviewerState() != ReviewerState.REMOVED).map(r -> r.getKey())).collect(Collectors.toSet());
currentReviewers.removeAll(reviewers.entrySet().stream().filter(r -> r.getValue().asReviewerState() == ReviewerState.REMOVED).map(r -> r.getKey()).collect(ImmutableSet.toImmutableSet()));
removeInactiveUsersFromAttentionSet(currentReviewers);
for (AttentionSetUpdate attentionSetUpdate : plannedAttentionSetUpdates.values()) {
if (attentionSetUpdate.operation() == AttentionSetUpdate.Operation.ADD && currentUsersInAttentionSet.contains(attentionSetUpdate.account())) {
// Skip users that are already in the attention set: no need to re-add them.
continue;
}
if (attentionSetUpdate.operation() == AttentionSetUpdate.Operation.REMOVE && !currentUsersInAttentionSet.contains(attentionSetUpdate.account())) {
// Skip users that are not in the attention set: no need to remove them.
continue;
}
if (attentionSetUpdate.operation() == AttentionSetUpdate.Operation.ADD && serviceUserClassifier.isServiceUser(attentionSetUpdate.account())) {
// Skip adding robots to the attention set.
continue;
}
if (attentionSetUpdate.operation() == AttentionSetUpdate.Operation.ADD && approvals.rowKeySet().contains(LabelId.legacySubmit().get())) {
// This ensures we don't add users to the attention set on submit.
continue;
}
// Don't add accounts that are not active in the change to the attention set.
if (attentionSetUpdate.operation() == AttentionSetUpdate.Operation.ADD && !isActiveOnChange(currentReviewers, attentionSetUpdate.account())) {
continue;
}
addFooter(msg, FOOTER_ATTENTION, noteUtil.attentionSetUpdateToJson(attentionSetUpdate));
}
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class CreateGroup method apply.
@Override
public Response<GroupInfo> apply(TopLevelResource resource, IdString id, GroupInput input) throws AuthException, BadRequestException, UnprocessableEntityException, ResourceConflictException, IOException, ConfigInvalidException, ResourceNotFoundException, PermissionBackendException {
String name = id.get();
if (input == null) {
input = new GroupInput();
}
if (input.name != null && !name.equals(input.name)) {
throw new BadRequestException("name must match URL");
}
AccountGroup.UUID ownerUuid = owner(input);
CreateGroupArgs args = new CreateGroupArgs();
args.setGroupName(name);
args.uuid = Strings.isNullOrEmpty(input.uuid) ? null : AccountGroup.UUID.parse(input.uuid);
if (args.uuid != null) {
if (!args.uuid.isInternalGroup()) {
throw new BadRequestException(String.format("invalid group UUID '%s'", args.uuid.get()));
}
if (groupCache.get(args.uuid).isPresent()) {
throw new ResourceConflictException(String.format("group with UUID '%s' already exists", args.uuid.get()));
}
}
args.groupDescription = Strings.emptyToNull(input.description);
args.visibleToAll = MoreObjects.firstNonNull(input.visibleToAll, defaultVisibleToAll);
args.ownerGroupUuid = ownerUuid;
if (input.members != null && !input.members.isEmpty()) {
List<Account.Id> members = new ArrayList<>();
for (String nameOrEmailOrId : input.members) {
Account a = addMembers.findAccount(nameOrEmailOrId);
if (!a.isActive()) {
throw new UnprocessableEntityException(String.format("Account Inactive: %s", nameOrEmailOrId));
}
members.add(a.id());
}
args.initialMembers = members;
} else {
args.initialMembers = ownerUuid == null ? Collections.singleton(self.get().getAccountId()) : Collections.emptySet();
}
try {
groupCreationValidationListeners.runEach(l -> l.validateNewGroup(args), ValidationException.class);
} catch (ValidationException e) {
throw new ResourceConflictException(e.getMessage(), e);
}
return Response.created(json.format(new InternalGroupDescription(createGroup(args))));
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class MailUtil method getRecipientsFromFooters.
public static MailRecipients getRecipientsFromFooters(AccountResolver accountResolver, List<FooterLine> footerLines) throws IOException, ConfigInvalidException {
MailRecipients recipients = new MailRecipients();
for (FooterLine footerLine : footerLines) {
try {
if (isReviewer(footerLine)) {
Account.Id accountId = toAccountId(accountResolver, footerLine.getValue().trim());
recipients.reviewers.add(accountId);
logger.atFine().log("Added account %d from footer line \"%s\" as reviewer", accountId.get(), footerLine);
} else if (footerLine.matches(FooterKey.CC)) {
Account.Id accountId = toAccountId(accountResolver, footerLine.getValue().trim());
recipients.cc.add(accountId);
logger.atFine().log("Added account %d from footer line \"%s\" as cc", accountId.get(), footerLine);
}
} catch (UnprocessableEntityException e) {
logger.atFine().log("Skip adding reviewer/cc from footer line \"%s\": %s", footerLine, e.getMessage());
continue;
}
}
return recipients;
}
Aggregations