Commit 8f425334a7794917c7947765875eab9d10e89f07
1 parent
aac91c37
Exists in
master
fix scim
Showing
2 changed files
with
16 additions
and
6 deletions
Show diff stats
app/controllers/scim_rails/scim_users_controller.rb
@@ -118,7 +118,19 @@ module ScimRails | @@ -118,7 +118,19 @@ module ScimRails | ||
118 | end | 118 | end |
119 | 119 | ||
120 | def find_value_for(attribute) | 120 | def find_value_for(attribute) |
121 | - params.dig(*path_for(attribute).map { |x| x.to_s }) rescue nil | 121 | + object = ScimRails.config.mutable_user_attributes_schema |
122 | + paths = Array.wrap(path_for(attribute, object)).compact.map(&:to_s) | ||
123 | + while paths.present? | ||
124 | + value = params.dig(*paths) rescue nil | ||
125 | + if value.present? | ||
126 | + break | ||
127 | + else | ||
128 | + object.delete(paths[0].to_sym) | ||
129 | + paths = Array.wrap(path_for(attribute, object)).compact.map(&:to_s) | ||
130 | + end | ||
131 | + end | ||
132 | + # params.dig(*path_for(attribute).map { |x| x.to_s }) rescue nil | ||
133 | + return value | ||
122 | end | 134 | end |
123 | 135 | ||
124 | # `path_for` is a recursive method used to find the "path" for | 136 | # `path_for` is a recursive method used to find the "path" for |
@@ -129,11 +141,9 @@ module ScimRails | @@ -129,11 +141,9 @@ module ScimRails | ||
129 | # like [:names, 0, :givenName]. `.dig` can then use that path | 141 | # like [:names, 0, :givenName]. `.dig` can then use that path |
130 | # against the params to translate the :name attribute to "John". | 142 | # against the params to translate the :name attribute to "John". |
131 | 143 | ||
132 | - def path_for(attribute, object = ScimRails.config.mutable_user_attributes_schema, path = []) | 144 | + def path_for(attribute, object = ScimRails.config.mutable_user_attributes_schema, path = [], finded_paths = []) |
133 | at_path = path.empty? ? object : object.dig(*path) | 145 | at_path = path.empty? ? object : object.dig(*path) |
134 | - if at_path == attribute && (params.dig(*path) rescue nil).present? | ||
135 | - return path | ||
136 | - end | 146 | + return if at_path == attribute |
137 | 147 | ||
138 | result = nil | 148 | result = nil |
139 | case at_path | 149 | case at_path |
lib/scim_rails/version.rb