dawarich/app/controllers/application_controller.rb
2025-02-15 16:48:03 +01:00

33 lines
799 B
Ruby

# frozen_string_literal: true
class ApplicationController < ActionController::Base
include Pundit::Authorization
before_action :unread_notifications, :set_self_hosted_status
protected
def unread_notifications
return [] unless current_user
@unread_notifications ||= Notification.where(user: current_user).unread
end
def authenticate_admin!
return if current_user&.admin?
redirect_to root_path, notice: 'You are not authorized to perform this action.', status: :see_other
end
def authenticate_self_hosted!
return if DawarichSettings.self_hosted?
redirect_to root_path, notice: 'You are not authorized to perform this action.', status: :see_other
end
private
def set_self_hosted_status
@self_hosted = DawarichSettings.self_hosted?
end
end