Skip to content

Commit 524031e

Browse files
dadachiclaude
andauthored
Add push devices to madmin dashboard (#72)
ApplicationPushDevice (action_push_native_devices) had no madmin resource, so registered devices weren't visible in the admin dashboard. Add the resource, controller, and route. Includes the project's first madmin controller tests: authenticated index/show render, and unauthenticated access redirects. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 045aaf4 commit 524031e

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Madmin
2+
class ApplicationPushDevicesController < Madmin::ResourceController
3+
end
4+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class ApplicationPushDeviceResource < Madmin::Resource
2+
# Attributes
3+
attribute :id, form: false
4+
attribute :platform
5+
attribute :token
6+
attribute :name
7+
attribute :bundle_id
8+
attribute :last_active_at, form: false
9+
attribute :created_at, form: false
10+
attribute :updated_at, form: false
11+
12+
# Associations
13+
attribute :owner
14+
15+
# Customize the default sort column and direction.
16+
def self.default_sort_column = "last_active_at"
17+
18+
def self.default_sort_direction = "desc"
19+
end

config/routes/madmin.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
resources :accounts_shopkeepers
88
resources :shops
99
resources :item_tags
10+
resources :application_push_devices
1011
resources :roles
1112
resources :permissions
1213
resources :roles_permissions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require "test_helper"
2+
3+
class Madmin::ApplicationPushDevicesControllerTest < ActionDispatch::IntegrationTest
4+
setup do
5+
@admin_user = AdminUser.create!(name: "Admin", email: "admin@example.com", password: "password")
6+
@device = ApplicationPushDevice.create!(
7+
owner: shopkeepers(:one),
8+
platform: "apple",
9+
token: "test-token"
10+
)
11+
end
12+
13+
def sign_in_admin
14+
post admin_session_path, params: {email: @admin_user.email, password: "password"}
15+
end
16+
17+
test "index renders for authenticated admin" do
18+
sign_in_admin
19+
get madmin_application_push_devices_path
20+
assert_response :success
21+
end
22+
23+
test "show renders for authenticated admin" do
24+
sign_in_admin
25+
get madmin_application_push_device_path(@device)
26+
assert_response :success
27+
end
28+
29+
test "redirects unauthenticated users" do
30+
get madmin_application_push_devices_path
31+
assert_redirected_to "/"
32+
end
33+
end

0 commit comments

Comments
 (0)