<% content_for(:title) do %>Push Diagnostics<% end %>

Send a test push notification to a specific user's registered devices to diagnose delivery issues. Results show the raw FCM / Web Push / relay response so you can see exactly what failed.

1. Look up user

<%= form_with url: super_admin_push_diagnostics_path, method: :get, local: true, class: 'flex gap-2 items-center' do |f| %> <%= f.text_field :user_query, value: @query, placeholder: 'user@example.com or numeric user ID', class: 'border border-slate-100 p-1.5 rounded-md w-80' %> <%= f.submit 'Look up', class: 'border border-slate-200 bg-slate-50 px-3 py-1.5 rounded-md cursor-pointer' %> <% end %> <% if @query.present? && @user.nil? %>

No user found for "<%= @query %>".

<% end %>
<% if @user %>

<%= @user.name %> · <%= @user.email %> · ID <%= @user.id %>

<% if @user.accounts.any? %>

Accounts: <% @user.accounts.each_with_index do |account, index| %> <%= ', ' if index.positive? %> <%= account.name %> (ID <%= account.id %>) <% end %>

<% end %>

2. Select subscriptions (<%= @subscriptions.count %>)

⚠️ This sends a real push to every selected device. Use only when diagnosing a reported issue.

<% if @subscriptions.empty? %>

This user has no push subscriptions registered.

<% else %> <%= form_with url: super_admin_push_diagnostics_path, method: :post, local: true do |f| %> <%= f.hidden_field :user_id, value: @user.id %>
<%= label_tag :push_title, 'Title', class: 'block text-xs font-medium text-slate-600 mb-1' %> <%= text_field_tag :push_title, params[:push_title].presence || Notification::PushTestService.default_title, class: 'border border-slate-100 p-1.5 rounded-md w-full text-sm' %>
<%= label_tag :push_body, 'Body', class: 'block text-xs font-medium text-slate-600 mb-1' %> <%= text_area_tag :push_body, params[:push_body].presence || Notification::PushTestService.default_body, rows: 2, class: 'border border-slate-100 p-1.5 rounded-md w-full text-sm' %>

Customers will see this text as a real push notification on their device.

<% @subscriptions.each do |sub| %> <% attrs = (sub.subscription_attributes || {}).stringify_keys %> <% if sub.browser_push? %> <% endpoint = attrs['endpoint'].to_s %> <% host = (begin; URI.parse(endpoint).host; rescue URI::InvalidURIError; nil; end) %> <% device_display = host.presence || endpoint.presence || '—' %> <% token_display = endpoint.present? ? "…#{endpoint.last(6)}" : '—' %> <% else %> <% device_display = attrs['device_id'].present? ? "…#{attrs['device_id'].to_s.last(6)}" : '—' %> <% token_display = attrs['push_token'].present? ? "…#{attrs['push_token'].to_s.last(6)}" : '—' %> <% end %> <% extra_attrs = attrs.except('endpoint', 'p256dh', 'auth', 'push_token', 'device_id') %> <% end %>
ID Type Device / endpoint Push token Device details Created Last updated
<%= check_box_tag 'subscription_ids[]', sub.id, false, class: 'subscription-checkbox' %> <%= sub.id %> <%= sub.subscription_type %> <%= device_display %> <%= token_display %> <% if extra_attrs.present? %> <% extra_attrs.each do |k, v| %>
<%= k %>: <%= v.to_s.truncate(40) %>
<% end %> <% else %> <% end %>
<%= sub.created_at.strftime('%Y-%m-%d %H:%M') %> <%= sub.updated_at.strftime('%Y-%m-%d %H:%M') %> (<%= time_ago_in_words(sub.updated_at) %> ago)
<%= f.submit 'Send Test Push to Selected', class: 'border border-slate-200 bg-slate-50 px-3 py-1.5 rounded-md cursor-pointer font-medium' %> <%= submit_tag 'Delete Selected Subscriptions', formaction: destroy_subscriptions_super_admin_push_diagnostics_path, formmethod: 'post', data: { confirm: "Delete the selected subscription(s)? The user won't receive pushes on those devices until their app re-registers." }, class: 'border border-red-200 bg-red-50 text-red-700 px-3 py-1.5 rounded-md cursor-pointer font-medium' %>
<% end %> <% end %>
<% if @results.present? %>

3. Results

<% @results.each do |r| %> <% end %>
Sub ID Type Device Push token Status Details
<%= r[:id] %> <%= r[:type] %> <%= r[:device] %> <%= r[:token_tail] %> <% color = { success: 'bg-green-100 text-green-800', failure: 'bg-red-100 text-red-800', skipped: 'bg-slate-100 text-slate-600' }[r[:status]] %> <%= r[:status] %> <%= r[:message] %>
<% end %> <% end %>
<% content_for :javascript do %> <% end %>