use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.
the class ReviewerModifier method addWholeGroup.
@Nullable
private ReviewerModification addWholeGroup(ReviewerInput input, ChangeNotes notes, CurrentUser user, boolean confirmed, boolean allowGroup, boolean allowByEmail) throws IOException, PermissionBackendException {
if (!allowGroup) {
return null;
}
GroupDescription.Basic group;
try {
// TODO(dborowitz): This currently doesn't work in the push path because InternalGroupBackend
// depends on the Provider<CurrentUser> which returns anonymous in that path.
group = groupResolver.parseInternal(input.reviewer);
} catch (UnprocessableEntityException e) {
if (!allowByEmail) {
return fail(input, FailureType.NOT_FOUND, MessageFormat.format(ChangeMessages.get().reviewerNotFoundUserOrGroup, input.reviewer));
}
return null;
}
if (!isLegalReviewerGroup(group.getGroupUUID())) {
return fail(input, FailureType.OTHER, MessageFormat.format(ChangeMessages.get().groupIsNotAllowed, group.getName()));
}
if (input.state().equals(REMOVED)) {
return fail(input, FailureType.OTHER, MessageFormat.format(ChangeMessages.get().groupRemovalIsNotAllowed, group.getName()));
}
Set<Account> reviewers = new HashSet<>();
Set<Account> members;
try {
members = groupMembers.listAccounts(group.getGroupUUID(), notes.getProjectName());
} catch (NoSuchProjectException e) {
return fail(input, FailureType.OTHER, 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) {
logger.atFine().log("Adding %d group members is not allowed (maxAllowed = %d)", members.size(), maxAllowed);
return fail(input, FailureType.OTHER, 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) {
logger.atFine().log("Adding %d group members as reviewer requires confirmation (maxWithoutConfirmation = %d)", members.size(), maxWithoutConfirmation);
return fail(input, FailureType.OTHER, true, MessageFormat.format(ChangeMessages.get().groupManyMembersConfirmation, group.getName(), members.size()));
}
for (Account member : members) {
if (isValidReviewer(notes.getChange().getDest(), member)) {
reviewers.add(member);
}
}
return new ReviewerModification(input, notes, user, reviewers, null, true, true);
}
use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.
the class PostReviewers method addByAccountId.
@Nullable
private Addition addByAccountId(String reviewer, ChangeResource rsrc, ReviewerState state, NotifyHandling notify, ListMultimap<RecipientType, Account.Id> accountsToNotify, boolean allowGroup, boolean allowByEmail) throws OrmException, PermissionBackendException {
Account.Id accountId = null;
try {
accountId = accounts.parse(reviewer).getAccountId();
} catch (UnprocessableEntityException | AuthException e) {
// AuthException won't occur since the user is authenticated at this point.
if (!allowGroup && !allowByEmail) {
// Only return failure if we aren't going to try other interpretations.
return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerNotFoundUser, reviewer));
}
return null;
}
ReviewerResource rrsrc = reviewerFactory.create(rsrc, accountId);
Account member = rrsrc.getReviewerUser().getAccount();
PermissionBackend.ForRef perm = permissionBackend.user(rrsrc.getReviewerUser()).ref(rrsrc.getChange().getDest());
if (isValidReviewer(member, perm)) {
return new Addition(reviewer, rsrc, ImmutableSet.of(member.getId()), null, state, notify, accountsToNotify);
}
if (!member.isActive()) {
if (allowByEmail && state == CC) {
return null;
}
return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerInactive, reviewer));
}
return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerCantSeeChange, reviewer));
}
use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.
the class RangeUtil method getRange.
/**
* Determine the range of values being requested in the given query.
*
* @param rangeQuery the raw query, e.g. "{@code added:>12345}"
* @param minValue the minimum possible value for the field, inclusive
* @param maxValue the maximum possible value for the field, inclusive
* @return the calculated {@link Range}, or null if the query is invalid
*/
@Nullable
public static Range getRange(String rangeQuery, int minValue, int maxValue) {
Matcher m = RANGE_PATTERN.matcher(rangeQuery);
String prefix;
String test;
Integer queryInt;
if (m.find()) {
prefix = rangeQuery.substring(0, m.start());
test = m.group(1);
queryInt = value(m.group(2));
if (queryInt == null) {
return null;
}
} else {
return null;
}
return getRange(prefix, test, queryInt, minValue, maxValue);
}
use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.
the class AccountLoader method fillOne.
@Nullable
public AccountInfo fillOne(@Nullable Account.Id id) throws PermissionBackendException {
AccountInfo info = get(id);
fill();
return info;
}
use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.
the class ReviewerModifier method byAccountId.
@Nullable
private ReviewerModification byAccountId(ReviewerInput input, ChangeNotes notes, CurrentUser user) throws PermissionBackendException, IOException, ConfigInvalidException {
IdentifiedUser reviewerUser;
boolean exactMatchFound = false;
try {
reviewerUser = accountResolver.resolveIncludeInactive(input.reviewer).asUniqueUser();
if (input.reviewer.equalsIgnoreCase(reviewerUser.getName()) || input.reviewer.equals(String.valueOf(reviewerUser.getAccountId()))) {
exactMatchFound = true;
}
} catch (UnprocessableEntityException e) {
// group, but if not, the error message will be useful.
return fail(input, FailureType.NOT_FOUND, e.getMessage());
}
if (isValidReviewer(notes.getChange().getDest(), reviewerUser.getAccount())) {
return new ReviewerModification(input, notes, user, ImmutableSet.of(reviewerUser.getAccount()), null, exactMatchFound, false);
}
return fail(input, FailureType.OTHER, MessageFormat.format(ChangeMessages.get().reviewerCantSeeChange, input.reviewer));
}
Aggregations