Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab625eb

Browse files
committed
add GET user's organizations
1 parent b468e3a commit ab625eb

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

auth0/v3/management/users.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,32 @@ def update(self, id, body):
145145
"""
146146
return self.client.patch(self._url(id), data=body)
147147

148+
def list_organizations(self, id, page=0, per_page=25, include_totals=True):
149+
"""List the organizations that the user is member of.
150+
151+
Args:
152+
id (str): The user's id.
153+
154+
page (int, optional): The result's page number (zero based). By default,
155+
retrieves the first page of results.
156+
157+
per_page (int, optional): The amount of entries per page. By default,
158+
retrieves 25 results per page.
159+
160+
include_totals (bool, optional): True if the query summary is
161+
to be included in the result, False otherwise. Defaults to True.
162+
163+
See https://auth0.com/docs/api/management/v2#!/Users/get_user_roles
164+
"""
165+
params = {
166+
'per_page': per_page,
167+
'page': page,
168+
'include_totals': str(include_totals).lower()
169+
}
170+
171+
url = self._url('{}/organizations'.format(id))
172+
return self.client.get(url, params=params)
173+
148174
def list_roles(self, id, page=0, per_page=25, include_totals=True):
149175
"""List the roles associated with a user.
150176

auth0/v3/test/management/test_users.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,32 @@ def test_update(self, mock_rc):
119119
self.assertEqual('https://domain/api/v2/users/an-id', args[0])
120120
self.assertEqual(kwargs['data'], {'a': 'b', 'c': 'd'})
121121

122+
@mock.patch('auth0.v3.management.users.RestClient')
123+
def test_list_organizations(self, mock_rc):
124+
mock_instance = mock_rc.return_value
125+
126+
u = Users(domain='domain', token='jwttoken')
127+
u.list_organizations('an-id')
128+
129+
args, kwargs = mock_instance.get.call_args
130+
self.assertEqual('https://domain/api/v2/users/an-id/organizations', args[0])
131+
self.assertEqual(kwargs['params'], {
132+
'per_page': 25,
133+
'page': 0,
134+
'include_totals': 'true'
135+
})
136+
137+
u.list_organizations(id='an-id', page=1, per_page=50, include_totals=False)
138+
139+
args, kwargs = mock_instance.get.call_args
140+
141+
self.assertEqual('https://domain/api/v2/users/an-id/organizations', args[0])
142+
self.assertEqual(kwargs['params'], {
143+
'per_page': 50,
144+
'page': 1,
145+
'include_totals': 'false'
146+
})
147+
122148
@mock.patch('auth0.v3.management.users.RestClient')
123149
def test_list_roles(self, mock_rc):
124150
mock_instance = mock_rc.return_value

0 commit comments

Comments
 (0)