Skip to content

fix: support createdFor org-scoping in user-creation-count report - #47

Open
divyagovindaiah wants to merge 1 commit into
Sunbird-Lern:mainfrom
divyagovindaiah:fix/user-creation-count-org-scoping
Open

fix: support createdFor org-scoping in user-creation-count report#47
divyagovindaiah wants to merge 1 commit into
Sunbird-Lern:mainfrom
divyagovindaiah:fix/user-creation-count-org-scoping

Conversation

@divyagovindaiah

Copy link
Copy Markdown

Summary

The Admin Reports "Total Users" widget calls POST /v1/observability/reports with reportId=user-creation-count and filters: { createdFor: <orgId> }. EsExecutor only ever read fromDate/toDate from the rendered query — createdFor was silently ignored.

This is a companion PR to a sunbird-spark-installer fix that adds createdFor to this report's supported_filters/query_template in standard_reports_meta (otherwise the request never even reaches EsExecutorFilterValidator rejects it first with Unsupported filter(s): createdFor).

Why this isn't just a filter-name fix

Once the filter passes validation, EsExecutor still needs to use createdFor — otherwise the "Total Users" widget would silently return a platform-wide count instead of the count for the admin's own org, which is a correctness/data-exposure issue for an org-scoped admin view, not just a 400 error.

Fix

EsExecutor.execute() now also reads createdFor from the rendered query. When present, both rangeCount() and monthlyBreakdown() wrap their existing date-range query in a boolQuery().filter(termQuery("rootOrgId", createdFor))rootOrgId being the same field already used elsewhere in this codebase for org-scoped user lookups (e.g. UserDeletionBackgroundJobActor). Without createdFor, behavior is unchanged (platform-wide, as before).

Note for reviewers

I don't have this project's build environment set up locally, so this hasn't been compiled/tested here — please have CI/a reviewer verify it builds and the existing observability test suite (ObservabilityReportServiceSpec) still passes before merging.

Test plan

  • Confirm build passes CI
  • Call /v1/observability/reports with reportId=user-creation-count, filters: {createdFor: <orgId>} (no dates) — should return a monthly breakdown scoped to that org, not platform-wide
  • Call with createdFor + fromDate/toDate together — should return a single org-scoped count for that range
  • Call with no createdFor at all (existing behavior) — should be unchanged, platform-wide

The Admin Reports "Total Users" widget sends filters.createdFor (an org
id) to /v1/observability/reports for reportId=user-creation-count, but
EsExecutor only ever read fromDate/toDate from the rendered query and
ignored createdFor entirely — so even once the filter passed validation,
the count returned was platform-wide, not scoped to the admin's org.

Add createdFor handling: when present, wrap the existing date-range query
in a bool filter on rootOrgId (the same field used elsewhere in this
codebase for org-scoped user lookups, e.g. UserDeletionBackgroundJobActor)
for both the single-range-count and monthly-breakdown code paths.

Companion fix in sunbird-spark-installer adds createdFor to
user-creation-count's supported_filters/query_template in
standard_reports_meta so the request passes FilterValidator in the
first place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant