[Git][noosfero/noosfero][master] 2 commits: allow change profile image in profile api endpoint

Victor Costa gitlab at mg.gitlab.com
Wed Aug 3 10:54:14 BRT 2016


Victor Costa pushed to branch master at Noosfero / noosfero


Commits:
172b3c93 by Leandro Nunes dos Santos at 2016-08-03T08:11:28-03:00
allow change profile image in profile api endpoint

- - - - -
841f32a9 by Victor Costa at 2016-08-03T13:53:59+00:00
Merge branch 'allow_change_profile_image' into 'master'

Allow change profile image in profile api endpoint



See merge request !996
- - - - -


3 changed files:

- app/api/helpers.rb
- app/api/v1/profiles.rb
- test/api/profiles_test.rb


Changes:

=====================================
app/api/helpers.rb
=====================================
--- a/app/api/helpers.rb
+++ b/app/api/helpers.rb
@@ -403,12 +403,12 @@ module Api
     end
 
     def asset_with_image params
-      if params.has_key? :image_builder
+      if !params.nil? && params.has_key?(:image_builder)
         asset_api_params = params
         asset_api_params[:image_builder] = base64_to_uploadedfile(asset_api_params[:image_builder])
         return asset_api_params
       end
-        params
+      params
     end
 
     def base64_to_uploadedfile(base64_image)


=====================================
app/api/v1/profiles.rb
=====================================
--- a/app/api/v1/profiles.rb
+++ b/app/api/v1/profiles.rb
@@ -28,7 +28,7 @@ module Api
           authenticate!
           profile = environment.profiles.find_by(id: params[:id])
           return forbidden! unless profile.allow_edit?(current_person)
-          profile.update_attributes!(params[:profile])
+          profile.update_attributes!(asset_with_image(params[:profile]))
           present profile, :with => Entities::Profile, :current_person => current_person
         end
 


=====================================
test/api/profiles_test.rb
=====================================
--- a/test/api/profiles_test.rb
+++ b/test/api/profiles_test.rb
@@ -218,4 +218,18 @@ class ProfilesTest < ActiveSupport::TestCase
     json = JSON.parse(last_response.body)
     assert_includes json["permissions"], 'allow_post_content'
   end
+
+  should 'update profile image' do
+    login_api
+    community = fast_create(Community)
+    community.add_member(person)
+    base64_image = create_base64_image
+    params.merge!({profile: {image_builder: base64_image}})
+    assert_nil person.image
+    post "/api/v1/profiles/#{community.id}?#{params.to_query}"
+    community.reload
+    assert_not_nil community.image
+    assert_equal community.image.filename, base64_image[:filename]
+  end
+
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/cef35259b132f8fc926f1f8667df3bd44a235a2a...841f32a9fccf24f58c67d427b31f0245b0d12ade
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160803/6048d117/attachment-0001.html>


More information about the Noosfero-dev mailing list