use of com.google.gerrit.extensions.common.EmailInfo in project gerrit by GerritCodeReview.
the class AccountIT method createAtomically.
@Test
@UseClockStep
public void createAtomically() throws Exception {
Account.Id accountId = Account.id(seq.nextAccountId());
String fullName = "Foo";
ExternalId extId = externalIdFactory.createEmail(accountId, "foo@example.com");
AccountState accountState = accountsUpdateProvider.get().insert("Create Account Atomically", accountId, u -> u.setFullName(fullName).addExternalId(extId));
assertThat(accountState.account().fullName()).isEqualTo(fullName);
AccountInfo info = gApi.accounts().id(accountId.get()).get();
assertThat(info.name).isEqualTo(fullName);
List<EmailInfo> emails = gApi.accounts().id(accountId.get()).getEmails();
assertThat(emails.stream().map(e -> e.email).collect(toSet())).containsExactly(extId.email());
RevCommit commitUserBranch = projectOperations.project(allUsers).getHead(RefNames.refsUsers(accountId));
RevCommit commitRefsMetaExternalIds = projectOperations.project(allUsers).getHead(RefNames.REFS_EXTERNAL_IDS);
assertThat(commitUserBranch.getCommitTime()).isEqualTo(commitRefsMetaExternalIds.getCommitTime());
}
use of com.google.gerrit.extensions.common.EmailInfo in project gerrit by GerritCodeReview.
the class CreateEmail method apply.
/**
* To be used from plugins that want to create emails without permission checks.
*/
@UsedAt(UsedAt.Project.PLUGIN_SERVICEUSER)
public EmailInfo apply(IdentifiedUser user, IdString id, EmailInput input) throws RestApiException, EmailException, MethodNotAllowedException, IOException, ConfigInvalidException, PermissionBackendException {
String email = id.get().trim();
if (input == null) {
input = new EmailInput();
}
if (input.email != null && !email.equals(input.email)) {
throw new BadRequestException("email address must match URL");
}
if (!validator.isValid(email)) {
throw new BadRequestException("invalid email address");
}
EmailInfo info = new EmailInfo();
info.email = email;
if (input.noConfirmation || isDevMode) {
if (isDevMode) {
logger.atWarning().log("skipping email validation in developer mode");
}
try {
accountManager.link(user.getAccountId(), authRequestFactory.createForEmail(email));
} catch (AccountException e) {
throw new ResourceConflictException(e.getMessage());
}
if (input.preferred) {
putPreferred.apply(new AccountResource.Email(user, email), null);
info.preferred = true;
}
} else {
try {
RegisterNewEmailSender emailSender = registerNewEmailFactory.create(email);
if (!emailSender.isAllowed()) {
throw new MethodNotAllowedException("Not allowed to add email address " + email);
}
emailSender.setMessageId(messageIdGenerator.fromAccountUpdate(user.getAccountId()));
emailSender.send();
info.pendingConfirmation = true;
} catch (EmailException | RuntimeException e) {
logger.atSevere().withCause(e).log("Cannot send email verification message to %s", email);
throw e;
}
}
return info;
}
use of com.google.gerrit.extensions.common.EmailInfo in project gerrit by GerritCodeReview.
the class GetEmail method apply.
@Override
public Response<EmailInfo> apply(AccountResource.Email rsrc) {
EmailInfo e = new EmailInfo();
e.email = rsrc.getEmail();
e.preferred(rsrc.getUser().getAccount().preferredEmail());
return Response.ok(e);
}
use of com.google.gerrit.extensions.common.EmailInfo in project gerrit by GerritCodeReview.
the class GetEmails method toEmailInfo.
private static EmailInfo toEmailInfo(AccountResource rsrc, String email) {
EmailInfo e = new EmailInfo();
e.email = email;
e.preferred(rsrc.getUser().getAccount().preferredEmail());
return e;
}
Aggregations