Fix 404 error when filtering admin action logs by non-existent target account (#16643)

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)
pull/16854/head
Claire 2021-10-14 20:53:11 +02:00 committed by GitHub
parent 032d9bcaed
commit 9b978872cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

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