scimitar 1.10.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/scimitar/active_record_backed_resources_controller.rb +23 -98
  3. data/app/controllers/scimitar/application_controller.rb +13 -41
  4. data/app/controllers/scimitar/resource_types_controller.rb +2 -0
  5. data/app/controllers/scimitar/resources_controller.rb +2 -0
  6. data/app/controllers/scimitar/schemas_controller.rb +3 -366
  7. data/app/controllers/scimitar/service_provider_configurations_controller.rb +1 -0
  8. data/app/models/scimitar/complex_types/address.rb +6 -0
  9. data/app/models/scimitar/engine_configuration.rb +5 -15
  10. data/app/models/scimitar/error_response.rb +0 -12
  11. data/app/models/scimitar/lists/query_parser.rb +13 -113
  12. data/app/models/scimitar/resource_invalid_error.rb +1 -1
  13. data/app/models/scimitar/resources/base.rb +9 -53
  14. data/app/models/scimitar/resources/mixin.rb +59 -646
  15. data/app/models/scimitar/schema/address.rb +0 -1
  16. data/app/models/scimitar/schema/attribute.rb +5 -14
  17. data/app/models/scimitar/schema/base.rb +1 -1
  18. data/app/models/scimitar/schema/name.rb +2 -2
  19. data/app/models/scimitar/schema/user.rb +10 -10
  20. data/app/models/scimitar/schema/vdtp.rb +1 -1
  21. data/app/models/scimitar/service_provider_configuration.rb +3 -14
  22. data/config/initializers/scimitar.rb +3 -69
  23. data/lib/scimitar/engine.rb +12 -57
  24. data/lib/scimitar/support/hash_with_indifferent_case_insensitive_access.rb +10 -140
  25. data/lib/scimitar/version.rb +2 -2
  26. data/lib/scimitar.rb +2 -7
  27. data/spec/apps/dummy/app/controllers/mock_groups_controller.rb +1 -1
  28. data/spec/apps/dummy/app/models/mock_group.rb +1 -1
  29. data/spec/apps/dummy/app/models/mock_user.rb +9 -52
  30. data/spec/apps/dummy/config/application.rb +1 -0
  31. data/spec/apps/dummy/config/environments/test.rb +28 -5
  32. data/spec/apps/dummy/config/initializers/scimitar.rb +10 -90
  33. data/spec/apps/dummy/config/routes.rb +7 -28
  34. data/spec/apps/dummy/db/migrate/20210304014602_create_mock_users.rb +1 -11
  35. data/spec/apps/dummy/db/migrate/20210308044214_create_join_table_mock_groups_mock_users.rb +3 -8
  36. data/spec/apps/dummy/db/schema.rb +4 -12
  37. data/spec/controllers/scimitar/application_controller_spec.rb +3 -126
  38. data/spec/controllers/scimitar/resource_types_controller_spec.rb +2 -2
  39. data/spec/controllers/scimitar/schemas_controller_spec.rb +48 -344
  40. data/spec/models/scimitar/complex_types/address_spec.rb +4 -3
  41. data/spec/models/scimitar/complex_types/email_spec.rb +2 -0
  42. data/spec/models/scimitar/lists/query_parser_spec.rb +9 -146
  43. data/spec/models/scimitar/resources/base_spec.rb +71 -217
  44. data/spec/models/scimitar/resources/base_validation_spec.rb +5 -43
  45. data/spec/models/scimitar/resources/mixin_spec.rb +129 -1508
  46. data/spec/models/scimitar/schema/attribute_spec.rb +3 -22
  47. data/spec/models/scimitar/schema/base_spec.rb +1 -1
  48. data/spec/models/scimitar/schema/user_spec.rb +2 -12
  49. data/spec/requests/active_record_backed_resources_controller_spec.rb +66 -1016
  50. data/spec/requests/application_controller_spec.rb +3 -16
  51. data/spec/requests/engine_spec.rb +0 -75
  52. data/spec/spec_helper.rb +1 -9
  53. data/spec/support/hash_with_indifferent_case_insensitive_access_spec.rb +0 -108
  54. metadata +26 -37
  55. data/LICENSE.txt +0 -21
  56. data/README.md +0 -717
  57. data/lib/scimitar/support/utilities.rb +0 -111
  58. data/spec/apps/dummy/app/controllers/custom_create_mock_users_controller.rb +0 -25
  59. data/spec/apps/dummy/app/controllers/custom_replace_mock_users_controller.rb +0 -25
  60. data/spec/apps/dummy/app/controllers/custom_save_mock_users_controller.rb +0 -24
  61. data/spec/apps/dummy/app/controllers/custom_update_mock_users_controller.rb +0 -25
