module Admin
class ReportedStatusesController < BaseController
+ include Authorization
+
before_action :set_report
before_action :set_status
end
def destroy
+ authorize @status, :destroy?
RemovalWorker.perform_async(@status.id)
redirect_to admin_report_path(@report)
end
def destroy
@status = Status.where(account_id: current_user.account).find(params[:id])
+ authorize @status, :destroy?
+
RemovalWorker.perform_async(@status.id)
+
render_empty
end
@status = reblog.reblog
@reblogs_map = { @status.id => false }
+ authorize reblog, :unreblog?
+
RemovalWorker.perform_async(reblog.id)
render :show
def show?
if direct?
- status.account.id == account&.id || status.mentions.where(account: account).exists?
+ owned? || status.mentions.where(account: account).exists?
elsif private?
- status.account.id == account&.id || account&.following?(status.account) || status.mentions.where(account: account).exists?
+ owned? || account&.following?(status.account) || status.mentions.where(account: account).exists?
else
account.nil? || !status.account.blocking?(account)
end
!direct? && !private? && show?
end
+ def destroy?
+ admin? || owned?
+ end
+
+ alias unreblog? destroy?
+
private
+ def admin?
+ account&.user&.admin?
+ end
+
def direct?
status.direct_visibility?
end
+ def owned?
+ status.account.id == account&.id
+ end
+
def private?
status.private_visibility?
end
class ProcessInteractionService < BaseService
include AuthorExtractor
+ include Authorization
# Record locally the remote interaction with our user
# @param [String] envelope Salmon envelope
reflect_unblock!(account, target_account)
end
end
- rescue Goldfinger::Error, HTTP::Error, OStatus2::BadSalmonError
+ rescue Goldfinger::Error, HTTP::Error, OStatus2::BadSalmonError, Mastodon::NotPermittedError
nil
end
return if status.nil?
- RemovalWorker.perform_async(status.id) if account.id == status.account_id
+ authorize_with account, status, :destroy?
+
+ RemovalWorker.perform_async(status.id)
end
def favourite!(xml, from_account)
RSpec.describe StatusPolicy, type: :model do
subject { described_class }
+ let(:admin) { Fabricate(:user, admin: true) }
let(:alice) { Fabricate(:account, username: 'alice') }
+ let(:bob) { Fabricate(:account, username: 'bob') }
let(:status) { Fabricate(:status, account: alice) }
permissions :show?, :reblog? do
expect(subject).to_not permit(viewer, status)
end
end
+
+ permissions :destroy?, :unreblog? do
+ it 'grants access when account is deleter' do
+ expect(subject).to permit(status.account, status)
+ end
+
+ it 'grants access when account is admin' do
+ expect(subject).to permit(admin.account, status)
+ end
+
+ it 'denies access when account is not deleter' do
+ expect(subject).to_not permit(bob, status)
+ end
+
+ it 'denies access when no deleter' do
+ expect(subject).to_not permit(nil, status)
+ end
+ end
end
subject { ProcessInteractionService.new }
+ describe 'status delete slap' do
+ let(:remote_status) { Fabricate(:status, account: remote_sender) }
+ let(:envelope) { OStatus2::Salmon.new.pack(payload, sender.keypair) }
+ let(:payload) {
+ <<~XML
+ <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
+ <author>
+ <email>carol@localdomain.com</email>
+ <name>carol</name>
+ <uri>https://webdomain.com/users/carol</uri>
+ </author>
+
+ <id>#{remote_status.id}</id>
+ <activity:verb>http://activitystrea.ms/schema/1.0/delete</activity:verb>
+ </entry>
+ XML
+ }
+
+ before do
+ receiver.update(locked: true)
+ remote_sender.update(private_key: sender.private_key, public_key: remote_sender.public_key)
+ end
+
+ it 'deletes a record' do
+ expect(RemovalWorker).to receive(:perform_async).with(remote_status.id)
+ subject.call(envelope, receiver)
+ end
+ end
+
describe 'follow request slap' do
before do
receiver.update(locked: true)
end
end
-
describe 'follow request authorization slap' do
before do
receiver.update(locked: true)