From c044e7480a4f9a8b7fb901f8ea573db1209c7f23 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Fri, 13 Jan 2017 08:23:16 +0100 Subject: [PATCH] AccountExternalIdInfo: Return null for boolean fields in case of false This is to be consistent with how the values for other boolean fields are returned. Change-Id: I10365265fa477613bbf40b043655743d40d6eb3c Signed-off-by: Edwin Kempin --- Documentation/rest-api-accounts.txt | 10 +++++----- .../gerrit/acceptance/api/accounts/AccountIT.java | 4 ++-- .../gerrit/server/account/GetExternalIds.java | 15 +++++++++------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Documentation/rest-api-accounts.txt b/Documentation/rest-api-accounts.txt index 14c716dc76..bef9c97c76 100644 --- a/Documentation/rest-api-accounts.txt +++ b/Documentation/rest-api-accounts.txt @@ -1702,8 +1702,7 @@ link:#account-external-id-info[AccountExternalIdInfo] entities. { "identity": "username:john", "email": "john.doe@example.com", - "trusted": true, - "can_delete": false + "trusted": true } ] ---- @@ -2142,9 +2141,10 @@ an account. |Field Name ||Description |`identity` ||The account external id. |`email` |optional|The email address for the external id. -|`trusted` ||True if the external id is trusted. -|`can_delete` || -True if the external id can be deleted by the calling user. +|`trusted` |not set if `false`| +Whether the external id is trusted. +|`can_delete` |not set if `false`| +Whether the external id can be deleted by the calling user. |============================ [[capability-info]] diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java index 60b86a07dc..ea074ad9ae 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java @@ -758,8 +758,8 @@ public class AccountIT extends AbstractDaemonTest { newGson().fromJson(response.getReader(), new TypeToken>() {}.getType()); - // 'canDelete' field will be all false. It will be better if we can find - // a way to test it. But it looks a little difficult. + // 'canDelete' field will be all null (false). It will be better if we can + // find a way to test it. But it looks a little difficult. externalIdInfoList.stream().sorted(); assertThat(expectedIdInfoList) .containsExactlyElementsIn(expectedIdInfoList); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/GetExternalIds.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/GetExternalIds.java index 215ef032c1..1eae4cfccb 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/GetExternalIds.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/GetExternalIds.java @@ -66,22 +66,25 @@ public class GetExternalIds implements RestReadView { AccountExternalIdInfo info = new AccountExternalIdInfo(); info.identity = id.getExternalId(); info.emailAddress = id.getEmailAddress(); - info.trusted = authConfig.isIdentityTrustable( - Collections.singleton(id)); + info.trusted = + toBoolean(authConfig.isIdentityTrustable(Collections.singleton(id))); // The identity can be deleted only if its not the one used to // establish this web session, and if only if an identity was // actually used to establish this web session. - if (id.isScheme(SCHEME_USERNAME)) { - info.canDelete = false; - } else { + if (!id.isScheme(SCHEME_USERNAME)) { CurrentUser.PropertyKey k = CurrentUser.PropertyKey.create(); AccountExternalId.Key last = resource.getUser().get(k); - info.canDelete = (last != null) && (!last.get().equals(info.identity)); + info.canDelete = + toBoolean(last != null && !last.get().equals(info.identity)); } result.add(info); } return result; } + + private static Boolean toBoolean(boolean v) { + return v ? v : null; + } }