Commit 532cef679340dc0934e2a30fc82af5a34a3cc293
1 parent
0eba5453
Exists in
staging
and in
41 other branches
API improvements
- Fixed bug on GET enterprise API showing communities and vice-versa. - Improved POST comment API to recieve multiple params, such as Title. Signed-off-by: André Bernardes <andrebsguedes@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Showing
3 changed files
with
12 additions
and
4 deletions
Show diff stats
lib/noosfero/api/v1/comments.rb
| ... | ... | @@ -38,7 +38,8 @@ module Noosfero |
| 38 | 38 | # POST api/v1/articles/12/comments?private_toke=234298743290432&body=new comment |
| 39 | 39 | post ":id/comments" do |
| 40 | 40 | article = find_article(environment.articles, params[:id]) |
| 41 | - present article.comments.create(:author => current_person, :body => params[:body]), :with => Entities::Comment | |
| 41 | + options = params[:comment].merge(:author => current_person) | |
| 42 | + present article.comments.create(options), :with => Entities::Comment | |
| 42 | 43 | end |
| 43 | 44 | end |
| 44 | 45 | ... | ... |
lib/noosfero/api/v1/communities.rb
| ... | ... | @@ -19,6 +19,7 @@ module Noosfero |
| 19 | 19 | get do |
| 20 | 20 | communities = select_filtered_collection_of(environment, 'communities', params) |
| 21 | 21 | communities = communities.visible_for_person(current_person) |
| 22 | + communities = communities.by_location(params) # Must be the last. May return Exception obj. | |
| 22 | 23 | present communities, :with => Entities::Community |
| 23 | 24 | end |
| 24 | 25 | |
| ... | ... | @@ -41,7 +42,10 @@ module Noosfero |
| 41 | 42 | end |
| 42 | 43 | |
| 43 | 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 | 49 | present community, :with => Entities::Community |
| 46 | 50 | end |
| 47 | 51 | ... | ... |
lib/noosfero/api/v1/enterprises.rb
| ... | ... | @@ -5,7 +5,7 @@ module Noosfero |
| 5 | 5 | before { authenticate! } |
| 6 | 6 | |
| 7 | 7 | resource :enterprises do |
| 8 | - | |
| 8 | + | |
| 9 | 9 | # Collect enterprises from environment |
| 10 | 10 | # |
| 11 | 11 | # Parameters: |
| ... | ... | @@ -26,7 +26,10 @@ module Noosfero |
| 26 | 26 | |
| 27 | 27 | desc "Return one enterprise by id" |
| 28 | 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 | 33 | present enterprise, :with => Entities::Enterprise |
| 31 | 34 | end |
| 32 | 35 | ... | ... |