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 %}