about summary refs log blame commit diff
path: root/app/policies/user_policy.rb
blob: 57af5c61c86b32b7cd32aacdcbde5462de9d4145 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11





                                    


                            







                                
          

              
                            


















                                           
# frozen_string_literal: true

class UserPolicy < ApplicationPolicy
  def reset_password?
    staff? && !record.staff?
  end

  def change_email?
    staff? && !record.staff?
  end

  def disable_2fa?
    admin? && !record.staff?
  end

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

  def enable?
    staff?
  end

  def disable?
    staff? && !record.admin?
  end

  def promote?
    admin? && promoteable?
  end

  def demote?
    admin? && !record.admin? && demoteable?
  end

  private

  def promoteable?
    !record.staff? || !record.admin?
  end

  def demoteable?
    record.staff?
  end
end