diff --git a/README.md b/README.md index 7dc3ce24..c7084485 100644 --- a/README.md +++ b/README.md @@ -644,7 +644,9 @@ descope_client.logout_user('') descope_client.logout_user_by_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| diff --git a/lib/descope/api/v1/management/user.rb b/lib/descope/api/v1/management/user.rb index 431059c1..46a032f7 100644 --- a/lib/descope/api/v1/management/user.rb +++ b/lib/descope/api/v1/management/user.rb @@ -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: [], @@ -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, @@ -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? + 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 @@ -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] Optional list of login ids # @param sort [Array] 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": []} # @@ -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 ||= [] @@ -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 diff --git a/spec/lib.descope/api/v1/management/user_spec.rb b/spec/lib.descope/api/v1/management/user_spec.rb index 5164d6e3..ea5838dd 100644 --- a/spec/lib.descope/api/v1/management/user_spec.rb +++ b/spec/lib.descope/api/v1/management/user_spec.rb @@ -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 @@ -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