Skip to content

Commit 8d43dc4

Browse files
committed
Update apis
1 parent 2fe851c commit 8d43dc4

2 files changed

Lines changed: 30 additions & 21 deletions

File tree

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: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,42 +58,38 @@
5858

5959

6060
def create_storage_item(
61-
server_context: ServerContext, type: str, props: dict, container_path: str = None, audit_user_comment: str = None
61+
server_context: ServerContext, type: str, props: dict, container_path: str = None
6262
):
6363
"""
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:
69-
:param audit_user_comment: optional comment that will be attached to the audit log record for this storage change.
7070
:return:
7171
"""
7272
url = server_context.build_url(STORAGE_CONTROLLER, "create.api", container_path)
7373
payload = {"type": type, "props": props}
74-
if audit_user_comment is not None:
75-
payload["auditUserComment"] = audit_user_comment
7674

7775
return server_context.make_request(url, json=payload)
7876

7977

8078
def update_storage_item(
81-
server_context: ServerContext, type: str, props: dict, container_path: str = None, audit_user_comment: str = None
79+
server_context: ServerContext, type: str, props: dict, container_path: str = None
8280
):
8381
"""
8482
Update an existing LabKey Freezer Manager storage item to change its properties or location within the storage hierarchy.
8583
For update_storage_item, the "rowId" primary key value is required to be set within the props.
8684
:param server_context: A LabKey server context. See utils.create_server_context.
8785
:param type:
88-
: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.
8988
:param container_path:
90-
:param audit_user_comment: optional comment that will be attached to the audit log record for this storage change.
9189
:return:
9290
"""
9391
url = server_context.build_url(STORAGE_CONTROLLER, "update.api", container_path)
9492
payload = {"type": type, "props": props}
95-
if audit_user_comment is not None:
96-
payload["auditUserComment"] = audit_user_comment
9793

9894
return server_context.make_request(url, json=payload)
9995

@@ -109,13 +105,14 @@ def delete_storage_item(
109105
:param type:
110106
:param row_id:
111107
:param container_path:
112-
:param audit_user_comment: optional comment that will be attached to the audit log record for this storage change.
108+
:param audit_user_comment: optional reason text recorded as the "Reason" on the resulting audit event.
113109
:return:
114110
"""
115111
url = server_context.build_url(STORAGE_CONTROLLER, "delete.api", container_path)
116-
payload = {"type": type, "props": {"rowId": row_id}}
112+
props = {"rowId": row_id}
117113
if audit_user_comment is not None:
118-
payload["auditUserComment"] = audit_user_comment
114+
props["auditUserComment"] = audit_user_comment
115+
payload = {"type": type, "props": props}
119116

120117
return server_context.make_request(url, json=payload)
121118

@@ -129,12 +126,12 @@ def __init__(self, server_context: ServerContext):
129126
self.server_context = server_context
130127

131128
@functools.wraps(create_storage_item)
132-
def create_storage_item(self, type: str, props: dict, container_path: str = None, audit_user_comment: str = None):
133-
return create_storage_item(self.server_context, type, props, container_path, audit_user_comment)
129+
def create_storage_item(self, type: str, props: dict, container_path: str = None):
130+
return create_storage_item(self.server_context, type, props, container_path)
134131

135132
@functools.wraps(update_storage_item)
136-
def update_storage_item(self, type: str, props: dict, container_path: str = None, audit_user_comment: str = None):
137-
return update_storage_item(self.server_context, type, props, container_path, audit_user_comment)
133+
def update_storage_item(self, type: str, props: dict, container_path: str = None):
134+
return update_storage_item(self.server_context, type, props, container_path)
138135

139136
@functools.wraps(delete_storage_item)
140137
def delete_storage_item(self, type: str, row_id: int, container_path: str = None, audit_user_comment: str = None):

0 commit comments

Comments
 (0)