mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-18 20:40:03 +08:00
Adds the frontend for the Reports section on the redesigned admin dashboard. Admins can choose which reports appear on their dashboard, reorder them, and add/remove cards via a "Manage reports" modal. A plugin API lets plugins ship their own report providers and custom card renderers — used by Data Explorer to surface DE queries alongside core reports. Follow-up to backend PR: https://github.com/discourse/discourse/pull/40017
36 lines
1.1 KiB
Ruby
Vendored
36 lines
1.1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module AdminDashboard
|
|
module Reports
|
|
class LayoutUpdater
|
|
def self.call(items:, guardian:)
|
|
items
|
|
.group_by { |item| item[:source] }
|
|
.each do |source, group|
|
|
provider = Registry.provider_for(source)
|
|
raise Discourse::InvalidParameters.new(:items) if provider.nil?
|
|
|
|
requested = group.map { |item| item[:identifier] }.to_set
|
|
accessible = provider.accessible_ids(requested.to_a, guardian: guardian)
|
|
raise Discourse::InvalidAccess unless requested.subset?(accessible)
|
|
end
|
|
|
|
AdminDashboardReport.transaction do
|
|
AdminDashboardReport.delete_all
|
|
now = Time.current
|
|
rows =
|
|
items.each_with_index.map do |item, index|
|
|
{
|
|
source: item[:source],
|
|
identifier: item[:identifier],
|
|
position: index,
|
|
created_at: now,
|
|
updated_at: now,
|
|
}
|
|
end
|
|
AdminDashboardReport.insert_all(rows) if rows.any?
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|