Commit 841f32a9fccf24f58c67d427b31f0245b0d12ade

Authored by Victor Costa
2 parents cef35259 172b3c93
Exists in fix_sign_up_form

Merge branch 'allow_change_profile_image' into 'master'

Allow change profile image in profile api endpoint



See merge request !996
app/api/helpers.rb
... ... @@ -403,12 +403,12 @@ module Api
403 403 end
404 404  
405 405 def asset_with_image params
406   - if params.has_key? :image_builder
  406 + if !params.nil? && params.has_key?(:image_builder)
407 407 asset_api_params = params
408 408 asset_api_params[:image_builder] = base64_to_uploadedfile(asset_api_params[:image_builder])
409 409 return asset_api_params
410 410 end
411   - params
  411 + params
412 412 end
413 413  
414 414 def base64_to_uploadedfile(base64_image)
... ...
app/api/v1/profiles.rb
... ... @@ -28,7 +28,7 @@ module Api
28 28 authenticate!
29 29 profile = environment.profiles.find_by(id: params[:id])
30 30 return forbidden! unless profile.allow_edit?(current_person)
31   - profile.update_attributes!(params[:profile])
  31 + profile.update_attributes!(asset_with_image(params[:profile]))
32 32 present profile, :with => Entities::Profile, :current_person => current_person
33 33 end
34 34  
... ...
test/api/profiles_test.rb
... ... @@ -218,4 +218,18 @@ class ProfilesTest < ActiveSupport::TestCase
218 218 json = JSON.parse(last_response.body)
219 219 assert_includes json["permissions"], 'allow_post_content'
220 220 end
  221 +
  222 + should 'update profile image' do
  223 + login_api
  224 + community = fast_create(Community)
  225 + community.add_member(person)
  226 + base64_image = create_base64_image
  227 + params.merge!({profile: {image_builder: base64_image}})
  228 + assert_nil person.image
  229 + post "/api/v1/profiles/#{community.id}?#{params.to_query}"
  230 + community.reload
  231 + assert_not_nil community.image
  232 + assert_equal community.image.filename, base64_image[:filename]
  233 + end
  234 +
221 235 end
... ...