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 <ekempin@google.com>
This commit is contained in:
@@ -1702,8 +1702,7 @@ link:#account-external-id-info[AccountExternalIdInfo] entities.
|
|||||||
{
|
{
|
||||||
"identity": "username:john",
|
"identity": "username:john",
|
||||||
"email": "john.doe@example.com",
|
"email": "john.doe@example.com",
|
||||||
"trusted": true,
|
"trusted": true
|
||||||
"can_delete": false
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
----
|
----
|
||||||
@@ -2142,9 +2141,10 @@ an account.
|
|||||||
|Field Name ||Description
|
|Field Name ||Description
|
||||||
|`identity` ||The account external id.
|
|`identity` ||The account external id.
|
||||||
|`email` |optional|The email address for the external id.
|
|`email` |optional|The email address for the external id.
|
||||||
|`trusted` ||True if the external id is trusted.
|
|`trusted` |not set if `false`|
|
||||||
|`can_delete` ||
|
Whether the external id is trusted.
|
||||||
True if the external id can be deleted by the calling user.
|
|`can_delete` |not set if `false`|
|
||||||
|
Whether the external id can be deleted by the calling user.
|
||||||
|============================
|
|============================
|
||||||
|
|
||||||
[[capability-info]]
|
[[capability-info]]
|
||||||
|
|||||||
@@ -758,8 +758,8 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
newGson().fromJson(response.getReader(),
|
newGson().fromJson(response.getReader(),
|
||||||
new TypeToken<List<AccountExternalIdInfo>>() {}.getType());
|
new TypeToken<List<AccountExternalIdInfo>>() {}.getType());
|
||||||
|
|
||||||
// 'canDelete' field will be all false. It will be better if we can find
|
// 'canDelete' field will be all null (false). It will be better if we can
|
||||||
// a way to test it. But it looks a little difficult.
|
// find a way to test it. But it looks a little difficult.
|
||||||
externalIdInfoList.stream().sorted();
|
externalIdInfoList.stream().sorted();
|
||||||
assertThat(expectedIdInfoList)
|
assertThat(expectedIdInfoList)
|
||||||
.containsExactlyElementsIn(expectedIdInfoList);
|
.containsExactlyElementsIn(expectedIdInfoList);
|
||||||
|
|||||||
@@ -66,22 +66,25 @@ public class GetExternalIds implements RestReadView<AccountResource> {
|
|||||||
AccountExternalIdInfo info = new AccountExternalIdInfo();
|
AccountExternalIdInfo info = new AccountExternalIdInfo();
|
||||||
info.identity = id.getExternalId();
|
info.identity = id.getExternalId();
|
||||||
info.emailAddress = id.getEmailAddress();
|
info.emailAddress = id.getEmailAddress();
|
||||||
info.trusted = authConfig.isIdentityTrustable(
|
info.trusted =
|
||||||
Collections.singleton(id));
|
toBoolean(authConfig.isIdentityTrustable(Collections.singleton(id)));
|
||||||
// The identity can be deleted only if its not the one used to
|
// The identity can be deleted only if its not the one used to
|
||||||
// establish this web session, and if only if an identity was
|
// establish this web session, and if only if an identity was
|
||||||
// actually used to establish this web session.
|
// actually used to establish this web session.
|
||||||
if (id.isScheme(SCHEME_USERNAME)) {
|
if (!id.isScheme(SCHEME_USERNAME)) {
|
||||||
info.canDelete = false;
|
|
||||||
} else {
|
|
||||||
CurrentUser.PropertyKey<AccountExternalId.Key> k =
|
CurrentUser.PropertyKey<AccountExternalId.Key> k =
|
||||||
CurrentUser.PropertyKey.create();
|
CurrentUser.PropertyKey.create();
|
||||||
AccountExternalId.Key last = resource.getUser().get(k);
|
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);
|
result.add(info);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Boolean toBoolean(boolean v) {
|
||||||
|
return v ? v : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user