diff --git a/controllers/myprofile/comment_paragraph_plugin_myprofile_controller.rb b/controllers/myprofile/comment_paragraph_plugin_myprofile_controller.rb new file mode 100644 index 0000000..56b0acc --- /dev/null +++ b/controllers/myprofile/comment_paragraph_plugin_myprofile_controller.rb @@ -0,0 +1,18 @@ +class CommentParagraphPluginMyprofileController < MyProfileController + + before_filter :check_permission + + def toggle_activation + @article.comment_paragraph_plugin_activate = !@article.comment_paragraph_plugin_activate + @article.save! + redirect_to @article.view_url + end + + protected + + def check_permission + @article = profile.articles.find(params[:id]) + render_access_denied unless @article.comment_paragraph_plugin_enabled? && @article.allow_edit?(user) + end + +end diff --git a/lib/comment_paragraph_plugin.rb b/lib/comment_paragraph_plugin.rb index f23fc0d..b51a89d 100644 --- a/lib/comment_paragraph_plugin.rb +++ b/lib/comment_paragraph_plugin.rb @@ -44,6 +44,13 @@ class CommentParagraphPlugin < Noosfero::Plugin 'manual' end + def article_header_extra_contents(article) + return unless article.comment_paragraph_plugin_enabled? + proc do + button :toggle_comment_paragraph, article.comment_paragraph_plugin_activated? ? _('Deactivate Comment Paragraph') : _('Activate Comment Paragraph'), :controller => 'comment_paragraph_plugin_myprofile', :action => 'toggle_activation', :id => article.id if article.allow_edit?(user) + end + end + end require_dependency 'comment_paragraph_plugin/macros/allow_comment' diff --git a/lib/ext/article.rb b/lib/ext/article.rb index 82d894f..36d0fa3 100644 --- a/lib/ext/article.rb +++ b/lib/ext/article.rb @@ -55,8 +55,7 @@ class Article def comment_paragraph_plugin_parse_paragraph(paragraph_content, paragraph_uuid) "
#{paragraph_content}
\r\n" + - "

 

" + "data-macro-paragraph_uuid='#{paragraph_uuid}'>#{paragraph_content}\r\n" end end diff --git a/public/style.css b/public/style.css index 746b64a..67eb9fb 100644 --- a/public/style.css +++ b/public/style.css @@ -1,3 +1,15 @@ +#content #article-toolbar .icon-toggle_comment_paragraph { + position: relative; + top: -71px; + border: 0; + background-color: transparent; + padding-left: 0; + color: gray; +} +#content #article-toolbar .icon-toggle_comment_paragraph:hover { + color: black; +} + #comment-bubble.visible { visibility: visible; } diff --git a/test/functional/comment_paragraph_plugin_myprofile_controller_test.rb b/test/functional/comment_paragraph_plugin_myprofile_controller_test.rb new file mode 100644 index 0000000..ae6790f --- /dev/null +++ b/test/functional/comment_paragraph_plugin_myprofile_controller_test.rb @@ -0,0 +1,35 @@ +require_relative '../test_helper' + +class CommentParagraphPluginMyprofileControllerTest < ActionController::TestCase + + def setup + @environment = Environment.default + @environment.enable_plugin(CommentParagraphPlugin) + @profile = fast_create(Profile) + @user = create_user_with_permission('testuser', 'post_content', @profile) + login_as(@user.identifier) + @article = fast_create(TextArticle, :profile_id => profile.id, :author_id => @user.id) + end + + attr_reader :article, :profile, :user, :environment + + should 'toggle comment paragraph activation' do + assert !article.comment_paragraph_plugin_activate + get :toggle_activation, :id => article.id, :profile => profile.identifier + assert article.reload.comment_paragraph_plugin_activate + assert_redirected_to article.view_url + end + + should 'deny access to toggle activation for forbidden users' do + login_as(create_user('anotheruser').login) + get :toggle_activation, :id => article.id, :profile => profile.identifier + assert_response :forbidden + end + + should 'deny access to toggle activation if plugin is not enabled' do + environment.disable_plugin(CommentParagraphPlugin) + get :toggle_activation, :id => article.id, :profile => profile.identifier + assert_response :forbidden + end + +end diff --git a/test/unit/comment_paragraph_plugin_test.rb b/test/unit/comment_paragraph_plugin_test.rb index 091840e..9506aaf 100644 --- a/test/unit/comment_paragraph_plugin_test.rb +++ b/test/unit/comment_paragraph_plugin_test.rb @@ -6,9 +6,10 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase def setup @environment = Environment.default @plugin = CommentParagraphPlugin.new + @user = create_user('testuser').person end - attr_reader :environment, :plugin + attr_reader :environment, :plugin, :user should 'have a name' do assert_not_equal Noosfero::Plugin.plugin_name, CommentParagraphPlugin::plugin_name @@ -35,4 +36,30 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase assert_nil /comment_paragraph_selected_area/.match(prok.call.inspect) end + should 'display button to toggle comment paragraph for users which can edit the article' do + article = fast_create(Article) + article.expects(:comment_paragraph_plugin_enabled?).returns(true) + article.expects(:allow_edit?).with(user).returns(true) + + content = plugin.article_header_extra_contents(article) + expects(:button).once + instance_eval(&content) + end + + should 'not display button to toggle comment paragraph for users which can not edit the article' do + article = fast_create(Article) + article.expects(:comment_paragraph_plugin_enabled?).returns(true) + article.expects(:allow_edit?).with(user).returns(false) + + content = plugin.article_header_extra_contents(article) + assert_equal nil, instance_eval(&content) + end + + should 'not display button to toggle comment paragraph if plugin is not enabled' do + article = fast_create(Article) + article.expects(:comment_paragraph_plugin_enabled?).returns(false) + + assert_equal nil, plugin.article_header_extra_contents(article) + end + end -- libgit2 0.21.2