Search in sources :

Example 1 with QueryRequiresAuthException

use of com.google.gerrit.index.query.QueryRequiresAuthException in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method visibleto.

@Operator
public Predicate<ChangeData> visibleto(String who) throws QueryParseException, IOException, ConfigInvalidException {
    if (isSelf(who)) {
        return isVisible();
    }
    Set<Account.Id> accounts = null;
    try {
        accounts = parseAccount(who);
    } catch (QueryParseException e) {
        if (e instanceof QueryRequiresAuthException) {
            throw e;
        }
    }
    if (accounts != null) {
        if (accounts.size() == 1) {
            return visibleto(args.userFactory.create(Iterables.getOnlyElement(accounts)));
        } else if (accounts.size() > 1) {
            throw error(String.format("\"%s\" resolves to multiple accounts", who));
        }
    }
    // If its not an account, maybe its a group?
    Collection<GroupReference> suggestions = args.groupBackend.suggest(who, null);
    if (!suggestions.isEmpty()) {
        HashSet<AccountGroup.UUID> ids = new HashSet<>();
        for (GroupReference ref : suggestions) {
            ids.add(ref.getUUID());
        }
        return visibleto(new GroupBackedUser(ids));
    }
    throw error("No user or group matches \"" + who + "\".");
}
Also used : QueryRequiresAuthException(com.google.gerrit.index.query.QueryRequiresAuthException) GroupReference(com.google.gerrit.entities.GroupReference) QueryParseException(com.google.gerrit.index.query.QueryParseException) HashSet(java.util.HashSet)

Aggregations

GroupReference (com.google.gerrit.entities.GroupReference)1 QueryParseException (com.google.gerrit.index.query.QueryParseException)1 QueryRequiresAuthException (com.google.gerrit.index.query.QueryRequiresAuthException)1 HashSet (java.util.HashSet)1