From 1dca08b76f25d15365127ded37202d783a50e298 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 3 Nov 2022 16:06:42 +0100 Subject: Fix admin action logs page (#19649) * Add tests * Fix crash when trying to display orphaned action logs * Add migration for older admin action logs --- lib/tasks/tests.rake | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/tasks/tests.rake b/lib/tasks/tests.rake index 65bff6a8e..96d2f7112 100644 --- a/lib/tasks/tests.rake +++ b/lib/tasks/tests.rake @@ -53,6 +53,41 @@ namespace :tests do VALUES (1, 2, 'test', '{ "home", "public" }', true, true, now(), now()), (2, 2, 'take', '{ "home" }', false, false, now(), now()); + + -- Orphaned admin action logs + + INSERT INTO "admin_action_logs" + (account_id, action, target_type, target_id, created_at, updated_at) + VALUES + (1, 'destroy', 'Account', 1312, now(), now()), + (1, 'destroy', 'User', 1312, now(), now()), + (1, 'destroy', 'Report', 1312, now(), now()), + (1, 'destroy', 'DomainBlock', 1312, now(), now()), + (1, 'destroy', 'EmailDomainBlock', 1312, now(), now()), + (1, 'destroy', 'Status', 1312, now(), now()), + (1, 'destroy', 'CustomEmoji', 1312, now(), now()); + + -- Admin action logs with linked objects + + INSERT INTO "domain_blocks" + (id, domain, created_at, updated_at) + VALUES + (1, 'example.org', now(), now()); + + INSERT INTO "email_domain_blocks" + (id, domain, created_at, updated_at) + VALUES + (1, 'example.org', now(), now()); + + INSERT INTO "admin_action_logs" + (account_id, action, target_type, target_id, created_at, updated_at) + VALUES + (1, 'destroy', 'Account', 1, now(), now()), + (1, 'destroy', 'User', 1, now(), now()), + (1, 'destroy', 'DomainBlock', 1312, now(), now()), + (1, 'destroy', 'EmailDomainBlock', 1312, now(), now()), + (1, 'destroy', 'Status', 1, now(), now()), + (1, 'destroy', 'CustomEmoji', 3, now(), now()); SQL end @@ -207,18 +242,18 @@ namespace :tests do -- custom emoji INSERT INTO "custom_emojis" - (shortcode, created_at, updated_at) + (id, shortcode, created_at, updated_at) VALUES - ('test', now(), now()), - ('Test', now(), now()), - ('blobcat', now(), now()); + (1, 'test', now(), now()), + (2, 'Test', now(), now()), + (3, 'blobcat', now(), now()); INSERT INTO "custom_emojis" - (shortcode, domain, uri, created_at, updated_at) + (id, shortcode, domain, uri, created_at, updated_at) VALUES - ('blobcat', 'remote.org', 'https://remote.org/emoji/blobcat', now(), now()), - ('blobcat', 'Remote.org', 'https://remote.org/emoji/blobcat', now(), now()), - ('Blobcat', 'remote.org', 'https://remote.org/emoji/Blobcat', now(), now()); + (4, 'blobcat', 'remote.org', 'https://remote.org/emoji/blobcat', now(), now()), + (5, 'blobcat', 'Remote.org', 'https://remote.org/emoji/blobcat', now(), now()), + (6, 'Blobcat', 'remote.org', 'https://remote.org/emoji/Blobcat', now(), now()); -- favourites -- cgit