Skip to content

Commit 4fb7a1d

Browse files
authored
Allow require reason on storage changes (#93)
1 parent 92dbbcc commit 4fb7a1d

4 files changed

Lines changed: 35 additions & 11 deletions

File tree

CHANGE.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
LabKey Python Client API News
33
+++++++++++
44

5+
What's New in the LabKey 4.3.0 package
6+
==============================
7+
8+
*Release date: 06/29/2026*
9+
- Freezer Manager API - add `auditUserComment` to create/update/delete_storage_item
10+
511
What's New in the LabKey 4.2.0 package
612
==============================
713

docs/storage.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,17 @@ else:
110110
box_id = result["data"]["rowId"]
111111

112112
###############
113-
# Update the location of a box in the freezer
113+
# Update the location of a box in the freezer. An optional "auditUserComment"
114+
# property may be included in the props dict; it is recorded as the "Reason"
115+
# on the resulting audit event.
114116
###############
115117
result = api.storage.update_storage_item(
116-
"Terminal Storage Location", {"rowId": box_id, "locationId": shelf2_row_id}
118+
"Terminal Storage Location",
119+
{
120+
"rowId": box_id,
121+
"locationId": shelf2_row_id,
122+
"auditUserComment": "Relocated to make room for incoming samples from Lab B.",
123+
},
117124
)
118125
if result is not None:
119126
print(result)
@@ -122,9 +129,14 @@ else:
122129
exit()
123130

124131
###############
125-
# Delete the freezer, which will delete the full hierarchy of non-terminal and terminal storage locations
132+
# Delete the freezer, which will delete the full hierarchy of non-terminal and terminal
133+
# storage locations. An optional audit_user_comment is supplied here for the audit log.
126134
###############
127-
result = api.storage.delete_storage_item("Freezer", freezer_row_id)
135+
result = api.storage.delete_storage_item(
136+
"Freezer",
137+
freezer_row_id,
138+
audit_user_comment="Decommissioning Freezer #1 per facilities request.",
139+
)
128140
if result is not None:
129141
print(result)
130142
else:

labkey/storage.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def create_storage_item(
6464
Create a new LabKey Freezer Manager storage item that can be used in the creation of a storage hierarchy.
6565
:param server_context: A LabKey server context. See utils.create_server_context.
6666
:param type:
67-
:param props:
67+
:param props: a dict of property values for the storage item. Any storage item type also accepts an optional
68+
"auditUserComment" (string) entry, which is recorded as the "Reason" on the resulting audit event.
6869
:param container_path:
6970
:return:
7071
"""
@@ -82,7 +83,8 @@ def update_storage_item(
8283
For update_storage_item, the "rowId" primary key value is required to be set within the props.
8384
:param server_context: A LabKey server context. See utils.create_server_context.
8485
:param type:
85-
:param props:
86+
:param props: a dict of property values for the storage item. Any storage item type also accepts an optional
87+
"auditUserComment" (string) entry, which is recorded as the "Reason" on the resulting audit event.
8688
:param container_path:
8789
:return:
8890
"""
@@ -93,7 +95,7 @@ def update_storage_item(
9395

9496

9597
def delete_storage_item(
96-
server_context: ServerContext, type: str, row_id: int, container_path: str = None
98+
server_context: ServerContext, type: str, row_id: int, container_path: str = None, audit_user_comment: str = None
9799
):
98100
"""
99101
Delete an existing LabKey Freezer Manager storage item. Note that deletion of freezers, primary storage, or locations
@@ -103,10 +105,14 @@ def delete_storage_item(
103105
:param type:
104106
:param row_id:
105107
:param container_path:
108+
:param audit_user_comment: optional reason text recorded as the "Reason" on the resulting audit event.
106109
:return:
107110
"""
108111
url = server_context.build_url(STORAGE_CONTROLLER, "delete.api", container_path)
109-
payload = {"type": type, "props": {"rowId": row_id}}
112+
props = {"rowId": row_id}
113+
if audit_user_comment is not None:
114+
props["auditUserComment"] = audit_user_comment
115+
payload = {"type": type, "props": props}
110116

111117
return server_context.make_request(url, json=payload)
112118

@@ -128,5 +134,5 @@ def update_storage_item(self, type: str, props: dict, container_path: str = None
128134
return update_storage_item(self.server_context, type, props, container_path)
129135

130136
@functools.wraps(delete_storage_item)
131-
def delete_storage_item(self, type: str, row_id: int, container_path: str = None):
132-
return delete_storage_item(self.server_context, type, row_id, container_path)
137+
def delete_storage_item(self, type: str, row_id: int, container_path: str = None, audit_user_comment: str = None):
138+
return delete_storage_item(self.server_context, type, row_id, container_path, audit_user_comment)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name="labkey"
7-
version = "4.2.0"
7+
version = "4.3.0"
88
description = "Python client API for LabKey Server"
99
dependencies = ["requests>=2.32.5"]
1010
readme = "README.md"

0 commit comments

Comments
 (0)