Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter get-users API by last login #258

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,34 @@ public ApiResponse users(Boolean pending, List<String> userIds, String prefix, S
* @throws Exception If the request fails.
*/
public ApiResponse users(Boolean pending, List<String> userIds, String prefix, String subAccountId, Map<String, Object> options) throws Exception {
return users(pending, userIds, prefix, subAccountId, options, null, null, null);
}

/**
* Get a list of the users according to filters.
*
* @param pending Optional. Limit results to pending users (true), users that are not pending (false), or all users (null)
* @param userIds Optionals. List of user IDs. Up to 100
* @param prefix Optional. Search by prefix of the user's name or email. Case-insensitive
* @param subAccountId Optional. Return only users who have access to the given sub-account
* @param options Generic advanced options map, see online documentation.
* @param lastLogin Optional. Return only users that last logged in in the specified range of dates (true), users that didn’t last logged in in that range (false), or all users (null).
* @param from Optional. Last login start date.
* @param to Optional. Last login end date.
* @return the users' details.
* @throws Exception If the request fails.
*/
public ApiResponse users(Boolean pending, List<String> userIds, String prefix, String subAccountId, Map<String, Object> options, Boolean lastLogin, Date from, Date to) throws Exception {
List<String> uri = Arrays.asList(PROVISIONING, ACCOUNTS, accountId, USERS);
return callAccountApi(Api.HttpMethod.GET, uri,
ObjectUtils.asMap("accountId", accountId,
"pending", pending,
"ids", userIds,
"prefix", prefix,
"sub_account_id", subAccountId), options);
"sub_account_id", subAccountId,
"last_login", lastLogin,
"from", ObjectUtils.toISO8601(from),
"to", ObjectUtils.toISO8601(to)), options);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,36 @@ public void testGetUsersBySubAccountIds() throws Exception {
assertEquals(1, ((ArrayList) usersBySubAccount.get("users")).size());
}

@Test
public void testGetUserByLastLoginTrue() throws Exception {
final long timeMillis = System.currentTimeMillis();
final String userName = String.format("SDK TEST Get Users By Last Login True %d", timeMillis);
final String userEmail = String.format("sdk-test-get-users-by-llt+%[email protected]", timeMillis);

createUser(userName,
userEmail,
Account.Role.BILLING,
Collections.<String>emptyList());

ApiResponse userByLastLogin = account.users(true, null, userName.substring(0, userName.length() - 1), null, null, true, new Date(), new Date());
assertEquals(0, ((ArrayList) userByLastLogin.get("users")).size());
}

@Test
public void testGetUserByLastLoginFalse() throws Exception {
final long timeMillis = System.currentTimeMillis();
final String userName = String.format("SDK TEST Get Users By Last Login False %d", timeMillis);
final String userEmail = String.format("sdk-test-get-users-by-llf+%[email protected]", timeMillis);

createUser(userName,
userEmail,
Account.Role.BILLING,
Collections.<String>emptyList());

ApiResponse userByLastLogin = account.users(true, null, userName.substring(0, userName.length() - 1), null, null, false, new Date(), new Date());
assertEquals(1, ((ArrayList) userByLastLogin.get("users")).size());
}

@Test
public void testGetUsersThrowsWhenSubAccountIdDoesntExist() throws Exception {
final String subAccountId = randomLetters();
Expand Down