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

Paginate users before making the request to avoid 414 #507

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 6 additions & 4 deletions audiences/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
audiences (1.5.3)
audiences (1.5.4)
rails (>= 6.0)

GEM
Expand Down Expand Up @@ -121,7 +121,6 @@ GEM
marcel (1.0.4)
method_source (1.1.0)
mini_mime (1.1.5)
mini_portile2 (2.8.8)
minitest (5.25.4)
mysql2 (0.5.6)
net-imap (0.4.17)
Expand All @@ -134,8 +133,11 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.4)
nokogiri (1.16.8)
mini_portile2 (~> 2.8.2)
nokogiri (1.16.8-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.8-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.8-x86_64-linux)
racc (~> 1.4)
parallel (1.26.3)
parser (3.3.6.0)
Expand Down
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
xjunior marked this conversation as resolved.
Show resolved Hide resolved
end
end

def self.wrap(resources)
Expand Down
3 changes: 3 additions & 0 deletions audiences/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Unreleased

# Version 1.5.4 (2024-12-19)

- Fix `authenticate` / `authentication` configuration [#481](https://github.com/powerhome/audiences/pull/481)
- Paginage user requests in audiences instead of SCIM [#507](https://github.com/powerhome/audiences/pull/507)

# Version 1.5.3 (2024-12-19)

Expand Down
2 changes: 1 addition & 1 deletion audiences/gemfiles/rails_6_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
audiences (1.5.3)
audiences (1.5.4)
rails (>= 6.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion audiences/gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
audiences (1.5.3)
audiences (1.5.4)
rails (>= 6.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion audiences/gemfiles/rails_7_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
audiences (1.5.3)
audiences (1.5.4)
rails (>= 6.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion audiences/lib/audiences/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Audiences
VERSION = "1.5.3"
VERSION = "1.5.4"
end
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
Loading