mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FIX: log post deletion even if user is deleted.
This commit is contained in:
parent
7d86d23eec
commit
5ee4d3ba8c
2 changed files with 11 additions and 1 deletions
|
@ -42,10 +42,13 @@ class StaffActionLogger
|
||||||
|
|
||||||
topic = deleted_post.topic || Topic.with_deleted.find(deleted_post.topic_id)
|
topic = deleted_post.topic || Topic.with_deleted.find(deleted_post.topic_id)
|
||||||
|
|
||||||
|
username = deleted_post.user.try(:username) || "unknown"
|
||||||
|
name = deleted_post.user.try(:name) || "unknown"
|
||||||
|
|
||||||
details = [
|
details = [
|
||||||
"id: #{deleted_post.id}",
|
"id: #{deleted_post.id}",
|
||||||
"created_at: #{deleted_post.created_at}",
|
"created_at: #{deleted_post.created_at}",
|
||||||
"user: #{deleted_post.user.username} (#{deleted_post.user.name})",
|
"user: #{username} (#{name})",
|
||||||
"topic: #{topic.title}",
|
"topic: #{topic.title}",
|
||||||
"post_number: #{deleted_post.post_number}",
|
"post_number: #{deleted_post.post_number}",
|
||||||
"raw: #{deleted_post.raw}"
|
"raw: #{deleted_post.raw}"
|
||||||
|
|
|
@ -63,6 +63,13 @@ describe StaffActionLogger do
|
||||||
it 'creates a new UserHistory record' do
|
it 'creates a new UserHistory record' do
|
||||||
expect { log_post_deletion }.to change { UserHistory.count }.by(1)
|
expect { log_post_deletion }.to change { UserHistory.count }.by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not explode if post does not have a user' do
|
||||||
|
expect {
|
||||||
|
deleted_post.update_columns(user_id: nil)
|
||||||
|
log_post_deletion
|
||||||
|
}.to change { UserHistory.count }.by(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'log_topic_deletion' do
|
describe 'log_topic_deletion' do
|
||||||
|
|
Loading…
Reference in a new issue