Skip to content

fix(directory): expose directory_group_id filter in list_directory_users#149

Open
ravibits wants to merge 5 commits into
mainfrom
fix/list-directory-users-group-filter
Open

fix(directory): expose directory_group_id filter in list_directory_users#149
ravibits wants to merge 5 commits into
mainfrom
fix/list-directory-users-group-filter

Conversation

@ravibits
Copy link
Copy Markdown
Contributor

@ravibits ravibits commented Apr 28, 2026

Summary

  • list_directory_users was missing the directory_group_id parameter despite it being defined as field 6 in the ListDirectoryUsersRequest proto
  • Added directory_group_id: Optional[str] = None to the method signature and wired it through to the gRPC request
  • Added 3 new test cases: test_list_directory_users, test_list_directory_users_filter_by_group, test_list_directory_groups

Test plan

  • test_list_directory_users — basic call returns OK with no filter
  • test_list_directory_users_filter_by_group — passing a group ID is accepted, returns empty users list for nonexistent group
  • test_list_directory_groups — basic group listing returns OK

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Directory user listing API now supports optional filtering by group membership, allowing retrieval of users based on specific directory group associations.
  • Tests

    • Added comprehensive test coverage for directory listing operations, including user and group retrieval validation with group-based filtering scenarios and edge cases.

The proto field existed (field 6 in ListDirectoryUsersRequest) but was
never wired through the Python SDK wrapper. Adds the missing param and
test coverage for filtering by group and listing groups.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

Warning

Rate limit exceeded

@ravibits has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 11 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0c0afa6a-c19b-47f5-b355-f4805def47cc

📥 Commits

Reviewing files that changed from the base of the PR and between 3f89a47 and d1d85c1.

📒 Files selected for processing (2)
  • scalekit/directory.py
  • tests/test_directory.py

Walkthrough

The PR adds an optional directory_group_id parameter to the list_directory_users method, enabling filtering of directory users by group membership. The parameter is forwarded to the underlying request object. Corresponding test cases validate the listing and filtering functionality.

Changes

Cohort / File(s) Summary
API Enhancement
scalekit/directory.py
Added optional directory_group_id parameter to list_directory_users method to support filtering users by group membership. Parameter forwarded to underlying ListDirectoryUsersRequest.
Test Coverage
tests/test_directory.py
Added three new test methods: test_list_directory_users validates basic user listing, test_list_directory_users_filter_by_group tests filtering by directory group ID, and test_list_directory_groups validates group listing functionality.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A filter whisker'd into place,
Groups now guide the listing space,
Users sorted, neat and spry,
Directory magic—hoppy sigh!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(directory): expose directory_group_id filter in list_directory_users' directly and specifically describes the main change: exposing a previously unavailable filter parameter in the list_directory_users method.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/list-directory-users-group-filter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/test_directory.py (1)

144-162: Strengthen the group-filter test so it actually validates filtering/wiring.

At Lines 157-161, asserting len(response[0].users) == 0 with a nonexistent group can pass even if directory_group_id is ignored (because the directory may already have no users). Consider asserting request wiring via a unit-level mock or using fixture data where unfiltered results are non-empty and filtered results differ.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_directory.py` around lines 144 - 162, The test
test_list_directory_users_filter_by_group currently asserts zero users for a
nonexistent directory_group_id which can pass even if directory_group_id is
ignored; change it to explicitly validate the filter wiring by either (a)
creating fixture data: create at least one user in the directory and a separate
user assigned to a real group, then call list_directory_users twice (once
without directory_group_id and once with a valid directory_group_id) and assert
the unfiltered response contains users while the filtered response only contains
the group member(s), or (b) use a unit-level mock for
scalekit_client.directory.list_directory_users to assert it was called with the
directory_group_id parameter; locate the test by function name
test_list_directory_users_filter_by_group and update calls to
list_directory_users and the setup using CreateDirectory/CreateOrganization to
ensure the scenario proves the filter is applied.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scalekit/directory.py`:
- Around line 75-76: The parameter order change in list_directory_users broke
positional-argument compatibility: move updated_after before directory_group_id
so existing positional callers keep passing their sixth argument to
updated_after; update the function signature of list_directory_users to restore
the original parameter ordering (place updated_after ahead of
directory_group_id) and ensure any internal calls or references to these
parameter names remain working with the restored order.

---

Nitpick comments:
In `@tests/test_directory.py`:
- Around line 144-162: The test test_list_directory_users_filter_by_group
currently asserts zero users for a nonexistent directory_group_id which can pass
even if directory_group_id is ignored; change it to explicitly validate the
filter wiring by either (a) creating fixture data: create at least one user in
the directory and a separate user assigned to a real group, then call
list_directory_users twice (once without directory_group_id and once with a
valid directory_group_id) and assert the unfiltered response contains users
while the filtered response only contains the group member(s), or (b) use a
unit-level mock for scalekit_client.directory.list_directory_users to assert it
was called with the directory_group_id parameter; locate the test by function
name test_list_directory_users_filter_by_group and update calls to
list_directory_users and the setup using CreateDirectory/CreateOrganization to
ensure the scenario proves the filter is applied.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f4d4db48-083b-46e1-9550-5580d7d08797

📥 Commits

Reviewing files that changed from the base of the PR and between 88c7982 and 3f89a47.

📒 Files selected for processing (2)
  • scalekit/directory.py
  • tests/test_directory.py

Comment thread scalekit/directory.py Outdated
ravibits and others added 4 commits April 29, 2026 00:25
…mpty

users attr on ListDirUsersResponse is only set when the loop runs —
accessing it on an empty response raises AttributeError.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…up filter test

- Initialize users=[] and groups=[] before mapping loops in list_directory_users
  and list_directory_groups — slots were unset causing AttributeError on non-empty responses
- Replace weak group filter test (nonexistent ID) with real SCIM-seeded test:
  creates a user+group via SCIM, asserts filtered result contains exactly that user

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ve positional arg order

Inserting before updated_after would silently break callers passing
updated_after positionally.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
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.

1 participant