Merge changes from topic "return-optional-from-currentuser"
* changes: IdentifiedUser#getLoggableName: Use preferred email if available Never return null from ReceiveCommits#displayName com.google.gerrit.server.account.AuthRequest#getUserName: Return Optional com.google.gerrit.server.auth.AuthRequest: Let methods return Optional Use identifiedUser.getUserName() instead of identifiedUser.state().getUserName() CurrentUser#getUserName: Return Optional<String> instead of nullable String
This commit is contained in:
@@ -108,7 +108,7 @@ public class AddSshKey implements RestModifyView<AccountResource, SshKeyInput> {
|
||||
"Cannot send SSH key added message to " + user.getAccount().getPreferredEmail(), e);
|
||||
}
|
||||
|
||||
sshKeyCache.evict(user.getUserName());
|
||||
user.getUserName().ifPresent(sshKeyCache::evict);
|
||||
return Response.<SshKeyInfo>created(GetSshKeys.newSshKeyInfo(sshKey));
|
||||
} catch (InvalidSshKeyException e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
|
||||
@@ -62,7 +62,7 @@ public class DeleteSshKey implements RestModifyView<AccountResource.SshKey, Inpu
|
||||
}
|
||||
|
||||
authorizedKeys.deleteKey(rsrc.getUser().getAccountId(), rsrc.getSshKey().getKey().get());
|
||||
sshKeyCache.evict(rsrc.getUser().getUserName());
|
||||
rsrc.getUser().getUserName().ifPresent(sshKeyCache::evict);
|
||||
|
||||
return Response.none();
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class GetOAuthToken implements RestReadView<AccountResource> {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
OAuthTokenInfo accessTokenInfo = new OAuthTokenInfo();
|
||||
accessTokenInfo.username = rsrc.getUser().state().getUserName().orElse(null);
|
||||
accessTokenInfo.username = rsrc.getUser().getUserName().orElse(null);
|
||||
accessTokenInfo.resourceHost = getHostName(canonicalWebUrlProvider.get());
|
||||
accessTokenInfo.accessToken = accessToken.getToken();
|
||||
accessTokenInfo.providerId = accessToken.getProviderId();
|
||||
|
||||
@@ -28,6 +28,6 @@ public class GetUsername implements RestReadView<AccountResource> {
|
||||
|
||||
@Override
|
||||
public String apply(AccountResource rsrc) throws AuthException, ResourceNotFoundException {
|
||||
return rsrc.getUser().state().getUserName().orElseThrow(ResourceNotFoundException::new);
|
||||
return rsrc.getUser().getUserName().orElseThrow(ResourceNotFoundException::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,11 +100,9 @@ public class PutHttpPassword implements RestModifyView<AccountResource, HttpPass
|
||||
public Response<String> apply(IdentifiedUser user, String newPassword)
|
||||
throws ResourceNotFoundException, ResourceConflictException, OrmException, IOException,
|
||||
ConfigInvalidException {
|
||||
if (user.getUserName() == null) {
|
||||
throw new ResourceConflictException("username must be set");
|
||||
}
|
||||
|
||||
ExternalId extId = externalIds.get(ExternalId.Key.create(SCHEME_USERNAME, user.getUserName()));
|
||||
String userName =
|
||||
user.getUserName().orElseThrow(() -> new ResourceConflictException("username must be set"));
|
||||
ExternalId extId = externalIds.get(ExternalId.Key.create(SCHEME_USERNAME, userName));
|
||||
if (extId == null) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user