[Git][noosfero/noosfero][master] 2 commits: Adds public fields to Profile API

Leandro Nunes gitlab at mg.gitlab.com
Wed Jul 20 12:26:48 BRT 2016


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
4c3176e0 by Tallys Martins at 2016-07-20T11:34:45-03:00
Adds public fields to Profile API

Signed-off-by: Paulo Tada <paulohtfs at gmail.com>
Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

- - - - -
19bc212e by Leandro Nunes at 2016-07-20T15:25:51+00:00
Merge branch 'profile_api_improvements' into 'master'

Adds public fields to Profile API

Signed-off-by: Paulo Tada <paulohtfs at gmail.com>
Signed-off-by: Tallys Martins <tallysmartins at gmail.com>

See merge request !981
- - - - -


2 changed files:

- app/api/entities.rb
- test/api/profiles_test.rb


Changes:

=====================================
app/api/entities.rb
=====================================
--- a/app/api/entities.rb
+++ b/app/api/entities.rb
@@ -111,6 +111,10 @@ module Api
           hash[value.custom_field.name]=value.value
         end
 
+        profile.public_fields.each do |field|
+          hash[field] = profile.send(field.to_sym)
+        end
+
         private_values = profile.custom_field_values - profile.public_values
         private_values.each do |value|
           if Entities.can_display_profile_field?(profile,options)


=====================================
test/api/profiles_test.rb
=====================================
--- a/test/api/profiles_test.rb
+++ b/test/api/profiles_test.rb
@@ -123,6 +123,24 @@ class ProfilesTest < ActiveSupport::TestCase
     assert_equal community.id, json['id']
   end
 
+  should 'display profile public fields to anonymous' do
+    some_person = create_user('test', { :email => "lappis at unb.br" }).person
+    Person.any_instance.stubs(:public_fields).returns(["email"])
+
+    get "/api/v1/profiles/#{some_person.id}?#{params.to_query}"
+    json = JSON.parse(last_response.body)
+    assert json['additional_data'].has_key?('email')
+    assert_equal "lappis at unb.br", json['additional_data']['email']
+  end
+
+  should 'not display private fields to anonymous' do
+    some_person = create_user('test', { :email => "lappis at unb.br" }).person
+
+    get "/api/v1/profiles/#{some_person.id}/?#{params.to_query}"
+    json = JSON.parse(last_response.body)
+    assert !json['additional_data'].has_key?('email')
+  end
+
   should 'display public custom fields to anonymous' do
     CustomField.create!(:name => "Rating", :format => "string", :customized_type => "Profile", :active => true, :environment => Environment.default)
     some_profile = fast_create(Profile)



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/441955c7a0d94eee1ddec2bab60117695fd6a774...19bc212ecc4920c90573dc6ad3bc5681dc501ff9
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160720/c79ca4e3/attachment-0001.html>


More information about the Noosfero-dev mailing list