minor optimizations for post rejected logs
This commit is contained in:
parent
597ffd7e3f
commit
36f9af4fa4
|
@ -46,9 +46,9 @@ class StaffActionLogger
|
|||
|
||||
topic = deleted_post.topic || Topic.with_deleted.find_by(id: deleted_post.topic_id)
|
||||
|
||||
username = deleted_post.user.try(:username) || "unknown"
|
||||
name = deleted_post.user.try(:name) || "unknown"
|
||||
topic_title = topic.try(:title) || "not found"
|
||||
username = deleted_post.user.try(:username) || I18n.t('staff_action_logs.unknown')
|
||||
name = deleted_post.user.try(:name) || I18n.t('staff_action_logs.unknown')
|
||||
topic_title = topic.try(:title) || I18n.t('staff_action_logs.not_found')
|
||||
|
||||
details = [
|
||||
"id: #{deleted_post.id}",
|
||||
|
@ -530,9 +530,9 @@ class StaffActionLogger
|
|||
raise Discourse::InvalidParameters.new(:rejected_post) unless rejected_post && rejected_post.is_a?(QueuedPost)
|
||||
|
||||
topic = rejected_post.topic || Topic.with_deleted.find_by(id: rejected_post.topic_id)
|
||||
topic_title = topic&.title || "not found"
|
||||
username = rejected_post.user&.username || "unknown"
|
||||
name = rejected_post.user&.name || "unknown"
|
||||
topic_title = topic&.title || I18n.t('staff_action_logs.not_found')
|
||||
username = rejected_post.user&.username || I18n.t('staff_action_logs.unknown')
|
||||
name = rejected_post.user&.name || I18n.t('staff_action_logs.unknown')
|
||||
|
||||
details = [
|
||||
"created_at: #{rejected_post.created_at}",
|
||||
|
|
|
@ -3881,3 +3881,7 @@ en:
|
|||
linked: '%{username} linked to your post from "%{topic}" - %{site_title}'
|
||||
confirm_title: 'Notifications enabled - %{site_title}'
|
||||
confirm_body: 'Success! Notifications have been enabled.'
|
||||
|
||||
staff_action_logs:
|
||||
not_found: "not found"
|
||||
unknown: "unknown"
|
||||
|
|
|
@ -86,8 +86,10 @@ describe QueuedPost do
|
|||
# It removes the pending action
|
||||
expect(UserAction.where(queued_post_id: qp.id).count).to eq(0)
|
||||
|
||||
# Logs staff action log for rejected post
|
||||
expect(UserHistory.where(action: UserHistory.actions[:post_rejected]).count).to eq(1)
|
||||
# Logs staff action for rejected post
|
||||
post_rejected_logs = UserHistory.where(action: UserHistory.actions[:post_rejected])
|
||||
expect(post_rejected_logs.count).to eq(1)
|
||||
expect(post_rejected_logs.first.details).to include(qp.raw)
|
||||
|
||||
# We can't reject twice
|
||||
expect(-> { qp.reject!(admin) }).to raise_error(QueuedPost::InvalidStateTransition)
|
||||
|
|
|
@ -504,6 +504,9 @@ describe StaffActionLogger do
|
|||
|
||||
it 'creates a new UserHistory record' do
|
||||
expect { log_post_rejected }.to change { UserHistory.count }.by(1)
|
||||
user_history = UserHistory.last
|
||||
expect(user_history.action).to eq(UserHistory.actions[:post_rejected])
|
||||
expect(user_history.details).to include(rejected_post.raw)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue