use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class IdentifiedUser method newRefLogIdent.
public PersonIdent newRefLogIdent(final Date when, final TimeZone tz) {
final Account ua = getAccount();
String name = ua.getFullName();
if (name == null || name.isEmpty()) {
name = ua.getPreferredEmail();
}
if (name == null || name.isEmpty()) {
name = anonymousCowardName;
}
String user = getUserName();
if (user == null) {
user = "";
}
user = user + "|account-" + ua.getId().toString();
return new PersonIdent(name, user + "@" + guessHost(), when, tz);
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class NotifyUtil method find.
private List<Account.Id> find(ReviewDb db, List<String> nameOrEmails) throws OrmException, BadRequestException {
List<String> missing = new ArrayList<>(nameOrEmails.size());
List<Account.Id> r = new ArrayList<>(nameOrEmails.size());
for (String nameOrEmail : nameOrEmails) {
Account a = accountResolver.find(db, nameOrEmail);
if (a != null) {
r.add(a.getId());
} else {
missing.add(nameOrEmail);
}
}
if (!missing.isEmpty()) {
throw new BadRequestException("The following accounts that should be notified could not be resolved: " + missing.stream().distinct().sorted().collect(joining(", ")));
}
return r;
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class PostReviewers method addWholeGroup.
@Nullable
private Addition addWholeGroup(String reviewer, ChangeResource rsrc, ReviewerState state, NotifyHandling notify, ListMultimap<RecipientType, Account.Id> accountsToNotify, boolean confirmed, boolean allowGroup, boolean allowByEmail) throws OrmException, IOException, PermissionBackendException {
if (!allowGroup) {
return null;
}
GroupDescription.Basic group = null;
try {
group = groupsCollection.parseInternal(reviewer);
} catch (UnprocessableEntityException e) {
if (!allowByEmail) {
return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerNotFoundUserOrGroup, reviewer));
}
return null;
}
if (!isLegalReviewerGroup(group.getGroupUUID())) {
return fail(reviewer, MessageFormat.format(ChangeMessages.get().groupIsNotAllowed, group.getName()));
}
Set<Account.Id> reviewers = new HashSet<>();
ChangeControl control = rsrc.getControl();
Set<Account> members;
try {
members = groupMembersFactory.create(control.getUser()).listAccounts(group.getGroupUUID(), control.getProject().getNameKey());
} catch (NoSuchGroupException e) {
return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerNotFoundUserOrGroup, group.getName()));
} catch (NoSuchProjectException e) {
return fail(reviewer, e.getMessage());
}
// if maxAllowed is set to 0, it is allowed to add any number of
// reviewers
int maxAllowed = cfg.getInt("addreviewer", "maxAllowed", DEFAULT_MAX_REVIEWERS);
if (maxAllowed > 0 && members.size() > maxAllowed) {
return fail(reviewer, MessageFormat.format(ChangeMessages.get().groupHasTooManyMembers, group.getName()));
}
// if maxWithoutCheck is set to 0, we never ask for confirmation
int maxWithoutConfirmation = cfg.getInt("addreviewer", "maxWithoutConfirmation", DEFAULT_MAX_REVIEWERS_WITHOUT_CHECK);
if (!confirmed && maxWithoutConfirmation > 0 && members.size() > maxWithoutConfirmation) {
return fail(reviewer, true, MessageFormat.format(ChangeMessages.get().groupManyMembersConfirmation, group.getName(), members.size()));
}
PermissionBackend.ForRef perm = permissionBackend.user(rsrc.getUser()).ref(rsrc.getChange().getDest());
for (Account member : members) {
if (isValidReviewer(member, perm)) {
reviewers.add(member.getId());
}
}
return new Addition(reviewer, rsrc, reviewers, null, state, notify, accountsToNotify);
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class DeleteMembers method apply.
@Override
public Response<?> apply(GroupResource resource, Input input) throws AuthException, MethodNotAllowedException, UnprocessableEntityException, OrmException, IOException {
AccountGroup internalGroup = resource.toAccountGroup();
if (internalGroup == null) {
throw new MethodNotAllowedException();
}
input = Input.init(input);
final GroupControl control = resource.getControl();
final Map<Account.Id, AccountGroupMember> members = getMembers(internalGroup.getId());
final List<AccountGroupMember> toRemove = new ArrayList<>();
for (final String nameOrEmail : input.members) {
Account a = accounts.parse(nameOrEmail).getAccount();
if (!control.canRemoveMember()) {
throw new AuthException("Cannot delete member: " + a.getFullName());
}
final AccountGroupMember m = members.remove(a.getId());
if (m != null) {
toRemove.add(m);
}
}
writeAudits(toRemove);
db.get().accountGroupMembers().delete(toRemove);
for (final AccountGroupMember m : toRemove) {
accountCache.evict(m.getAccountId());
}
return Response.none();
}
use of com.google.gerrit.reviewdb.client.Account in project gerrit by GerritCodeReview.
the class ChangeData method draftRefs.
public Map<Account.Id, Ref> draftRefs() throws OrmException {
if (draftsByUser == null) {
if (!lazyLoad) {
return Collections.emptyMap();
}
Change c = change();
if (c == null) {
return Collections.emptyMap();
}
draftsByUser = new HashMap<>();
if (notesMigration.readChanges()) {
for (Ref ref : commentsUtil.getDraftRefs(notes.getChangeId())) {
Account.Id account = Account.Id.fromRefSuffix(ref.getName());
if (account != null && // this point.
!notes().getDraftComments(account, ref).isEmpty()) {
draftsByUser.put(account, ref);
}
}
} else {
for (Comment sc : commentsUtil.draftByChange(db, notes())) {
draftsByUser.put(sc.author.getId(), null);
}
}
}
return draftsByUser;
}
Aggregations