Skip to content

fix(revenue-analytics): add access-control checks to taxonomy and joins viewsets#73009

Merged
Piccirello merged 4 commits into
masterfrom
tom/revenue-analytics-taxonomy-access-control
Jul 22, 2026
Merged

fix(revenue-analytics): add access-control checks to taxonomy and joins viewsets#73009
Piccirello merged 4 commits into
masterfrom
tom/revenue-analytics-taxonomy-access-control

Conversation

@Piccirello

Copy link
Copy Markdown
Member

Problem

RevenueAnalyticsTaxonomyViewSet and RevenueAnalyticsJoinViewSet use scope_object = "INTERNAL", which opts them out of the revenue_analytics resource access-control check the rest of the module enforces. A member whose revenue_analytics access is restricted can still hit both endpoints.

Changes

Enforce revenue_analytics access in both actions, matching the query runners:

  • taxonomy values requires viewer
  • joins create requires editor

Explicit check_access_level_for_resource(...) raising PermissionDenied, kept scope_object = "INTERNAL". Instances without the access-control feature already default to access, so nothing changes for them.

How did you test this code?

Added test_api_access_control.py: a restricted member gets 403 on both endpoints, a viewer gets 200 on taxonomy and 403 on the joins write (so the check is what blocks, not project access). These need ClickHouse, which my local test harness couldn't reach this session, so they run in CI. Locally I confirmed the underlying check_access_level_for_resource behavior via the existing RBAC tests, plus ruff and mypy on the changed file.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

I (Claude) wrote this with Tom. Invoked /improving-drf-endpoints and /writing-tests. Chose the explicit access check over flipping scope_object to "revenue_analytics", since no other viewset uses that value and the explicit check mirrors validate_query_runner_access without relying on the scope machinery. Fixed both viewsets together, same root cause.

@Piccirello Piccirello added the stamphog Request AI approval (no full review) label Jul 22, 2026
@Piccirello Piccirello self-assigned this Jul 22, 2026
@trunk-io

trunk-io Bot commented Jul 22, 2026

Copy link
Copy Markdown

😎 This pull request was merged.

@assign-reviewers-posthog
assign-reviewers-posthog Bot requested a review from a team July 22, 2026 21:09
@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
products/revenue_analytics/backend/test/test_api_access_control.py:11-14
**Missing EE Module Leaves Undefined Name**

When this test is collected in an environment without the EE package, the import error is swallowed but every test later calls `AccessControl.objects.create`. The suite then fails with `NameError` instead of skipping this EE-only module.

```suggestion
AccessControl = pytest.importorskip("ee.models.rbac.access_control").AccessControl
```

Reviews (1): Last reviewed commit: "fix(revenue-analytics): add access-contr..." | Re-trigger Greptile

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds a missing access-control check to two revenue-analytics endpoints, mirroring the exact pattern already used by the module's query runners; well-tested (403/200 cases covered), and the one Greptile-flagged test-hygiene nit matches an existing repo-wide convention (try/except ImportError for the EE-only model) rather than a real risk.

  • 👍 on the PR from greptile-apps[bot], hex-security-app[bot].
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 13L, 1F substantive, 80L/2F incl. docs/generated/snapshots — within ceiling
tier T1-agent / T1b-small (80L, 2F, single-area, fix)
stamphog 2.0.0b3 .stamphog/policy.yml @ 4f472f3 · reviewed head 6c5fcc5

@stamphog

stamphog Bot commented Jul 22, 2026

Copy link
Copy Markdown

Retaining stamphog approval — delta since last review classified as trivial_paths.

@Piccirello
Piccirello enabled auto-merge (squash) July 22, 2026 21:14
@stamphog

stamphog Bot commented Jul 22, 2026

Copy link
Copy Markdown

Retaining stamphog approval — delta since last review classified as trivial_paths.

@tests-posthog
tests-posthog Bot disabled auto-merge July 22, 2026 21:54
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

🤖 CI report

Playwright — all passed

All tests passed.

View test results →

⚠️ Backend snapshots — 11 updated (11 modified, 0 added, 0 deleted)

Query snapshots: Backend query snapshots updated

Changes: 11 snapshots (11 modified, 0 added, 0 deleted)

What this means:

  • Query snapshots have been automatically updated to match current output
  • These changes reflect modifications to database queries or schema

Next steps:

  • Review the query changes to ensure they're intentional
  • If unexpected, investigate what caused the query to change

Review snapshot changes →

@stamphog

stamphog Bot commented Jul 22, 2026

Copy link
Copy Markdown

Retaining stamphog approval — delta since last review classified as trivial_paths.

@Piccirello
Piccirello merged commit b2a037d into master Jul 22, 2026
250 checks passed
@Piccirello
Piccirello deleted the tom/revenue-analytics-taxonomy-access-control branch July 22, 2026 22:27
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 22, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-22 23:16 UTC Run
prod-us ✅ Deployed 2026-07-22 23:30 UTC Run
prod-eu ✅ Deployed 2026-07-22 23:30 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant