Problem/Motivation

The AI Metering dashboard lists one row per editor. On sites with hundreds or
thousands of users this is impractical: the table is too long to scan and the
per-user detail is often not what administrators need. What matters for budget
attribution and planning is a role-level view: "how much did our editorial team
spend on AI this month, combined?" or "which role is driving the most cloud calls?"

The per-user breakdown remains useful for quota governance; the per-role breakdown
is the right view for cost reporting and capacity planning. Both should be available.

Steps to reproduce

  1. Install ai_metering on a site with multiple roles (e.g. editor, senior editor, administrator).
  2. Open /admin/reports/ai-metering.
  3. The only available view lists individual users; there is no way to see aggregated spend by role.

Environment

  • Drupal version: 11.3.11
  • ai_metering version: 1.0.0-alpha1
  • AI provider module + version: any (e.g. ai_provider_anthropic 1.2.2)
  • AI feature module tested: N/A

Proposed resolution

Add a second dashboard page at /admin/reports/ai-metering/by-role
that aggregates usage data by Drupal role: one row per role sorted by total token
volume, with columns for role label, number of users in role, call count
(cloud vs. local split), input tokens, output tokens, total cost, and combined
budget. The page includes the same Chart.js charts (doughnut for token split, bar
chart for cost per role), a month selector, and CSV + JSON export endpoints,
consistent with the per-user dashboard. A menu link is added under Reports
alongside "AI Usage by Editor", and each view links to the other.

The implementation reuses the existing dashboard library and CSS classes and adds
no new theme hooks, JS files, or CSS files.

Remaining tasks

  • Commit src/Controller/AiMeteringByRoleController.php (already written locally).
  • Add menu link ai_metering.dashboard_by_role to ai_metering.links.menu.yml.
  • Add a cross-link between the per-user and by-role dashboards.
  • Add functional test asserting role aggregation and export endpoints respond correctly.
  • PHPCS.
  • Review.

User interface changes

Yes. New page at /admin/reports/ai-metering/by-role with role-level breakdown, charts (token split doughnut, cost per role bar chart), month filter, and CSV/JSON export. Menu link added under Reports.

API changes

N/A

Data model changes

N/A. The by-role view aggregates the existing ai_metering_usage and ai_metering_quota tables; no new columns or tables.

AI assistance

N/A

Comments

codeitwisely created an issue. See original summary.

  • eb3b7ff9 committed on 1.0.x-3604346-by-role-dashboard
    Issue #3604346 by codeitwisely: Add by-role dashboard with CSV/JSON...

  • a765eb8e committed on 1.0.x-3604346-by-role-dashboard
    Issue #3604346 by codeitwisely: Move by-role markup to Twig template;...

  • 749b9d33 committed on 1.0.x-3604346-by-role-dashboard
    Issue #3604346 by codeitwisely: Add by-role dashboard with CSV/JSON...

  • 0ba8bba6 committed on 1.0.x-3604346-by-role-dashboard
    Issue #3604346 by codeitwisely: Add by-role dashboard with CSV/JSON...

  • f46959b2 committed on 1.0.x-3604346-by-role-dashboard
    Issue #3604346 by codeitwisely: Add by-role dashboard with CSV/JSON...

  • f1bbb8ed committed on 1.0.x-3604346-by-role-dashboard
    Issue #3604346 by codeitwisely: Add by-role dashboard with CSV/JSON...

  • a794ebab committed on 1.0.x-3604346-by-role-dashboard
    Issue #3604346 by codeitwisely: Add by-role dashboard with CSV/JSON...

  • d6be2112 committed on 1.0.x-3604346-by-role-dashboard
    Issue #3604346 by codeitwisely: Add by-role dashboard with CSV/JSON...

  • codeitwisely committed 2680af97 on 1.0.x
    Issue #3604346: Add by-role dashboard with CSV/JSON exports
    

  • 532020fe committed on 1.0.x-3604346-by-role-dashboard
    Issue #3604346 by codeitwisely: Add by-role dashboard with CSV/JSON...
codeitwisely’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.