about summary refs log tree commit diff
path: root/app/policies/user_policy.rb
blob: aad20f366e43e389167a1b8a678f815a0f8f97d9 (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
50
51
52
53
# frozen_string_literal: true

class UserPolicy < ApplicationPolicy
  def reset_password?
    !defanged? && staff? && has_more_authority_than?(record)
  end

  def change_email?
    !defanged? && staff? && has_more_authority_than?(record)
  end

  def disable_2fa?
    !defanged? && admin? && has_more_authority_than?(record)
  end

  def confirm?
    !defanged? && staff? && !record.confirmed?
  end

  def enable?
    !defanged? && staff?
  end

  def approve?
    !defanged? && staff? && !record.approved?
  end

  def reject?
    !defanged? && staff? && !record.approved?
  end

  def disable?
    !defanged? && staff? && has_more_authority_than?(record)
  end

  def promote?
    !defanged? && admin? && promoteable?
  end

  def demote?
    !defanged? && admin? && has_more_authority_than?(record) && demoteable?
  end

  private

  def promoteable?
    record.approved? && !record.can_moderate?
  end

  def demoteable?
    record.can_moderate?
  end
end