use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class GroupMembers method getGroupMembers.
private Set<Account> getGroupMembers(InternalGroup group, @Nullable Project.NameKey project, Set<AccountGroup.UUID> seen) throws NoSuchProjectException, IOException {
seen.add(group.getGroupUUID());
GroupControl groupControl = groupControlFactory.controlFor(new InternalGroupDescription(group));
Set<Account> directMembers = group.getMembers().stream().filter(groupControl::canSeeMember).map(accountCache::get).flatMap(Streams::stream).map(AccountState::account).collect(toImmutableSet());
Set<Account> indirectMembers = new HashSet<>();
if (groupControl.canSeeGroup()) {
for (AccountGroup.UUID subgroupUuid : group.getSubgroups()) {
if (!seen.contains(subgroupUuid)) {
indirectMembers.addAll(listAccounts(subgroupUuid, project, seen));
}
}
}
return Sets.union(directMembers, indirectMembers);
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class InternalAccountDirectory method fill.
private void fill(AccountInfo info, AccountState accountState, Set<FillOptions> options) {
Account account = accountState.account();
if (options.contains(FillOptions.ID)) {
info._accountId = account.id().get();
} else {
// Was previously set to look up account for filling.
info._accountId = null;
}
if (options.contains(FillOptions.NAME)) {
info.name = Strings.emptyToNull(account.fullName());
if (info.name == null) {
info.name = accountState.userName().orElse(null);
}
}
if (options.contains(FillOptions.EMAIL)) {
info.email = account.preferredEmail();
}
if (options.contains(FillOptions.SECONDARY_EMAILS)) {
info.secondaryEmails = getSecondaryEmails(account, accountState.externalIds());
}
if (options.contains(FillOptions.USERNAME)) {
info.username = accountState.userName().orElse(null);
}
if (options.contains(FillOptions.DISPLAY_NAME)) {
info.displayName = account.displayName();
}
if (options.contains(FillOptions.STATUS)) {
info.status = account.status();
}
if (options.contains(FillOptions.STATE)) {
info.inactive = account.inactive() ? true : null;
}
if (options.contains(FillOptions.TAGS)) {
List<String> tags = getTags(account.id());
if (!tags.isEmpty()) {
info.tags = tags;
}
}
if (options.contains(FillOptions.AVATARS)) {
AvatarProvider ap = avatar.get();
if (ap != null) {
info.avatars = new ArrayList<>();
IdentifiedUser user = userFactory.create(account.id());
// PolyGerrit UI uses the following sizes for avatars:
// - 32px for avatars next to names e.g. on the dashboard. This is also Gerrit's default.
// - 56px for the user's own avatar in the menu
// - 100ox for other user's avatars on dashboards
// - 120px for the user's own profile settings page
addAvatar(ap, info, user, AvatarInfo.DEFAULT_SIZE);
if (!info.avatars.isEmpty()) {
addAvatar(ap, info, user, 56);
addAvatar(ap, info, user, 100);
addAvatar(ap, info, user, 120);
}
}
}
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class AllAccountsIndexer method reindexAccounts.
private SiteIndexer.Result reindexAccounts(AccountIndex index, List<Account.Id> ids, ProgressMonitor progress) {
progress.beginTask("Reindexing accounts", ids.size());
List<ListenableFuture<?>> futures = new ArrayList<>(ids.size());
AtomicBoolean ok = new AtomicBoolean(true);
AtomicInteger done = new AtomicInteger();
AtomicInteger failed = new AtomicInteger();
Stopwatch sw = Stopwatch.createStarted();
for (Account.Id id : ids) {
String desc = "account " + id;
ListenableFuture<?> future = executor.submit(() -> {
try {
Optional<AccountState> a = accountCache.get(id);
if (a.isPresent()) {
if (isFirstInsertForEntry.equals(IsFirstInsertForEntry.YES)) {
index.insert(a.get());
} else {
index.replace(a.get());
}
} else {
index.delete(id);
}
verboseWriter.println("Reindexed " + desc);
done.incrementAndGet();
} catch (Exception e) {
failed.incrementAndGet();
throw e;
}
return null;
});
addErrorListener(future, desc, progress, ok);
futures.add(future);
}
try {
Futures.successfulAsList(futures).get();
} catch (ExecutionException | InterruptedException e) {
logger.atSevere().withCause(e).log("Error waiting on account futures");
return SiteIndexer.Result.create(sw, false, 0, 0);
}
progress.endTask();
return SiteIndexer.Result.create(sw, ok.get(), done.get(), failed.get());
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class CommitRewriter method verifyCommit.
/**
* Verifies that the commit does not contain user data of accounts in {@code accounts}.
*/
private boolean verifyCommit(String commitMessage, PersonIdent author, Collection<AccountState> accounts) {
for (AccountState accountState : accounts) {
Account account = accountState.account();
if (commitMessage.contains(account.getName())) {
return false;
}
if (account.fullName() != null && commitMessage.contains(account.fullName())) {
return false;
}
if (account.displayName() != null && commitMessage.contains(account.displayName())) {
return false;
}
if (account.preferredEmail() != null && commitMessage.contains(account.preferredEmail())) {
return false;
}
if (accountState.userName().isPresent() && commitMessage.contains(accountState.userName().get())) {
return false;
}
Stream<String> allEmails = accountState.externalIds().stream().map(ExternalId::email).filter(Objects::nonNull);
if (allEmails.anyMatch(email -> commitMessage.contains(email))) {
return false;
}
if (author.toString().contains(account.getName())) {
return false;
}
}
return true;
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class ReviewersUtil method suggestAccounts.
private List<Account.Id> suggestAccounts(SuggestReviewers suggestReviewers) throws BadRequestException {
try (Timer0.Context ctx = metrics.queryAccountsLatency.start()) {
// For performance reasons we don't use AccountQueryProvider as it would always load the
// complete account from the cache (or worse, from NoteDb) even though we only need the ID
// which we can directly get from the returned results.
Predicate<AccountState> pred = Predicate.and(AccountPredicates.isActive(), accountQueryBuilder.defaultQuery(suggestReviewers.getQuery()));
logger.atFine().log("accounts index query: %s", pred);
accountIndexRewriter.validateMaxTermsInQuery(pred);
boolean useLegacyNumericFields = accountIndexes.getSearchIndex().getSchema().useLegacyNumericFields();
FieldDef<AccountState, ?> idField = useLegacyNumericFields ? AccountField.ID : AccountField.ID_STR;
ResultSet<FieldBundle> result = accountIndexes.getSearchIndex().getSource(pred, QueryOptions.create(indexConfig, 0, suggestReviewers.getLimit(), ImmutableSet.of(idField.getName()))).readRaw();
List<Account.Id> matches = result.toList().stream().map(f -> fromIdField(f, useLegacyNumericFields)).collect(toList());
logger.atFine().log("Matches: %s", matches);
return matches;
} catch (TooManyTermsInQueryException e) {
throw new BadRequestException(e.getMessage());
} catch (QueryParseException e) {
logger.atWarning().withCause(e).log("Suggesting accounts failed, return empty result.");
return ImmutableList.of();
} catch (StorageException e) {
if (e.getCause() instanceof TooManyTermsInQueryException) {
throw new BadRequestException(e.getMessage());
}
if (e.getCause() instanceof QueryParseException) {
return ImmutableList.of();
}
throw e;
}
}
Aggregations