Set `has_new_reports` global in ApplicationController

This commit is contained in:
Andreas Nedbal 2024-03-01 22:11:18 +01:00 committed by Andreas Nedbal
parent f3cba7b620
commit 34421b34f3
1 changed files with 13 additions and 0 deletions

View File

@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base
around_action :switch_locale around_action :switch_locale
before_action :banned? before_action :banned?
before_action :find_active_announcements before_action :find_active_announcements
before_action :set_has_new_reports
# check if user wants to read # check if user wants to read
def switch_locale(&) def switch_locale(&)
@ -48,6 +49,18 @@ class ApplicationController < ActionController::Base
@active_announcements ||= Announcement.find_active @active_announcements ||= Announcement.find_active
end 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 include ApplicationHelper
protected protected