dawarich/app/controllers/application_controller.rb

34 lines
799 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class ApplicationController < ActionController::Base
2023-02-03 09:42:56 -05:00
include Pundit::Authorization
before_action :unread_notifications, :set_self_hosted_status
2024-07-04 16:20:12 -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
2025-01-15 15:52:59 -05:00
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