From 34421b34f3eba871d421e05c7c1893e57de503c4 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Fri, 1 Mar 2024 22:11:18 +0100 Subject: [PATCH] Set `has_new_reports` global in ApplicationController --- app/controllers/application_controller.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 35eda9f9..67ee3571 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base around_action :switch_locale before_action :banned? before_action :find_active_announcements + before_action :set_has_new_reports # check if user wants to read def switch_locale(&) @@ -48,6 +49,18 @@ class ApplicationController < ActionController::Base @active_announcements ||= Announcement.find_active end + def set_has_new_reports + return unless current_user&.mod? + + @has_new_reports = if current_user.last_reports_visit.nil? + true + else + Report.where(deleted: false) + .where("created_at > ?", current_user.last_reports_visit) + .count > 0 + end + end + include ApplicationHelper protected