2024-02-03 22:37:17 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
module Abilities
|
|
|
|
|
module TemplateConditions
|
|
|
|
|
module_function
|
|
|
|
|
|
2026-06-24 14:17:17 +03:00
|
|
|
def collection(user)
|
|
|
|
|
Template.where(account_id: user.account_id)
|
2024-02-03 22:37:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def entity(template, user:, ability: nil)
|
2025-05-11 16:11:02 +03:00
|
|
|
return true if template.account_id.blank?
|
2024-02-03 22:37:17 +02:00
|
|
|
return true if template.account_id == user.account_id
|
2025-05-11 16:11:02 +03:00
|
|
|
return false unless user.account.linked_account_account
|
|
|
|
|
return false if template.template_sharings.to_a.blank?
|
2024-02-03 22:37:17 +02:00
|
|
|
|
|
|
|
|
account_ids = [user.account_id, TemplateSharing::ALL_ID]
|
|
|
|
|
|
2025-05-11 16:11:02 +03:00
|
|
|
template.template_sharings.to_a.any? do |e|
|
2025-01-29 00:56:14 +02:00
|
|
|
e.account_id.in?(account_ids) && (ability.nil? || e.ability == 'manage' || e.ability == ability)
|
2024-02-03 22:37:17 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|