diff options
author | Jack Jennings <jack@standard-library.com> | 2017-05-29 09:22:22 -0700 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-29 18:22:22 +0200 |
commit | 3a2003ba863252f305fb32098bcd3f095b10e2ff (patch) | |
tree | 6ff5f4a1cf6c9d042baca1441409afb9ac46775d /app/policies | |
parent | 9a81be0d3715eb846d940794f8b34cbbe4ba67a5 (diff) |
Extract authorization policy for viewing statuses (#3150)
Diffstat (limited to 'app/policies')
-rw-r--r-- | app/policies/status_policy.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/policies/status_policy.rb b/app/policies/status_policy.rb new file mode 100644 index 000000000..658ba6d12 --- /dev/null +++ b/app/policies/status_policy.rb @@ -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 |