audiences 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd34ee00e56f72a0ea41a829b12ac9ddbc491380c0ae693ccaab7eba2de4dda1
4
- data.tar.gz: cb81d224d20d2ce709cafa5b25d6f3d36b006f5ff5d694fd12f03b37e60f3692
3
+ metadata.gz: 8f83dd42249d90e09a66c7f11b5adb821e7f0fbc3add8089f075fe2668e79d35
4
+ data.tar.gz: 351a6676df1a297b691842e06fc18b721d3581a9bdd0ea6101bce2ed81cee06e
5
5
  SHA512:
6
- metadata.gz: d14d0e9bdc98f4cbf166330a48f7e70ae236fafe3556034b37b4fea18a61c9b3dd2b8f9e4ea99028413ad6caaf399eb821ea4999285f8402a190b2ab03f476a4
7
- data.tar.gz: 898d631afc7d53bd7941f58dc89cc2bc351ae071fbe2739c5a778255328bdf702a92770fb5a47420d88d59fcb62741233aeebf924b8a09dba13e540c43601894
6
+ metadata.gz: f90802d28319f4cbc95a8be9f9f2e68115ac7142ab6fcbf4c9be0437a14a2e57b6d58632e1befeb37b19ba1b2ce9de1d6f8fc2d9b674b120ee51d240e47140dd
7
+ data.tar.gz: d70f080cdad97a5bdfc31b701d7659a300dbeeef3c380371b1d91c7198a30c4ff9899c5106a0eb2af972e8b6d53e77ab718fb962c6f8734c960375394ffa60c6
@@ -44,7 +44,7 @@ module Audiences
44
44
  params.permit(
45
45
  :match_all,
46
46
  criteria: [groups: {}],
47
- extra_users: [:externalId, :displayName, { photos: %i[type value] }]
47
+ extra_users: Audiences.config.resources[:Users].attributes
48
48
  ).to_h.symbolize_keys
49
49
  end
50
50
  end
@@ -6,7 +6,7 @@ module Audiences
6
6
  resources = Audiences::Scim.resource(params[:scim_path].to_sym)
7
7
  .query(filter: params[:filter])
8
8
 
9
- render json: resources
9
+ render json: resources, except: %w[schemas meta]
10
10
  end
11
11
  end
12
12
  end
data/docs/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Unreleased
2
2
 
3
+ # Version 1.3.0 (2024-09-03)
4
+
5
+ - Filter out inactive users by default [#382](https://github.com/powerhome/audiences/pull/382)
6
+
7
+ # Version 1.2.2 (2024-08-21)
8
+
9
+ - Permit configured resource attributes [#375](https://github.com/powerhome/audiences/pull/375)
10
+
3
11
  # Version 1.2.1 (2024-08-06)
4
12
 
5
13
  - Fix audiences URL helpers [#372](https://github.com/powerhome/audiences/pull/372)
data/docs/README.md CHANGED
@@ -103,12 +103,12 @@ See a working example in our dummy app:
103
103
 
104
104
  ### SCIM Resource Attributes
105
105
 
106
- Configure which attributes are requested from the SCIM backend for each resource type. `Audiences` requires at least `id` and `displayName`, and also requests `photos` and `externalId` for users by default. To request additional attributes:
106
+ Configure which attributes are requested from the SCIM backend for each resource type. `Audiences` includes `id`, `externalId`, and `displayName` by default in every resource type. It also requests `photos.type` and `photos.value` for users by default. To request additional attributes:
107
107
 
108
108
  ```ruby
109
109
  Audiences.configure do |config|
110
- config.resource :Users, attributes: "id,externalId,displayName,photos,name"
111
- config.resource :Groups, attributes: "id,displayName,mfaRequired"
110
+ config.resource :Users, attributes: ["name" => %w[givenName familyName formatted]]
111
+ config.resource :Groups, attributes: %w[mfaRequired]
112
112
  end
113
113
  ```
114
114
 
@@ -46,7 +46,8 @@ module Audiences
46
46
  # @see `resource`.
47
47
  #
48
48
  config_accessor :resources do
49
- { Users: Scim::Resource.new(type: :Users, attributes: "id,externalId,displayName,photos") }
49
+ { Users: Scim::Resource.new(type: :Users, attributes: ["active", { "photos" => %w[type value] }],
50
+ filter: "active eq true") }
50
51
  end
51
52
 
52
53
  #
@@ -55,8 +56,8 @@ module Audiences
55
56
  # @param type [Symbol] the resource type in plural, as in scim (i.e.: :Users)
56
57
  # @param attributes [String] the list of attributes to fetch for the resource (i.e.: "id,externalId,displayName")
57
58
  # @see [Audiences::Scim::Resource]
58
- def config.resource(type:, **kwargs)
59
- config.resources[type] = Scim::Resource.new(type: type, **kwargs)
59
+ def config.resource(type, **kwargs)
60
+ resources[type] = Scim::Resource.new(type: type, **kwargs)
60
61
  end
61
62
 
62
63
  #
@@ -3,16 +3,41 @@
3
3
  module Audiences
4
4
  module Scim
5
5
  class Resource
6
- attr_accessor :options, :type
6
+ attr_accessor :options, :type, :attributes, :filter
7
7
 
8
- def initialize(type:, attributes: "id,externalId,displayName", **options)
8
+ def initialize(type:, attributes: [], filter: nil, **options)
9
9
  @type = type
10
10
  @options = options
11
- @options[:attributes] = attributes
11
+ @attributes = ["id", "externalId", "displayName", *attributes]
12
+ @filter = filter
12
13
  end
13
14
 
14
15
  def query(**options)
15
- ResourcesQuery.new(Scim.client, resource: self, **@options, **options)
16
+ options_filter = options.delete(:filter)
17
+ ResourcesQuery.new(Scim.client, resource: self,
18
+ attributes: scim_attributes,
19
+ filter: merged_filter(options_filter),
20
+ **@options, **options)
21
+ end
22
+
23
+ def scim_attributes
24
+ @attributes.reduce([]) do |attrs, attr|
25
+ case attr
26
+ when Hash
27
+ attrs + attr.map do |key, nested_attrs|
28
+ nested_attrs.map { "#{key}.#{_1}" }
29
+ end
30
+ else
31
+ attrs + [attr]
32
+ end
33
+ end.join(",")
34
+ end
35
+
36
+ def merged_filter(filter)
37
+ return @filter unless filter
38
+ return filter unless @filter
39
+
40
+ "(#{@filter}) and (#{filter})"
16
41
  end
17
42
  end
18
43
  end
@@ -12,9 +12,9 @@ module Audiences
12
12
  Client.new(**Audiences.config.scim)
13
13
  end
14
14
 
15
- def resource(type, **options)
15
+ def resource(type)
16
16
  Audiences.config.resources.fetch(type) do
17
- Resource.new(type: type, **options)
17
+ Resource.new(type: type)
18
18
  end
19
19
  end
20
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Audiences
4
- VERSION = "1.2.1"
4
+ VERSION = "1.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audiences
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Palhares
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-06 00:00:00.000000000 Z
11
+ date: 2024-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails