Commit 98e689313ce6b49c0282843854d1c701c861a5dc

Authored by ๆŽ่™น้œ–
1 parent 5b290a5d
Exists in master

Add user update for patch api

app/controllers/scim_rails/scim_users_controller.rb
... ... @@ -20,7 +20,7 @@ module ScimRails
20 20 counts = ScimCount.new(
21 21 start_index: params[:startIndex],
22 22 limit: params[:count],
23   - total: users.count
  23 + total: users.count,
24 24 )
25 25  
26 26 json_scim_response(object: users, counts: counts)
... ... @@ -66,18 +66,19 @@ module ScimRails
66 66 user = @company.public_send(ScimRails.config.scim_users_scope).find(params[:id])
67 67 update_user(user) rescue ""
68 68 update_status(user) rescue "" # Azure AD uses PATCH to update user, not just status.
  69 + user.update!(permitted_user_params)
69 70 json_scim_response(object: user)
70 71 end
71 72  
72 73 def update_user(user)
73   - user_params = {}
  74 + user_params = {}
74 75 operations = params["Operations"] || params[:Operations] || {}
75 76 postal_code = params[:addresses][0][:postalCode] || params["addresses"][0]["addresses"] rescue ""
76 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 79 end
79 80 if postal_code.present?
80   - user_params.merge!({postal_code: postal_code})
  81 + user_params.merge!({ postal_code: postal_code })
81 82 end
82 83 user.update!(user_params)
83 84 end
... ... @@ -97,7 +98,7 @@ module ScimRails
97 98 end
98 99  
99 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 102 end
102 103  
103 104 # `path_for` is a recursive method used to find the "path" for
... ... @@ -163,7 +164,7 @@ module ScimRails
163 164 raise ScimRails::ExceptionHandler::UnsupportedPatchRequest
164 165 end
165 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 168 return valid_operation["value"].to_s.downcase == "true" if valid_operation.present?
168 169  
169 170 valid_operation = operations.find(handle_invalid) do |operation|
... ... @@ -173,7 +174,6 @@ module ScimRails
173 174 valid_operation.dig("value", "active")
174 175 end
175 176  
176   -
177 177 def valid_patch_operation?(operation)
178 178 operation["op"].casecmp("replace") &&
179 179 operation["value"] &&
... ...
lib/scim_rails/version.rb
1 1 module ScimRails
2   - VERSION = '0.3.4'
  2 + VERSION = "0.3.5"
3 3 end
... ...