diff --git a/app/api/entities.rb b/app/api/entities.rb index d49692b..eb4b35f 100644 --- 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) diff --git a/test/api/profiles_test.rb b/test/api/profiles_test.rb index 57ed552..6144b02 100644 --- 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@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@unb.br", json['additional_data']['email'] + end + + should 'not display private fields to anonymous' do + some_person = create_user('test', { :email => "lappis@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) -- libgit2 0.21.2