]> cat aescling's git repositories - mastodon.git/commitdiff
Fix 404 error when filtering admin action logs by non-existent target account (#16643)
authorClaire <claire.github-309c@sitedethib.com>
Thu, 14 Oct 2021 18:53:11 +0000 (20:53 +0200)
committerGitHub <noreply@github.com>
Thu, 14 Oct 2021 18:53:11 +0000 (20:53 +0200)
Currently, there is no way for an admin to delete an account record. However,
should that happen in the future, or should an admin mistype an account id,
`/admin/action_logs?target_account_id=<non-existent-account-id>` currently
returns a 404 instead of an empty list.

With this commit, the aforementioned page returns a correct list instead
(potentially non-empty if the account has been manually deleted)

app/models/admin/action_log_filter.rb

index a1c156a8bf8d265556928f2917aa272b5bc53d8c..6e19dcf70890e11d775f630b886f4b1c0c7613ce 100644 (file)
@@ -76,7 +76,7 @@ class Admin::ActionLogFilter
     when 'account_id'
       Admin::ActionLog.where(account_id: value)
     when 'target_account_id'
-      account = Account.find(value)
+      account = Account.find_or_initialize_by(id: value)
       Admin::ActionLog.where(target: [account, account.user].compact)
     else
       raise "Unknown filter: #{key}"