dograh/api
Komal Vardhan Lolugu f32395f859
fix(auth): allow invited org members to start workflow runs (#509)
* fix(auth): allow invited org members to start workflow runs

Users invited to an org could not start workflows belonging to that org
because the authorization check compared actor.selected_organization_id
directly against workflow.organization_id. An invited user's selected
org correctly reflects the invited org, but if the Stack Auth token
resolves to a different org id than expected the strict equality fails.

Per api/AGENTS.md: "Whenever you read or write an organization-scoped
field, you must filter or validate by organization_id." The correct
policy is org membership, not selected-org identity.

- Add is_user_member_of_organization() to OrganizationClient; queries
  the organization_users association table directly (no lazy-load risk).
- Replace the identity check in authorize_workflow_run_start() with a
  membership lookup. Deny when actor_user.id is not in the org's member
  set; error_code stays workflow_not_found to avoid leaking existence.
- Update test: rename rejects_actor_from_another_org to
  rejects_actor_not_a_member (reflects actual policy), add positive test
  allows_invited_member that seeds membership and asserts has_quota=True.

Closes #491

* fix(auth): skip membership check for personal workflows (organization_id=None)

When workflow.organization_id is None (personal or legacy workflow with no
org), the membership lookup was still called, producing a SQL IS NULL
comparison that matched nothing and denied the run.

Guard the check so it only runs when the workflow is org-scoped.

Adds a regression test confirming that an actor with a known id can start a
personal workflow without triggering is_user_member_of_organization.

* fix(auth): fail closed on workflow membership lookup errors

---------

Co-authored-by: Abhishek Kumar <abhishek@a6k.me>
2026-07-08 17:59:20 +05:30
..
alembic feat(webhooks): durable retrying delivery for final webhooks (#478) 2026-07-02 21:44:14 +05:30
assets feat: telephony call transfer (#155) 2026-02-16 14:33:33 +05:30
db fix(auth): allow invited org members to start workflow runs (#509) 2026-07-08 17:59:20 +05:30
errors Feat/inbound telephony (#113) 2026-01-12 10:10:30 +05:30
mcp_server chore: improve upon mcp prompts (#494) 2026-07-03 18:14:03 +05:30
native/rnnoise Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30
routes chore: cleaup mps v1 billing (#507) 2026-07-07 18:38:29 +05:30
schemas feat: client gen default configurations (#499) 2026-07-04 18:37:50 +05:30
services fix(auth): allow invited org members to start workflow runs (#509) 2026-07-08 17:59:20 +05:30
tasks chore: cleaup mps v1 billing (#507) 2026-07-07 18:38:29 +05:30
tests fix(auth): allow invited org members to start workflow runs (#509) 2026-07-08 17:59:20 +05:30
utils Feat/enhanced timestamped transcript (#501) 2026-07-07 14:47:43 +05:30
.cursorignore Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30
.dockerignore Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30
.env.example chore: drain active calls before rolling updates (#474) 2026-06-29 06:00:31 +05:30
.env.test.example chore: drain active calls before rolling updates (#474) 2026-06-29 06:00:31 +05:30
.gitignore Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30
__init__.py Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30
AGENTS.md feat: add chat based testing for voice agent (#308) 2026-05-21 15:20:02 +05:30
alembic.ini chore: bump pipecat version and fix tests (#263) 2026-05-04 21:35:37 +05:30
app.py fix: add CORS preflight handler and ACAO header for embed config endpoint (#403) 2026-06-03 21:27:44 +05:30
CLAUDE.md Chore/add setup and contributing docs (#90) 2025-12-27 09:25:20 +05:30
conftest.py feat: add devcontainer based setup (#352) 2026-05-25 20:44:22 +05:30
constants.py feat(webhooks): durable retrying delivery for final webhooks (#478) 2026-07-02 21:44:14 +05:30
Dockerfile feat: add Helm chart for Kubernetes deployment (#365) 2026-07-03 12:39:39 +05:30
enums.py chore: refactor status processor (#465) 2026-06-24 22:07:35 +05:30
logging_config.py feat: add headless mode, redesign floating widget, refactor lifecycle callbacks (#268) 2026-05-07 12:23:41 +05:30
pyproject.toml chore(main): release dograh 1.41.0 (#497) 2026-07-06 21:37:02 +05:30
pytest.ini feat: refactor node spec and add mcp tools (#244) 2026-04-21 07:56:16 +05:30
requirements.dev.txt feat: add devcontainer based setup (#352) 2026-05-25 20:44:22 +05:30
requirements.txt Implement cost calculator for Tuber (#471) 2026-07-02 12:51:14 +05:30
sdk_expose.py feat: refactor node spec and add mcp tools (#244) 2026-04-21 07:56:16 +05:30