feat(ntfy): add admin Notifications settings page with test button

This commit is contained in:
Min Zeya Phyo
2026-07-28 02:25:50 +08:00
parent 4236d12a84
commit 9fa6c37297
5 changed files with 302 additions and 4 deletions

View File

@@ -0,0 +1,41 @@
module Admin
class NotificationsController < BaseController
def show
@admin = current_admin
end
def update
@admin = current_admin
if @admin.update(admin_params)
redirect_to admin_notifications_path, notice: "Notification settings saved"
else
flash.now[:alert] = "Failed to save settings"
render :show, status: :unprocessable_entity
end
end
def test
admin = current_admin
if admin.ntfy_configured?
SendNtfyNotificationJob.perform_now(
admin.id,
"test_notification",
title: "Test notification from MySMSAPio",
message: "If you can read this, your ntfy setup is working! Sent at #{Time.current.strftime('%H:%M:%S')}.",
priority: 3,
tags: [ "tada", "white_check_mark" ]
)
redirect_to admin_notifications_path, notice: "Test notification sent"
else
redirect_to admin_notifications_path, alert: "Configure ntfy topic and token first"
end
end
private
def admin_params
params.require(:admin_user).permit(:ntfy_enabled, :ntfy_topic, :ntfy_token, :ntfy_server_url)
end
end
end