Set `has_new_reports` global in ApplicationController
This commit is contained in:
parent
f3cba7b620
commit
34421b34f3
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue