mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-23 05:03:04 +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).
41 lines
1.4 KiB
Ruby
Vendored
41 lines
1.4 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
require "seed_data/admin_dashboard_reports"
|
|
|
|
RSpec.describe SeedData::AdminDashboardReports do
|
|
before do
|
|
SiteSetting.admin_dashboard_reports_seeded = false
|
|
AdminDashboardReport.delete_all
|
|
end
|
|
|
|
describe "first-time seed" do
|
|
it "seeds daily_engaged_users and time_to_first_response in order" do
|
|
described_class.create
|
|
|
|
rows = AdminDashboardReport.order(:position).pluck(:source, :identifier, :position)
|
|
expect(rows).to eq(
|
|
[["core_report", "daily_engaged_users", 1], ["core_report", "time_to_first_response", 2]],
|
|
)
|
|
end
|
|
|
|
it "flips the marker site setting after seeding" do
|
|
described_class.create
|
|
expect(SiteSetting.admin_dashboard_reports_seeded).to eq(true)
|
|
end
|
|
end
|
|
|
|
describe "re-seed protection" do
|
|
it "does nothing when the marker is already set" do
|
|
SiteSetting.admin_dashboard_reports_seeded = true
|
|
expect { described_class.create }.not_to change { AdminDashboardReport.count }
|
|
end
|
|
|
|
it "does not resurrect removed defaults on subsequent calls" do
|
|
described_class.create
|
|
AdminDashboardReport.where(identifier: "daily_engaged_users").destroy_all
|
|
|
|
expect { described_class.create }.not_to change { AdminDashboardReport.count }
|
|
expect(AdminDashboardReport.exists?(identifier: "daily_engaged_users")).to eq(false)
|
|
end
|
|
end
|
|
end
|