[Git][noosfero/noosfero][master] 3 commits: expose boxes in profile and people api
Leandro Nunes
gitlab at mg.gitlab.com
Fri Aug 4 10:44:37 BRT 2017
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
94e632d2 by Leandro Nunes dos Santos at 2017-08-04T09:45:14-03:00
expose boxes in profile and people api
- - - - -
998e4144 by Leandro Nunes dos Santos at 2017-08-04T10:10:00-03:00
remove unnecessary code
- - - - -
2e1c6ef9 by Leandro Nunes at 2017-08-04T13:44:23+00:00
Merge branch 'expose_boxes' into 'master'
expose boxes in profile and people api
See merge request !1295
- - - - -
5 changed files:
- app/api/entities.rb
- app/api/v1/people.rb
- app/api/v1/profiles.rb
- test/api/people_test.rb
- test/api/profiles_test.rb
Changes:
=====================================
app/api/entities.rb
=====================================
--- a/app/api/entities.rb
+++ b/app/api/entities.rb
@@ -147,6 +147,8 @@ module Api
expose :theme do |profile, options|
profile.theme || profile.environment.theme
end
+ expose :boxes, :using => Box, :if => lambda {|profile, options| Entities.expose_optional_field?(:boxes, options)}
+
end
class UserBasic < Entity
=====================================
app/api/v1/people.rb
=====================================
--- a/app/api/v1/people.rb
+++ b/app/api/v1/people.rb
@@ -47,7 +47,7 @@ module Api
get ':id' do
person = environment.people.visible.find_by(id: params[:id])
return not_found! if person.blank?
- present_partial person, :with => Entities::Person, :current_person => current_person
+ present_partial person, :with => Entities::Person, :current_person => current_person, :params => params
end
desc "Update person information"
=====================================
app/api/v1/profiles.rb
=====================================
--- a/app/api/v1/profiles.rb
+++ b/app/api/v1/profiles.rb
@@ -22,7 +22,7 @@ module Api
Enterprise => Entities::Enterprise
}[profile.class] || Entities::Profile
- present profile, :with => type_map, :current_person => current_person
+ present profile, :with => type_map, :current_person => current_person, :params => params
else
not_found!
end
=====================================
test/api/people_test.rb
=====================================
--- a/test/api/people_test.rb
+++ b/test/api/people_test.rb
@@ -101,6 +101,16 @@ class PeopleTest < ActiveSupport::TestCase
assert_equal some_person.id, json['id']
end
+ should 'display boxes if proper optional field parameter is passed' do
+ login_api
+ some_person = fast_create(Person)
+
+ get "/api/v1/people/#{some_person.id}?#{params.merge({:optional_fields => [:boxes]}).to_query}"
+ json = JSON.parse(last_response.body)
+ assert_equal some_person.id, json['id']
+ assert_not_nil json['boxes']
+ end
+
should 'anonymous get person' do
some_person = fast_create(Person)
=====================================
test/api/profiles_test.rb
=====================================
--- a/test/api/profiles_test.rb
+++ b/test/api/profiles_test.rb
@@ -25,6 +25,16 @@ class ProfilesTest < ActiveSupport::TestCase
assert_equal some_person.id, json['id']
end
+ should 'display boxes if proper optional field parameter is passed' do
+ login_api
+ some_person = fast_create(Person)
+
+ get "/api/v1/profiles/#{some_person.id}?#{params.merge({:optional_fields => [:boxes]}).to_query}"
+ json = JSON.parse(last_response.body)
+ assert_equal some_person.id, json['id']
+ assert_not_nil json['boxes']
+ end
+
should 'not get inexistent profile' do
login_api
get "/api/v1/profiles/invalid_id?#{params.to_query}"
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/4dd233665426293e5333838a04f61d5e35f1236f...2e1c6ef94e8273e156908eb40bcf31b6cd2113bd
---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/4dd233665426293e5333838a04f61d5e35f1236f...2e1c6ef94e8273e156908eb40bcf31b6cd2113bd
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170804/7406729f/attachment-0001.html>
More information about the Noosfero-dev
mailing list