diff --git a/app/helpers/comment_helper.rb b/app/helpers/comment_helper.rb index aee6300..9359654 100644 --- a/app/helpers/comment_helper.rb +++ b/app/helpers/comment_helper.rb @@ -1,8 +1,8 @@ module CommentHelper def article_title(article, args = {}) + title = article.title title = article.display_title if article.kind_of?(UploadedFile) && article.image? - title = article.title if title.blank? title = content_tag('h1', h(title), :class => 'title') if article.belongs_to_blog? unless args[:no_link] @@ -21,7 +21,7 @@ module CommentHelper end title end - + def comment_actions(comment) url = url_for(:profile => profile.identifier, :controller => :comment, :action => :check_actions, :id => comment.id) links = links_for_comment_actions(comment) @@ -46,10 +46,12 @@ module CommentHelper end def link_for_spam(comment) - if comment.spam? - {:link => link_to_function(_('Mark as NOT SPAM'), 'remove_comment(this, %s); return false;' % url_for(:profile => profile.identifier, :mark_comment_as_ham => comment.id).to_json, :class => 'comment-footer comment-footer-link comment-footer-hide')} - elsif (logged_in? && (user == profile || user.has_permission?(:moderate_comments, profile))) - {:link => link_to_function(_('Mark as SPAM'), 'remove_comment(this, %s, %s); return false;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :mark_as_spam, :id => comment.id).to_json, _('Are you sure you want to mark this comment as SPAM?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide')} + if comment.can_be_marked_as_spam_by?(user) + if comment.spam? + {:link => link_to_function(_('Mark as NOT SPAM'), 'remove_comment(this, %s); return false;' % url_for(:profile => profile.identifier, :mark_comment_as_ham => comment.id).to_json, :class => 'comment-footer comment-footer-link comment-footer-hide')} + else + {:link => link_to_function(_('Mark as SPAM'), 'remove_comment(this, %s, %s); return false;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :mark_as_spam, :id => comment.id).to_json, _('Are you sure you want to mark this comment as SPAM?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide')} + end end end diff --git a/test/unit/comment_helper_test.rb b/test/unit/comment_helper_test.rb index 6929572..e73fe41 100644 --- a/test/unit/comment_helper_test.rb +++ b/test/unit/comment_helper_test.rb @@ -18,7 +18,8 @@ class CommentHelperTest < ActiveSupport::TestCase attr_reader :user, :profile should 'show menu if it has links for actions' do - comment = Comment.new + article = Article.new(:profile => profile) + comment = Comment.new(:article => article) menu = comment_actions(comment) assert menu end @@ -41,7 +42,8 @@ class CommentHelperTest < ActiveSupport::TestCase end should 'include actions of plugins in menu' do - comment = Comment.new + article = Article.new(:profile => profile) + comment = Comment.new(:article => article) plugin_action = {:link => 'plugin_action'} @plugins.stubs(:dispatch).returns([plugin_action]) links = links_for_comment_actions(comment) @@ -49,7 +51,8 @@ class CommentHelperTest < ActiveSupport::TestCase end should 'include lambda actions of plugins in menu' do - comment = Comment.new + article = Article.new(:profile => profile) + comment = Comment.new(:article => article) plugin_action = lambda{[{:link => 'plugin_action'}, {:link => 'plugin_action2'}]} @plugins.stubs(:dispatch).returns([plugin_action]) links = links_for_comment_actions(comment) @@ -72,17 +75,34 @@ class CommentHelperTest < ActiveSupport::TestCase should 'return link for mark comment as spam' do comment = Comment.new + comment.stubs(:can_be_marked_as_spam_by?).with(user).returns(true) link = link_for_spam(comment) assert_match /Mark as SPAM/, link[:link] end + should 'not return link for mark comment as spam if user does not have the permissions' do + comment = Comment.new + comment.stubs(:can_be_marked_as_spam_by?).with(user).returns(false) + link = link_for_spam(comment) + assert_nil link + end + should 'return link for mark comment as not spam' do comment = Comment.new comment.spam = true + comment.stubs(:can_be_marked_as_spam_by?).with(user).returns(true) link = link_for_spam(comment) assert_match /Mark as NOT SPAM/, link[:link] end + should 'not return link for mark comment as not spam if user does not have the permissions' do + comment = Comment.new + comment.spam = true + comment.stubs(:can_be_marked_as_spam_by?).with(user).returns(false) + link = link_for_spam(comment) + assert_nil link + end + should 'do not return link for edit comment' do comment = Comment.new link = link_for_edit(comment) -- libgit2 0.21.2