about summary refs log tree commit diff
path: root/app/policies/invite_policy.rb
blob: 44fa56049b5199941f8cb8d564d854962f653bb0 (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
# frozen_string_literal: true

class InvitePolicy < ApplicationPolicy
  def index?
    !defanged? && can_moderate?
  end

  def create?
    min_required_role?
  end

  def deactivate_all?
    !defanged? && admin?
  end

  def destroy?
    owner? || (!defanged? && (Setting.min_invite_role == 'admin' ? admin? : can_moderate?))
  end

  private

  def owner?
    record.user_id == current_user&.id
  end

  def min_required_role?
    current_user&.role?(Setting.min_invite_role)
  end
end