Extract authorization policy for viewing statuses (#3150)
This commit is contained in:
parent
9a81be0d37
commit
3a2003ba86
16 changed files with 155 additions and 80 deletions
20
app/policies/status_policy.rb
Normal file
20
app/policies/status_policy.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class StatusPolicy
|
||||
attr_reader :account, :status
|
||||
|
||||
def initialize(account, status)
|
||||
@account = account
|
||||
@status = status
|
||||
end
|
||||
|
||||
def show?
|
||||
if status.direct_visibility?
|
||||
status.account.id == account&.id || status.mentions.where(account: account).exists?
|
||||
elsif status.private_visibility?
|
||||
status.account.id == account&.id || account&.following?(status.account) || status.mentions.where(account: account).exists?
|
||||
else
|
||||
account.nil? || !status.account.blocking?(account)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue