use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class ChangeNotesParser method parseApprover.
/**
* Identifies the {@link com.google.gerrit.entities.Account.Id} that issued the vote.
*
* <p>There are potentially 3 accounts involved here: 1. The account from the commit, which is the
* effective IdentifiedUser that produced the update. 2. The account in the label footer itself,
* which is used during submit to copy other users' labels to a new patch set. 3. The account in
* the Real-user footer, indicating that the whole update operation was executed by this user on
* behalf of the effective user.
*/
private Account.Id parseApprover(Account.Id committerId, ParsedPatchSetApproval parsedPatchSetApproval) throws ConfigInvalidException {
Account.Id effectiveAccountId;
if (parsedPatchSetApproval.accountIdent().isPresent()) {
PersonIdent ident = RawParseUtils.parsePersonIdent(parsedPatchSetApproval.accountIdent().get());
checkFooter(ident != null, FOOTER_LABEL, parsedPatchSetApproval.footerLine());
effectiveAccountId = parseIdent(ident);
} else {
effectiveAccountId = committerId;
}
return effectiveAccountId;
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class MailProcessor method processImpl.
private void processImpl(BatchUpdate.Factory buf, MailMessage message) throws UpdateException, RestApiException, IOException {
for (Extension<MailFilter> filter : mailFilters) {
if (!filter.getProvider().get().shouldProcessMessage(message)) {
logger.atWarning().log("Message %s filtered by plugin %s %s. Will delete message.", message.id(), filter.getPluginName(), filter.getExportName());
return;
}
}
MailMetadata metadata = MailHeaderParser.parse(message);
if (!metadata.hasRequiredFields()) {
logger.atSevere().log("Message %s is missing required metadata, have %s. Will delete message.", message.id(), metadata);
sendRejectionEmail(message, InboundEmailError.PARSING_ERROR);
return;
}
Set<Account.Id> accountIds = emails.getAccountFor(metadata.author);
if (accountIds.size() != 1) {
logger.atSevere().log("Address %s could not be matched to a unique account. It was matched to %s." + " Will delete message.", metadata.author, accountIds);
// We don't want to send an email if no accounts are linked to it.
if (accountIds.size() > 1) {
sendRejectionEmail(message, InboundEmailError.UNKNOWN_ACCOUNT);
}
return;
}
Account.Id accountId = accountIds.iterator().next();
Optional<AccountState> accountState = accountCache.get(accountId);
if (!accountState.isPresent()) {
logger.atWarning().log("Mail: Account %s doesn't exist. Will delete message.", accountId);
return;
}
if (!accountState.get().account().isActive()) {
logger.atWarning().log("Mail: Account %s is inactive. Will delete message.", accountId);
sendRejectionEmail(message, InboundEmailError.INACTIVE_ACCOUNT);
return;
}
persistComments(buf, message, metadata, accountId);
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class PutName method apply.
public Response<String> apply(IdentifiedUser user, NameInput input) throws MethodNotAllowedException, ResourceNotFoundException, IOException, ConfigInvalidException {
if (input == null) {
input = new NameInput();
}
Account.Id accountId = user.getAccountId();
if (realm.accountBelongsToRealm(externalIds.byAccount(accountId)) && !realm.allowsEdit(AccountFieldName.FULL_NAME)) {
throw new MethodNotAllowedException("realm does not allow editing name");
}
String newName = input.name;
AccountState accountState = accountsUpdateProvider.get().update("Set Full Name via API", accountId, u -> u.setFullName(newName)).orElseThrow(() -> new ResourceNotFoundException("account not found"));
return Strings.isNullOrEmpty(accountState.account().fullName()) ? Response.none() : Response.ok(accountState.account().fullName());
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class GetDetail method apply.
@Override
public Response<AccountDetailInfo> apply(AccountResource rsrc) throws PermissionBackendException {
Account a = rsrc.getUser().getAccount();
AccountDetailInfo info = new AccountDetailInfo(a.id().get());
info.setRegisteredOn(a.registeredOn());
info.inactive = !a.isActive() ? true : null;
directory.fillAccountInfo(Collections.singleton(info), EnumSet.allOf(FillOptions.class));
return Response.ok(info);
}
use of com.google.gerrit.entities.Account in project gerrit by GerritCodeReview.
the class GetWatchedProjects method apply.
@Override
public Response<List<ProjectWatchInfo>> apply(AccountResource rsrc) throws AuthException, IOException, ConfigInvalidException, PermissionBackendException, ResourceNotFoundException {
if (!self.get().hasSameAccountId(rsrc.getUser())) {
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
}
Account.Id accountId = rsrc.getUser().getAccountId();
AccountState account = accounts.get(accountId).orElseThrow(ResourceNotFoundException::new);
return Response.ok(account.projectWatches().entrySet().stream().map(e -> toProjectWatchInfo(e.getKey(), e.getValue())).sorted(comparing((ProjectWatchInfo pwi) -> pwi.project).thenComparing(pwi -> Strings.nullToEmpty(pwi.filter))).collect(toList()));
}
Aggregations