Commit 6105dd65dea1aaf6a49f41891efe0021efefe7a8

Authored by Leandro Santos
2 parents 4caf1712 fcfcc7be
Exists in staging and in 1 other branch production

Merge branch 'master' into staging

app/helpers/users_helper.rb
1 1 module UsersHelper
2 2  
3   - FILTER_TRANSLATION = {
  3 + def filter_translation
  4 + {
4 5 'all_users' => _('All users'),
5 6 'admin_users' => _('Admin users'),
6 7 'activated_users' => _('Activated users'),
7 8 'deactivated_users' => _('Deativated users'),
8   - }
  9 + }
  10 + end
9 11  
10 12 def filter_selector(filter, float = 'right')
11   - options = options_for_select(FILTER_TRANSLATION.map {|key, name| [name, key]}, :selected => filter)
  13 + options = options_for_select(filter_translation.map {|key, name| [name, key]}, :selected => filter)
12 14 url_params = url_for(params.merge(:filter => 'FILTER'))
13 15 onchange = "document.location.href = '#{url_params}'.replace('FILTER', this.value)"
14 16 select_field = select_tag(:filter, options, :onchange => onchange)
... ... @@ -19,7 +21,7 @@ module UsersHelper
19 21 end
20 22  
21 23 def users_filter_title(filter)
22   - FILTER_TRANSLATION[filter]
  24 + filter_translation[filter]
23 25 end
24 26  
25 27 end
... ...
app/views/content_viewer/blog_page.html.erb
... ... @@ -4,7 +4,7 @@
4 4  
5 5 <div>
6 6 <div class='blog-description'>
7   - <%= blog.body %>
  7 + <%= blog.body.html_safe %>
8 8 </div>
9 9 </div>
10 10 <hr class="pre-posts"/>
... ...
plugins/admin_notifications/po/admin_notifications.pot
... ... @@ -8,8 +8,8 @@ msgid &quot;&quot;
8 8 msgstr ""
9 9 "Project-Id-Version: PACKAGE VERSION\n"
10 10 "Report-Msgid-Bugs-To: \n"
11   -"POT-Creation-Date: 2016-05-16 14:48-0300\n"
12   -"PO-Revision-Date: 2016-05-16 14:48-0300\n"
  11 +"POT-Creation-Date: 2016-05-17 15:38-0300\n"
  12 +"PO-Revision-Date: 2016-05-17 15:38-0300\n"
13 13 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14 14 "Language-Team: LANGUAGE <LL@li.org>\n"
15 15 "Language: \n"
... ... @@ -113,6 +113,10 @@ msgid &quot;Red - Danger&quot;
113 113 msgstr ""
114 114  
115 115 #: ../views/shared/_form.html.erb:23
  116 +msgid "Display only in the profile homepage"
  117 +msgstr ""
  118 +
  119 +#: ../views/shared/_form.html.erb:23
116 120 msgid "Display only in the homepage"
117 121 msgstr ""
118 122  
... ...
plugins/admin_notifications/po/pt/admin_notifications.po
... ... @@ -89,6 +89,9 @@ msgstr &quot;Verde - Sucesso&quot;
89 89 msgid "Red - Danger"
90 90 msgstr "Vermelho - Perigo"
91 91  
  92 +msgid "Display only in the profile homepage"
  93 +msgstr "Apresentar apenas na página inicial do perfil"
  94 +
92 95 msgid "Display only in the homepage"
93 96 msgstr "Apresentar apenas na página inicial"
94 97  
... ...
plugins/admin_notifications/views/shared/_form.html.erb
... ... @@ -20,7 +20,7 @@
20 20 <%= labelled_form_field(_('Notifications Color/Type'), select(:notifications, :type, options_for_select_with_title({_("Blue - Information") => "AdminNotificationsPlugin::InformationNotification", _("Yellow - Warning") => "AdminNotificationsPlugin::WarningNotification", _("Green - Success") => "AdminNotificationsPlugin::SuccessNotification", _("Red - Danger") => "AdminNotificationsPlugin::DangerNotification"}, @notification.type))) %>
21 21  
22 22 <div>
23   - <%= labelled_check_box(_("Display only in the homepage"), 'notifications[display_only_in_homepage]', '1', @notification.display_only_in_homepage?) %>
  23 + <%= labelled_check_box(profile.present? ? _("Display only in the profile homepage") : _("Display only in the homepage") , 'notifications[display_only_in_homepage]', '1', @notification.display_only_in_homepage?) %>
