Commit 1cf85a75a5ad4f56b7a777b67f3d2552957468ae
Exists in
staging
and in
1 other branch
fix conflit with master
Showing
6 changed files
with
94 additions
and
15 deletions
Show diff stats
lib/noosfero/api/entities.rb
... | ... | @@ -112,6 +112,8 @@ module Noosfero |
112 | 112 | expose :image, :using => Image |
113 | 113 | expose :region, :using => Region |
114 | 114 | expose :type |
115 | + expose :custom_header | |
116 | + expose :custom_footer | |
115 | 117 | end |
116 | 118 | |
117 | 119 | class UserBasic < Entity |
... | ... | @@ -148,6 +150,18 @@ module Noosfero |
148 | 150 | expose :members, :using => Person |
149 | 151 | end |
150 | 152 | |
153 | + class CommentBase < Entity | |
154 | + expose :body, :title, :id | |
155 | + expose :created_at, :format_with => :timestamp | |
156 | + expose :author, :using => Profile | |
157 | + expose :reply_of, :using => CommentBase | |
158 | + end | |
159 | + | |
160 | + class Comment < CommentBase | |
161 | + root 'comments', 'comment' | |
162 | + expose :children, as: :replies, :using => Comment | |
163 | + end | |
164 | + | |
151 | 165 | class ArticleBase < Entity |
152 | 166 | root 'articles', 'article' |
153 | 167 | expose :id |
... | ... | @@ -177,6 +191,7 @@ module Noosfero |
177 | 191 | expose :comments_count |
178 | 192 | expose :archived, :documentation => {:type => "Boolean", :desc => "Defines if a article is readonly"} |
179 | 193 | expose :type |
194 | + expose :comments, using: CommentBase, :if => lambda{|obj,opt| opt[:params] && ['1','true',true].include?(opt[:params][:show_comments])} | |
180 | 195 | end |
181 | 196 | |
182 | 197 | class Article < ArticleBase |
... | ... | @@ -187,18 +202,6 @@ module Noosfero |
187 | 202 | end |
188 | 203 | end |
189 | 204 | |
190 | - class CommentBase < Entity | |
191 | - expose :body, :title, :id | |
192 | - expose :created_at, :format_with => :timestamp | |
193 | - expose :author, :using => Profile | |
194 | - expose :reply_of, :using => CommentBase | |
195 | - end | |
196 | - | |
197 | - class Comment < CommentBase | |
198 | - root 'comments', 'comment' | |
199 | - expose :children, as: :replies, :using => Comment | |
200 | - end | |
201 | - | |
202 | 205 | class User < Entity |
203 | 206 | root 'users', 'user' |
204 | 207 | ... | ... |
lib/noosfero/api/helpers.rb
... | ... | @@ -148,7 +148,7 @@ require_relative '../../find_by_contents' |
148 | 148 | |
149 | 149 | def present_article(asset) |
150 | 150 | article = find_article(asset.articles, params[:id]) |
151 | - present_partial article, :with => Entities::Article | |
151 | + present_partial article, :with => Entities::Article, :params => params | |
152 | 152 | end |
153 | 153 | |
154 | 154 | def present_articles_for_asset(asset, method = 'articles') |
... | ... | @@ -157,7 +157,7 @@ require_relative '../../find_by_contents' |
157 | 157 | end |
158 | 158 | |
159 | 159 | def present_articles(articles) |
160 | - present_partial paginate(articles), :with => Entities::Article | |
160 | + present_partial paginate(articles), :with => Entities::Article, :params => params | |
161 | 161 | end |
162 | 162 | |
163 | 163 | def find_articles(asset, method = 'articles') | ... | ... |
lib/noosfero/api/v1/profiles.rb
... | ... | @@ -19,6 +19,19 @@ module Noosfero |
19 | 19 | profile = profiles.find_by id: params[:id] |
20 | 20 | present profile, :with => Entities::Profile, :current_person => current_person |
21 | 21 | end |
22 | + | |
23 | + delete ':id' do | |
24 | + profiles = environment.profiles | |
25 | + profile = profiles.find_by id: params[:id] | |
26 | + | |
27 | + not_found! if profile.blank? | |
28 | + | |
29 | + if current_person.has_permission?(:destroy_profile, profile) | |
30 | + profile.destroy | |
31 | + else | |
32 | + forbidden! | |
33 | + end | |
34 | + end | |
22 | 35 | end |
23 | 36 | end |
24 | 37 | end | ... | ... |
plugins/proposals_discussion
test/api/articles_test.rb
... | ... | @@ -698,4 +698,19 @@ class ArticlesTest < ActiveSupport::TestCase |
698 | 698 | end |
699 | 699 | end |
700 | 700 | |
701 | + should 'only show article comments when show_comments is present' do | |
702 | + person = fast_create(Person) | |
703 | + article = fast_create(Article, :profile_id => person.id, :name => "Some thing") | |
704 | + article.comments.create!(:body => "another comment", :author => person) | |
705 | + | |
706 | + get "/api/v1/articles/#{article.id}/?#{params.merge(:show_comments => '1').to_query}" | |
707 | + json = JSON.parse(last_response.body) | |
708 | + assert_includes json["article"].keys, "comments" | |
709 | + assert_equal json["article"]["comments"].first["body"], "another comment" | |
710 | + | |
711 | + get "/api/v1/articles/#{article.id}/?#{params.to_query}" | |
712 | + json = JSON.parse(last_response.body) | |
713 | + assert_not_includes json["article"].keys, "comments" | |
714 | + end | |
715 | + | |
701 | 716 | end | ... | ... |
test/api/profiles_test.rb
... | ... | @@ -29,4 +29,52 @@ class ProfilesTest < ActiveSupport::TestCase |
29 | 29 | json = JSON.parse(last_response.body) |
30 | 30 | assert_equal community.id, json['id'] |
31 | 31 | end |
32 | + | |
33 | + group_kinds = %w(community enterprise) | |
34 | + group_kinds.each do |kind| | |
35 | + should "delete #{kind} from profile id with permission" do | |
36 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
37 | + give_permission(@person, 'destroy_profile', profile) | |
38 | + assert_not_nil Profile.find_by_id profile.id | |
39 | + | |
40 | + delete "/api/v1/profiles/#{profile.id}?#{params.to_query}" | |
41 | + | |
42 | + assert_equal 200, last_response.status | |
43 | + assert_nil Profile.find_by_id profile.id | |
44 | + end | |
45 | + | |
46 | + should "not delete #{kind} from profile id without permission" do | |
47 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
48 | + assert_not_nil Profile.find_by_id profile.id | |
49 | + | |
50 | + delete "/api/v1/profiles/#{profile.id}?#{params.to_query}" | |
51 | + | |
52 | + assert_equal 403, last_response.status | |
53 | + assert_not_nil Profile.find_by_id profile.id | |
54 | + end | |
55 | + end | |
56 | + | |
57 | + should 'person delete itself' do | |
58 | + delete "/api/v1/profiles/#{@person.id}?#{params.to_query}" | |
59 | + assert_equal 200, last_response.status | |
60 | + assert_nil Profile.find_by_id @person.id | |
61 | + end | |
62 | + | |
63 | + should 'only admin delete other people' do | |
64 | + profile = fast_create(Person, :environment_id => environment.id) | |
65 | + assert_not_nil Profile.find_by_id profile.id | |
66 | + | |
67 | + delete "/api/v1/profiles/#{profile.id}?#{params.to_query}" | |
68 | + | |
69 | + assert_equal 403, last_response.status | |
70 | + assert_not_nil Profile.find_by_id profile.id | |
71 | + | |
72 | + environment.add_admin(@person) | |
73 | + | |
74 | + delete "/api/v1/profiles/#{profile.id}?#{params.to_query}" | |
75 | + | |
76 | + assert_equal 200, last_response.status | |
77 | + assert_nil Profile.find_by_id profile.id | |
78 | + | |
79 | + end | |
32 | 80 | end | ... | ... |