dograh/api/services
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
..
auth chore: cleaup mps v1 billing (#507) 2026-07-07 18:38:29 +05:30
campaign feat: centralise workflow run authorization 2026-06-12 18:16:30 +05:30
configuration feat(tts): add xAI as a Voice (TTS) provider (#476) 2026-07-08 09:05:43 +05:30
filesystem chore: refactor file upload mechanism to avoid NFS dependency (#496) 2026-07-03 20:01:52 +05:30
gen_ai chore: cleaup mps v1 billing (#507) 2026-07-07 18:38:29 +05:30
gender Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30
integrations feat: add template variable rendering for transfer call destination 2026-07-02 13:36:29 +05:30
pipecat feat(tts): add xAI as a Voice (TTS) provider (#476) 2026-07-08 09:05:43 +05:30
reports feat: billing and credit management v2 (#429) 2026-06-12 14:55:30 +05:30
telephony fix: fix agent stream contract with cloudonix (#504) 2026-07-06 23:58:04 +05:30
voice_prompting_guide chore: improve upon mcp prompts (#494) 2026-07-03 18:14:03 +05:30
worker_sync feat: add worker sync events 2026-04-04 14:26:47 +05:30
workflow chore: cleaup mps v1 billing (#507) 2026-07-07 18:38:29 +05:30
managed_model_services.py feat: centralise workflow run authorization 2026-06-12 18:16:30 +05:30
mps_billing.py feat: billing and credit management v2 (#429) 2026-06-12 14:55:30 +05:30
mps_service_key_client.py chore: cleaup mps v1 billing (#507) 2026-07-07 18:38:29 +05:30
organization_context.py feat: billing and credit management v2 (#429) 2026-06-12 14:55:30 +05:30
organization_preferences.py feat: add config v2 to simplify billing (#428) 2026-06-09 16:10:26 +05:30
posthog_client.py chore: fix phantom user creation in posthog 2026-06-19 21:08:09 +05:30
quota_service.py fix(auth): allow invited org members to start workflow runs (#509) 2026-07-08 17:59:20 +05:30
storage.py fix: pass s3 compose settings into storage 2026-06-24 18:37:20 +05:30
tool_management.py feat: create tools using MCP 2026-05-31 16:50:44 +05:30
user_onboarding.py feat: UI refresh and user onboarding (#430) 2026-06-17 19:49:33 +05:30
workflow_run_artifacts.py chore: refactor file upload mechanism to avoid NFS dependency (#496) 2026-07-03 20:01:52 +05:30
workflow_run_billing.py chore: cleaup mps v1 billing (#507) 2026-07-07 18:38:29 +05:30