Skip to content

Commit

Permalink
Fix moderator rights inconsistencies (#26729)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Sep 19, 2023
1 parent 1afae8c commit 4bde23b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
File renamed without changes.
9 changes: 9 additions & 0 deletions app/lib/admin/account_statuses_filter.rb
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class Admin::AccountStatusesFilter < AccountStatusesFilter
private

def blocked?
false
end
end
2 changes: 1 addition & 1 deletion app/models/admin/status_batch_action.rb
Expand Up @@ -137,6 +137,6 @@ def report_params
end

def allowed_status_ids
AccountStatusesFilter.new(@report.target_account, current_account).results.with_discarded.where(id: status_ids).pluck(:id)
Admin::AccountStatusesFilter.new(@report.target_account, current_account).results.with_discarded.where(id: status_ids).pluck(:id)
end
end
8 changes: 7 additions & 1 deletion app/policies/admin/status_policy.rb
Expand Up @@ -12,7 +12,7 @@ def index?
end

def show?
role.can?(:manage_reports, :manage_users) && (record.public_visibility? || record.unlisted_visibility? || record.reported?)
role.can?(:manage_reports, :manage_users) && (record.public_visibility? || record.unlisted_visibility? || record.reported? || viewable_through_normal_policy?)
end

def destroy?
Expand All @@ -26,4 +26,10 @@ def update?
def review?
role.can?(:manage_taxonomies)
end

private

def viewable_through_normal_policy?
StatusPolicy.new(current_account, record, @preloaded_relations).show?
end
end
20 changes: 16 additions & 4 deletions spec/controllers/admin/statuses_controller_spec.rb
Expand Up @@ -40,24 +40,36 @@
end

describe 'POST #batch' do
before do
post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } }
end
subject { post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } } }

let(:status_ids) { [media_attached_status.id] }

context 'when action is report' do
shared_examples 'when action is report' do
let(:action) { 'report' }

it 'creates a report' do
subject

report = Report.last
expect(report.target_account_id).to eq account.id
expect(report.status_ids).to eq status_ids
end

it 'redirects to report page' do
subject

expect(response).to redirect_to(admin_report_path(Report.last.id))
end
end

it_behaves_like 'when action is report'

context 'when the moderator is blocked by the author' do
before do
account.block!(user.account)
end

it_behaves_like 'when action is report'
end
end
end

0 comments on commit 4bde23b

Please sign in to comment.