Skip to content

Fix/scope user query by team - #127

Merged
sergiosja merged 2 commits into
mainfrom
fix/scope-user-query-by-team-id
Mar 18, 2026
Merged

Fix/scope user query by team#127
sergiosja merged 2 commits into
mainfrom
fix/scope-user-query-by-team-id

Conversation

@stianjsu

Copy link
Copy Markdown
Collaborator

Scopes the user query in invite_multiple_if_needed by team_id so the fairness algorithm only considers users from the event's own organization.

Key additions

  • slack_user_service.get() now receives team_id=event['team_id'] — prevents the lookback window and employee count from being inflated by users from other orgs
  • test_multi_tenant_fairness_isolation.py — seeds two orgs (Org A with 6 users, Org B with 12), builds up 6 finalized past events with attendance history, and proves the correct users get invited. Without the fix, the inflated lookback flips the outcome entirely (User1/2/3 invited instead of User4/5/6)

Motivation and Context

In multi-org deployments, slack_user_service.get() was called without team_id, returning all users across every organization. This inflated total_number_of_employees, which controls number_of_events_regarded = ceil(total / per_event) — the lookback window for the fairness algorithm. A larger window pulls in older history and skews invitation priority ordering. No cross-org invitations occurred (the group subquery correctly scopes users), but who gets invited within an org could be wrong.

How Has This Been Tested?

  • test_invite_uses_org_scoped_user_count — with correct per-org lookback (ceil(6/3) = 2), User4/5/6 have 0 recent attendances and get invited. With the buggy global count (ceil(18/3) = 6), the window expands, User4/5/6 show 4 attendances each, and User1/2/3 get invited instead. Verified the test fails without the fix and passes with it.
  • Full backend suite passes (131 tests)

@sergiosja
sergiosja merged commit 73874e0 into main Mar 18, 2026
1 check passed
@sergiosja
sergiosja deleted the fix/scope-user-query-by-team-id branch March 18, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants