Search in sources :

Example 1 with NameInput

use of com.google.gerrit.extensions.common.NameInput in project gerrit by GerritCodeReview.

the class SetAccountCommand method setAccount.

private void setAccount() throws Failure {
    user = genericUserFactory.create(id);
    rsrc = new AccountResource(user.asIdentifiedUser());
    try {
        for (String email : addEmails) {
            addEmail(email);
        }
        for (String email : deleteEmails) {
            deleteEmail(email);
        }
        if (preferredEmail != null) {
            putPreferred(preferredEmail);
        }
        if (fullName != null) {
            NameInput in = new NameInput();
            in.name = fullName;
            putName.apply(rsrc, in);
        }
        if (httpPassword != null || clearHttpPassword || generateHttpPassword) {
            HttpPasswordInput in = new HttpPasswordInput();
            in.httpPassword = httpPassword;
            if (generateHttpPassword) {
                in.generate = true;
            }
            Response<String> resp = putHttpPassword.apply(rsrc, in);
            if (generateHttpPassword) {
                stdout.print("New password: " + resp.value() + "\n");
            }
        }
        if (active) {
            putActive.apply(rsrc, null);
        } else if (inactive) {
            try {
                deleteActive.apply(rsrc, null);
            } catch (ResourceNotFoundException e) {
            // user is already inactive
            }
        }
        addSshKeys = readSshKey(addSshKeys);
        if (!addSshKeys.isEmpty()) {
            addSshKeys(addSshKeys);
        }
        deleteSshKeys = readSshKey(deleteSshKeys);
        if (!deleteSshKeys.isEmpty()) {
            deleteSshKeys(deleteSshKeys);
        }
        for (String externalId : externalIdsToDelete) {
            deleteExternalId(externalId);
        }
    } catch (RestApiException e) {
        throw die(e.getMessage());
    } catch (Exception e) {
        throw new Failure(1, "unavailable", e);
    }
}
Also used : AccountResource(com.google.gerrit.server.account.AccountResource) HttpPasswordInput(com.google.gerrit.extensions.common.HttpPasswordInput) IdString(com.google.gerrit.extensions.restapi.IdString) NameInput(com.google.gerrit.extensions.common.NameInput) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) EmailException(com.google.gerrit.exceptions.EmailException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) AuthException(com.google.gerrit.extensions.restapi.AuthException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) IOException(java.io.IOException)

Example 2 with NameInput

use of com.google.gerrit.extensions.common.NameInput in project gerrit by GerritCodeReview.

the class RenameGroupCommand method run.

@Override
protected void run() throws Failure {
    enableGracefulStop();
    try {
        GroupResource rsrc = groups.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(groupName));
        NameInput input = new NameInput();
        input.name = newGroupName;
        putName.apply(rsrc, input);
    } catch (RestApiException | IOException | ConfigInvalidException e) {
        throw die(e);
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) NameInput(com.google.gerrit.extensions.common.NameInput) IOException(java.io.IOException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) GroupResource(com.google.gerrit.server.group.GroupResource)

Example 3 with NameInput

use of com.google.gerrit.extensions.common.NameInput in project gerrit by GerritCodeReview.

the class AccountApiImpl method setName.

@Override
public void setName(String name) throws RestApiException {
    NameInput input = new NameInput();
    input.name = name;
    try {
        putName.apply(account, input);
    } catch (Exception e) {
        throw asRestApiException("Cannot set account name", e);
    }
}
Also used : NameInput(com.google.gerrit.extensions.common.NameInput) DisplayNameInput(com.google.gerrit.extensions.api.accounts.DisplayNameInput) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 4 with NameInput

use of com.google.gerrit.extensions.common.NameInput in project gerrit by GerritCodeReview.

the class GroupApiImpl method name.

@Override
public void name(String name) throws RestApiException {
    NameInput in = new NameInput();
    in.name = name;
    try {
        putName.apply(rsrc, in);
    } catch (Exception e) {
        throw asRestApiException("Cannot put group name", e);
    }
}
Also used : NameInput(com.google.gerrit.extensions.common.NameInput) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 5 with NameInput

use of com.google.gerrit.extensions.common.NameInput 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)

Aggregations

NameInput (com.google.gerrit.extensions.common.NameInput)5 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)4 IOException (java.io.IOException)3 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)3 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 AccountResource (com.google.gerrit.server.account.AccountResource)2 ApiUtil.asRestApiException (com.google.gerrit.server.api.ApiUtil.asRestApiException)2 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)2 Strings (com.google.common.base.Strings)1 Account (com.google.gerrit.entities.Account)1 EmailException (com.google.gerrit.exceptions.EmailException)1 DisplayNameInput (com.google.gerrit.extensions.api.accounts.DisplayNameInput)1 AccountFieldName (com.google.gerrit.extensions.client.AccountFieldName)1 HttpPasswordInput (com.google.gerrit.extensions.common.HttpPasswordInput)1 IdString (com.google.gerrit.extensions.restapi.IdString)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 Response (com.google.gerrit.extensions.restapi.Response)1 RestModifyView (com.google.gerrit.extensions.restapi.RestModifyView)1 CurrentUser (com.google.gerrit.server.CurrentUser)1