agnes-the-ai-analyst/app/api
ZdenekSrotyr 62336bfd32
fix(rbac): stack-gated analyst access + first-demo polish (#333 follow-up) (#356)
* fix(rbac): stack-gate analyst table access via data_packages exclusively

Previously analysts could see a table in ``agnes catalog`` /
``/api/sync/manifest`` either by:
  1. being in a group with ``resource_grants(group, 'table', id)``, or
  2. being in a group with ``resource_grants(group, 'data_package', …)``
     for a package containing the table.

Path 1 leaked: admins who minted a per-table grant without ever
wrapping the table in a data_package still shipped the table to
analysts — directly contradicting the unified-stack mental model
("the stack is the unit of access"). User report:
"i když to admin nedal do data package tak to by default uživatelé
dostali to by se nemělo stát".

New policy: analyst visibility is strictly stack-gated. A table is
visible iff at least one data_package containing it is in the
analyst's stack (required ∪ subscribed). Admin god-mode and the three
internal data-source tables (agnes_sessions / _telemetry / _audit
with row-level RBAC) keep their existing carve-outs.

Touched surfaces:
* ``src/rbac.can_access_table`` + ``get_accessible_tables`` —
  routed through ``StackResolver.stack(user, DATA_PACKAGE)`` +
  ``data_package_tables`` join instead of ``resource_grants(table)``.
* ``app/api/sync._build_direct_tables_section`` — always returns
  ``[]`` (key kept for older CLI destructuring); per-table grants
  no longer manifest.
* Standardised 403 detail across ``/api/data/*``, ``/api/query``,
  ``/api/v2/sample``, ``/api/v2/scan``, ``/api/v2/schema``:
  ``Table 'X' is not in your stack. Ask an admin to add it to a
  Data Package you have access to (Required or in your stack),
  then run `agnes pull` to refresh.`` Single source of truth lives
  in ``src.rbac.table_not_in_stack_message`` so the wording stays
  consistent across CLI surfaces.

UX side: ``/catalog/t/<id>`` (table detail page) dropped the four
editorial sections (Sample questions, What's inside, Things to know,
Pairs well with) per user feedback — the page's job is now
"what is this table, where do I find it" (hero + parent packages).

Tests:
* ``tests/conftest.grant_table_via_package`` / ``revoke_table_via_package``
  — shared helpers that wrap a table in an auto-named data_package +
  grant the package required to a custom group. Replaces the legacy
  per-test ``_grant_table_to_analyst`` table-grant pattern.
* All 17 previously-failing legacy tests (test_access_control,
  test_journey_rbac, test_audit_gap_*, test_rbac, …) migrated to use
  the new helper; logic stays the same.
* ``tests/fixtures/analyst_bootstrap._grant_table_access`` updated
  to wrap via data_package so the ``test_pat`` fixture's "two table
  grants" semantics still ship parquets through ``agnes init``.
* New ``tests/test_table_not_in_stack_message.py`` locks in the
  standardised 403 detail across the data + check-access endpoints.

5204 tests passing (added 1).

* fix(catalog): first-demo UX feedback — required-first grouping + longer card description

Two minor polish items from the 2026-05-19 stakeholder demo:

1. Required packages cluster at the top of the Browse grid instead of
   being interleaved by ``created_at``. Sort key
   ``(requirement != 'required', name)`` runs before the adapter
   call in both /catalog (data_packages) and /corporate-memory
   (memory_domains) so the required block is visible without
   scrolling. Regression test pins the order via
   ``data-id="…"`` position in rendered HTML.

2. ``.stack-card__desc`` line clamp bumped 2 → 4 lines. Two-line clamp
   trailed almost every admin-authored description off in "…" before
   the second clause, forcing a click-through to read it. The detail
   page (/catalog/p/<slug>) keeps the unclamped body for longer
   content.

* release: 0.55.3 — stack-gated analyst RBAC (BREAKING) + first-demo UX polish + #345 A/B/C/D + #347 UI consistency
2026-05-19 17:01:14 +02:00
..
__init__.py feat: add FastAPI server with auth, RBAC, and all API endpoints 2026-03-27 15:19:18 +01:00
_metadata_models.py feat(catalog): entity_type + validated where_examples + view-aware cost-guard + scheduler hygiene 2026-05-12 10:37:35 +02:00
access.py feat(stack): unified Browse + My Stack for Data Packages and Memory (v49 schema) (#333) 2026-05-19 15:00:15 +02:00
activity.py feat(stack): unified Browse + My Stack for Data Packages and Memory (v49 schema) (#333) 2026-05-19 15:00:15 +02:00
admin.py feat(stack): unified Browse + My Stack for Data Packages and Memory (v49 schema) (#333) 2026-05-19 15:00:15 +02:00
admin_bigquery_test.py feat(admin): #160 BQ test-connection endpoint + billing_project placeholder UI 2026-05-04 10:31:35 +02:00
admin_sessions.py Activity Center: audit log + telemetry + sessions + agnes_* tables (#278) 2026-05-12 22:41:19 +02:00
admin_usage.py feat(marketplace): telemetry v46 + flea inner parity + listing polish (#329) 2026-05-15 20:58:03 +02:00
admin_usage_summary.py Activity Center: audit log + telemetry + sessions + agnes_* tables (#278) 2026-05-12 22:41:19 +02:00
admin_user_sessions.py fix(security): RBAC filter uses stable user_id instead of mutable email local-part (#293) (#299) 2026-05-14 14:12:54 +00:00
bq_metadata_refresh.py release: 0.52.0 — UX/hygiene round (5 fixes from 0.51.0 retro) 2026-05-12 15:09:14 +02:00
cache_warmup.py release: 0.50.0 — persistent BQ metadata cache + scheduled refresh; catalog never blocks on BigQuery 2026-05-11 20:37:17 +02:00
catalog.py fix(api): harden API surface before Swagger (issue #336) (#339) 2026-05-18 15:13:21 +02:00
claude_md.py chore(cli-rename): replace stale da verbs in active code paths 2026-05-04 21:10:43 +02:00
cli_artifacts.py feat(web): consolidate the personal /me/* surface — /me/activity + /me/profile (#304) 2026-05-14 21:29:51 +02:00
data.py fix(rbac): stack-gated analyst access + first-demo polish (#333 follow-up) (#356) 2026-05-19 17:01:14 +02:00
data_packages.py feat(stack): unified Browse + My Stack for Data Packages and Memory (v49 schema) (#333) 2026-05-19 15:00:15 +02:00
health.py feat(diagnose): role-aware overall status (#345 B) (#355) 2026-05-19 16:53:56 +02:00
initial_workspace.py fix(api): redirect unauthorized browser requests to login for initial workspace zip (#315) 2026-05-15 15:18:39 +02:00
jira_webhooks.py fix(api): harden API surface before Swagger (issue #336) (#339) 2026-05-18 15:13:21 +02:00
marketplace.py feat(flea): marketplace refactor — data model, attribution, UI unification (#342) 2026-05-19 02:32:41 +02:00
marketplaces.py feat(api): enforce API design rules via pytest + fix DELETE/status-code violations (#338) 2026-05-18 15:25:07 +02:00
me.py fix(security): RBAC filter uses stable user_id instead of mutable email local-part (#293) (#299) 2026-05-14 14:12:54 +00:00
me_debug.py feat(web): consolidate the personal /me/* surface — /me/activity + /me/profile (#304) 2026-05-14 21:29:51 +02:00
me_stats.py feat(web): consolidate the personal /me/* surface — /me/activity + /me/profile (#304) 2026-05-14 21:29:51 +02:00
memory.py feat(stack): unified Browse + My Stack for Data Packages and Memory (v49 schema) (#333) 2026-05-19 15:00:15 +02:00
memory_domain_suggestions.py feat(stack): unified Browse + My Stack for Data Packages and Memory (v49 schema) (#333) 2026-05-19 15:00:15 +02:00
memory_domains.py feat(stack): unified Browse + My Stack for Data Packages and Memory (v49 schema) (#333) 2026-05-19 15:00:15 +02:00
metadata.py feat(rbac+marketplace): RBAC v13 + Claude Code marketplace + #81/#83/#44 hardening 2026-04-28 14:25:04 +02:00
metrics.py feat(api): enforce API design rules via pytest + fix DELETE/status-code violations (#338) 2026-05-18 15:25:07 +02:00
my_stack.py feat(flea): marketplace refactor — data model, attribution, UI unification (#342) 2026-05-19 02:32:41 +02:00
news.py feat(home): state-aware /home + /setup-advanced + schema v26 (#228) 2026-05-08 18:28:47 +02:00
observability.py feat(api): enforce API design rules via pytest + fix DELETE/status-code violations (#338) 2026-05-18 15:25:07 +02:00
query.py fix(rbac): stack-gated analyst access + first-demo polish (#333 follow-up) (#356) 2026-05-19 17:01:14 +02:00
query_hybrid.py Activity Center: audit log + telemetry + sessions + agnes_* tables (#278) 2026-05-12 22:41:19 +02:00
recipes.py feat(stack): unified Browse + My Stack for Data Packages and Memory (v49 schema) (#333) 2026-05-19 15:00:15 +02:00
scripts.py Activity Center: audit log + telemetry + sessions + agnes_* tables (#278) 2026-05-12 22:41:19 +02:00
settings.py feat(rbac): drop dataset_permissions + users.role + is_public; v19 migration (#150) 2026-04-30 22:02:16 +02:00
stack.py feat(stack): unified Browse + My Stack for Data Packages and Memory (v49 schema) (#333) 2026-05-19 15:00:15 +02:00
stack_views.py feat(stack): unified Browse + My Stack for Data Packages and Memory (v49 schema) (#333) 2026-05-19 15:00:15 +02:00
store.py feat(flea): marketplace refactor — data model, attribution, UI unification (#342) 2026-05-19 02:32:41 +02:00
sync.py fix(rbac): stack-gated analyst access + first-demo polish (#333 follow-up) (#356) 2026-05-19 17:01:14 +02:00
telegram.py feat: complete system — web UI, all API endpoints, governance, admin, CLI commands 2026-03-27 16:52:22 +01:00
tokens.py fix(api): harden API surface before Swagger (issue #336) (#339) 2026-05-18 15:13:21 +02:00
upload.py Activity Center: audit log + telemetry + sessions + agnes_* tables (#278) 2026-05-12 22:41:19 +02:00
uploads.py feat(stack): unified Browse + My Stack for Data Packages and Memory (v49 schema) (#333) 2026-05-19 15:00:15 +02:00
users.py fix(api): harden API surface before Swagger (issue #336) (#339) 2026-05-18 15:13:21 +02:00
v2_arrow.py feat(v2): claude-driven fetch primitives + 0.14.0 (#102) 2026-04-29 01:07:19 +02:00
v2_cache.py feat(v2): claude-driven fetch primitives + 0.14.0 (#102) 2026-04-29 01:07:19 +02:00
v2_catalog.py Activity Center: audit log + telemetry + sessions + agnes_* tables (#278) 2026-05-12 22:41:19 +02:00
v2_quota.py refactor(quota): #160 relocate _build_quota_tracker to v2_quota.py 2026-05-04 10:31:35 +02:00
v2_sample.py fix(rbac): stack-gated analyst access + first-demo polish (#333 follow-up) (#356) 2026-05-19 17:01:14 +02:00
v2_scan.py fix(rbac): stack-gated analyst access + first-demo polish (#333 follow-up) (#356) 2026-05-19 17:01:14 +02:00
v2_schema.py fix(rbac): stack-gated analyst access + first-demo polish (#333 follow-up) (#356) 2026-05-19 17:01:14 +02:00
welcome.py fix(devin-review): dashboard CTA respects override; PUT validates anon path 2026-05-03 21:45:32 +02:00
where_validator.py feat(v2): claude-driven fetch primitives + 0.14.0 (#102) 2026-04-29 01:07:19 +02:00