Skip to content

Commit

Permalink
Add fields to all_organization_members
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath committed Oct 19, 2023
1 parent 32a8cc8 commit be23eb0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
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

0 comments on commit be23eb0

Please sign in to comment.