scim-kit 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scim/kit/v2/attributable.rb +7 -4
- data/lib/scim/kit/v2/attribute.rb +21 -3
- data/lib/scim/kit/v2/attribute_type.rb +1 -0
- data/lib/scim/kit/v2/mutability.rb +5 -2
- data/lib/scim/kit/v2/resource.rb +11 -1
- data/lib/scim/kit/v2/templates/attribute.json.jbuilder +1 -1
- data/lib/scim/kit/v2/templates/resource.json.jbuilder +7 -5
- data/lib/scim/kit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33385c673e7d22f17ef8d63edc67fe1bbd6929804f911c9975a5b182bb7de303
|
4
|
+
data.tar.gz: 397e0416ac4feb3c286eed89556b2ddcea84978eaf6ffb31cd475ae4ca8f90b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94870076efae7bb2854afa211cc3670ae4a27f73a1cf330b3a6ef65bc8ae885bc68cb2258d73eb1d79d3638f9aaec75697486dbfd4ba4733515e192422e2ed2d
|
7
|
+
data.tar.gz: 3fc8ccfb002af55083f41490486cf79b7d8d443e1005f6252592b11cf23166e8ccdec491e37d807048aedca63411ddfab0abcbc634bbd76be29023a4837ff521
|
@@ -7,9 +7,9 @@ module Scim
|
|
7
7
|
module Attributable
|
8
8
|
attr_reader :dynamic_attributes
|
9
9
|
|
10
|
-
def define_attributes_for(types)
|
10
|
+
def define_attributes_for(resource, types)
|
11
11
|
@dynamic_attributes = {}.with_indifferent_access
|
12
|
-
types.each { |x| attribute(x) }
|
12
|
+
types.each { |x| attribute(x, resource) }
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -42,8 +42,11 @@ module Scim
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def attribute(type)
|
46
|
-
dynamic_attributes[type.name] = Attribute.new(
|
45
|
+
def attribute(type, resource)
|
46
|
+
dynamic_attributes[type.name] = Attribute.new(
|
47
|
+
type: type,
|
48
|
+
resource: resource
|
49
|
+
)
|
47
50
|
extend(create_module_for(type))
|
48
51
|
end
|
49
52
|
end
|
@@ -9,16 +9,18 @@ module Scim
|
|
9
9
|
include Attributable
|
10
10
|
include Templatable
|
11
11
|
attr_reader :type
|
12
|
+
attr_reader :_resource
|
12
13
|
attr_reader :_value
|
13
14
|
|
14
15
|
validate :presence_of_value, if: proc { |x| x.type.required }
|
15
16
|
validate :inclusion_of_value, if: proc { |x| x.type.canonical_values }
|
16
17
|
validate :validate_type
|
17
18
|
|
18
|
-
def initialize(type:, value: nil)
|
19
|
+
def initialize(resource:, type:, value: nil)
|
19
20
|
@type = type
|
20
|
-
@_value = value
|
21
|
-
|
21
|
+
@_value = value || type.multi_valued ? [] : nil
|
22
|
+
@_resource = resource
|
23
|
+
define_attributes_for(resource, type.attributes)
|
22
24
|
end
|
23
25
|
|
24
26
|
def _assign(new_value, coerce: true)
|
@@ -29,6 +31,14 @@ module Scim
|
|
29
31
|
_assign(new_value, coerce: true)
|
30
32
|
end
|
31
33
|
|
34
|
+
def renderable?
|
35
|
+
return false if read_only? && _resource.mode?(:client)
|
36
|
+
return false if write_only? &&
|
37
|
+
(_resource.mode?(:server) || _value.blank?)
|
38
|
+
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
32
42
|
private
|
33
43
|
|
34
44
|
def presence_of_value
|
@@ -48,6 +58,14 @@ module Scim
|
|
48
58
|
|
49
59
|
errors.add(type.name, I18n.t('errors.messages.invalid'))
|
50
60
|
end
|
61
|
+
|
62
|
+
def read_only?
|
63
|
+
type.mutability == Mutability::READ_ONLY
|
64
|
+
end
|
65
|
+
|
66
|
+
def write_only?
|
67
|
+
type.mutability == Mutability::WRITE_ONLY
|
68
|
+
end
|
51
69
|
end
|
52
70
|
end
|
53
71
|
end
|
@@ -10,10 +10,13 @@ module Scim
|
|
10
10
|
IMMUTABLE = 'immutable'
|
11
11
|
WRITE_ONLY = 'writeOnly'
|
12
12
|
VALID = {
|
13
|
+
immutable: IMMUTABLE,
|
13
14
|
read_only: READ_ONLY,
|
14
15
|
read_write: READ_WRITE,
|
15
|
-
|
16
|
-
|
16
|
+
readonly: READ_ONLY,
|
17
|
+
readwrite: READ_WRITE,
|
18
|
+
write_only: WRITE_ONLY,
|
19
|
+
writeonly: WRITE_ONLY
|
17
20
|
}.freeze
|
18
21
|
|
19
22
|
def self.find(value)
|
data/lib/scim/kit/v2/resource.rb
CHANGED
@@ -21,7 +21,17 @@ module Scim
|
|
21
21
|
@meta.disable_timestamps
|
22
22
|
@schemas = schemas
|
23
23
|
schemas.each do |schema|
|
24
|
-
define_attributes_for(schema.attributes)
|
24
|
+
define_attributes_for(self, schema.attributes)
|
25
|
+
end
|
26
|
+
yield self if block_given?
|
27
|
+
end
|
28
|
+
|
29
|
+
def mode?(type)
|
30
|
+
case type.to_sym
|
31
|
+
when :server
|
32
|
+
meta&.location
|
33
|
+
else
|
34
|
+
meta&.location.nil?
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
@@ -1,23 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
json.key_format! camelize: :lower
|
4
|
-
if
|
4
|
+
if mode?(:server)
|
5
5
|
json.meta do
|
6
6
|
render meta, json: json
|
7
7
|
end
|
8
8
|
end
|
9
9
|
json.schemas schemas.map(&:id)
|
10
|
-
json.id id if
|
11
|
-
json.external_id external_id if external_id
|
10
|
+
json.id id if mode?(:server)
|
11
|
+
json.external_id external_id if mode?(:client) && external_id
|
12
12
|
schemas.each do |schema|
|
13
13
|
if schema.core?
|
14
14
|
schema.attributes.each do |type|
|
15
|
-
|
15
|
+
attribute = dynamic_attributes[type.name]
|
16
|
+
render attribute, json: json
|
16
17
|
end
|
17
18
|
else
|
18
19
|
json.set! schema.id do
|
19
20
|
schema.attributes.each do |type|
|
20
|
-
|
21
|
+
attribute = dynamic_attributes[type.name]
|
22
|
+
render attribute, json: json
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/scim/kit/version.rb
CHANGED