Skip to content

Commit

Permalink
Paginate users before making the request to avoid 414
Browse files Browse the repository at this point in the history
  • Loading branch information
xjunior committed Feb 4, 2025
1 parent 1af41ec commit 73be562
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions audiences/app/models/audiences/external_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class ExternalUser < ApplicationRecord
inverse_of: false
end

def self.fetch(external_ids)
def self.fetch(external_ids, count: 100)
return [] unless external_ids.any?

filter = Array(external_ids).map { "externalId eq #{_1}" }.join(" OR ")
Audiences::Scim.resource(:Users).all(filter: filter)
Array(external_ids).in_groups_of(count, false).flat_map do |ids|
filter = Array(ids).map { "externalId eq #{_1}" }.join(" OR ")
Audiences::Scim.resource(:Users).all(count: count, filter: filter).to_a
end
end

def self.wrap(resources)
Expand Down
1 change: 1 addition & 0 deletions audiences/spec/controllers/contexts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
stub_request(:get, "http://example.com/scim/v2/Users")
.with(query: {
attributes: "id,externalId,displayName,active,photos.type,photos.value",
count: 100,
filter: "(active eq true) and (externalId eq 123)",
})
.to_return(status: 200, body: { "Resources" => [{ "displayName" => "John Doe", "confidential" => "data",
Expand Down
1 change: 1 addition & 0 deletions audiences/spec/lib/audiences_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
stub_request(:get, "http://example.com/scim/v2/Users")
.with(query: {
attributes: "id,externalId,displayName,active,photos.type,photos.value",
count: 100,
filter: "(active eq true) and (externalId eq 678 OR externalId eq 321)",
})
.to_return(status: 200, body: { "Resources" => [{ "displayName" => "John", "externalId" => 678 },
Expand Down

0 comments on commit 73be562

Please sign in to comment.