Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,9 @@ descope_client.logout_user('<login-id>')
descope_client.logout_user_by_id('<user-id>')

# Search all users, optionally according to tenant and/or role filter
# results can be paginated using the limit and page parameters
# results can be paginated using the limit and page parameters,
# as well as filtered by time with from_created_time, to_created_time,
# from_modified_time, and to_modified_time (Unix epoch milliseconds)
users_resp = descope_client.search_all_users(tenant_ids = ['my-tenant-id'])
users = users_resp['users']
users.each do |user|
Expand Down
28 changes: 26 additions & 2 deletions lib/descope/api/v1/management/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def logout_user_by_id(user_id)

# Search for users, using a valid management key.
# @see https://docs.descope.com/api/openapi/usermanagement/operation/SearchUsers/
# @param from_created_time [Integer, nil] only include users created after this time (Unix epoch milliseconds).
# @param to_created_time [Integer, nil] only include users created on or before this time (Unix epoch milliseconds).
# @param from_modified_time [Integer, nil] only include users modified after this time (Unix epoch milliseconds).
# @param to_modified_time [Integer, nil] only include users modified on or before this time (Unix epoch milliseconds).
def search_all_users(
login_id: nil,
tenant_ids: [],
Expand All @@ -187,7 +191,11 @@ def search_all_users(
phones: [],
sso_app_ids: [],
tenant_role_ids: {},
tenant_role_names: {}
tenant_role_names: {},
from_created_time: nil,
to_created_time: nil,
from_modified_time: nil,
to_modified_time: nil
)
body = {
loginId: login_id,
Expand Down Expand Up @@ -216,6 +224,10 @@ def search_all_users(
body[:roleNames] = role_names unless role_names.empty?
body[:tenantRoleIds] = map_to_values_object(tenant_role_ids) unless tenant_role_ids.nil? || tenant_role_ids.empty?
body[:tenantRoleNames] = map_to_values_object(tenant_role_names) unless tenant_role_names.nil? || tenant_role_names.empty?
body[:fromCreatedTime] = from_created_time unless from_created_time.nil?
Comment thread
dishanthirpara-maker marked this conversation as resolved.
body[:toCreatedTime] = to_created_time unless to_created_time.nil?
body[:fromModifiedTime] = from_modified_time unless from_modified_time.nil?
body[:toModifiedTime] = to_modified_time unless to_modified_time.nil?
post(Common::USERS_SEARCH_PATH, body)
end

Expand Down Expand Up @@ -530,6 +542,10 @@ def generate_embedded_link(login_id: nil, custom_claims: nil)
# @param text [String] Optional string, allows free text search among all user's attributes.
# @param login_ids [Array<String>] Optional list of login ids
# @param sort [Array<Hash>] Optional array, allows to sort by fields.
# @param from_created_time [Integer, nil] Optional, only include users created after this time (Unix epoch milliseconds).
# @param to_created_time [Integer, nil] Optional, only include users created on or before this time (Unix epoch milliseconds).
# @param from_modified_time [Integer, nil] Optional, only include users modified after this time (Unix epoch milliseconds).
# @param to_modified_time [Integer, nil] Optional, only include users modified on or before this time (Unix epoch milliseconds).
#
# @return [Hash] Return hash in the format {"users": []}
#
Expand All @@ -551,7 +567,11 @@ def search_all_test_users(
text: nil,
login_ids: [],
tenant_role_ids: {},
tenant_role_names: {}
tenant_role_names: {},
from_created_time: nil,
to_created_time: nil,
from_modified_time: nil,
to_modified_time: nil
)
tenant_ids ||= []
role_names ||= []
Expand Down Expand Up @@ -581,6 +601,10 @@ def search_all_test_users(
body[:text] = text unless text.nil? || text.empty?
body[:tenantRoleIds] = map_to_values_object(tenant_role_ids) unless tenant_role_ids.nil? || tenant_role_ids.empty?
body[:tenantRoleNames] = map_to_values_object(tenant_role_names) unless tenant_role_names.nil? || tenant_role_names.empty?
body[:fromCreatedTime] = from_created_time unless from_created_time.nil?
body[:toCreatedTime] = to_created_time unless to_created_time.nil?
body[:fromModifiedTime] = from_modified_time unless from_modified_time.nil?
body[:toModifiedTime] = to_modified_time unless to_modified_time.nil?

post(Common::TEST_USERS_SEARCH_PATH, body)
end
Expand Down
56 changes: 56 additions & 0 deletions spec/lib.descope/api/v1/management/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,36 @@
)
end.not_to raise_error
end

it 'is expected to include time-range filters when provided' do
expect(@instance).to receive(:post).with(
USERS_SEARCH_PATH, {
loginId: nil,
tenantIds: [],
roleNames: [],
limit: 0,
page: 0,
text: nil,
ssoAppIds: [],
ssoOnly: false,
testUsersOnly: false,
withTestUser: false,
fromCreatedTime: 1_700_000_000_000,
toCreatedTime: 1_800_000_000_000,
fromModifiedTime: 1_700_000_000_000,
toModifiedTime: 1_800_000_000_000
}
)

expect do
@instance.search_all_users(
from_created_time: 1_700_000_000_000,
to_created_time: 1_800_000_000_000,
from_modified_time: 1_700_000_000_000,
to_modified_time: 1_800_000_000_000
)
end.not_to raise_error
end
end

context '.get_provider_token' do
Expand Down Expand Up @@ -791,5 +821,31 @@
)
end.not_to raise_error
end

it 'is expected to include time-range filters when provided' do
expect(@instance).to receive(:post).with(
TEST_USERS_SEARCH_PATH, {
tenantIds: [],
roleNames: [],
limit: 0,
page: 0,
testUsersOnly: true,
withTestUser: true,
fromCreatedTime: 1_700_000_000_000,
toCreatedTime: 1_800_000_000_000,
fromModifiedTime: 1_700_000_000_000,
toModifiedTime: 1_800_000_000_000
}
)

expect do
@instance.search_all_test_users(
from_created_time: 1_700_000_000_000,
to_created_time: 1_800_000_000_000,
from_modified_time: 1_700_000_000_000,
to_modified_time: 1_800_000_000_000
)
end.not_to raise_error
end
end
end