Commit 68e9c453f969d90352b1e85bd8c22b0c10225a81

Authored by Leandro Santos
2 parents c2cea31c 2409576d
Exists in production

Merge branch 'staging' into production

.gitmodules
1 1 [submodule "plugins/pairwise"]
2 2 path = plugins/pairwise
3   - url = https://gitlab.com/noosfero-plugins/pairwise.git
  3 + url = https://softwarepublico.gov.br/gitlab/noosfero-plugins/pairwise.git
4 4 [submodule "plugins/proposals_discussion"]
5 5 path = plugins/proposals_discussion
6   - url = https://gitlab.com/noosfero-plugins/proposals_discussion.git
  6 + url = https://softwarepublico.gov.br/gitlab/noosfero-plugins/proposals_discussion.git
7 7 [submodule "plugins/gamification"]
8 8 path = plugins/gamification
9   - url = https://gitlab.com/noosfero-plugins/gamification.git
  9 + url = https://softwarepublico.gov.br/gitlab/noosfero-plugins/gamification.git
10 10 [submodule "plugins/notification"]
11 11 path = plugins/notification
12   - url = https://gitlab.com/noosfero-plugins/notification.git
  12 + url = https://softwarepublico.gov.br/gitlab/noosfero-plugins/notification.git
13 13 [submodule "plugins/email_article"]
14 14 path = plugins/email_article
15   - url = https://gitlab.com/noosfero-plugins/email_article.git
  15 + url = https://softwarepublico.gov.br/gitlab/noosfero-plugins/email_article.git
16 16 [submodule "public/proposal-app"]
17 17 path = public/proposal-app
18 18 url = https://gitlab.com/participa/proposal-app.git
19 19 [submodule "plugins/gravatar_provider"]
20 20 path = plugins/gravatar_provider
21   - url = https://gitlab.com/noosfero-plugins/gravatar-provider.git
  21 + url = https://softwarepublico.gov.br/gitlab/noosfero-plugins/gravatar-provider.git
22 22 [submodule "plugins/juventude"]
23 23 path = plugins/juventude
24   - url = https://gitlab.com/noosfero-plugins/juventude.git
  24 + url = https://softwarepublico.gov.br/gitlab/noosfero-plugins/juventude.git
25 25 [submodule "plugins/dialoga"]
26 26 path = plugins/dialoga
27   - url = https://gitlab.com/participa/dialoga-plugin.git
  27 + url = https://softwarepublico.gov.br/gitlab/noosfero-plugins/dialoga-plugin.git
28 28 [submodule "rest-clients/confjuvapp"]
29 29 path = rest-clients/confjuvapp
30   - url = https://gitlab.com/participa/confjuvapp.git
  30 + url = https://softwarepublico.gov.br/gitlab/noosfero-apps/confjuvapp.git
31 31 [submodule "rest-clients/proposal-app"]
32 32 path = rest-clients/proposal-app
33   - url = https://gitlab.com/participa/proposal-app.git
  33 + url = https://softwarepublico.gov.br/gitlab/noosfero-apps/proposal-app.git
34 34 [submodule "plugins/serpro_captcha"]
35 35 path = plugins/serpro_captcha
36   - url = https://gitlab.com/noosfero-plugins/serpro_captcha.git
  36 + url = https://softwarepublico.gov.br/gitlab/noosfero-plugins/serpro_captcha.git
... ...
Gemfile.lock
... ... @@ -40,11 +40,8 @@ GEM
40 40 multi_json (~> 1.0)
41 41 acts-as-taggable-on (3.4.4)
42 42 activerecord (>= 3.2, < 5)
43   - addressable (2.3.8)
  43 + ambry (0.3.1)
44 44 api-pagination (4.1.1)
45   - api_smith (1.3.0)
46   - hashie (>= 1.0, < 3.0)
47   - httparty
48 45 arel (3.0.3)
49 46 axiom-types (0.1.1)
50 47 descendants_tracker (~> 0.0.4)
... ... @@ -62,8 +59,6 @@ GEM
62 59 chronic (0.10.2)
63 60 coercible (1.0.0)
64 61 descendants_tracker (~> 0.0.1)
65   - css_parser (1.3.7)
66   - addressable
67 62 cucumber (1.0.6)
68 63 builder (>= 2.1.2)
69 64 diff-lcs (>= 1.1.2)
... ... @@ -89,10 +84,6 @@ GEM
89 84 actionmailer (>= 3.0.4)
90 85 activesupport (>= 3.0.4)
91 86 execjs (2.6.0)
92   - faraday (0.9.2)
93   - multipart-post (>= 1.2, < 3)
94   - faraday_middleware (0.10.0)
95   - faraday (>= 0.7.4, < 0.10)
96 87 fast_gettext (0.6.12)
97 88 ffi (1.9.10)
98 89 gettext (2.2.1)
... ... @@ -116,11 +107,8 @@ GEM
116 107 grape-swagger (0.10.2)
117 108 grape (>= 0.8.0)
118 109 grape-entity
119   - hashie (2.1.2)
  110 + hashie (3.4.2)
