Skip to content

Commit 5b0e314

Browse files
dadachiclaude
andauthored
Add noticed events and notifications to madmin dashboard (#73)
The noticed_events and noticed_notifications tables had no madmin resources, so delivered notifications and their events weren't visible in the admin dashboard. Register both as namespaced resources (mirroring the ActiveStorage pattern), with the notification's event association now linkable to the event resource. Includes index/show render and unauthenticated-redirect tests for both. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 524031e commit 5b0e314

7 files changed

Lines changed: 116 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 Noticed::EventsController < Madmin::ResourceController
3+
end
4+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Madmin
2+
class Noticed::NotificationsController < Madmin::ResourceController
3+
end
4+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Noticed::EventResource < Madmin::Resource
2+
# Attributes
3+
attribute :id, form: false
4+
attribute :type
5+
attribute :params
6+
attribute :notifications_count, form: false
7+
attribute :created_at, form: false
8+
attribute :updated_at, form: false
9+
10+
# Associations
11+
attribute :record
12+
attribute :notifications
13+
14+
# Customize the default sort column and direction.
15+
def self.default_sort_column = "created_at"
16+
17+
def self.default_sort_direction = "desc"
18+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Noticed::NotificationResource < Madmin::Resource
2+
# Attributes
3+
attribute :id, form: false
4+
attribute :type
5+
attribute :read_at
6+
attribute :seen_at
7+
attribute :created_at, form: false
8+
attribute :updated_at, form: false
9+
10+
# Associations
11+
attribute :event
12+
attribute :recipient
13+
14+
# Customize the default sort column and direction.
15+
def self.default_sort_column = "created_at"
16+
17+
def self.default_sort_direction = "desc"
18+
end

config/routes/madmin.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
resources :shops
99
resources :item_tags
1010
resources :application_push_devices
11+
namespace :noticed do
12+
resources :events
13+
resources :notifications
14+
end
1115
resources :roles
1216
resources :permissions
1317
resources :roles_permissions
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require "test_helper"
2+
3+
class Madmin::Noticed::EventsControllerTest < ActionDispatch::IntegrationTest
4+
setup do
5+
@admin_user = AdminUser.create!(name: "Admin", email: "admin@example.com", password: "password")
6+
7+
shopkeeper = shopkeepers(:one)
8+
shopkeeper.create_default_account
9+
item_tag = shopkeeper.created_shops.first.item_tags.first
10+
ItemTagNotifier.with(record: item_tag).deliver(shopkeeper)
11+
@event = Noticed::Event.last
12+
end
13+
14+
def sign_in_admin
15+
post admin_session_path, params: {email: @admin_user.email, password: "password"}
16+
end
17+
18+
test "index renders for authenticated admin" do
19+
sign_in_admin
20+
get madmin_noticed_events_path
21+
assert_response :success
22+
end
23+
24+
test "show renders for authenticated admin" do
25+
sign_in_admin
26+
get madmin_noticed_event_path(@event)
27+
assert_response :success
28+
end
29+
30+
test "redirects unauthenticated users" do
31+
get madmin_noticed_events_path
32+
assert_redirected_to "/"
33+
end
34+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require "test_helper"
2+
3+
class Madmin::Noticed::NotificationsControllerTest < ActionDispatch::IntegrationTest
4+
setup do
5+
@admin_user = AdminUser.create!(name: "Admin", email: "admin@example.com", password: "password")
6+
7+
shopkeeper = shopkeepers(:one)
8+
shopkeeper.create_default_account
9+
item_tag = shopkeeper.created_shops.first.item_tags.first
10+
ItemTagNotifier.with(record: item_tag).deliver(shopkeeper)
11+
@notification = shopkeeper.notifications.last
12+
end
13+
14+
def sign_in_admin
15+
post admin_session_path, params: {email: @admin_user.email, password: "password"}
16+
end
17+
18+
test "index renders for authenticated admin" do
19+
sign_in_admin
20+
get madmin_noticed_notifications_path
21+
assert_response :success
22+
end
23+
24+
test "show renders for authenticated admin" do
25+
sign_in_admin
26+
get madmin_noticed_notification_path(@notification)
27+
assert_response :success
28+
end
29+
30+
test "redirects unauthenticated users" do
31+
get madmin_noticed_notifications_path
32+
assert_redirected_to "/"
33+
end
34+
end

0 commit comments

Comments
 (0)