2024-05-25 06:47:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-04-06 14:46:10 -04:00
|
|
|
class ApplicationController < ActionController::Base
|
2023-02-03 09:42:56 -05:00
|
|
|
include Pundit::Authorization
|
2024-05-25 06:47:25 -04:00
|
|
|
|
2024-07-04 16:20:12 -04:00
|
|
|
before_action :unread_notifications
|
|
|
|
|
|
2024-05-25 06:47:25 -04:00
|
|
|
protected
|
|
|
|
|
|
2024-07-04 16:20:12 -04:00
|
|
|
def unread_notifications
|
|
|
|
|
return [] unless current_user
|
|
|
|
|
|
|
|
|
|
@unread_notifications ||= Notification.where(user: current_user).unread
|
|
|
|
|
end
|
|
|
|
|
|
2024-07-16 16:26:16 -04:00
|
|
|
def authenticate_admin!
|
2024-11-08 11:56:14 -05:00
|
|
|
return if current_user&.admin?
|
2024-07-09 14:28:59 -04:00
|
|
|
|
2024-07-19 14:37:57 -04:00
|
|
|
redirect_to root_path, notice: 'You are not authorized to perform this action.', status: :see_other
|
2024-07-09 14:28:59 -04:00
|
|
|
end
|
2022-04-06 14:46:10 -04:00
|
|
|
end
|