120 111 hike (1.2.3)
121   - httparty (0.12.0)
122   - json (~> 1.8)
123   - multi_xml (>= 0.5.2)
124 112 i18n (0.7.0)
125 113 ice_nine (0.11.1)
126 114 journey (1.0.4)
... ... @@ -128,7 +116,6 @@ GEM
128 116 kgio (2.10.0)
129 117 kramdown (1.9.0)
130 118 libv8 (3.16.14.11)
131   - link_header (0.0.8)
132 119 liquid (3.0.6)
133 120 locale (2.0.9)
134 121 magic (0.2.9)
... ... @@ -136,6 +123,8 @@ GEM
136 123 mail (2.5.4)
137 124 mime-types (~> 1.16)
138 125 treetop (~> 1.4.8)
  126 + merit (2.3.2)
  127 + ambry (~> 0.3.0)
139 128 metaclass (0.0.4)
140 129 mime-types (1.25.1)
141 130 mini_portile (0.6.2)
... ... @@ -144,13 +133,8 @@ GEM
144 133 metaclass (~> 0.0.1)
145 134 multi_json (1.11.2)
146 135 multi_xml (0.5.5)
147   - multipart-post (2.0.0)
148 136 nokogiri (1.6.6.2)
149 137 mini_portile (~> 0.6.0)
150   - oai (0.3.1)
151   - builder (>= 2.0.0)
152   - faraday
153   - faraday_middleware
154 138 pg (0.13.2)
155 139 polyglot (0.3.5)
156 140 rack (1.4.7)
... ... @@ -187,24 +171,12 @@ GEM
187 171 thor (>= 0.14.6, < 2.0)
188 172 raindrops (0.15.0)
189 173 rake (10.4.2)
190   - rdf (1.1.17.1)
191   - link_header (~> 0.0, >= 0.0.8)
192   - rdf-virtuoso (0.1.6)
193   - api_smith (~> 1.3.0)
194   - httparty (~> 0.12.0)
195   - rdf (~> 1.1.0)
196 174 rdoc (3.12.2)
197 175 json (~> 1.4)
198 176 ref (2.0.0)
199 177 rest-client (1.6.9)
200 178 mime-types (~> 1.16)
201 179 rmagick (2.13.4)
202   - roadie (3.0.5)
203   - css_parser (~> 1.3.4)
204   - nokogiri (~> 1.6.0)
205   - roadie-rails (1.0.6)
206   - railties (>= 3.0, < 4.3)
207   - roadie (~> 3.0)
208 180 rspec (2.14.1)
209 181 rspec-core (~> 2.14.0)
210 182 rspec-expectations (~> 2.14.0)
... ... @@ -297,22 +269,18 @@ DEPENDENCIES
297 269 kramdown
298 270 liquid (~> 3.0.3)
299 271 locale (~> 2.0.5)
  272 + merit (~> 2.3.1)
300 273 minitest (~> 3.2.0)
301 274 mocha (~> 1.1.0)
302 275 nokogiri (~> 1.6.0)
303   - oai (= 0.3.1)
304 276 pg (~> 0.13.2)
305 277 rack-contrib
306 278 rack-cors
307 279 rails (~> 3.2.22)
308 280 rails_autolink (~> 1.1.5)
309 281 rake
310   - rdf
311   - rdf-virtuoso
312 282 rest-client (~> 1.6.7)
313 283 rmagick (~> 2.13.1)
314   - roadie (= 3.0.5)
315   - roadie-rails
316 284 rspec (~> 2.14.0)
317 285 rspec-rails (~> 2.14.1)
318 286 ruby-feedparser (~> 0.7)
... ...
lib/noosfero/api/entities.rb
... ... @@ -52,7 +52,9 @@ module Noosfero
52 52 end
53 53  
54 54 class Profile < Entity
55   - expose :identifier, :name, :id
  55 + expose :id
  56 + expose :identifier
  57 + expose :name
56 58 expose :created_at, :format_with => :timestamp
57 59 expose :updated_at, :format_with => :timestamp
58 60 expose :image, :using => Image
... ... @@ -67,6 +69,17 @@ module Noosfero
67 69 class Person < Profile
68 70 root 'people', 'person'
69 71 expose :user, :using => UserBasic, documentation: {type: 'User', desc: 'The user data of a person' }
  72 + expose :vote_count, if: lambda { |object, options| options[:fields].present? ? options[:fields].include?('vote_count') : false}
  73 + expose :comments_count, if: lambda { |object, options| options[:fields].present? ? options[:fields].include?('comments_count') : false} do |person, options|
  74 + person.comments.count
  75 + end
  76 + expose :following_articles_count, if: lambda { |object, options| options[:fields].present? ? options[:fields].include?('following_articles_count') : false} do |person, options|
  77 + person.following_articles.count
  78 + end
  79 + expose :articles_count, if: lambda { |object, options| options[:fields].present? ? options[:fields].include?('articles_count') : false} do |person, options|
  80 + person.articles.count
  81 + end
  82 +
