Add audit history
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2024-08-06 15:43:48 +03:00
parent aa76374f1f
commit 495ddd3e21
2 changed files with 38 additions and 7 deletions

View File

@@ -447,14 +447,29 @@ def view_inventory(slug=None):
@login_required(groups=["k-space:janitors"])
def view_inventory_audit(item_id):
user = read_user()
db.inventory.update_one({
"_id": ObjectId(item_id),
}, {
item = db.inventory.find_one(filter = {
"_id": ObjectId(item_id)
}, projection = {
"inventory.audit": 1
})
q = {
"$set": {
"inventory.audit.username": user["username"],
"inventory.audit.timestamp": datetime.utcnow(),
},
})
}
if item["inventory"].get("audit"):
q["$push"] = {
"inventory.audit.log": {
"username": item["inventory"]["audit"]["username"],
"timestamp": item["inventory"]["audit"]["timestamp"],
}
}
db.inventory.update_one({
"_id": ObjectId(item_id)
}, q)
if request.form and request.form.get("noRedirect", False):
return {}
else: