Commit 1b6854864b958b1a34dab970ed88c81709ac796d
1 parent
929da83d
Exists in
master
and in
29 other branches
ActionItem529: moderator/admin can remove comments from articles
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2194 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
51 additions
and
7 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
... | ... | @@ -72,7 +72,7 @@ class ContentViewerController < PublicController |
72 | 72 | |
73 | 73 | def remove_comment |
74 | 74 | @comment = @page.comments.find(params[:remove_comment]) |
75 | - if (user == @comment.author) || (user == @page.profile) | |
75 | + if (user == @comment.author || user == @page.profile || user.has_permission?(:moderate_comments, @page.profile)) | |
76 | 76 | @comment.destroy |
77 | 77 | flash[:notice] = _('Comment succesfully deleted') |
78 | 78 | end | ... | ... |
app/models/profile.rb
... | ... | @@ -34,6 +34,7 @@ class Profile < ActiveRecord::Base |
34 | 34 | 'manage_friends' => N_('Manage friends'), |
35 | 35 | 'validate_enterprise' => N_('Validate enterprise'), |
36 | 36 | 'perform_task' => N_('Perform task'), |
37 | + 'moderate_comments' => N_('Moderate comments'), | |
37 | 38 | } |
38 | 39 | |
39 | 40 | acts_as_accessible | ... | ... |
app/views/content_viewer/_comment.rhtml
1 | 1 | <%= content_tag('a', '', :name => comment.anchor) %> |
2 | 2 | <div class="article-comment<%= ' comment-from-owner' if ( comment.author && (@page.profile.name == comment.author.name) ) %> comment-logged-<%= comment.author ? 'in' : 'out' %>"> |
3 | - <% if logged_in? && (user == @page.profile || user == comment.author) %> | |
3 | + <% if logged_in? && (user == @page.profile || user == comment.author || user.has_permission?(:moderate_comments, @page.profile)) %> | |
4 | 4 | <% button_bar(:style => 'float: right; margin-top: 0;') do %> |
5 | 5 | <%= icon_button(:delete, _('Remove'), { :remove_comment => comment.id }, :method => :post, :confirm => _('Are you sure you want to remove this comment?')) %> |
6 | 6 | <% end %> | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +class MoreNewPermissions < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + admin = Profile::Roles.admin | |
4 | + admin.permissions += ['moderate_comments'] | |
5 | + admin.save | |
6 | + | |
7 | + moderator = Profile::Roles.moderator | |
8 | + moderator.permissions += ['moderate_comments'] | |
9 | + moderator.save | |
10 | + end | |
11 | + | |
12 | + def self.down | |
13 | + admin = Profile::Roles.admin | |
14 | + admin.permissions -= ['moderate_comments'] | |
15 | + admin.save | |
16 | + | |
17 | + moderator = Profile::Roles.moderator | |
18 | + moderator.permissions -= ['moderate_comments'] | |
19 | + moderator.save | |
20 | + end | |
21 | +end | ... | ... |
db/schema.rb
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | # |
10 | 10 | # It's strongly recommended to check this file into your version control system. |
11 | 11 | |
12 | -ActiveRecord::Schema.define(:version => 44) do | |
12 | +ActiveRecord::Schema.define(:version => 45) do | |
13 | 13 | |
14 | 14 | create_table "article_versions", :force => true do |t| |
15 | 15 | t.integer "article_id" | ... | ... |
test/fixtures/roles.yml
... | ... | @@ -3,7 +3,7 @@ one: |
3 | 3 | id: 1 |
4 | 4 | name: 'member' |
5 | 5 | permissions: |
6 | - - post_content | |
6 | + - post_content | |
7 | 7 | two: |
8 | 8 | id: 2 |
9 | 9 | name: 'owner' |
... | ... | @@ -16,7 +16,7 @@ three: |
16 | 16 | id: 3 |
17 | 17 | name: 'moderator' |
18 | 18 | permissions: |
19 | - - manage_memberships | |
19 | + - manage_memberships | |
20 | 20 | four: |
21 | 21 | id: 4 |
22 | 22 | name: 'admin' |
... | ... | @@ -27,6 +27,7 @@ four: |
27 | 27 | - manage_environment_categories |
28 | 28 | - manage_environment_roles |
29 | 29 | - manage_environment_validators |
30 | + - moderate_comments | |
30 | 31 | profile_admin: |
31 | 32 | id: 5 |
32 | 33 | key: 'profile_admin' |
... | ... | @@ -34,6 +35,7 @@ profile_admin: |
34 | 35 | system: true |
35 | 36 | permissions: |
36 | 37 | - edit_profile_design |
38 | + - moderate_comments | |
37 | 39 | profile_member: |
38 | 40 | id: 6 |
39 | 41 | key: 'profile_member' |
... | ... | @@ -48,3 +50,5 @@ profile_moderator: |
48 | 50 | key: 'profile_moderator' |
49 | 51 | name: 'Profile Moderator' |
50 | 52 | system: true |
53 | + permissions: | |
54 | + - moderate_comments | ... | ... |
test/functional/content_viewer_controller_test.rb
... | ... | @@ -160,7 +160,6 @@ class ContentViewerControllerTest < Test::Unit::TestCase |
160 | 160 | post :view_page, :profile => profile.identifier, :page => [ 'test' ], :remove_comment => comment.id |
161 | 161 | assert_response :redirect |
162 | 162 | end |
163 | - | |
164 | 163 | end |
165 | 164 | |
166 | 165 | should 'not be able to post comment while inverse captcha field filled' do |
... | ... | @@ -174,6 +173,19 @@ class ContentViewerControllerTest < Test::Unit::TestCase |
174 | 173 | end |
175 | 174 | end |
176 | 175 | |
176 | + should 'be able to remove comments if is moderator' do | |
177 | + commenter = create_user('commenter_user').person | |
178 | + community = Community.create!(:name => 'Community test', :identifier => 'community-test') | |
179 | + article = community.articles.create!(:name => 'test') | |
180 | + comment = article.comments.create!(:author => commenter, :title => 'a comment', :body => 'lalala') | |
181 | + community.add_moderator(profile) | |
182 | + login_as profile.identifier | |
183 | + assert_difference Comment, :count, -1 do | |
184 | + post :view_page, :profile => community.identifier, :page => [ 'test' ], :remove_comment => comment.id | |
185 | + assert_response :redirect | |
186 | + end | |
187 | + end | |
188 | + | |
177 | 189 | should 'render inverse captcha field' do |
178 | 190 | profile = create_user('popstar').person |
179 | 191 | page = profile.articles.build(:name => 'myarticle', :body => 'the body of the text') | ... | ... |
test/unit/organization_test.rb
... | ... | @@ -188,7 +188,6 @@ class OrganizationTest < Test::Unit::TestCase |
188 | 188 | assert_not_includes c.members, p |
189 | 189 | end |
190 | 190 | |
191 | - # FIXME why members dont return moderators??? | |
192 | 191 | should 'allow to add new moderator' do |
193 | 192 | o = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') |
194 | 193 | p = create_user('myanothertestuser').person |
... | ... | @@ -198,4 +197,11 @@ class OrganizationTest < Test::Unit::TestCase |
198 | 197 | assert o.members.include?(p), "Organization should add the new moderator" |
199 | 198 | end |
200 | 199 | |
200 | + should 'moderator has moderate_comments permission' do | |
201 | + o = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
202 | + p = create_user('myanothertestuser').person | |
203 | + o.add_moderator(p) | |
204 | + assert p.has_permission?(:moderate_comments, o) | |
205 | + end | |
206 | + | |
201 | 207 | end | ... | ... |