2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-10-04 14:57:32 +02:00
|
|
|
class ReleaseNotesController < ApplicationController
|
|
|
|
before_action :ensure_access_allowed!
|
2023-10-31 10:50:28 +01:00
|
|
|
after_action :touch_default_categories_seen_at
|
2023-10-04 14:57:32 +02:00
|
|
|
|
|
|
|
def index
|
2023-10-31 10:50:28 +01:00
|
|
|
@categories = params[:categories].presence || helpers.infer_default_announce_categories
|
2023-10-04 14:57:32 +02:00
|
|
|
|
|
|
|
# Paginate per group of dates, then show all announces for theses dates
|
|
|
|
@paginated_groups = ReleaseNote.published
|
|
|
|
.for_categories(@categories)
|
|
|
|
.select(:released_on)
|
|
|
|
.group(:released_on)
|
|
|
|
.order(released_on: :desc)
|
|
|
|
.page(params[:page]).per(5)
|
|
|
|
|
|
|
|
@announces = ReleaseNote.where(released_on: @paginated_groups.map(&:released_on))
|
|
|
|
.with_rich_text_body
|
|
|
|
.for_categories(@categories)
|
|
|
|
.order(released_on: :desc, id: :asc)
|
|
|
|
|
|
|
|
render "scrollable_list" if params[:page].present?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-10-31 10:50:28 +01:00
|
|
|
def touch_default_categories_seen_at
|
|
|
|
return if params[:categories].present? || params[:page].present?
|
|
|
|
return if current_user.blank?
|
|
|
|
|
|
|
|
return if current_user.announces_seen_at&.after?(@announces.max_by(&:released_on).released_on)
|
|
|
|
|
|
|
|
current_user.touch(:announces_seen_at)
|
2023-10-04 14:57:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_access_allowed!
|
|
|
|
return if administrateur_signed_in?
|
|
|
|
return if instructeur_signed_in?
|
|
|
|
return if expert_signed_in?
|
|
|
|
|
|
|
|
flash[:alert] = t('release_notes.index.forbidden')
|
|
|
|
redirect_to root_path
|
|
|
|
end
|
|
|
|
end
|