2023-02-13 17:31:57 +01:00
|
|
|
# frozen_string_literal: true
|
2022-03-18 19:44:30 +01:00
|
|
|
|
2023-02-13 17:31:57 +01:00
|
|
|
# Check the access policies for API::SupportingDocumentFilesController
|
|
|
|
class SupportingDocumentFilePolicy < ApplicationPolicy
|
2022-03-18 19:44:30 +01:00
|
|
|
def index?
|
|
|
|
user.privileged?
|
|
|
|
end
|
|
|
|
|
2023-05-24 19:56:48 +02:00
|
|
|
%w[create update download].each do |action|
|
|
|
|
define_method "#{action}?" do
|
|
|
|
user.privileged? ||
|
|
|
|
(record.supportable_type == 'User' && record.supportable_id.to_i == user.id) ||
|
|
|
|
(record.supportable_type == 'Child' && user.children.exists?(id: record.supportable_id.to_i))
|
|
|
|
end
|
2022-03-18 19:44:30 +01:00
|
|
|
end
|
|
|
|
end
|