Skip to content

Commit 93fceb9

Browse files
committed
Allow searching for users with all roles in a tenant
1 parent 3770d75 commit 93fceb9

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

descope/management/common.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,3 @@ def sort_to_dict(sort: List[Sort]) -> list:
407407
}
408408
)
409409
return sort_list
410-
411-
412-
def map_to_values_object(input_map: dict):
413-
if not input_map:
414-
return {}
415-
return {k: {"values": v} for k, v in input_map.items()}

descope/management/user.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,9 @@ def search_all(
666666
to_modified_time (int): Optional int, only include users whose last modification/update occurred on or before this time (in Unix epoch milliseconds)
667667
user_ids (List[str]): Optional list of user IDs to filter by
668668
tenant_role_ids (dict): Optional mapping of tenant ID to list of role IDs.
669+
Dict value is in the form of {"tenant_id": {"values":["role_id1", "role_id2"], "and": True}} if you want to match all roles (AND) or any role (OR).
669670
tenant_role_names (dict): Optional mapping of tenant ID to list of role names.
671+
Dict value is in the form of {"tenant_id": {"values":["role_name1", "role_name2"], "and": True}} if you want to match all roles (AND) or any role (OR).
670672
671673
Return value (dict):
672674
Return dict in the format
@@ -733,9 +735,9 @@ def search_all(
733735
body["toModifiedTime"] = to_modified_time
734736

735737
if tenant_role_ids is not None:
736-
body["tenantRoleIds"] = map_to_values_object(tenant_role_ids)
738+
body["tenantRoleIds"] = tenant_role_ids
737739
if tenant_role_names is not None:
738-
body["tenantRoleNames"] = map_to_values_object(tenant_role_names)
740+
body["tenantRoleNames"] = tenant_role_names
739741

740742
response = self._auth.do_post(
741743
MgmtV1.users_search_path,
@@ -786,7 +788,9 @@ def search_all_test_users(
786788
from_modified_time (int): Optional int, only include users whose last modification/update occurred on or after this time (in Unix epoch milliseconds)
787789
to_modified_time (int): Optional int, only include users whose last modification/update occurred on or before this time (in Unix epoch milliseconds)
788790
tenant_role_ids (dict): Optional mapping of tenant ID to list of role IDs.
791+
Dict value is in the form of {"tenant_id": {"values":["role_id1", "role_id2"], "and": True}} if you want to match all roles (AND) or any role (OR).
789792
tenant_role_names (dict): Optional mapping of tenant ID to list of role names.
793+
Dict value is in the form of {"tenant_id": {"values":["role_name1", "role_name2"], "and": True}} if you want to match all roles (AND) or any role (OR).
790794
791795
Return value (dict):
792796
Return dict in the format
@@ -850,9 +854,9 @@ def search_all_test_users(
850854
body["toModifiedTime"] = to_modified_time
851855

852856
if tenant_role_ids is not None:
853-
body["tenantRoleIds"] = map_to_values_object(tenant_role_ids)
857+
body["tenantRoleIds"] = tenant_role_ids
854858
if tenant_role_names is not None:
855-
body["tenantRoleNames"] = map_to_values_object(tenant_role_names)
859+
body["tenantRoleNames"] = tenant_role_names
856860

857861
response = self._auth.do_post(
858862
MgmtV1.test_users_search_path,

tests/management/test_user.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def test_invite_batch(self):
323323
users = resp["users"]
324324
self.assertEqual(users[0]["id"], "u1")
325325

326-
expectedUsers = {
326+
expected_users = {
327327
"users": [
328328
{
329329
"loginId": "[email protected]",
@@ -369,7 +369,7 @@ def test_invite_batch(self):
369369
"x-descope-project-id": self.dummy_project_id,
370370
},
371371
params=None,
372-
json=expectedUsers,
372+
json=expected_users,
373373
allow_redirects=False,
374374
verify=True,
375375
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -403,8 +403,8 @@ def test_invite_batch(self):
403403
send_sms=True,
404404
)
405405

406-
del expectedUsers["users"][0]["hashedPassword"]
407-
expectedUsers["users"][0]["password"] = "clear"
406+
del expected_users["users"][0]["hashedPassword"]
407+
expected_users["users"][0]["password"] = "clear"
408408
mock_post.assert_called_with(
409409
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_create_batch_path}",
410410
headers={
@@ -413,7 +413,7 @@ def test_invite_batch(self):
413413
"x-descope-project-id": self.dummy_project_id,
414414
},
415415
params=None,
416-
json=expectedUsers,
416+
json=expected_users,
417417
allow_redirects=False,
418418
verify=True,
419419
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -426,7 +426,7 @@ def test_invite_batch(self):
426426
send_sms=True,
427427
)
428428

429-
del expectedUsers["users"][0]["password"]
429+
del expected_users["users"][0]["password"]
430430
mock_post.assert_called_with(
431431
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_create_batch_path}",
432432
headers={
@@ -435,7 +435,7 @@ def test_invite_batch(self):
435435
"x-descope-project-id": self.dummy_project_id,
436436
},
437437
params=None,
438-
json=expectedUsers,
438+
json=expected_users,
439439
allow_redirects=False,
440440
verify=True,
441441
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -1056,8 +1056,8 @@ def test_search_all(self):
10561056
)
10571057
mock_post.return_value = network_resp
10581058
resp = self.client.mgmt.user.search_all(
1059-
tenant_role_ids={"tenant1": ["roleA", "roleB"]},
1060-
tenant_role_names={"tenant2": ["admin", "user"]},
1059+
tenant_role_ids={"tenant1": {"values": ["roleA", "roleB"], "and": True}},
1060+
tenant_role_names={"tenant2": {"values": ["admin", "user"], "and": False}},
10611061
)
10621062
users = resp["users"]
10631063
self.assertEqual(len(users), 2)
@@ -1078,8 +1078,8 @@ def test_search_all(self):
10781078
"page": 0,
10791079
"testUsersOnly": False,
10801080
"withTestUser": False,
1081-
"tenantRoleIds": {"tenant1": {"values": ["roleA", "roleB"]}},
1082-
"tenantRoleNames": {"tenant2": {"values": ["admin", "user"]}},
1081+
"tenantRoleIds": {"tenant1": {"values": ["roleA", "roleB"], "and": True}},
1082+
"tenantRoleNames": {"tenant2": {"values": ["admin", "user"], "and": False}},
10831083
},
10841084
allow_redirects=False,
10851085
verify=True,
@@ -1324,8 +1324,8 @@ def test_search_all_test_users(self):
13241324
"page": 0,
13251325
"testUsersOnly": True,
13261326
"withTestUser": True,
1327-
"tenantRoleIds": {"tenant1": {"values": ["roleA", "roleB"]}},
1328-
"tenantRoleNames": {"tenant2": {"values": ["admin", "user"]}},
1327+
"tenantRoleIds": {"tenant1": {"values": ["roleA", "roleB"], "and": True}},
1328+
"tenantRoleNames": {"tenant2": {"values": ["admin", "user"], "and": False}},
13291329
},
13301330
allow_redirects=False,
13311331
verify=True,

0 commit comments

Comments
 (0)