aboutsummaryrefslogtreecommitdiffstats
path: root/app/policies/referential_policy.rb
blob: 1fce6b2c79001f61db404b0d66b64e47f1ae8781 (plain)
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
class ReferentialPolicy < ApplicationPolicy
  class Scope < Scope
    def resolve
      scope
    end
  end

  def create?
    user.has_permission?('referentials.create')
  end

  def destroy?
    !referential_read_only? && organisation_match? && user.has_permission?('referentials.destroy')
  end

  def update?
    !referential_read_only? && organisation_match? && user.has_permission?('referentials.update')
  end

  def clone?
    !referential_read_only? && create?
  end

  def validate?
    !referential_read_only? && create? && organisation_match?
  end

  def archive?
    record.archived_at.nil? && organisation_match? && user.has_permission?('referentials.update')
  end

  def unarchive?
    !record.archived_at.nil? && organisation_match? && user.has_permission?('referentials.update')
  end

  def common_lines?
    # TODO: Replace with correct BL ASA available, c.f. https://projects.af83.io/issues/2692
    true
  end

end