about summary refs log tree commit diff
path: root/app/policies/status_policy.rb
blob: 5573289b6e7f7182304e0a35c7ee71af2979b5cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

class StatusPolicy < ApplicationPolicy
  def index?
    staff?
  end

  def show?
    if direct?
      owned? || record.mentions.where(account: current_account).exists?
    elsif private?
      owned? || current_account&.following?(author) || record.mentions.where(account: current_account).exists?
    else
      current_account.nil? || !author.blocking?(current_account)
    end
  end

  def reblog?
    !direct? && (!private? || owned?) && show?
  end

  def destroy?
    staff? || owned?
  end

  alias unreblog? destroy?

  def update?
    staff?
  end

  private

  def direct?
    record.direct_visibility?
  end

  def owned?
    author.id == current_account&.id
  end

  def private?
    record.private_visibility?
  end

  def author
    record.account
  end
end