@@ -35,45 +35,14 @@ module Scimitar
35
35
  @errors = ActiveModel::Errors.new(self)
36
36
  end
37
37
 
38
- # Scimitar has at present a general limitation in handling schema IDs,
39
- # which just involves stripping them and requiring attributes across all
40
- # extension schemas to be overall unique.
41
- #
42
- # This method takes an options payload for the initializer and strips out
43
- # *recognised* schema IDs, so that the resulting attribute data matches
44
- # the resource attribute map.
45
- #
46
- # +attributes+:: Attributes to assign via initializer; typically a POST
47
- # payload of attributes that has been run through Rails
48
- # strong parameters for safety.
49
- #
50
- # Returns a new object of the same class as +options+ with recognised
51
- # schema IDs removed.
52
- #
53
38
  def flatten_extension_attributes(options)
54
- flattened = options.class.new
55
- lower_case_schema_ids = self.class.extended_schemas.map do | schema |
56
- schema.id.downcase()
57
- end
58
-
59
- options.each do | key, value |
60
- path = Scimitar::Support::Utilities::path_str_to_array(
61
- self.class.extended_schemas,
62
- key
63
- )
64
-
65
- if path.first.include?(':') && lower_case_schema_ids.include?(path.first.downcase)
66
- path.shift()
67
- end
68
-
69
- if path.empty?
70
- flattened.merge!(value)
71
- else
72
- flattened[path.join('.')] = value
39
+ flattened = options.dup
40
+ self.class.extended_schemas.each do |extended_schema|
41
+ if extension_attrs = flattened.delete(extended_schema.id)
42
+ flattened.merge!(extension_attrs)
73
43
  end
74
44
  end
75
-
76
- return flattened
45
+ flattened
77
46
  end
78
47
 
79
48
  # Can be used to extend an existing resource type's schema. For example:
@@ -143,7 +112,7 @@ module Scimitar
143
112
  end
144
113
 
145
114
  def self.complex_scim_attributes
146
- schemas.flat_map(&:scim_attributes).select(&:complexType).group_by(&:name)
115
+ schema.scim_attributes.select(&:complexType).group_by(&:name)
147
116
  end
148
117
 
149
118
  def complex_type_from_hash(scim_attribute, attr_value)
@@ -160,7 +129,7 @@ module Scimitar
160
129
 
161
130
  if scim_attribute && scim_attribute.complexType
162
131
  if scim_attribute.multiValued
163
- self.send("#{attr_name}=", attr_value&.map {|attr_for_each_item| complex_type_from_hash(scim_attribute, attr_for_each_item)})
132
+ self.send("#{attr_name}=", attr_value.map {|attr_for_each_item| complex_type_from_hash(scim_attribute, attr_for_each_item)})
164
133
  else
165
134
  self.send("#{attr_name}=", complex_type_from_hash(scim_attribute, attr_value))
166
135
  end
@@ -168,28 +137,15 @@ module Scimitar
168
137
  end
169
138
  end
170
139
 
171
- # Renders *in full* as JSON; typically used for write-based operations...
172
- #
173
- # record = self.storage_class().new
174
- # record.from_scim!(scim_hash: scim_resource.as_json())
175
- # self.save!(record)
176
- #
177
- # ...so all fields, even those marked "returned: false", are included.
178
- # Use Scimitar::Resources::Mixin::to_scim to obtain a SCIM object with
179
- # non-returnable fields omitted, rendering *that* as JSON via #to_json.
180
- #
181
140
  def as_json(options = {})
182
- self.meta = Meta.new unless self.meta && self.meta.is_a?(Meta)
183
- self.meta.resourceType = self.class.resource_type_id
184
-
141
+ self.meta = Meta.new unless self.meta
142
+ meta.resourceType = self.class.resource_type_id
185
143
  original_hash = super(options).except('errors')
186
144
  original_hash.merge!('schemas' => self.class.schemas.map(&:id))
187
-
188
145
  self.class.extended_schemas.each do |extension_schema|
189
146
  extension_attributes = extension_schema.scim_attributes.map(&:name)
190
147
  original_hash.merge!(extension_schema.id => original_hash.extract!(*extension_attributes))
191
148
  end
192
-
193
149
  original_hash
194
150
  end
195
151