From e072f55f362d2a45123610b7a8d3e9044bab7383 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 19 Jul 2018 14:39:52 -0400 Subject: [PATCH] FEATURE: improves staff note report support It will now appear in the new discourse core moderation tab in the dashboard --- .../recent-staff-notes-report-table.hbs | 4 ++ assets/stylesheets/staff_notes.scss | 4 ++ config/locales/server.en.yml | 8 ++++ plugin.rb | 43 +++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-staff-notes-report-table.hbs diff --git a/assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-staff-notes-report-table.hbs b/assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-staff-notes-report-table.hbs new file mode 100644 index 0000000..8d2a379 --- /dev/null +++ b/assets/javascripts/discourse/templates/connectors/admin-dashboard-moderation-bottom/recent-staff-notes-report-table.hbs @@ -0,0 +1,4 @@ +{{admin-report + dataSourceName="recent_staff_notes" + startDate=lastWeek + endDate=endDate}} diff --git a/assets/stylesheets/staff_notes.scss b/assets/stylesheets/staff_notes.scss index 70adbbf..dceb9eb 100644 --- a/assets/stylesheets/staff_notes.scss +++ b/assets/stylesheets/staff_notes.scss @@ -45,3 +45,7 @@ } cursor: pointer; } + +.admin-report.recent-staff-notes { + grid-column: span 12; +} diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 5f08317..c2da8b5 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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 diff --git a/plugin.rb b/plugin.rb index fef3cef..61ae8fd 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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 doesn’t 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