From 83d72f355e93386036901b0c568c2e4d27177ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20M=C3=A4gi?= Date: Mon, 14 Aug 2023 04:35:27 +0300 Subject: [PATCH] Add user cards view --- inventory-app/doorboy.py | 26 ++++++++++++++- inventory-app/templates/doorboy.html | 3 ++ inventory-app/templates/doorboy_admin.html | 6 ++-- inventory-app/templates/doorboy_user.html | 37 ++++++++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 inventory-app/templates/doorboy_user.html diff --git a/inventory-app/doorboy.py b/inventory-app/doorboy.py index ce54717..4a35ec0 100644 --- a/inventory-app/doorboy.py +++ b/inventory-app/doorboy.py @@ -2,7 +2,7 @@ from datetime import datetime, timedelta from dateutil.parser import parse, ParserError from bson.objectid import ObjectId -from flask import Blueprint, g, redirect, render_template, request +from flask import Blueprint, g, redirect, render_template, request, abort from flask_wtf import FlaskForm from pymongo import MongoClient from wtforms import StringField, IntegerField, SelectField, BooleanField, DateTimeField, validators @@ -195,6 +195,30 @@ def view_doorboy(): latest_swipes = db.inventory.find({"component": "doorboy", "type":"token"}).sort([("last_seen", -1)]).limit(10); return render_template("doorboy.html", **locals()) +@page_doorboy.route("/m/doorboy/user//cards") +@login_required(groups=["k-space:board", "k-space:kubernetes:admins"]) +def view_user_cards(username): + return view_user_cards_inner(username) + +@page_doorboy.route("/m/doorboy/me") +@login_required +def view_own_cards(): + user = read_user() + return view_user_cards_inner(user["username"]) + +def view_user_cards_inner(username): + user = read_user() + subject_user = users_lookup.get(username) + if not subject_user: + return abort(404) + is_self = user["username"] == subject_user["username"] + cards = db.inventory.find({ + "component": "doorboy", + "type":"token", + "inventory.owner.username": username + }).sort([("last_seen", -1)]) + return render_template("doorboy_user.html", **locals()) + @page_doorboy.route("/m/doorboy/admin") @login_required(groups=["k-space:board", "k-space:kubernetes:admins"]) def view_doorboy_admin(): diff --git a/inventory-app/templates/doorboy.html b/inventory-app/templates/doorboy.html index ed2025f..8faa6e3 100644 --- a/inventory-app/templates/doorboy.html +++ b/inventory-app/templates/doorboy.html @@ -14,6 +14,9 @@ --> +

Manage your keycards or keyfobs here:

+personMy cards +

Recent door open requests via Slack or the buttons above

diff --git a/inventory-app/templates/doorboy_admin.html b/inventory-app/templates/doorboy_admin.html index a8dfbe5..4989b4f 100644 --- a/inventory-app/templates/doorboy_admin.html +++ b/inventory-app/templates/doorboy_admin.html @@ -13,8 +13,10 @@
+ + + + + + + + + + + {% for c in cards %} + + + + + + + + {% endfor %} + +
EnabledCommentUID hash tailLast seen 
{% if c.token.enabled %}check_circle{% else %} {% endif %}{{ c.token.comment }}{{ c.token.uid_hash[-6:] }}{{ c.last_seen | timeago }} + {% if is_self %} + editEdit + {% else %} +   + {% endif %} +
+ +{% endblock %}