Search in sources :

Example 81 with Account

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;
}
Also used : Account(com.google.gerrit.entities.Account) PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Example 82 with Account

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);
}
Also used : MailFilter(com.google.gerrit.server.mail.MailFilter) Account(com.google.gerrit.entities.Account) MailMetadata(com.google.gerrit.mail.MailMetadata) AccountState(com.google.gerrit.server.account.AccountState)

Example 83 with Account

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());
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Inject(com.google.inject.Inject) Response(com.google.gerrit.extensions.restapi.Response) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) RestModifyView(com.google.gerrit.extensions.restapi.RestModifyView) Strings(com.google.common.base.Strings) AuthException(com.google.gerrit.extensions.restapi.AuthException) AccountsUpdate(com.google.gerrit.server.account.AccountsUpdate) GlobalPermission(com.google.gerrit.server.permissions.GlobalPermission) CurrentUser(com.google.gerrit.server.CurrentUser) AccountResource(com.google.gerrit.server.account.AccountResource) Account(com.google.gerrit.entities.Account) NameInput(com.google.gerrit.extensions.common.NameInput) AccountFieldName(com.google.gerrit.extensions.client.AccountFieldName) IOException(java.io.IOException) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) ExternalIds(com.google.gerrit.server.account.externalids.ExternalIds) Provider(com.google.inject.Provider) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ServerInitiated(com.google.gerrit.server.ServerInitiated) AccountState(com.google.gerrit.server.account.AccountState) Realm(com.google.gerrit.server.account.Realm) Singleton(com.google.inject.Singleton) Account(com.google.gerrit.entities.Account) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) NameInput(com.google.gerrit.extensions.common.NameInput) AccountState(com.google.gerrit.server.account.AccountState) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 84 with Account

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);
}
Also used : Account(com.google.gerrit.entities.Account) AccountDetailInfo(com.google.gerrit.extensions.common.AccountDetailInfo) FillOptions(com.google.gerrit.server.account.AccountDirectory.FillOptions)

Example 85 with Account

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()));
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Inject(com.google.inject.Inject) Response(com.google.gerrit.extensions.restapi.Response) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) Accounts(com.google.gerrit.server.account.Accounts) Strings(com.google.common.base.Strings) AuthException(com.google.gerrit.extensions.restapi.AuthException) Comparator.comparing(java.util.Comparator.comparing) GlobalPermission(com.google.gerrit.server.permissions.GlobalPermission) ImmutableSet(com.google.common.collect.ImmutableSet) RestReadView(com.google.gerrit.extensions.restapi.RestReadView) AccountResource(com.google.gerrit.server.account.AccountResource) Account(com.google.gerrit.entities.Account) IOException(java.io.IOException) ProjectWatchKey(com.google.gerrit.server.account.ProjectWatches.ProjectWatchKey) Collectors.toList(java.util.stream.Collectors.toList) Provider(com.google.inject.Provider) List(java.util.List) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) NotifyType(com.google.gerrit.entities.NotifyConfig.NotifyType) ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) AccountState(com.google.gerrit.server.account.AccountState) Singleton(com.google.inject.Singleton) Account(com.google.gerrit.entities.Account) ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) AccountState(com.google.gerrit.server.account.AccountState) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Aggregations

Account (com.google.gerrit.entities.Account)124 Test (org.junit.Test)59 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)37 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)35 AccountState (com.google.gerrit.server.account.AccountState)35 IOException (java.io.IOException)31 Repository (org.eclipse.jgit.lib.Repository)31 Change (com.google.gerrit.entities.Change)28 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)26 Inject (com.google.inject.Inject)25 PersonIdent (org.eclipse.jgit.lib.PersonIdent)25 List (java.util.List)24 ArrayList (java.util.ArrayList)23 HashSet (java.util.HashSet)23 Set (java.util.Set)22 RefNames (com.google.gerrit.entities.RefNames)21 AuthRequest (com.google.gerrit.server.account.AuthRequest)21 Map (java.util.Map)21 ObjectId (org.eclipse.jgit.lib.ObjectId)21 ImmutableList (com.google.common.collect.ImmutableList)20