From ac2054e45ce436ce92c2a11106a9d7a4e8d8bbf4 Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Tue, 28 Jul 2026 02:34:26 +0800 Subject: [PATCH] style(ntfy): fix bracket-spacing lint offenses --- app/controllers/admin/base_controller.rb | 17 +- app/controllers/admin/sessions_controller.rb | 11 +- .../concerns/admin_authentication.rb | 11 + app/helpers/admin_helper.rb | 7 - app/helpers/application_helper.rb | 9 - app/jobs/check_gateway_health_job.rb | 2 +- app/models/api_key.rb | 2 +- app/models/gateway.rb | 4 +- app/models/sms_message.rb | 4 +- app/views/admin/sessions/new.html.erb | 50 +- ...26-07-28-ntfy-notifications-integration.md | 1395 +++++++++++++++++ test/fixtures/admin_users.yml | 12 +- test/integration/admin/sessions_flow_test.rb | 48 + 13 files changed, 1502 insertions(+), 70 deletions(-) create mode 100644 app/controllers/concerns/admin_authentication.rb create mode 100644 docs/superpowers/plans/2026-07-28-ntfy-notifications-integration.md create mode 100644 test/integration/admin/sessions_flow_test.rb diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index ff876a6..b0d868e 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -1,6 +1,7 @@ module Admin class BaseController < ActionController::Base include Pagy::Backend + include AdminAuthentication # Enable session and flash for admin controllers # (needed because the app is in API-only mode) @@ -9,22 +10,12 @@ module Admin layout "admin" before_action :require_admin + helper_method :current_admin, :logged_in? + private - def current_admin - @current_admin ||= AdminUser.find_by(id: session[:admin_id]) if session[:admin_id] - end - helper_method :current_admin - - def logged_in? - current_admin.present? - end - helper_method :logged_in? - def require_admin - unless logged_in? - redirect_to admin_login_path, alert: "Please log in to continue" - end + redirect_to admin_login_path, alert: "Please log in to continue" unless logged_in? end end end diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index 0eafbbc..770d0fd 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -1,11 +1,15 @@ module Admin class SessionsController < ActionController::Base + include AdminAuthentication + layout "admin" # CSRF protection is enabled by default in ActionController::Base # We need it for the create action but not for the new (GET) action protect_from_forgery with: :exception + helper_method :current_admin, :logged_in? + def new redirect_to admin_dashboard_path if current_admin end @@ -27,12 +31,5 @@ module Admin session.delete(:admin_id) redirect_to admin_login_path, notice: "You have been logged out" end - - private - - def current_admin - @current_admin ||= AdminUser.find_by(id: session[:admin_id]) if session[:admin_id] - end - helper_method :current_admin end end diff --git a/app/controllers/concerns/admin_authentication.rb b/app/controllers/concerns/admin_authentication.rb new file mode 100644 index 0000000..7a0f4e2 --- /dev/null +++ b/app/controllers/concerns/admin_authentication.rb @@ -0,0 +1,11 @@ +module AdminAuthentication + extend ActiveSupport::Concern + + def current_admin + @current_admin ||= AdminUser.find_by(id: session[:admin_id]) if session[:admin_id] + end + + def logged_in? + current_admin.present? + end +end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index b7b8929..d5c6d35 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -1,9 +1,2 @@ module AdminHelper - def current_admin - @current_admin ||= AdminUser.find_by(id: session[:admin_id]) if session[:admin_id] - end - - def logged_in? - current_admin.present? - end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6fe8ed4..ed6a048 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,12 +1,3 @@ module ApplicationHelper include Pagy::Frontend - - # Admin authentication helpers - def current_admin - @current_admin ||= AdminUser.find_by(id: session[:admin_id]) if session[:admin_id] - end - - def logged_in? - current_admin.present? - end end diff --git a/app/jobs/check_gateway_health_job.rb b/app/jobs/check_gateway_health_job.rb index 79b270c..51aebbe 100644 --- a/app/jobs/check_gateway_health_job.rb +++ b/app/jobs/check_gateway_health_job.rb @@ -18,7 +18,7 @@ class CheckGatewayHealthJob < ApplicationJob title: "Gateway offline", message: "#{name} (#{device_id}) went offline — no heartbeat for 2+ minutes", priority: 4, - tags: ["rotating_light"]) + tags: [ "rotating_light" ]) end end end diff --git a/app/models/api_key.rb b/app/models/api_key.rb index fd8142a..9326214 100644 --- a/app/models/api_key.rb +++ b/app/models/api_key.rb @@ -63,7 +63,7 @@ class ApiKey < ApplicationRecord title: "API key revoked", message: "API key '#{name}' (#{key_prefix}...) was revoked", priority: 3, - tags: ["key", "no_entry"]) + tags: [ "key", "no_entry" ]) end # Deactivate expired keys diff --git a/app/models/gateway.rb b/app/models/gateway.rb index d20acc4..ca3328c 100644 --- a/app/models/gateway.rb +++ b/app/models/gateway.rb @@ -45,7 +45,7 @@ class Gateway < ApplicationRecord title: "Gateway online", message: "#{name} (#{device_id}) came back online", priority: 3, - tags: ["white_check_mark"], + tags: [ "white_check_mark" ], click: nil) end end @@ -60,7 +60,7 @@ class Gateway < ApplicationRecord title: "Gateway offline", message: "#{name} (#{device_id}) went offline", priority: 4, - tags: ["rotating_light"]) + tags: [ "rotating_light" ]) end end diff --git a/app/models/sms_message.rb b/app/models/sms_message.rb index e3a67ec..6483223 100644 --- a/app/models/sms_message.rb +++ b/app/models/sms_message.rb @@ -60,7 +60,7 @@ class SmsMessage < ApplicationRecord title: "SMS delivered", message: "Message to #{phone_number} (#{message_id}) was delivered", priority: 2, - tags: ["white_check_mark"]) + tags: [ "white_check_mark" ]) end # Mark message as failed @@ -71,7 +71,7 @@ class SmsMessage < ApplicationRecord title: "SMS failed", message: "Message to #{phone_number} (#{message_id}) failed#{error_msg ? ": #{error_msg}" : ''}", priority: 5, - tags: ["x", "rotating_light"]) + tags: [ "x", "rotating_light" ]) end # Increment retry counter diff --git a/app/views/admin/sessions/new.html.erb b/app/views/admin/sessions/new.html.erb index fb3abb8..7dcf01d 100644 --- a/app/views/admin/sessions/new.html.erb +++ b/app/views/admin/sessions/new.html.erb @@ -1,22 +1,27 @@ -
+
-
- +
+ + + +
+ +
-

MySMSAPio Admin

-

Sign in to your admin account

+

MySMSAPio

+

Admin Console

-
- <%= form_with url: admin_login_path, method: :post, local: true, class: "space-y-6" do |f| %> +