fix: support createdFor org-scoping in user-creation-count report - #47
Open
divyagovindaiah wants to merge 1 commit into
Open
fix: support createdFor org-scoping in user-creation-count report#47divyagovindaiah wants to merge 1 commit into
divyagovindaiah wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Admin Reports "Total Users" widget calls
POST /v1/observability/reportswithreportId=user-creation-countandfilters: { createdFor: <orgId> }.EsExecutoronly ever readfromDate/toDatefrom the rendered query —createdForwas silently ignored.This is a companion PR to a
sunbird-spark-installerfix that addscreatedForto this report'ssupported_filters/query_templateinstandard_reports_meta(otherwise the request never even reachesEsExecutor—FilterValidatorrejects it first withUnsupported filter(s): createdFor).Why this isn't just a filter-name fix
Once the filter passes validation,
EsExecutorstill needs to usecreatedFor— 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 readscreatedForfrom the rendered query. When present, bothrangeCount()andmonthlyBreakdown()wrap their existing date-range query in aboolQuery().filter(termQuery("rootOrgId", createdFor))—rootOrgIdbeing the same field already used elsewhere in this codebase for org-scoped user lookups (e.g.UserDeletionBackgroundJobActor). WithoutcreatedFor, 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
/v1/observability/reportswithreportId=user-creation-count,filters: {createdFor: <orgId>}(no dates) — should return a monthly breakdown scoped to that org, not platform-widecreatedFor+fromDate/toDatetogether — should return a single org-scoped count for that rangecreatedForat all (existing behavior) — should be unchanged, platform-wide