diff --git a/app/controllers/admin/notifications_controller.rb b/app/controllers/admin/notifications_controller.rb new file mode 100644 index 0000000..a76af2a --- /dev/null +++ b/app/controllers/admin/notifications_controller.rb @@ -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 diff --git a/app/views/admin/notifications/show.html.erb b/app/views/admin/notifications/show.html.erb new file mode 100644 index 0000000..5a59b32 --- /dev/null +++ b/app/views/admin/notifications/show.html.erb @@ -0,0 +1,89 @@ +
Configure ntfy push notifications for your phone.
++ Install the ntfy app + on your phone, subscribe to your topic, and enter the details below. +
+The topic name you subscribe to in the ntfy app. Treat this like a password.
+ <%= f.text_field :ntfy_topic, + class: "mt-2 block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm py-2.5", + placeholder: "mysmsa-pio-your-secret-topic" %> +Required only if your ntfy server has access control enabled.
+ <%= f.text_field :ntfy_token, + class: "mt-2 block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm py-2.5", + placeholder: "tk_..." %> +Leave blank to use the default (from NTFY_SERVER_URL env var or ntfy.sh).
+ <%= f.text_field :ntfy_server_url, + class: "mt-2 block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm py-2.5", + placeholder: "https://ntfy.yourdomain.com" %> +Sends a test push to your configured ntfy topic right now.
+<%= flash[:alert] %>
+<%= flash[:notice] %>
+