Commit c05d42061a98fbe9944af790b68f676a20930404

Authored by Rodrigo Souto
2 parents 6dbdae92 532cef67

Merge branch 'api_fixies' into 'api'

API improvements

- Fixed bug on GET enterprise API showing communities and vice-versa.
- Improved POST comment API to recieve multiple params, such as Title.

See merge request !610
lib/noosfero/api/v1/comments.rb
@@ -30,7 +30,8 @@ module Noosfero @@ -30,7 +30,8 @@ module Noosfero
30 # POST api/v1/articles/12/comments?private_toke=234298743290432&body=new comment 30 # POST api/v1/articles/12/comments?private_toke=234298743290432&body=new comment
31 post ":id/comments" do 31 post ":id/comments" do
32 article = find_article(environment.articles, params[:id]) 32 article = find_article(environment.articles, params[:id])
33 - present article.comments.create(:author => current_person, :body => params[:body]), :with => Entities::Comment 33 + options = params[:comment].merge(:author => current_person)
  34 + present article.comments.create(options), :with => Entities::Comment
34 end 35 end
35 end 36 end
36 37
lib/noosfero/api/v1/communities.rb
@@ -19,6 +19,7 @@ module Noosfero @@ -19,6 +19,7 @@ module Noosfero
19 get do 19 get do
20 communities = select_filtered_collection_of(environment, 'communities', params) 20 communities = select_filtered_collection_of(environment, 'communities', params)
21 communities = communities.visible_for_person(current_person) 21 communities = communities.visible_for_person(current_person)
  22 + communities = communities.by_location(params) # Must be the last. May return Exception obj.
22 present communities, :with => Entities::Community 23 present communities, :with => Entities::Community
23 end 24 end
24 25
@@ -41,7 +42,10 @@ module Noosfero @@ -41,7 +42,10 @@ module Noosfero
41 end 42 end
42 43
43 get ':id' do 44 get ':id' do
44 - community = environment.communities.visible.find_by_id(params[:id]) 45 + community = environment.communities.find_by_id(params[:id])
  46 + unless community.nil?
  47 + community = nil unless community.display_info_to?(current_person)
  48 + end
45 present community, :with => Entities::Community 49 present community, :with => Entities::Community
46 end 50 end
47 51
lib/noosfero/api/v1/enterprises.rb
@@ -5,7 +5,7 @@ module Noosfero @@ -5,7 +5,7 @@ module Noosfero
5 before { authenticate! } 5 before { authenticate! }
6 6
7 resource :enterprises do 7 resource :enterprises do
8 - 8 +
9 # Collect enterprises from environment 9 # Collect enterprises from environment
10 # 10 #
11 # Parameters: 11 # Parameters:
@@ -26,7 +26,10 @@ module Noosfero @@ -26,7 +26,10 @@ module Noosfero
26 26
27 desc "Return one enterprise by id" 27 desc "Return one enterprise by id"
28 get ':id' do 28 get ':id' do
29 - enterprise = environment.enterprises.visible.find_by_id(params[:id]) 29 + enterprise = environment.enterprises.find_by_id(params[:id])
  30 + unless enterprise.nil?
  31 + enterprise = nil unless enterprise.display_info_to?(current_person)
  32 + end
30 present enterprise, :with => Entities::Enterprise 33 present enterprise, :with => Entities::Enterprise
31 end 34 end
32 35