Commit f0228cddd66d1aacde7b261cf003c756c398de7b
Exists in
master
Merge branch 'master' of gitlab.com:noosfero-plugins/comment-paragraph
Showing
4 changed files
with
37 additions
and
21 deletions
Show diff stats
db/migrate/20140715190749_add_setting_to_comments.rb
lib/comment_paragraph_plugin.rb
... | ... | @@ -44,11 +44,14 @@ class CommentParagraphPlugin < Noosfero::Plugin |
44 | 44 | 'manual' |
45 | 45 | end |
46 | 46 | |
47 | - def article_toolbar_actions(article) | |
48 | - return unless article.comment_paragraph_plugin_enabled? | |
49 | - proc do | |
50 | - button :toggle_comment_paragraph, article.comment_paragraph_plugin_activated? ? _('Deactivate Comments') : _('Activate Comments'), :controller => 'comment_paragraph_plugin_myprofile', :profile => article.profile.identifier, :action => 'toggle_activation', :id => article.id if article.allow_edit?(user) | |
51 | - end | |
47 | + def article_extra_toolbar_buttons(article) | |
48 | + return [] if !article.comment_paragraph_plugin_enabled? || !article.allow_edit?(current_person) | |
49 | + { | |
50 | + :title => article.comment_paragraph_plugin_activated? ? _('Deactivate Comments') : _('Activate Comments'), | |
51 | + :url => {:controller => 'comment_paragraph_plugin_myprofile', :profile => article.profile.identifier, :action => 'toggle_activation', :id => article.id}, | |
52 | + :icon => :toggle_comment_paragraph | |
53 | + } | |
54 | + | |
52 | 55 | end |
53 | 56 | |
54 | 57 | end | ... | ... |
public/comment_paragraph_macro.js
... | ... | @@ -65,6 +65,9 @@ jQuery(document).ready(function($) { |
65 | 65 | $('#comment-bubble').removeClass('visible'); |
66 | 66 | container.addClass('comment-paragraph-slide-left selected'); |
67 | 67 | container.find('.side-comment').show(); |
68 | + if(!$('body').hasClass('logged-in') && $('meta[name="profile.allow_unauthenticated_comments"]').length == 0) { | |
69 | + container.addClass('require-login-popup'); | |
70 | + } | |
68 | 71 | //Loads the comments |
69 | 72 | var url = container.find('.side-comment').data('comment_paragraph_url'); |
70 | 73 | $.ajax(url).done(function(data) { | ... | ... |
test/unit/comment_paragraph_plugin_test.rb
... | ... | @@ -5,8 +5,10 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase |
5 | 5 | |
6 | 6 | def setup |
7 | 7 | @environment = Environment.default |
8 | - @plugin = CommentParagraphPlugin.new | |
9 | 8 | @user = create_user('testuser').person |
9 | + context = mock() | |
10 | + context.stubs(:current_person).returns(@user) | |
11 | + @plugin = CommentParagraphPlugin.new(context) | |
10 | 12 | end |
11 | 13 | |
12 | 14 | attr_reader :environment, :plugin, :user |
... | ... | @@ -42,9 +44,7 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase |
42 | 44 | article.expects(:comment_paragraph_plugin_enabled?).returns(true) |
43 | 45 | article.expects(:allow_edit?).with(user).returns(true) |
44 | 46 | |
45 | - content = plugin.article_toolbar_actions(article) | |
46 | - expects(:button).once | |
47 | - instance_eval(&content) | |
47 | + assert_not_equal [], plugin.article_extra_toolbar_buttons(article) | |
48 | 48 | end |
49 | 49 | |
50 | 50 | should 'not display button to toggle comment paragraph for users which can not edit the article' do |
... | ... | @@ -53,8 +53,7 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase |
53 | 53 | article.expects(:comment_paragraph_plugin_enabled?).returns(true) |
54 | 54 | article.expects(:allow_edit?).with(user).returns(false) |
55 | 55 | |
56 | - content = plugin.article_toolbar_actions(article) | |
57 | - assert_equal nil, instance_eval(&content) | |
56 | + assert_equal [], plugin.article_extra_toolbar_buttons(article) | |
58 | 57 | end |
59 | 58 | |
60 | 59 | should 'not display button to toggle comment paragraph if plugin is not enabled' do |
... | ... | @@ -62,7 +61,27 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase |
62 | 61 | article = fast_create(Article, :profile_id => profile.id) |
63 | 62 | article.expects(:comment_paragraph_plugin_enabled?).returns(false) |
64 | 63 | |
65 | - assert_equal nil, plugin.article_toolbar_actions(article) | |
64 | + assert_equal [], plugin.article_extra_toolbar_buttons(article) | |
65 | + end | |
66 | + | |
67 | + should 'display Activate Comments title if comment paragraph plugin is activated' do | |
68 | + profile = fast_create(Profile) | |
69 | + article = fast_create(Article, :profile_id => profile.id) | |
70 | + article.expects(:comment_paragraph_plugin_enabled?).returns(true) | |
71 | + article.expects(:allow_edit?).with(user).returns(true) | |
72 | + article.expects(:comment_paragraph_plugin_activated?).returns(false) | |
73 | + | |
74 | + assert_equal 'Activate Comments', plugin.article_extra_toolbar_buttons(article)[:title] | |
75 | + end | |
76 | + | |
77 | + should 'display Deactivate Comments title if comment paragraph plugin is deactivated' do | |
78 | + profile = fast_create(Profile) | |
79 | + article = fast_create(Article, :profile_id => profile.id) | |
80 | + article.expects(:comment_paragraph_plugin_enabled?).returns(true) | |
81 | + article.expects(:allow_edit?).with(user).returns(true) | |
82 | + article.expects(:comment_paragraph_plugin_activated?).returns(true) | |
83 | + | |
84 | + assert_equal 'Deactivate Comments', plugin.article_extra_toolbar_buttons(article)[:title] | |
66 | 85 | end |
67 | 86 | |
68 | 87 | end | ... | ... |