accounts: Add list view
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from decimal import Decimal
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, File, Form, HTTPException, Request
|
||||
@@ -8,7 +7,14 @@ from starlette.responses import RedirectResponse
|
||||
|
||||
from allmende_payment_system import types
|
||||
from allmende_payment_system.api.dependencies import SessionDep, UserDep
|
||||
from allmende_payment_system.models import Area, Permission, Product, User, UserGroup
|
||||
from allmende_payment_system.models import (
|
||||
Account,
|
||||
Area,
|
||||
Permission,
|
||||
Product,
|
||||
User,
|
||||
UserGroup,
|
||||
)
|
||||
from allmende_payment_system.tools import get_jinja_renderer
|
||||
|
||||
admin_router = APIRouter(prefix="/admin")
|
||||
@@ -276,3 +282,22 @@ async def new_product_post(
|
||||
return RedirectResponse(
|
||||
url="/admin/products", status_code=status.HTTP_303_SEE_OTHER
|
||||
)
|
||||
|
||||
|
||||
@admin_router.get("/accounts")
|
||||
async def get_accounts(
|
||||
request: Request,
|
||||
session: SessionDep,
|
||||
user: UserDep,
|
||||
):
|
||||
if not user.has_permission("account", "edit"):
|
||||
raise HTTPException(status_code=403, detail="Insufficient permissions")
|
||||
|
||||
templates = get_jinja_renderer()
|
||||
|
||||
accounts = session.scalars(select(Account)).all()
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"accounts.html.jinja",
|
||||
context={"request": request, "accounts": accounts},
|
||||
)
|
||||
|
||||
@@ -30,7 +30,10 @@ async def get_user(request: Request) -> dict:
|
||||
if "ynh_user" not in request.headers:
|
||||
raise HTTPException(status_code=401, detail="Missing ynh_user header")
|
||||
|
||||
return {"username": request.headers["ynh_user"], "display_name": request.headers["ynh_user_fullname"]}
|
||||
return {
|
||||
"username": request.headers["ynh_user"],
|
||||
"display_name": request.headers["ynh_user_fullname"],
|
||||
}
|
||||
|
||||
|
||||
async def get_user_object(request: Request, session: SessionDep) -> User:
|
||||
|
||||
35
src/allmende_payment_system/templates/accounts.html.jinja
Normal file
35
src/allmende_payment_system/templates/accounts.html.jinja
Normal file
@@ -0,0 +1,35 @@
|
||||
{% extends "base.html.jinja" %}
|
||||
{% block content %}
|
||||
<div class="mb-4">
|
||||
<h2 class="h4 mb-3">Konten verwalten</h2>
|
||||
<a class="btn btn-primary" href="/admin/accounts/new">Neues Konto erstellen</a>
|
||||
</div>
|
||||
|
||||
{% if accounts|length == 0 %}
|
||||
<div class="alert alert-info">Keine Konten vorhanden.</div>
|
||||
{% else %}
|
||||
<div class="table-responsive">
|
||||
<table class="table align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Nutzer</th>
|
||||
<th>Kontostand</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for account in accounts %}
|
||||
<tr>
|
||||
<td>{{ account.name }}</td>
|
||||
<td>{{ account.users | map(attribute='display_name') | join(", ") }}</td>
|
||||
<td>{{ account.balance | format_number }} €</td>
|
||||
<td> actions </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
@@ -48,6 +48,13 @@
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if request.state.user.has_permission("account", "edit") %}
|
||||
<li class="nav-item">
|
||||
<a href="/admin/accounts" class="nav-link{% if request.url.path.startswith("/admin/accounts")%} active{% endif %}">
|
||||
Kontenverwaltung
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
<!-- Shopping Cart at Bottom -->
|
||||
|
||||
Reference in New Issue
Block a user