2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-10-03 16:14:09 +02:00
|
|
|
class ReleaseNote < ApplicationRecord
|
2023-10-03 16:20:13 +02:00
|
|
|
has_rich_text :body
|
|
|
|
|
|
|
|
CATEGORIES = [
|
|
|
|
'administrateur',
|
|
|
|
'instructeur',
|
|
|
|
'expert',
|
|
|
|
'usager',
|
|
|
|
'api'
|
|
|
|
]
|
|
|
|
|
|
|
|
validates :categories, presence: true, inclusion: { in: CATEGORIES }
|
|
|
|
validates :body, presence: true
|
2023-10-04 14:57:32 +02:00
|
|
|
|
|
|
|
scope :published, -> { where(published: true, released_on: ..Date.current) }
|
|
|
|
scope :for_categories, -> (categories) { where("categories && ARRAY[?]::varchar[]", categories) }
|
2023-10-31 10:50:28 +01:00
|
|
|
|
|
|
|
def self.default_categories_for_role(role, instance = nil)
|
|
|
|
case role
|
|
|
|
when :administrateur
|
|
|
|
['administrateur', 'usager', instance.api_tokens.exists? ? 'api' : nil]
|
|
|
|
when :instructeur
|
|
|
|
['instructeur', instance.user.expert? ? 'expert' : nil]
|
|
|
|
when :expert
|
|
|
|
['expert', instance.user.instructeur? ? 'instructeur' : nil]
|
|
|
|
else
|
|
|
|
['usager']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.most_recent_announce_date_for_categories(categories)
|
|
|
|
published.for_categories(categories).maximum(:released_on)
|
|
|
|
end
|
2023-10-03 16:14:09 +02:00
|
|
|
end
|