Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix moderator rights inconsistencies #26729

Merged
merged 3 commits into from Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -140,6 +140,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 @@ -52,24 +52,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
17 changes: 14 additions & 3 deletions spec/policies/admin/status_policy_spec.rb
Expand Up @@ -7,7 +7,8 @@
let(:policy) { described_class }
let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
let(:john) { Fabricate(:account) }
let(:status) { Fabricate(:status) }
let(:status) { Fabricate(:status, visibility: status_visibility) }
let(:status_visibility) { :public }

permissions :index?, :update?, :review?, :destroy? do
context 'with an admin' do
Expand All @@ -26,19 +27,29 @@
permissions :show? do
context 'with an admin' do
context 'with a public visible status' do
before { allow(status).to receive(:public_visibility?).and_return(true) }
let(:status_visibility) { :public }

it 'permits' do
expect(policy).to permit(admin, status)
end
end

context 'with a not public visible status' do
before { allow(status).to receive(:public_visibility?).and_return(false) }
let(:status_visibility) { :direct }

it 'denies' do
expect(policy).to_not permit(admin, status)
end

context 'when the status mentions the admin' do
before do
status.mentions.create!(account: admin)
end

it 'permits' do
expect(policy).to permit(admin, status)
end
end
end
end

Expand Down