Search in sources :

Example 1 with DisplayNameInput

use of com.google.gerrit.extensions.api.accounts.DisplayNameInput in project gerrit by GerritCodeReview.

the class PutDisplayName method apply.

@Override
public Response<String> apply(AccountResource rsrc, @Nullable DisplayNameInput input) throws AuthException, ResourceNotFoundException, IOException, PermissionBackendException, ConfigInvalidException {
    IdentifiedUser user = rsrc.getUser();
    if (!self.get().hasSameAccountId(user)) {
        permissionBackend.currentUser().check(GlobalPermission.MODIFY_ACCOUNT);
    }
    if (input == null) {
        input = new DisplayNameInput();
    }
    String newDisplayName = input.displayName;
    AccountState accountState = accountsUpdateProvider.get().update("Set Display Name via API", user.getAccountId(), u -> u.setDisplayName(newDisplayName)).orElseThrow(() -> new ResourceNotFoundException("account not found"));
    return Strings.isNullOrEmpty(accountState.account().displayName()) ? Response.none() : Response.ok(accountState.account().displayName());
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) GlobalPermission(com.google.gerrit.server.permissions.GlobalPermission) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) CurrentUser(com.google.gerrit.server.CurrentUser) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Inject(com.google.inject.Inject) AccountResource(com.google.gerrit.server.account.AccountResource) IOException(java.io.IOException) 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) Provider(com.google.inject.Provider) Nullable(com.google.gerrit.common.Nullable) DisplayNameInput(com.google.gerrit.extensions.api.accounts.DisplayNameInput) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ServerInitiated(com.google.gerrit.server.ServerInitiated) AuthException(com.google.gerrit.extensions.restapi.AuthException) AccountState(com.google.gerrit.server.account.AccountState) AccountsUpdate(com.google.gerrit.server.account.AccountsUpdate) Singleton(com.google.inject.Singleton) DisplayNameInput(com.google.gerrit.extensions.api.accounts.DisplayNameInput) AccountState(com.google.gerrit.server.account.AccountState) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Aggregations

Strings (com.google.common.base.Strings)1 Nullable (com.google.gerrit.common.Nullable)1 DisplayNameInput (com.google.gerrit.extensions.api.accounts.DisplayNameInput)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 Response (com.google.gerrit.extensions.restapi.Response)1 RestModifyView (com.google.gerrit.extensions.restapi.RestModifyView)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1 ServerInitiated (com.google.gerrit.server.ServerInitiated)1 AccountResource (com.google.gerrit.server.account.AccountResource)1 AccountState (com.google.gerrit.server.account.AccountState)1 AccountsUpdate (com.google.gerrit.server.account.AccountsUpdate)1 GlobalPermission (com.google.gerrit.server.permissions.GlobalPermission)1 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1 Singleton (com.google.inject.Singleton)1 IOException (java.io.IOException)1