dograh/api/db
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
..
__init__.py Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30
agent_trigger_client.py fix: make trigger paths globally unique 2026-04-25 19:44:44 +05:30
api_key_client.py Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30
base_client.py Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30
campaign_client.py feat: persist split user and bot audio 2026-06-16 15:19:49 +05:30
database.py Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30
db_client.py feat(webhooks): durable retrying delivery for final webhooks (#478) 2026-07-02 21:44:14 +05:30
embed_token_client.py fix: add error in cloudonix cdr report 2026-01-29 20:43:53 +05:30
filters.py feat: billing and credit management v2 (#429) 2026-06-12 14:55:30 +05:30
folder_client.py feat: add google stt and tts. add folders to organize agents 2026-05-22 14:36:50 +05:30
integration_client.py feat: add agent skills to review PR (#320) 2026-05-19 17:02:26 +05:30
knowledge_base_client.py fix: enable knowledge base with Dograh config v2 2026-06-25 22:21:11 +05:30
models.py feat(webhooks): durable retrying delivery for final webhooks (#478) 2026-07-02 21:44:14 +05:30
organization_client.py fix(auth): allow invited org members to start workflow runs (#509) 2026-07-08 17:59:20 +05:30
organization_configuration_client.py feat: custom telemetry configuration 2026-03-23 11:36:39 +05:30
organization_usage_client.py feat: UI refresh and user onboarding (#430) 2026-06-17 19:49:33 +05:30
reports_client.py Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30
telephony_configuration_client.py feat: support inbound vonage calls (#480) 2026-06-29 16:27:19 +05:30
telephony_phone_number_client.py feat: agent stream for cloudonix OPBX (#261) 2026-05-02 15:53:58 +05:30
tool_client.py feat: add end_call tool (#118) 2026-01-14 16:40:40 +05:30
user_client.py chore: update documentation 2026-06-19 18:11:35 +05:30
webhook_credential_client.py Feat/Add API Trigger and Webhooks in Agent Builder (#83) 2025-12-22 14:08:30 +05:30
webhook_delivery_client.py feat(webhooks): durable retrying delivery for final webhooks (#478) 2026-07-02 21:44:14 +05:30
workflow_client.py feat: add google stt and tts. add folders to organize agents 2026-05-22 14:36:50 +05:30
workflow_recording_client.py feat: allow recordings in tool transitions 2026-04-10 16:18:01 +05:30
workflow_run_client.py feat(webhooks): durable retrying delivery for final webhooks (#478) 2026-07-02 21:44:14 +05:30
workflow_run_text_session_client.py feat: add chat based testing for voice agent (#308) 2026-05-21 15:20:02 +05:30
workflow_template_client.py Initial Commit 🚀 🚀 2025-09-09 14:37:32 +05:30