2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-10-04 14:57:32 +02:00
|
|
|
module ReleaseNotesHelper
|
|
|
|
def announce_category_badge(category)
|
2023-12-18 14:39:27 +01:00
|
|
|
color_class = color_by_role(category)
|
|
|
|
|
|
|
|
content_tag(:span, ReleaseNote.human_attribute_name("categories.#{category}"), class: "fr-badge #{color_class}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def color_by_role(role)
|
|
|
|
case role.to_sym
|
2023-10-04 14:57:32 +02:00
|
|
|
when :administrateur
|
2023-12-13 12:07:46 +01:00
|
|
|
'fr-badge--blue-cumulus'
|
2023-10-04 14:57:32 +02:00
|
|
|
when :instructeur
|
2023-12-13 12:07:46 +01:00
|
|
|
'fr-badge--yellow-tournesol'
|
2023-10-04 14:57:32 +02:00
|
|
|
when :expert
|
2023-12-13 12:07:46 +01:00
|
|
|
'fr-badge--purple-glycine'
|
2023-10-04 14:57:32 +02:00
|
|
|
when :usager
|
2023-12-13 12:07:46 +01:00
|
|
|
'fr-badge--green-emeraude'
|
2023-10-04 14:57:32 +02:00
|
|
|
when :api
|
2023-12-13 12:07:46 +01:00
|
|
|
'fr-badge--pink-macaron'
|
2023-10-04 14:57:32 +02:00
|
|
|
end
|
|
|
|
end
|
2023-10-31 10:50:28 +01:00
|
|
|
|
|
|
|
def infer_default_announce_categories
|
|
|
|
if administrateur_signed_in?
|
|
|
|
ReleaseNote.default_categories_for_role(:administrateur, current_administrateur)
|
|
|
|
elsif instructeur_signed_in?
|
|
|
|
ReleaseNote.default_categories_for_role(:instructeur, current_instructeur)
|
|
|
|
elsif expert_signed_in?
|
|
|
|
ReleaseNote.default_categories_for_role(:expert, current_expert)
|
|
|
|
else
|
|
|
|
ReleaseNote.default_categories_for_role(:usager)
|
|
|
|
end
|
|
|
|
end
|
2023-11-14 12:21:06 +01:00
|
|
|
|
|
|
|
def render_release_note_content(content)
|
|
|
|
allowed_attributes.merge ["rel", "target"] # title already allowed
|
|
|
|
|
|
|
|
content.body.fragment.source.css("a[href]").each do |link|
|
|
|
|
uri = URI.parse(link['href'])
|
|
|
|
|
|
|
|
link.set_attribute('rel', 'noreferrer noopener')
|
|
|
|
link.set_attribute('target', '_blank')
|
|
|
|
link.set_attribute('title', new_tab_suffix(uri.host))
|
|
|
|
end
|
|
|
|
|
|
|
|
content
|
|
|
|
end
|
2023-10-04 14:57:32 +02:00
|
|
|
end
|