Commit 172b3c93eab45836a8ee5a5710e0d035576ce5d5
1 parent
cef35259
Exists in
staging
and in
4 other branches
allow change profile image in profile api endpoint
Showing
3 changed files
with
17 additions
and
3 deletions
Show diff stats
app/api/helpers.rb
| @@ -403,12 +403,12 @@ module Api | @@ -403,12 +403,12 @@ module Api | ||
| 403 | end | 403 | end |
| 404 | 404 | ||
| 405 | def asset_with_image params | 405 | def asset_with_image params |
| 406 | - if params.has_key? :image_builder | 406 | + if !params.nil? && params.has_key?(:image_builder) |
| 407 | asset_api_params = params | 407 | asset_api_params = params |
| 408 | asset_api_params[:image_builder] = base64_to_uploadedfile(asset_api_params[:image_builder]) | 408 | asset_api_params[:image_builder] = base64_to_uploadedfile(asset_api_params[:image_builder]) |
| 409 | return asset_api_params | 409 | return asset_api_params |
| 410 | end | 410 | end |
| 411 | - params | 411 | + params |
| 412 | end | 412 | end |
| 413 | 413 | ||
| 414 | def base64_to_uploadedfile(base64_image) | 414 | def base64_to_uploadedfile(base64_image) |
app/api/v1/profiles.rb
| @@ -28,7 +28,7 @@ module Api | @@ -28,7 +28,7 @@ module Api | ||
| 28 | authenticate! | 28 | authenticate! |
| 29 | profile = environment.profiles.find_by(id: params[:id]) | 29 | profile = environment.profiles.find_by(id: params[:id]) |
| 30 | return forbidden! unless profile.allow_edit?(current_person) | 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 | present profile, :with => Entities::Profile, :current_person => current_person | 32 | present profile, :with => Entities::Profile, :current_person => current_person |
| 33 | end | 33 | end |
| 34 | 34 |
test/api/profiles_test.rb
| @@ -218,4 +218,18 @@ class ProfilesTest < ActiveSupport::TestCase | @@ -218,4 +218,18 @@ class ProfilesTest < ActiveSupport::TestCase | ||
| 218 | json = JSON.parse(last_response.body) | 218 | json = JSON.parse(last_response.body) |
| 219 | assert_includes json["permissions"], 'allow_post_content' | 219 | assert_includes json["permissions"], 'allow_post_content' |
| 220 | end | 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 | end | 235 | end |