mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 11:36:31 +08:00
Adds the backend for the customisable Reports section on the new admin dashboard, gated by `dashboard_improvements`. - `admin_dashboard_reports` table + AR model for pinned reports. - Plugin-extension contract via `Plugin::Instance#register_admin_dashboard_report_source` and the `AdminDashboard::Reports::SourceProvider` base class. Core ships a built-in provider; `discourse-data-explorer` registers its own. - `AdminDashboard::Reports::Section` builds the `reports` entry in the dashboard's `sections` payload; `AdminDashboard::Reports::BulkFetch` powers the bulk endpoint. Both share a `Registry.dispatch_per_source` helper that batches work by source. - `POST /admin/dashboard/reports/bulk` fetches data for multiple mounted reports in one round trip, batched by source. - Defaults are seeded via core + plugin fixtures (Daily engaged users, Time to first response; `accepted_solutions` when Solved is in use). Next: list-available and save-layout endpoints for the Manage Reports modal, plus the frontend (section UI, modal, bulk loader).
53 lines
1.6 KiB
Ruby
Vendored
53 lines
1.6 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe AdminDashboard::Reports::Registry do
|
|
let(:fake_provider) do
|
|
Class.new(AdminDashboard::Reports::SourceProvider) { def self.source_name = "fake_source" }
|
|
end
|
|
|
|
let(:plugin) { Plugin::Instance.new }
|
|
|
|
after do
|
|
DiscoursePluginRegistry._raw_admin_dashboard_report_sources.reject! do |entry|
|
|
entry[:value] == fake_provider
|
|
end
|
|
end
|
|
|
|
describe ".provider_for" do
|
|
it "returns nil for an unknown source name" do
|
|
expect(described_class.provider_for("nonexistent_source")).to be_nil
|
|
end
|
|
|
|
context "with a plugin-registered provider" do
|
|
before do
|
|
DiscoursePluginRegistry.register_admin_dashboard_report_source(fake_provider, plugin)
|
|
end
|
|
|
|
it "finds it by source_name" do
|
|
expect(described_class.provider_for("fake_source")).to eq(fake_provider)
|
|
end
|
|
|
|
it "accepts symbol source names" do
|
|
expect(described_class.provider_for(:fake_source)).to eq(fake_provider)
|
|
end
|
|
end
|
|
|
|
it "ignores providers from disabled plugins" do
|
|
DiscoursePluginRegistry.register_admin_dashboard_report_source(
|
|
fake_provider,
|
|
stub(enabled?: false),
|
|
)
|
|
|
|
expect(described_class.provider_for("fake_source")).to be_nil
|
|
end
|
|
end
|
|
|
|
describe ".providers" do
|
|
before { DiscoursePluginRegistry.register_admin_dashboard_report_source(fake_provider, plugin) }
|
|
|
|
it "combines core providers and plugin-registered providers" do
|
|
expect(described_class.providers).to include(fake_provider)
|
|
described_class::CORE_PROVIDERS.each { |p| expect(described_class.providers).to include(p) }
|
|
end
|
|
end
|
|
end
|