70 83 end
71 84  
72 85 class Enterprise < Profile
... ... @@ -102,9 +115,11 @@ module Noosfero
102 115 expose :end_date, :documentation => {type: 'DateTime', desc: 'The date of finish of the article'}
103 116 expose :tag_list
104 117 expose :children_count
105   - expose :followers_count
106 118 expose :slug, :documentation => {:type => "String", :desc => "Trimmed and parsed name of a article"}
107 119 expose :path
  120 + expose :followers_count
  121 + expose :votes_count
  122 + expose :comments_count
108 123 end
109 124  
110 125 class Article < ArticleBase
... ...
lib/noosfero/api/v1/people.rb
... ... @@ -33,12 +33,12 @@ module Noosfero
33 33 get do
34 34 people = select_filtered_collection_of(environment, 'people', params)
35 35 people = people.visible_for_person(current_person)
36   - present people, :with => Entities::Person
  36 + present people, :with => Entities::Person, :fields => params[:fields]
37 37 end
38 38  
39 39 desc "Return the logged user information"
40 40 get "/me" do
41   - present current_person, :with => Entities::Person
  41 + present current_person, :with => Entities::Person, :fields => params[:fields]
42 42 end
43 43  
44 44 desc "Return the person information"
... ...
plugins/gamification
1   -Subproject commit 2195363864f69e172952dcc3ac1ac254e7f65937
  1 +Subproject commit 617998d737b15d3bea32bde76d2b456be90e8f17
... ...
test/unit/api/articles_test.rb
... ... @@ -607,4 +607,17 @@ class ArticlesTest &lt; ActiveSupport::TestCase
607 607 assert_equal json['articles'].count, 2
608 608 end
609 609  
  610 + ARTICLE_ATTRIBUTES = %w(followers_count votes_count comments_count)
  611 +
  612 + ARTICLE_ATTRIBUTES.map do |attribute|
  613 +
  614 + define_method "test_should_expose_#{attribute}_attribute_in_article_enpoints" do
  615 + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
  616 + get "/api/v1/articles/#{article.id}?#{params.to_query}"
  617 + json = JSON.parse(last_response.body)
  618 + assert_not_nil json['article'][attribute]
  619 + end
  620 +
  621 + end
  622 +
610 623 end
... ...
test/unit/api/people_test.rb
... ... @@ -47,12 +47,27 @@ class PeopleTest &lt; ActiveSupport::TestCase
47 47 assert_equal some_person.id, json['person']['id']
48 48 end
49 49  
  50 + should 'people endpoint filter by fields parameter' do
  51 + get "/api/v1/people?#{params.to_query}&fields=name"
  52 + json = JSON.parse(last_response.body)
  53 + expected = {'people' => [{'name' => person.name}]}
  54 + assert_equal expected, json
  55 + end
  56 +
  57 +
50 58 should 'get logged person' do
51 59 get "/api/v1/people/me?#{params.to_query}"
52 60 json = JSON.parse(last_response.body)
53 61 assert_equal person.id, json['person']['id']
54 62 end
55 63  
  64 + should 'me endpoint filter by fields parameter' do
  65 + get "/api/v1/people/me?#{params.to_query}&fields=name"
  66 + json = JSON.parse(last_response.body)
  67 + expected = {'person' => {'name' => person.name}}
  68 + assert_equal expected, json
  69 + end
  70 +
56 71 should 'not get invisible person' do
57 72 person = fast_create(Person, :visible => false)
58 73  
... ... @@ -165,4 +180,22 @@ class PeopleTest &lt; ActiveSupport::TestCase
165 180 assert_equal another_name, person.name
166 181 end
167 182  
  183 + PERSON_ATTRIBUTES = %w(vote_count comments_count following_articles_count articles_count)
  184 +
  185 + PERSON_ATTRIBUTES.map do |attribute|
  186 +
  187 + define_method "test_should_not_expose_#{attribute}_attribute_in_person_enpoint_if_field_parameter_is_not_passed" do
  188 + get "/api/v1/people/me?#{params.to_query}"
  189 + json = JSON.parse(last_response.body)
  190 + assert_nil json['person'][attribute]
  191 + end
  192 +
  193 + define_method "test_should_expose_#{attribute}_attribute_in_person_enpoints_only_if_field_parameter_is_passed" do
  194 + get "/api/v1/people/me?#{params.to_query}&fields=#{attribute}"
  195 + json = JSON.parse(last_response.body)
  196 + assert_not_nil json['person'][attribute]
  197 + end
  198 +
  199 + end
  200 +
168 201 end
... ...