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-05-25 06:47:25 -04:00
|
|
|
def authenticate_api_key
|
|
|
|
|
return head :unauthorized unless current_api_user
|
|
|
|
|
|
|
|
|
|
true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def current_api_user
|
|
|
|
|
@current_api_user ||= User.find_by(api_key: params[:api_key])
|
|
|
|
|
end
|
2022-04-06 14:46:10 -04:00
|
|
|
end
|