FEATURE: improves staff note report support

It will now appear in the new discourse core moderation tab in the dashboard
This commit is contained in:
Joffrey JAFFEUX 2018-07-19 14:39:52 -04:00
parent 166937b9c2
commit e072f55f36
4 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,4 @@
{{admin-report
dataSourceName="recent_staff_notes"
startDate=lastWeek
endDate=endDate}}

View File

@ -45,3 +45,7 @@
}
cursor: pointer;
}
.admin-report.recent-staff-notes {
grid-column: span 12;
}

View File

@ -7,3 +7,11 @@ en:
official_warning: "Received an official warning from @%{username} -- %{warning_link}"
user_suspended: "@%{username} suspended this account until %{suspended_till}. Reason: %{reason}"
user_silenced: "@%{username} silenced this account until %{silenced_till}. Reason: %{reason}"
reports:
recent_staff_notes:
title: "Recent staff notes"
labels:
user: User
note: Note
moderator: Moderator

View File

@ -263,4 +263,47 @@ after_initialize do
)
end
if respond_to? :add_report
add_report('recent_staff_notes') do |report|
report.modes = [:table]
report.data = []
# TODO
# plugin store row doesnt have created_at
# this could be improved by querying on the text field
report.dates_filtering = false
report.labels = [
{ type: :link, properties: ["username", "user_url"], title: I18n.t("reports.recent_staff_notes.labels.user") },
{ type: :text, properties: ["note"], title: I18n.t("reports.recent_staff_notes.labels.note") },
{ type: :link, properties: ["moderator_username", "moderator_url"], title: I18n.t("reports.recent_staff_notes.labels.moderator")}
]
values = PluginStoreRow.where(plugin_name: 'staff_notes')
.order(id: :desc)
.limit(report.limit || 10)
.pluck(:value)
values.each do |value|
data = {}
note = JSON.parse(value)[0]
created_at = Time.parse(note['created_at'])
user = User.find_by(id: note['user_id'])
moderator = User.find_by(id: note['created_by'])
if user && moderator
data[:created_at] = created_at
data[:user_id] = user.id
data[:user_url] = "/admin/users/#{user.id}/#{user.username_lower}"
data[:username] = user.username
data[:moderator_id] = moderator.id
data[:moderator_username] = moderator.username
data[:moderator_url] = "/admin/users/#{moderator.id}/#{moderator.username_lower}"
data[:note] = note['raw']
report.data << data
end
end
end
end
end