Add status destroy authorization to policy (#3453)
* Add status destroy authorization to policy * Create explicit unreblog status authorization
This commit is contained in:
parent
3576fa0d59
commit
33f669a5f8
6 changed files with 78 additions and 5 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
module Admin
|
||||
class ReportedStatusesController < BaseController
|
||||
include Authorization
|
||||
|
||||
before_action :set_report
|
||||
before_action :set_status
|
||||
|
||||
|
@ -11,6 +13,7 @@ module Admin
|
|||
end
|
||||
|
||||
def destroy
|
||||
authorize @status, :destroy?
|
||||
RemovalWorker.perform_async(@status.id)
|
||||
redirect_to admin_report_path(@report)
|
||||
end
|
||||
|
|
|
@ -79,7 +79,10 @@ class Api::V1::StatusesController < ApiController
|
|||
|
||||
def destroy
|
||||
@status = Status.where(account_id: current_user.account).find(params[:id])
|
||||
authorize @status, :destroy?
|
||||
|
||||
RemovalWorker.perform_async(@status.id)
|
||||
|
||||
render_empty
|
||||
end
|
||||
|
||||
|
@ -93,6 +96,8 @@ class Api::V1::StatusesController < ApiController
|
|||
@status = reblog.reblog
|
||||
@reblogs_map = { @status.id => false }
|
||||
|
||||
authorize reblog, :unreblog?
|
||||
|
||||
RemovalWorker.perform_async(reblog.id)
|
||||
|
||||
render :show
|
||||
|
|
|
@ -10,9 +10,9 @@ class StatusPolicy
|
|||
|
||||
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
|
||||
|
@ -22,12 +22,26 @@ class StatusPolicy
|
|||
!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
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class ProcessInteractionService < BaseService
|
||||
include AuthorExtractor
|
||||
include Authorization
|
||||
|
||||
# Record locally the remote interaction with our user
|
||||
# @param [String] envelope Salmon envelope
|
||||
|
@ -46,7 +47,7 @@ class ProcessInteractionService < BaseService
|
|||
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
|
||||
|
||||
|
@ -103,7 +104,9 @@ class ProcessInteractionService < BaseService
|
|||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue