Skip to content

Commit 9c34d66

Browse files
committed
add new API and fix int variables
1 parent b64aeea commit 9c34d66

File tree

2 files changed

+54
-27
lines changed

2 files changed

+54
-27
lines changed

databunkerpro/api.py

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,19 @@ def create_user(
254254
# Handle groupname/groupid
255255
if "groupname" in options:
256256
if str(options["groupname"]).isdigit():
257-
data["groupid"] = options["groupname"]
257+
data["groupid"] = int(options["groupname"])
258258
else:
259259
data["groupname"] = options["groupname"]
260260
elif "groupid" in options:
261-
data["groupid"] = options["groupid"]
261+
data["groupid"] = int(options["groupid"])
262262
# Handle rolename/roleid
263263
if "rolename" in options:
264264
if str(options["rolename"]).isdigit():
265-
data["roleid"] = options["rolename"]
265+
data["roleid"] = int(options["rolename"])
266266
else:
267267
data["rolename"] = options["rolename"]
268268
elif "roleid" in options:
269-
data["roleid"] = options["roleid"]
269+
data["roleid"] = int(options["roleid"])
270270
# Handle time parameters
271271
if "slidingtime" in options:
272272
data["slidingtime"] = options["slidingtime"]
@@ -312,29 +312,17 @@ def create_users_bulk(
312312
{
313313
"profile": record["profile"],
314314
**(
315-
{
316-
(
317-
"groupid"
318-
if str(record.get("groupname", "")).isdigit()
319-
else "groupname"
320-
): record["groupname"]
321-
}
322-
if "groupname" in record
323-
else {}
315+
{"groupid": int(record["groupname"])}
316+
if "groupname" in record and str(record.get("groupname", "")).isdigit()
317+
else ({"groupname": record["groupname"]} if "groupname" in record else {})
324318
),
325-
**({"groupid": record["groupid"]} if "groupid" in record else {}),
319+
**({"groupid": int(record["groupid"])} if "groupid" in record else {}),
326320
**(
327-
{
328-
(
329-
"roleid"
330-
if str(record.get("rolename", "")).isdigit()
331-
else "rolename"
332-
): record["rolename"]
333-
}
334-
if "rolename" in record
335-
else {}
321+
{"roleid": int(record["rolename"])}
322+
if "rolename" in record and str(record.get("rolename", "")).isdigit()
323+
else ({"rolename": record["rolename"]} if "rolename" in record else {})
336324
),
337-
**({"roleid": record["roleid"]} if "roleid" in record else {}),
325+
**({"roleid": int(record["roleid"])} if "roleid" in record else {}),
338326
}
339327
for record in records
340328
]
@@ -1169,7 +1157,7 @@ def update_group(
11691157
) -> Dict[str, Any]:
11701158
"""Update group information."""
11711159
data = {**options}
1172-
data["groupid"] = group_id
1160+
data["groupid"] = int(group_id)
11731161
return self._make_request("GroupUpdate", data, request_metadata)
11741162

11751163
def delete_group(
@@ -1367,7 +1355,7 @@ def update_role(
13671355
"""Update role information."""
13681356
data = {**options}
13691357
if isinstance(role_id, int) or str(role_id).isdigit():
1370-
data["roleid"] = role_id
1358+
data["roleid"] = int(role_id)
13711359
else:
13721360
data["rolename"] = str(role_id)
13731361
return self._make_request("RoleUpdate", data, request_metadata)
@@ -1598,6 +1586,45 @@ def search_user_profiles(
15981586
}
15991587
return self._make_request("SystemSearchUserProfiles", data, request_metadata)
16001588

1589+
def delete_user_profiles(
1590+
self,
1591+
mode: str,
1592+
identity: str,
1593+
unlock_uuid: str,
1594+
tenant_ref: Optional[Union[str, int]] = None,
1595+
request_metadata: Optional[Dict[str, Any]] = None,
1596+
) -> Dict[str, Any]:
1597+
"""Delete user profiles across all tenants. Only accessible by the main tenant admin."""
1598+
data: Dict[str, Any] = {
1599+
"mode": mode,
1600+
"identity": identity,
1601+
"unlockuuid": unlock_uuid,
1602+
}
1603+
if tenant_ref is not None:
1604+
if isinstance(tenant_ref, int) or str(tenant_ref).isdigit():
1605+
data["tenantid"] = int(tenant_ref)
1606+
else:
1607+
data["tenantname"] = str(tenant_ref)
1608+
return self._make_request("SystemDeleteUserProfiles", data, request_metadata)
1609+
1610+
def restore_user_profile(
1611+
self,
1612+
token: str,
1613+
unlock_uuid: str,
1614+
tenant_ref: Union[str, int],
1615+
request_metadata: Optional[Dict[str, Any]] = None,
1616+
) -> Dict[str, Any]:
1617+
"""Restore a deleted user profile for a specific tenant. Only accessible by the main tenant admin."""
1618+
data: Dict[str, Any] = {
1619+
"token": token,
1620+
"unlockuuid": unlock_uuid,
1621+
}
1622+
if isinstance(tenant_ref, int) or str(tenant_ref).isdigit():
1623+
data["tenantid"] = int(tenant_ref)
1624+
else:
1625+
data["tenantname"] = str(tenant_ref)
1626+
return self._make_request("SystemRestoreUserProfile", data, request_metadata)
1627+
16011628
def get_user_report(
16021629
self,
16031630
mode: str,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="databunkerpro",
8-
version="0.1.3",
8+
version="0.1.4",
99
author="Databunker team",
1010
author_email="hello@databunker.org",
1111
description="Python client library for DatabunkerPro API",

0 commit comments

Comments
 (0)