use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class AccountsUpdate method commit.
private void commit(Repository allUsersRepo, List<UpdatedAccount> updatedAccounts) throws IOException {
if (updatedAccounts.isEmpty()) {
return;
}
beforeCommit.run();
BatchRefUpdate batchRefUpdate = allUsersRepo.getRefDatabase().newBatchUpdate();
String externalIdUpdateMessage = updatedAccounts.size() == 1 ? Iterables.getOnlyElement(updatedAccounts).message : "Batch update for " + updatedAccounts.size() + " accounts";
for (UpdatedAccount updatedAccount : updatedAccounts) {
// These updates are all for different refs (because batches never update the same account
// more than once), so there can be multiple commits in the same batch, all with the same base
// revision in their AccountConfig.
commitAccountConfig(updatedAccount.message, allUsersRepo, batchRefUpdate, updatedAccount.accountConfig, updatedAccount.created);
// When creating a new account we must allow empty commits so that the user branch gets
// created with an empty commit when no account properties are set and hence no
// 'account.config' file will be created.
// These update the same ref, so they need to be stacked on top of one another using the same
// ExternalIdNotes instance.
commitExternalIdUpdates(externalIdUpdateMessage, allUsersRepo, batchRefUpdate);
}
RefUpdateUtil.executeChecked(batchRefUpdate, allUsersRepo);
Set<Account.Id> accountsToSkipForReindex = getUpdatedAccountIds(batchRefUpdate);
extIdNotesLoader.updateExternalIdCacheAndMaybeReindexAccounts(externalIdNotes, accountsToSkipForReindex);
gitRefUpdated.fire(allUsersName, batchRefUpdate, currentUser.map(IdentifiedUser::state).orElse(null));
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class AccountManager method addGroupMember.
private void addGroupMember(AccountGroup.UUID groupUuid, IdentifiedUser user) throws IOException, ConfigInvalidException, AccountException {
// The user initiated this request by logging in. -> Attribute all modifications to that user.
GroupsUpdate groupsUpdate = groupsUpdateFactory.create(user);
GroupDelta groupDelta = GroupDelta.builder().setMemberModification(memberIds -> Sets.union(memberIds, ImmutableSet.of(user.getAccountId()))).build();
try {
groupsUpdate.updateGroup(groupUuid, groupDelta);
} catch (NoSuchGroupException e) {
throw new AccountException(String.format("Group %s not found", groupUuid), e);
}
}
use of com.google.gerrit.server.IdentifiedUser 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.server.IdentifiedUser 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));
}
use of com.google.gerrit.server.IdentifiedUser in project gerrit by GerritCodeReview.
the class ModifyReviewersEmail method emailReviewersAsync.
public void emailReviewersAsync(IdentifiedUser user, Change change, Collection<Account.Id> added, Collection<Account.Id> copied, Collection<Account.Id> removed, Collection<Address> addedByEmail, Collection<Address> copiedByEmail, Collection<Address> removedByEmail, NotifyResolver.Result notify) {
// The user knows they added/removed themselves, don't bother emailing them.
Account.Id userId = user.getAccountId();
ImmutableList<Account.Id> immutableToMail = added.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
ImmutableList<Account.Id> immutableToCopy = copied.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
ImmutableList<Account.Id> immutableToRemove = removed.stream().filter(id -> !id.equals(userId)).collect(toImmutableList());
if (immutableToMail.isEmpty() && immutableToCopy.isEmpty() && immutableToRemove.isEmpty() && addedByEmail.isEmpty() && copiedByEmail.isEmpty() && removedByEmail.isEmpty()) {
return;
}
// Make immutable copies of collections and hand over only immutable data types to the other
// thread.
Change.Id cId = change.getId();
Project.NameKey projectNameKey = change.getProject();
ImmutableList<Address> immutableAddedByEmail = ImmutableList.copyOf(addedByEmail);
ImmutableList<Address> immutableCopiedByEmail = ImmutableList.copyOf(copiedByEmail);
ImmutableList<Address> immutableRemovedByEmail = ImmutableList.copyOf(removedByEmail);
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = sendEmailsExecutor.submit(() -> {
try {
ModifyReviewerSender emailSender = addReviewerSenderFactory.create(projectNameKey, cId);
emailSender.setNotify(notify);
emailSender.setFrom(userId);
emailSender.addReviewers(immutableToMail);
emailSender.addReviewersByEmail(immutableAddedByEmail);
emailSender.addExtraCC(immutableToCopy);
emailSender.addExtraCCByEmail(immutableCopiedByEmail);
emailSender.addRemovedReviewers(immutableToRemove);
emailSender.addRemovedByEmailReviewers(immutableRemovedByEmail);
emailSender.setMessageId(messageIdGenerator.fromChangeUpdate(change.getProject(), change.currentPatchSetId()));
emailSender.send();
} catch (Exception err) {
logger.atSevere().withCause(err).log("Cannot send email to new reviewers of change %s", change.getId());
}
});
}
Aggregations