Commit 98e689313ce6b49c0282843854d1c701c861a5dc
1 parent
5b290a5d
Exists in
master
Add user update for patch api
Showing
2 changed files
with
8 additions
and
8 deletions
Show diff stats
app/controllers/scim_rails/scim_users_controller.rb
@@ -20,7 +20,7 @@ module ScimRails | @@ -20,7 +20,7 @@ module ScimRails | ||
20 | counts = ScimCount.new( | 20 | counts = ScimCount.new( |
21 | start_index: params[:startIndex], | 21 | start_index: params[:startIndex], |
22 | limit: params[:count], | 22 | limit: params[:count], |
23 | - total: users.count | 23 | + total: users.count, |
24 | ) | 24 | ) |
25 | 25 | ||
26 | json_scim_response(object: users, counts: counts) | 26 | json_scim_response(object: users, counts: counts) |
@@ -66,18 +66,19 @@ module ScimRails | @@ -66,18 +66,19 @@ module ScimRails | ||
66 | user = @company.public_send(ScimRails.config.scim_users_scope).find(params[:id]) | 66 | user = @company.public_send(ScimRails.config.scim_users_scope).find(params[:id]) |
67 | update_user(user) rescue "" | 67 | update_user(user) rescue "" |
68 | update_status(user) rescue "" # Azure AD uses PATCH to update user, not just status. | 68 | update_status(user) rescue "" # Azure AD uses PATCH to update user, not just status. |
69 | + user.update!(permitted_user_params) | ||
69 | json_scim_response(object: user) | 70 | json_scim_response(object: user) |
70 | end | 71 | end |
71 | 72 | ||
72 | def update_user(user) | 73 | def update_user(user) |
73 | - user_params = {} | 74 | + user_params = {} |
74 | operations = params["Operations"] || params[:Operations] || {} | 75 | operations = params["Operations"] || params[:Operations] || {} |
75 | postal_code = params[:addresses][0][:postalCode] || params["addresses"][0]["addresses"] rescue "" | 76 | postal_code = params[:addresses][0][:postalCode] || params["addresses"][0]["addresses"] rescue "" |
76 | if postal_code.blank? | 77 | if postal_code.blank? |
77 | - postal_code = operations.find{|operation| (operation["path"] || operation[:path]).to_s.downcase == 'addresses[type eq "work"].postalcode' }[:value] rescue "" | 78 | + postal_code = operations.find { |operation| (operation["path"] || operation[:path]).to_s.downcase == 'addresses[type eq "work"].postalcode' }[:value] rescue "" |
78 | end | 79 | end |
79 | if postal_code.present? | 80 | if postal_code.present? |
80 | - user_params.merge!({postal_code: postal_code}) | 81 | + user_params.merge!({ postal_code: postal_code }) |
81 | end | 82 | end |
82 | user.update!(user_params) | 83 | user.update!(user_params) |
83 | end | 84 | end |
@@ -97,7 +98,7 @@ module ScimRails | @@ -97,7 +98,7 @@ module ScimRails | ||
97 | end | 98 | end |
98 | 99 | ||
99 | def find_value_for(attribute) | 100 | def find_value_for(attribute) |
100 | - params.dig(*path_for(attribute).map{|x| x.to_s}) rescue nil | 101 | + params.dig(*path_for(attribute).map { |x| x.to_s }) rescue nil |
101 | end | 102 | end |
102 | 103 | ||
103 | # `path_for` is a recursive method used to find the "path" for | 104 | # `path_for` is a recursive method used to find the "path" for |
@@ -163,7 +164,7 @@ module ScimRails | @@ -163,7 +164,7 @@ module ScimRails | ||
163 | raise ScimRails::ExceptionHandler::UnsupportedPatchRequest | 164 | raise ScimRails::ExceptionHandler::UnsupportedPatchRequest |
164 | end | 165 | end |
165 | operations = params["Operations"] || params[:Operations] || {} | 166 | operations = params["Operations"] || params[:Operations] || {} |
166 | - valid_operation = operations.find{|operation| (operation["op"] || operation[:op]).to_s.downcase == "replace" && (operation["path"] || operation[:path]).to_s.downcase == "active" } rescue {} | 167 | + valid_operation = operations.find { |operation| (operation["op"] || operation[:op]).to_s.downcase == "replace" && (operation["path"] || operation[:path]).to_s.downcase == "active" } rescue {} |
167 | return valid_operation["value"].to_s.downcase == "true" if valid_operation.present? | 168 | return valid_operation["value"].to_s.downcase == "true" if valid_operation.present? |
168 | 169 | ||
169 | valid_operation = operations.find(handle_invalid) do |operation| | 170 | valid_operation = operations.find(handle_invalid) do |operation| |
@@ -173,7 +174,6 @@ module ScimRails | @@ -173,7 +174,6 @@ module ScimRails | ||
173 | valid_operation.dig("value", "active") | 174 | valid_operation.dig("value", "active") |
174 | end | 175 | end |
175 | 176 | ||
176 | - | ||
177 | def valid_patch_operation?(operation) | 177 | def valid_patch_operation?(operation) |
178 | operation["op"].casecmp("replace") && | 178 | operation["op"].casecmp("replace") && |
179 | operation["value"] && | 179 | operation["value"] && |
lib/scim_rails/version.rb