Commit c6fa090178bd4202f87c71e5eec10493ea89c132
1 parent
4a0c41a8
Exists in
master
comment_paragraph: add button that toggle activation
Showing
6 changed files
with
101 additions
and
3 deletions
Show diff stats
controllers/myprofile/comment_paragraph_plugin_myprofile_controller.rb
0 → 100644
| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | +class CommentParagraphPluginMyprofileController < MyProfileController | |
| 2 | + | |
| 3 | + before_filter :check_permission | |
| 4 | + | |
| 5 | + def toggle_activation | |
| 6 | + @article.comment_paragraph_plugin_activate = !@article.comment_paragraph_plugin_activate | |
| 7 | + @article.save! | |
| 8 | + redirect_to @article.view_url | |
| 9 | + end | |
| 10 | + | |
| 11 | + protected | |
| 12 | + | |
| 13 | + def check_permission | |
| 14 | + @article = profile.articles.find(params[:id]) | |
| 15 | + render_access_denied unless @article.comment_paragraph_plugin_enabled? && @article.allow_edit?(user) | |
| 16 | + end | |
| 17 | + | |
| 18 | +end | ... | ... |
lib/comment_paragraph_plugin.rb
| ... | ... | @@ -44,6 +44,13 @@ class CommentParagraphPlugin < Noosfero::Plugin |
| 44 | 44 | 'manual' |
| 45 | 45 | end |
| 46 | 46 | |
| 47 | + def article_header_extra_contents(article) | |
| 48 | + return unless article.comment_paragraph_plugin_enabled? | |
| 49 | + proc do | |
| 50 | + 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) | |
| 51 | + end | |
| 52 | + end | |
| 53 | + | |
| 47 | 54 | end |
| 48 | 55 | |
| 49 | 56 | require_dependency 'comment_paragraph_plugin/macros/allow_comment' | ... | ... |
lib/ext/article.rb
| ... | ... | @@ -55,8 +55,7 @@ class Article |
| 55 | 55 | def comment_paragraph_plugin_parse_paragraph(paragraph_content, paragraph_uuid) |
| 56 | 56 | "<div class='macro article_comments paragraph_comment' " + |
| 57 | 57 | "data-macro='comment_paragraph_plugin/allow_comment' " + |
| 58 | - "data-macro-paragraph_uuid='#{paragraph_uuid}'>#{paragraph_content}</div>\r\n" + | |
| 59 | - "<p> </p>" | |
| 58 | + "data-macro-paragraph_uuid='#{paragraph_uuid}'>#{paragraph_content}</div>\r\n" | |
| 60 | 59 | end |
| 61 | 60 | |
| 62 | 61 | end | ... | ... |
public/style.css
| 1 | +#content #article-toolbar .icon-toggle_comment_paragraph { | |
| 2 | + position: relative; | |
| 3 | + top: -71px; | |
| 4 | + border: 0; | |
| 5 | + background-color: transparent; | |
| 6 | + padding-left: 0; | |
| 7 | + color: gray; | |
| 8 | +} | |
| 9 | +#content #article-toolbar .icon-toggle_comment_paragraph:hover { | |
| 10 | + color: black; | |
| 11 | +} | |
| 12 | + | |
| 1 | 13 | #comment-bubble.visible { |
| 2 | 14 | visibility: visible; |
| 3 | 15 | } | ... | ... |
test/functional/comment_paragraph_plugin_myprofile_controller_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,35 @@ |
| 1 | +require_relative '../test_helper' | |
| 2 | + | |
| 3 | +class CommentParagraphPluginMyprofileControllerTest < ActionController::TestCase | |
| 4 | + | |
| 5 | + def setup | |
| 6 | + @environment = Environment.default | |
| 7 | + @environment.enable_plugin(CommentParagraphPlugin) | |
| 8 | + @profile = fast_create(Profile) | |
| 9 | + @user = create_user_with_permission('testuser', 'post_content', @profile) | |
| 10 | + login_as(@user.identifier) | |
| 11 | + @article = fast_create(TextArticle, :profile_id => profile.id, :author_id => @user.id) | |
| 12 | + end | |
| 13 | + | |
| 14 | + attr_reader :article, :profile, :user, :environment | |
| 15 | + | |
| 16 | + should 'toggle comment paragraph activation' do | |
| 17 | + assert !article.comment_paragraph_plugin_activate | |
| 18 | + get :toggle_activation, :id => article.id, :profile => profile.identifier | |
| 19 | + assert article.reload.comment_paragraph_plugin_activate | |
| 20 | + assert_redirected_to article.view_url | |
| 21 | + end | |
| 22 | + | |
| 23 | + should 'deny access to toggle activation for forbidden users' do | |
| 24 | + login_as(create_user('anotheruser').login) | |
| 25 | + get :toggle_activation, :id => article.id, :profile => profile.identifier | |
| 26 | + assert_response :forbidden | |
| 27 | + end | |
| 28 | + | |
| 29 | + should 'deny access to toggle activation if plugin is not enabled' do | |
| 30 | + environment.disable_plugin(CommentParagraphPlugin) | |
| 31 | + get :toggle_activation, :id => article.id, :profile => profile.identifier | |
| 32 | + assert_response :forbidden | |
| 33 | + end | |
| 34 | + | |
| 35 | +end | ... | ... |
test/unit/comment_paragraph_plugin_test.rb
| ... | ... | @@ -6,9 +6,10 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase |
| 6 | 6 | def setup |
| 7 | 7 | @environment = Environment.default |
| 8 | 8 | @plugin = CommentParagraphPlugin.new |
| 9 | + @user = create_user('testuser').person | |
| 9 | 10 | end |
| 10 | 11 | |
| 11 | - attr_reader :environment, :plugin | |
| 12 | + attr_reader :environment, :plugin, :user | |
| 12 | 13 | |
| 13 | 14 | should 'have a name' do |
| 14 | 15 | assert_not_equal Noosfero::Plugin.plugin_name, CommentParagraphPlugin::plugin_name |
| ... | ... | @@ -35,4 +36,30 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase |
| 35 | 36 | assert_nil /comment_paragraph_selected_area/.match(prok.call.inspect) |
| 36 | 37 | end |
| 37 | 38 | |
| 39 | + should 'display button to toggle comment paragraph for users which can edit the article' do | |
| 40 | + article = fast_create(Article) | |
| 41 | + article.expects(:comment_paragraph_plugin_enabled?).returns(true) | |
| 42 | + article.expects(:allow_edit?).with(user).returns(true) | |
| 43 | + | |
| 44 | + content = plugin.article_header_extra_contents(article) | |
| 45 | + expects(:button).once | |
| 46 | + instance_eval(&content) | |
| 47 | + end | |
| 48 | + | |
| 49 | + should 'not display button to toggle comment paragraph for users which can not edit the article' do | |
| 50 | + article = fast_create(Article) | |
| 51 | + article.expects(:comment_paragraph_plugin_enabled?).returns(true) | |
| 52 | + article.expects(:allow_edit?).with(user).returns(false) | |
| 53 | + | |
| 54 | + content = plugin.article_header_extra_contents(article) | |
| 55 | + assert_equal nil, instance_eval(&content) | |
| 56 | + end | |
| 57 | + | |
| 58 | + should 'not display button to toggle comment paragraph if plugin is not enabled' do | |
| 59 | + article = fast_create(Article) | |
| 60 | + article.expects(:comment_paragraph_plugin_enabled?).returns(false) | |
| 61 | + | |
| 62 | + assert_equal nil, plugin.article_header_extra_contents(article) | |
| 63 | + end | |
| 64 | + | |
| 38 | 65 | end | ... | ... |