This repository has been archived on 2023-07-01. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon/app/policies/status_policy.rb
beatrix f0a2a6c875 try to tighten up local only toot stuff, like... properly (#163)
* try to tighten up local only toot stuff, like... properly

* try to un-break tests
2017-10-09 09:56:17 -04:00

55 lines
909 B
Ruby

# frozen_string_literal: true
class StatusPolicy
attr_reader :account, :status
def initialize(account, status)
@account = account
@status = status
end
def show?
return false if local_only? && account.nil?
if direct?
owned? || status.mentions.where(account: account).exists?
elsif private?
owned? || account&.following?(status.account) || status.mentions.where(account: account).exists?
else
account.nil? || !status.account.blocking?(account)
end
end
def reblog?
!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
def local_only?
status.local_only?
end
end