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

Skip to content

Commit b468e3a

Browse files
committed
add CRUD for organization invitations
1 parent dd935ec commit b468e3a

File tree

2 files changed

+124
-2
lines changed

2 files changed

+124
-2
lines changed

auth0/v3/management/organizations.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,66 @@ def delete_organization_member_roles(self, id, user_id, body):
271271
See: https://auth0.com/docs/api/management/v2#!/Clients/delete_clients_by_id
272272
"""
273273

274-
return self.client.delete(self._url(id, 'members', user_id, 'roles'), data=body)
274+
return self.client.delete(self._url(id, 'members', user_id, 'roles'), data=body)
275+
276+
277+
# Organization Invitations
278+
def all_organization_invitations(self, id, page=None, per_page=None):
279+
"""Retrieves a list of all the organization invitations.
280+
281+
Args:
282+
id (str): the ID of the organization.
283+
284+
page (int): The result's page number (zero based). When not set,
285+
the default value is up to the server.
286+
287+
per_page (int, optional): The amount of entries per page. When not set,
288+
the default value is up to the server.
289+
290+
See: https://auth0.com/docs/api/management/v2#!/Clients/get_clients
291+
"""
292+
params = {}
293+
params['page'] = page
294+
params['per_page'] = per_page
295+
296+
return self.client.get(self._url(id, 'invitations'), params=params)
297+
298+
def get_organization_invitation(self, id, invitaton_id):
299+
"""Retrieves an organization invitation by its ID.
300+
301+
Args:
302+
id (str): the ID of the organization.
303+
304+
invitaton_id (str): the ID of the invitation.
305+
306+
See: https://auth0.com/docs/api/management/v2#!/Clients/get_clients
307+
"""
308+
params = {}
309+
310+
return self.client.get(self._url(id, 'invitations', invitaton_id), params=params)
311+
312+
def create_organization_invitation(self, id, body):
313+
"""Create an invitation to an organization.
314+
315+
Args:
316+
id (str): the ID of the organization.
317+
318+
body (dict): Attributes for the invitation to create.
319+
320+
See: https://auth0.com/docs/api/v2#!/Clients/post_clients
321+
"""
322+
323+
return self.client.post(self._url(id, 'invitations'), data=body)
324+
325+
def delete_organization_invitation(self, id, invitation_id):
326+
"""Deletes an invitation from the given organization.
327+
328+
Args:
329+
id (str): Id of organization.
330+
331+
invitation_id (str): the ID of the invitation to delete.
332+
333+
See: https://auth0.com/docs/api/management/v2#!/Clients/delete_clients_by_id
334+
"""
335+
336+
return self.client.delete(self._url(id, 'invitations', invitation_id))

auth0/v3/test/management/test_organizations.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,64 @@ def test_delete_organization_member_roles(self, mock_rc):
251251
mock_instance.delete.assert_called_with(
252252
'https://domain/api/v2/organizations/test-org/members/test-user/roles',
253253
data={'a': 'b', 'c': 'd'}
254-
)
254+
)
255+
256+
# Organization Invitations
257+
@mock.patch('auth0.v3.management.organizations.RestClient')
258+
def test_all_organization_invitations(self, mock_rc):
259+
mock_instance = mock_rc.return_value
260+
261+
c = Organizations(domain='domain', token='jwttoken')
262+
263+
# Default parameters are requested
264+
c.all_organization_invitations('test-org')
265+
266+
args, kwargs = mock_instance.get.call_args
267+
268+
self.assertEqual('https://domain/api/v2/organizations/test-org/invitations', args[0])
269+
self.assertEqual(kwargs['params'], {'page': None,
270+
'per_page': None})
271+
272+
# Specific pagination
273+
c.all_organization_invitations('test-org', page=7, per_page=25)
274+
275+
args, kwargs = mock_instance.get.call_args
276+
277+
self.assertEqual('https://domain/api/v2/organizations/test-org/invitations', args[0])
278+
self.assertEqual(kwargs['params'], {'page': 7,
279+
'per_page': 25})
280+
281+
@mock.patch('auth0.v3.management.organizations.RestClient')
282+
def test_get_organization_invitation(self, mock_rc):
283+
mock_instance = mock_rc.return_value
284+
285+
c = Organizations(domain='domain', token='jwttoken')
286+
c.get_organization_invitation('test-org', 'test-inv')
287+
288+
args, kwargs = mock_instance.get.call_args
289+
290+
self.assertEqual('https://domain/api/v2/organizations/test-org/invitations/test-inv', args[0])
291+
self.assertEqual(kwargs['params'], {})
292+
293+
@mock.patch('auth0.v3.management.organizations.RestClient')
294+
def test_create_organization_invitation(self, mock_rc):
295+
mock_instance = mock_rc.return_value
296+
297+
c = Organizations(domain='domain', token='jwttoken')
298+
c.create_organization_invitation('test-org', {'a': 'b', 'c': 'd'})
299+
300+
mock_instance.post.assert_called_with(
301+
'https://domain/api/v2/organizations/test-org/invitations',
302+
data={'a': 'b', 'c': 'd'}
303+
)
304+
305+
@mock.patch('auth0.v3.management.organizations.RestClient')
306+
def test_delete_organization_invitation(self, mock_rc):
307+
mock_instance = mock_rc.return_value
308+
309+
c = Organizations(domain='domain', token='jwttoken')
310+
c.delete_organization_invitation('test-org', 'test-inv')
311+
312+
mock_instance.delete.assert_called_with(
313+
'https://domain/api/v2/organizations/test-org/invitations/test-inv'
314+
)

0 commit comments

Comments
 (0)