24 24 </div>
25 25  
26 26 <div>
... ...
plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb
... ... @@ -20,45 +20,8 @@ class RelevantContentPlugin::RelevantContentBlock &lt; Block
20 20  
21 21 attr_accessible :limit, :show_most_voted, :show_most_disliked, :show_most_liked, :show_most_commented, :show_most_read
22 22  
23   - include ActionView::Helpers
24   - include Rails.application.routes.url_helpers
25   -
26   - def content(args={})
27   -
28   - content = block_title(title, subtitle)
29   -
30   - if self.show_most_read
31   - docs = Article.most_accessed(owner, self.limit)
32   - content += subcontent(docs, _("Most read articles"), "mread") unless docs.blank?
33   - end
34   -
35   - if self.show_most_commented
36   - docs = Article.most_commented_relevant_content(owner, self.limit)
37   - content += subcontent(docs, _("Most commented articles"), "mcommented") unless docs.blank?
38   - end
39   -
40   - if owner.kind_of?(Environment)
41   - env = owner
42   - else
43   - env = owner.environment
44   - end
45   -
46   - if env.plugin_enabled?('VotePlugin')
47   - if self.show_most_liked
48   - docs = Article.more_positive_votes(owner, self.limit)
49   - content += subcontent(docs, _("Most liked articles"), "mliked") unless docs.blank?
50   - end
51   - if self.show_most_disliked
52   - docs = Article.more_negative_votes(owner, self.limit)
53   - content += subcontent(docs, _("Most disliked articles"), "mdisliked") unless docs.blank?
54   - end
55   -
56   - if self.show_most_voted
57   - docs = Article.most_voted(owner, self.limit)
58   - content += subcontent(docs, _("Most voted articles"), "mvoted") unless docs.blank?
59   - end
60   - end
61   - return content.html_safe
  23 + def env
  24 + owner.kind_of?(Environment) ? owner : owner.environment
62 25 end
63 26  
64 27 def timeout
... ... @@ -69,14 +32,4 @@ class RelevantContentPlugin::RelevantContentBlock &lt; Block
69 32 { :profile => [:article], :environment => [:article] }
70 33 end
71 34  
72   - protected
73   -
74   - def subcontent(docs, title, html_class)
75   - subcontent = safe_join([
76   - content_tag(:span, title, class: "title #{html_class}"),
77   - content_tag(:ul, safe_join(docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}, "\n"))
78   - ], "\n")
79   - content_tag(:div, subcontent, :class=>"block #{html_class}")
80   - end
81   -
82 35 end
... ...
plugins/relevant_content/test/unit/relevant_content_block_test.rb
... ... @@ -42,20 +42,6 @@ class RelevantContentBlockTest &lt; ActiveSupport::TestCase
42 42 assert_equal RelevantContentPlugin::RelevantContentBlock.expire_on, {:environment=>[:article], :profile=>[:article]}
43 43 end
44 44  
45   - should 'not crash if vote plugin is not found' do
46   - box = fast_create(Box, :owner_id => @profile.id, :owner_type => 'Profile')
47   - block = RelevantContentPlugin::RelevantContentBlock.new(:box => box)
48   -
49   - Environment.any_instance.stubs(:enabled_plugins).returns(['RelevantContent'])
50   - # When the plugin is disabled from noosfero instance, its constant name is
51   - # undefined. To test this case, I have to manually undefine the constant
52   - # if necessary.
53   - Object.send(:remove_const, VotePlugin.to_s) if defined? VotePlugin
54   -
55   - assert_nothing_raised do
56   - block.content
57   - end
58   - end
59 45  
60 46 should 'check most voted articles from profile with relevant content block' do
61 47 community = fast_create(Community)
... ... @@ -77,11 +63,41 @@ class RelevantContentBlockTest &lt; ActiveSupport::TestCase
77 63 assert_equal false, data.empty?
78 64 end
79 65  
  66 +end
  67 +
  68 +require 'boxes_helper'
  69 +
  70 +class RelevantContentBlockViewTest < ActionView::TestCase
  71 + include BoxesHelper
  72 +
  73 + def setup
  74 + @profile = create_user('testinguser').person
  75 + end
  76 +
  77 + should 'not crash if vote plugin is not found' do
  78 + box = fast_create(Box, :owner_id => @profile.id, :owner_type => 'Profile')
  79 + block = RelevantContentPlugin::RelevantContentBlock.new(:box => box)
  80 +
  81 + Environment.any_instance.stubs(:enabled_plugins).returns(['RelevantContent'])
  82 + ActionView::Base.any_instance.expects(:block_title).returns("")
  83 + # When the plugin is disabled from noosfero instance, its constant name is
  84 + # undefined. To test this case, I have to manually undefine the constant
  85 + # if necessary.
  86 + Object.send(:remove_const, VotePlugin.to_s) if defined? VotePlugin
  87 +
  88 + assert_nothing_raised do
  89 + render_block_content(block)
  90 + end
  91 + end
  92 +
