Fix/scope user query by team - #127
Merged
Merged
Conversation
sergiosja
approved these changes
Mar 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scopes the user query in
invite_multiple_if_neededbyteam_idso the fairness algorithm only considers users from the event's own organization.Key additions
slack_user_service.get()now receivesteam_id=event['team_id']— prevents the lookback window and employee count from being inflated by users from other orgstest_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 withoutteam_id, returning all users across every organization. This inflatedtotal_number_of_employees, which controlsnumber_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.