Commit c9d279cd75945726dc74d0a1285b07d7f88cd1a7
1 parent
7732936c
Exists in
master
and in
28 other branches
stoa-person-api: not provide information of private articles tags
Showing
2 changed files
with
12 additions
and
3 deletions
Show diff stats
plugins/stoa/lib/stoa_plugin/person_api.rb
@@ -24,7 +24,7 @@ class StoaPlugin::PersonApi < Noosfero::FieldsDecorator | @@ -24,7 +24,7 @@ class StoaPlugin::PersonApi < Noosfero::FieldsDecorator | ||
24 | end | 24 | end |
25 | 25 | ||
26 | def tags | 26 | def tags |
27 | - articles.tag_counts({:order => 'tags.count desc', :limit => 10}).inject({}) do |memo,tag| | 27 | + articles.published.tag_counts({:order => 'tags.count desc', :limit => 10}).inject({}) do |memo,tag| |
28 | memo[tag.name] = tag.count | 28 | memo[tag.name] = tag.count |
29 | memo | 29 | memo |
30 | end | 30 | end |
plugins/stoa/test/unit/person_api_test.rb
@@ -92,10 +92,19 @@ class StoaPlugin::PersonApiTest < ActiveSupport::TestCase | @@ -92,10 +92,19 @@ class StoaPlugin::PersonApiTest < ActiveSupport::TestCase | ||
92 | assert_nil tags['n'] | 92 | assert_nil tags['n'] |
93 | end | 93 | end |
94 | 94 | ||
95 | + should 'not provide information of private articles tags' do | ||
96 | + create_article_with_tags(person.id, 'free_software, noosfero, linux', {:published => false}) | ||
97 | + create_article_with_tags(person.id, 'free_software, linux') | ||
98 | + create_article_with_tags(person.id, 'free_software') | ||
99 | + | ||
100 | + api = StoaPlugin::PersonApi.new(person) | ||
101 | + assert !api.tags.has_key?('noosfero') | ||
102 | + end | ||
103 | + | ||
95 | private | 104 | private |
96 | 105 | ||
97 | - def create_article_with_tags(profile_id, tags = '') | ||
98 | - article = fast_create(Article, :profile_id => profile_id) | 106 | + def create_article_with_tags(profile_id, tags = '', options = {}) |
107 | + article = fast_create(Article, options.merge(:profile_id => profile_id)) | ||
99 | article.tag_list = tags | 108 | article.tag_list = tags |
100 | article.save! | 109 | article.save! |
101 | article | 110 | article |