80 93 should 'not escape html in block content' do
81   - fast_create(Article, profile_id: profile.id, hits: 10)
82   - box = fast_create(Box, :owner_id => profile.id, :owner_type => 'Profile')
  94 + fast_create(Article, profile_id: @profile.id, hits: 10)
  95 + box = fast_create(Box, :owner_id => @profile.id, :owner_type => 'Profile')
83 96 block = RelevantContentPlugin::RelevantContentBlock.new(:box => box)
  97 +
84 98 Environment.any_instance.stubs(:enabled_plugins).returns(['RelevantContent'])
85   - assert_tag_in_string block.content, tag: 'span', attributes: { class: 'title mread' }
  99 + ActionView::Base.any_instance.expects(:block_title).returns("")
  100 +
  101 + assert_tag_in_string render_block_content(block), tag: 'span', attributes: { class: 'title mread' }
86 102 end
87 103 end
... ...
plugins/relevant_content/views/blocks/_doc.slim 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +li
  2 + = link_to(h(doc.title), doc.url)
... ...
plugins/relevant_content/views/blocks/_subcontent.slim 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +- unless docs.blank?
  2 + div class="block #{html_class}"
  3 + span class="title #{html_class}"
  4 + = title
  5 + ul
  6 + = render partial: 'blocks/doc', collection: docs
... ...
plugins/relevant_content/views/blocks/relevant_content.slim 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 += block_title(block.title, block.subtitle)
  2 +
  3 +- if block.show_most_read
  4 + = render partial: 'blocks/subcontent', locals: {docs: Article.most_accessed(block.owner, block.limit), title: _("Most read articles"), html_class: 'mread'}
  5 +- if block.show_most_commented
  6 + = render partial: 'blocks/subcontent', locals: {docs: Article.most_commented_relevant_content(block.owner, block.limit), title: _("Most commented articles"), html_class: 'mcommented'}
  7 +
  8 +- if block.env.plugin_enabled?('VotePlugin')
  9 + - if block.show_most_liked
  10 + = render partial: 'blocks/subcontent', locals: {docs: Article.more_positive_votes(block.owner, block.limit), title: _("Most liked articles"), html_class: 'mliked'}
  11 + - if block.show_most_disliked
  12 + = render partial: 'blocks/subcontent', locals: {docs: Article.more_negative_votes(block.owner, block.limit), title: _("Most disliked articles"), html_class: 'mdisliked'}
  13 + - if block.show_most_voted
  14 + = render partial: 'blocks/subcontent', locals: {docs: Article.most_voted(block.owner, block.limit), title: _("Most voted articles"), html_class: 'mvoted'}
... ...