Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-4656] Add fields to all_organization_members #537

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion auth0/management/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,14 @@ def all_organization_members(
include_totals: bool = True,
from_param: str | None = None,
take: int | None = None,
fields: list[str] | None = None,
include_fields: bool = True,
):
"""Retrieves a list of all the organization members.

Member roles are not sent by default. Use `fields=roles` to retrieve the roles assigned to each listed member.
To use this parameter, you must include the `read:organization_member_roles scope` in the token.

Args:
id (str): the ID of the organization.

Expand All @@ -267,7 +272,14 @@ def all_organization_members(
take (int, optional): The total amount of entries to retrieve when
using the from parameter. When not set, the default value is up to the server.

See: https://auth0.com/docs/api/management/v2#!/Organizations/get_members
fields (list of str, optional): A list of fields to include or
exclude from the result (depending on include_fields). If fields is left blank,
all fields (except roles) are returned.

include_fields (bool, optional): True if the fields specified are
to be included in the result, False otherwise. Defaults to True.

See: https://auth0.com/docs/api/management/v2/organizations/get-members
"""

params = {
Expand All @@ -276,6 +288,8 @@ def all_organization_members(
"include_totals": str(include_totals).lower(),
"from": from_param,
"take": take,
"fields": fields and ",".join(fields) or None,
"include_fields": str(include_fields).lower(),
}

return self.client.get(self._url(id, "members"), params=params)
Expand Down
27 changes: 27 additions & 0 deletions auth0/test/management/test_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def test_all_organization_members(self, mock_rc):
"include_totals": "true",
"from": None,
"take": None,
"fields": None,
"include_fields": "true",
},
)

Expand All @@ -253,6 +255,8 @@ def test_all_organization_members(self, mock_rc):
"include_totals": "false",
"from": None,
"take": None,
"fields": None,
"include_fields": "true",
},
)

Expand All @@ -272,6 +276,29 @@ def test_all_organization_members(self, mock_rc):
"page": None,
"per_page": None,
"include_totals": "true",
"fields": None,
"include_fields": "true",
},
)

# With fields
c.all_organization_members("test-org", fields=["a,b"], include_fields=False)

args, kwargs = mock_instance.get.call_args

self.assertEqual(
"https://domain/api/v2/organizations/test-org/members", args[0]
)
self.assertEqual(
kwargs["params"],
{
"page": None,
"per_page": None,
"include_totals": "true",
"from": None,
"take": None,
"fields": "a,b",
"include_fields": "false",
},
)

Expand Down