Add user cards view
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
This commit is contained in:
parent
a2af2162f9
commit
83d72f355e
@ -2,7 +2,7 @@ from datetime import datetime, timedelta
|
|||||||
from dateutil.parser import parse, ParserError
|
from dateutil.parser import parse, ParserError
|
||||||
|
|
||||||
from bson.objectid import ObjectId
|
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 flask_wtf import FlaskForm
|
||||||
from pymongo import MongoClient
|
from pymongo import MongoClient
|
||||||
from wtforms import StringField, IntegerField, SelectField, BooleanField, DateTimeField, validators
|
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);
|
latest_swipes = db.inventory.find({"component": "doorboy", "type":"token"}).sort([("last_seen", -1)]).limit(10);
|
||||||
return render_template("doorboy.html", **locals())
|
return render_template("doorboy.html", **locals())
|
||||||
|
|
||||||
|
@page_doorboy.route("/m/doorboy/user/<username>/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")
|
@page_doorboy.route("/m/doorboy/admin")
|
||||||
@login_required(groups=["k-space:board", "k-space:kubernetes:admins"])
|
@login_required(groups=["k-space:board", "k-space:kubernetes:admins"])
|
||||||
def view_doorboy_admin():
|
def view_doorboy_admin():
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
-->
|
-->
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<p>Manage your keycards or keyfobs here:</p>
|
||||||
|
<a href="/m/doorboy/me" class="waves-effect waves-light btn"><i class="material-icons left">person</i>My cards</a>
|
||||||
|
|
||||||
<p>Recent door open requests via Slack or the buttons above</p>
|
<p>Recent door open requests via Slack or the buttons above</p>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
|
@ -13,8 +13,10 @@
|
|||||||
<ul class="collapsible-body collection collapsible-collection">
|
<ul class="collapsible-body collection collapsible-collection">
|
||||||
{% for u, t in last_seen.items() %}
|
{% for u, t in last_seen.items() %}
|
||||||
<li class="collection-item">
|
<li class="collection-item">
|
||||||
<i class="material-icons tiny">person</i>
|
<a href="/m/doorboy/user/{{u}}/cards">
|
||||||
{{u | display_name}}
|
<i class="material-icons tiny">person</i>
|
||||||
|
{{u | display_name}}
|
||||||
|
</a>
|
||||||
<div class="secondary-content black-text">
|
<div class="secondary-content black-text">
|
||||||
<i class="material-icons tiny">access_time</i>
|
<i class="material-icons tiny">access_time</i>
|
||||||
{{t | timeago}}
|
{{t | timeago}}
|
||||||
|
37
inventory-app/templates/doorboy_user.html
Normal file
37
inventory-app/templates/doorboy_user.html
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<h4>Doorboy info for {{subject_user.username | display_name}}</h4>
|
||||||
|
<br/>
|
||||||
|
<h5>Users cards:</h5>
|
||||||
|
<table class="striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Enabled</th>
|
||||||
|
<th>Comment</th>
|
||||||
|
<th>UID hash tail</th>
|
||||||
|
<th>Last seen</th>
|
||||||
|
<th> </th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for c in cards %}
|
||||||
|
<tr>
|
||||||
|
<td>{% if c.token.enabled %}<i class="material-icons">check_circle</i>{% else %} {% endif %}</td>
|
||||||
|
<td>{{ c.token.comment }}</td>
|
||||||
|
<td><a href="/m/doorboy/{{ c._id }}/events">{{ c.token.uid_hash[-6:] }}</a></td>
|
||||||
|
<td>{{ c.last_seen | timeago }}</td>
|
||||||
|
<td>
|
||||||
|
{% if is_self %}
|
||||||
|
<a href="/m/doorboy/{{ c._id }}/edit" class="waves-effect waves-light btn"><i class="material-icons left">edit</i>Edit</a>
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user