use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class CommitMessageOutputTest method anonymousUser.
@Test
public void anonymousUser() throws Exception {
Account anon = new Account(new Account.Id(3), TimeUtil.nowTs());
accountCache.put(anon);
Change c = newChange();
ChangeUpdate update = newUpdate(c, userFactory.create(anon.getId()));
update.setChangeMessage("Comment on the change.");
update.commit();
RevCommit commit = parseCommit(update.getResult());
assertBodyEquals("Update patch set 1\n\nComment on the change.\n\nPatch-set: 1\n", commit);
PersonIdent author = commit.getAuthorIdent();
assertThat(author.getName()).isEqualTo("Anonymous Coward (3)");
assertThat(author.getEmailAddress()).isEqualTo("3@gerrit");
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class PutPreferred method apply.
public Response<String> apply(IdentifiedUser user, String email) throws ResourceNotFoundException, OrmException, IOException {
AtomicBoolean alreadyPreferred = new AtomicBoolean(false);
Account a = dbProvider.get().accounts().atomicUpdate(user.getAccountId(), new AtomicUpdate<Account>() {
@Override
public Account update(Account a) {
if (email.equals(a.getPreferredEmail())) {
alreadyPreferred.set(true);
} else {
a.setPreferredEmail(email);
}
return a;
}
});
if (a == null) {
throw new ResourceNotFoundException("account not found");
}
byIdCache.evict(a.getId());
return alreadyPreferred.get() ? Response.ok("") : Response.created("");
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class DeleteActive method apply.
@Override
public Response<?> apply(AccountResource rsrc, Input input) throws RestApiException, OrmException, IOException {
if (self.get() == rsrc.getUser()) {
throw new ResourceConflictException("cannot deactivate own account");
}
AtomicBoolean alreadyInactive = new AtomicBoolean(false);
Account a = dbProvider.get().accounts().atomicUpdate(rsrc.getUser().getAccountId(), new AtomicUpdate<Account>() {
@Override
public Account update(Account a) {
if (!a.isActive()) {
alreadyInactive.set(true);
} else {
a.setActive(false);
}
return a;
}
});
if (a == null) {
throw new ResourceNotFoundException("account not found");
}
if (alreadyInactive.get()) {
throw new ResourceConflictException("account not active");
}
byIdCache.evict(a.getId());
return Response.none();
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class GroupMembers method getGroupMembers.
private Set<Account> getGroupMembers(final AccountGroup group, final Project.NameKey project, final Set<AccountGroup.UUID> seen) throws NoSuchGroupException, OrmException, NoSuchProjectException, IOException {
seen.add(group.getGroupUUID());
final GroupDetail groupDetail = groupDetailFactory.create(group.getId()).call();
final Set<Account> members = new HashSet<>();
if (groupDetail.members != null) {
for (final AccountGroupMember member : groupDetail.members) {
members.add(accountCache.get(member.getAccountId()).getAccount());
}
}
if (groupDetail.includes != null) {
for (final AccountGroupById groupInclude : groupDetail.includes) {
final AccountGroup includedGroup = groupCache.get(groupInclude.getIncludeUUID());
if (includedGroup != null && !seen.contains(includedGroup.getGroupUUID())) {
members.addAll(listAccounts(includedGroup.getGroupUUID(), project, seen));
}
}
}
return members;
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class ReceiveCommits method validateNewCommits.
private void validateNewCommits(RefControl ctl, ReceiveCommand cmd) {
if (ctl.canForgeAuthor() && ctl.canForgeCommitter() && ctl.canForgeGerritServerIdentity() && ctl.canUploadMerges() && !projectControl.getProjectState().isUseSignedOffBy() && Iterables.isEmpty(rejectCommits) && !RefNames.REFS_CONFIG.equals(ctl.getRefName()) && !(MagicBranch.isMagicBranch(cmd.getRefName()) || NEW_PATCHSET.matcher(cmd.getRefName()).matches())) {
logDebug("Short-circuiting new commit validation");
return;
}
boolean defaultName = Strings.isNullOrEmpty(user.getAccount().getFullName());
RevWalk walk = rp.getRevWalk();
walk.reset();
walk.sort(RevSort.NONE);
try {
RevObject parsedObject = walk.parseAny(cmd.getNewId());
if (!(parsedObject instanceof RevCommit)) {
return;
}
ListMultimap<ObjectId, Ref> existing = changeRefsById();
walk.markStart((RevCommit) parsedObject);
markHeadsAsUninteresting(walk, cmd.getRefName());
int i = 0;
for (RevCommit c; (c = walk.next()) != null; ) {
i++;
if (existing.keySet().contains(c)) {
continue;
} else if (!validCommit(walk, ctl, cmd, c)) {
break;
}
if (defaultName && user.hasEmailAddress(c.getCommitterIdent().getEmailAddress())) {
try {
Account a = db.accounts().get(user.getAccountId());
if (a != null && Strings.isNullOrEmpty(a.getFullName())) {
a.setFullName(c.getCommitterIdent().getName());
db.accounts().update(Collections.singleton(a));
user.getAccount().setFullName(a.getFullName());
accountCache.evict(a.getId());
}
} catch (OrmException e) {
logWarn("Cannot default full_name", e);
} finally {
defaultName = false;
}
}
}
logDebug("Validated {} new commits", i);
} catch (IOException err) {
cmd.setResult(REJECTED_MISSING_OBJECT);
logError("Invalid pack upload; one or more objects weren't sent", err);
}
}
Aggregations