From e67f00652b66c38cde5e17e95461057ec8579ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20M=C3=A4gi?= Date: Tue, 29 Aug 2023 20:47:53 +0300 Subject: [PATCH] Add inventory audit feature --- inventory-app/inventory.py | 15 +++++ inventory-app/templates/inventory_view.html | 72 +++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/inventory-app/inventory.py b/inventory-app/inventory.py index 73fc975..2a5be19 100644 --- a/inventory-app/inventory.py +++ b/inventory-app/inventory.py @@ -1,5 +1,6 @@ import boto3 import pymongo +from datetime import datetime from bson.objectid import ObjectId from flask import Blueprint, abort, g, make_response, redirect, render_template, request from jpegtran import JPEGImage @@ -398,6 +399,20 @@ def view_inventory(slug=None): return render_template(template, **locals()) +@page_inventory.route("/m/inventory//audit", methods=["POST"]) +@login_required(groups=["k-space:janitors"]) +def view_inventory_audit(item_id): + user = read_user() + db.inventory.update_one({ + "_id": ObjectId(item_id), + }, { + "$set": { + "inventory.audit.username": user["username"], + "inventory.audit.timestamp": datetime.utcnow(), + }, + }) + return redirect("/m/inventory/%s/view" % item_id) + @page_inventory.route("/m/inventory//claim", methods=["POST"]) @login_required def view_inventory_claim(item_id): diff --git a/inventory-app/templates/inventory_view.html b/inventory-app/templates/inventory_view.html index d774e55..869c49f 100644 --- a/inventory-app/templates/inventory_view.html +++ b/inventory-app/templates/inventory_view.html @@ -65,6 +65,19 @@ {{ item.inventory.get("user").username | display_name }} + + Last audited + + {% if item.inventory.get("audit") %} + {{ item.inventory.audit.timestamp | timeago }} + by + {{ item.inventory.audit.username | display_name }} + {% else %} + Never + {% endif %} + + + URL slug @@ -149,6 +162,48 @@ +{% if can_audit %} +
+
+ +
+
+ +{% endif %} + {% endblock %}