Commit 15720094d082994f46253c5eb0b8728bfe5c3844
1 parent
4d40b678
Exists in
master
and in
29 other branches
[comments-refactor-review] Checking permissions to show remove link
Showing
2 changed files
with
15 additions
and
1 deletions
Show diff stats
app/helpers/comment_helper.rb
... | ... | @@ -62,7 +62,7 @@ module CommentHelper |
62 | 62 | end |
63 | 63 | |
64 | 64 | def link_for_remove(comment) |
65 | - if logged_in? && (user == profile || user == comment.author || user.has_permission?(:moderate_comments, profile)) | |
65 | + if comment.can_be_destroyed_by?(user) | |
66 | 66 | {:link => link_to_function(_('Remove'), 'remove_comment(this, %s, %s); return false ;' % [url_for(:profile => profile.identifier, :controller => 'comment', :action => :destroy, :id => comment.id).to_json, _('Are you sure you want to remove this comment and all its replies?').to_json], :class => 'comment-footer comment-footer-link comment-footer-hide remove-children')} |
67 | 67 | end |
68 | 68 | end | ... | ... |
test/unit/comment_helper_test.rb
... | ... | @@ -117,6 +117,20 @@ class CommentHelperTest < ActiveSupport::TestCase |
117 | 117 | assert link |
118 | 118 | end |
119 | 119 | |
120 | + should 'do not return link for remove comment' do | |
121 | + comment = Comment.new | |
122 | + comment.stubs(:can_be_destroyed_by?).with(user).returns(false) | |
123 | + link = link_for_remove(comment) | |
124 | + assert_nil link | |
125 | + end | |
126 | + | |
127 | + should 'return link for remove comment' do | |
128 | + comment = Comment.new | |
129 | + comment.stubs(:can_be_destroyed_by?).with(user).returns(true) | |
130 | + link = link_for_remove(comment) | |
131 | + assert link | |
132 | + end | |
133 | + | |
120 | 134 | def link_to_function(content, url, options = {}) |
121 | 135 | link_to(content, url, options) |
122 | 136 | end | ... | ... |