Add clamp connection
This commit is contained in:
1 parent
0168b023af
commit
59184124e7
14 files changed
+452
-2
No files matched your search
@@ -0,0 +1,29 @@
|
|||||||
|
"""add clamp_connections
|
||||||
|
|
||||||
|
Revision ID: c7882cedc9ae
|
||||||
|
Revises: bfbce324cd5f
|
||||||
|
Create Date: 2026-07-02 13:31:57.064381
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = 'c7882cedc9ae'
|
||||||
|
down_revision: Union[str, None] = 'bfbce324cd5f'
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
pass
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
pass
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
from app.core.database import get_db
|
||||||
|
from app.crud import audit as audit_crud
|
||||||
|
from app.crud import clamp_connection as clamp_connection_crud
|
||||||
|
from app.deps import require_permission
|
||||||
|
from app.models.user import User
|
||||||
|
from app.schemas.clamp_connection import (
|
||||||
|
ClampConnectionCreate,
|
||||||
|
ClampConnectionRead,
|
||||||
|
ClampConnectionUpdate,
|
||||||
|
)
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("", response_model=list[ClampConnectionRead])
|
||||||
|
async def list_clamp_connections(
|
||||||
|
skip: int = 0,
|
||||||
|
limit: int = 100,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
_: User = Depends(require_permission("clamp_connections:read")),
|
||||||
|
):
|
||||||
|
return await clamp_connection_crud.list_all(db, skip=skip, limit=limit)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("", response_model=ClampConnectionRead, status_code=status.HTTP_201_CREATED)
|
||||||
|
async def create_clamp_connection(
|
||||||
|
payload: ClampConnectionCreate,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(require_permission("clamp_connections:write")),
|
||||||
|
):
|
||||||
|
cc = await clamp_connection_crud.create(
|
||||||
|
db,
|
||||||
|
min_mm=payload.min_mm,
|
||||||
|
max_mm=payload.max_mm,
|
||||||
|
min_in=payload.min_in,
|
||||||
|
max_in=payload.max_in,
|
||||||
|
)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="create", resource_type="ClampConnection",
|
||||||
|
resource_id=cc.id,
|
||||||
|
description=audit_crud.describe_create(
|
||||||
|
"ClampConnection", cc.id,
|
||||||
|
f"{cc.min_mm}–{cc.max_mm} mm" if cc.min_mm is not None else f"{cc.min_in}–{cc.max_in} in",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return cc
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/{clamp_connection_id}", response_model=ClampConnectionRead)
|
||||||
|
async def get_clamp_connection(
|
||||||
|
clamp_connection_id: int,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
_: User = Depends(require_permission("clamp_connections:read")),
|
||||||
|
):
|
||||||
|
cc = await clamp_connection_crud.get(db, clamp_connection_id)
|
||||||
|
if cc is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Clamp connection not found")
|
||||||
|
return cc
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/{clamp_connection_id}", response_model=ClampConnectionRead)
|
||||||
|
async def update_clamp_connection(
|
||||||
|
clamp_connection_id: int,
|
||||||
|
payload: ClampConnectionUpdate,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(require_permission("clamp_connections:write")),
|
||||||
|
):
|
||||||
|
cc = await clamp_connection_crud.get(db, clamp_connection_id)
|
||||||
|
if cc is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Clamp connection not found")
|
||||||
|
changes = payload.model_dump(exclude_unset=True)
|
||||||
|
cc = await clamp_connection_crud.update(db, cc, changes)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="update", resource_type="ClampConnection",
|
||||||
|
resource_id=cc.id,
|
||||||
|
description=audit_crud.describe_update("ClampConnection", cc.id, changes),
|
||||||
|
)
|
||||||
|
return cc
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/{clamp_connection_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
|
async def delete_clamp_connection(
|
||||||
|
clamp_connection_id: int,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(require_permission("clamp_connections:delete")),
|
||||||
|
):
|
||||||
|
cc = await clamp_connection_crud.get(db, clamp_connection_id)
|
||||||
|
if cc is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Clamp connection not found")
|
||||||
|
label = (
|
||||||
|
f"{cc.min_mm}–{cc.max_mm} mm" if cc.min_mm is not None
|
||||||
|
else f"{cc.min_in}–{cc.max_in} in"
|
||||||
|
)
|
||||||
|
await clamp_connection_crud.delete(db, cc)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="delete", resource_type="ClampConnection",
|
||||||
|
resource_id=clamp_connection_id,
|
||||||
|
description=audit_crud.describe_delete("ClampConnection", clamp_connection_id, label),
|
||||||
|
)
|
||||||
+2
-1
@@ -1,6 +1,6 @@
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|
||||||
from app.api import audit_log, augmented_parts, auth, imported_parts, iso_threads, manufacturers, part_colours, part_types, roles, scope_models, static_connections, sub_part_types, unc_threads, users
|
from app.api import audit_log, augmented_parts, auth, clamp_connections, imported_parts, iso_threads, manufacturers, part_colours, part_types, roles, scope_models, static_connections, sub_part_types, unc_threads, users
|
||||||
|
|
||||||
api_router = APIRouter()
|
api_router = APIRouter()
|
||||||
api_router.include_router(auth.router, prefix="/auth", tags=["auth"])
|
api_router.include_router(auth.router, prefix="/auth", tags=["auth"])
|
||||||
@@ -14,6 +14,7 @@ api_router.include_router(part_colours.router, prefix="/part-colours", tags=["pa
|
|||||||
api_router.include_router(part_types.router, prefix="/part-types", tags=["part-types"])
|
api_router.include_router(part_types.router, prefix="/part-types", tags=["part-types"])
|
||||||
api_router.include_router(sub_part_types.router, prefix="/sub-part-types", tags=["sub-part-types"])
|
api_router.include_router(sub_part_types.router, prefix="/sub-part-types", tags=["sub-part-types"])
|
||||||
api_router.include_router(static_connections.router, prefix="/static-connections", tags=["static-connections"])
|
api_router.include_router(static_connections.router, prefix="/static-connections", tags=["static-connections"])
|
||||||
|
api_router.include_router(clamp_connections.router, prefix="/clamp-connections", tags=["clamp-connections"])
|
||||||
api_router.include_router(imported_parts.router, prefix="/imported-parts", tags=["imported-parts"])
|
api_router.include_router(imported_parts.router, prefix="/imported-parts", tags=["imported-parts"])
|
||||||
api_router.include_router(augmented_parts.router, prefix="/augmented-parts", tags=["augmented-parts"])
|
api_router.include_router(augmented_parts.router, prefix="/augmented-parts", tags=["augmented-parts"])
|
||||||
api_router.include_router(audit_log.router, prefix="/audit-log", tags=["audit-log"])
|
api_router.include_router(audit_log.router, prefix="/audit-log", tags=["audit-log"])
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
from app.models.clamp_connection import ClampConnection
|
||||||
|
|
||||||
|
|
||||||
|
async def get(db: AsyncSession, clamp_connection_id: int) -> ClampConnection | None:
|
||||||
|
return await db.get(ClampConnection, clamp_connection_id)
|
||||||
|
|
||||||
|
|
||||||
|
async def list_all(
|
||||||
|
db: AsyncSession, skip: int = 0, limit: int = 100
|
||||||
|
) -> list[ClampConnection]:
|
||||||
|
result = await db.execute(
|
||||||
|
select(ClampConnection)
|
||||||
|
.order_by(ClampConnection.min_mm.nulls_last(), ClampConnection.min_in.nulls_last())
|
||||||
|
.offset(skip)
|
||||||
|
.limit(limit)
|
||||||
|
)
|
||||||
|
return list(result.scalars().all())
|
||||||
|
|
||||||
|
|
||||||
|
async def create(
|
||||||
|
db: AsyncSession,
|
||||||
|
*,
|
||||||
|
min_mm: float | None,
|
||||||
|
max_mm: float | None,
|
||||||
|
min_in: float | None,
|
||||||
|
max_in: float | None,
|
||||||
|
) -> ClampConnection:
|
||||||
|
cc = ClampConnection(min_mm=min_mm, max_mm=max_mm, min_in=min_in, max_in=max_in)
|
||||||
|
db.add(cc)
|
||||||
|
await db.commit()
|
||||||
|
await db.refresh(cc)
|
||||||
|
return cc
|
||||||
|
|
||||||
|
|
||||||
|
async def update(
|
||||||
|
db: AsyncSession, cc: ClampConnection, data: dict
|
||||||
|
) -> ClampConnection:
|
||||||
|
for field, value in data.items():
|
||||||
|
setattr(cc, field, value)
|
||||||
|
await db.commit()
|
||||||
|
await db.refresh(cc)
|
||||||
|
return cc
|
||||||
|
|
||||||
|
|
||||||
|
async def delete(db: AsyncSession, cc: ClampConnection) -> None:
|
||||||
|
await db.delete(cc)
|
||||||
|
await db.commit()
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
from app.models.associations import augmented_part_imported_parts, role_permissions, user_roles
|
from app.models.associations import augmented_part_imported_parts, role_permissions, user_roles
|
||||||
from app.models.audit_log import AuditLog
|
from app.models.audit_log import AuditLog
|
||||||
from app.models.augmented_part import AugmentedPart
|
from app.models.augmented_part import AugmentedPart
|
||||||
|
from app.models.clamp_connection import ClampConnection
|
||||||
from app.models.imported_part import ImportedPart
|
from app.models.imported_part import ImportedPart
|
||||||
from app.models.imported_part_config import ImportedPartConfig
|
from app.models.imported_part_config import ImportedPartConfig
|
||||||
from app.models.iso_thread import IsoThread
|
from app.models.iso_thread import IsoThread
|
||||||
@@ -21,6 +22,7 @@ from app.models.user import User
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
"AuditLog",
|
"AuditLog",
|
||||||
"AugmentedPart",
|
"AugmentedPart",
|
||||||
|
"ClampConnection",
|
||||||
"ImportedPart",
|
"ImportedPart",
|
||||||
"ImportedPartConfig",
|
"ImportedPartConfig",
|
||||||
"IsoThread",
|
"IsoThread",
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
from sqlalchemy import Float
|
||||||
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
|
||||||
|
from app.core.database import Base
|
||||||
|
|
||||||
|
|
||||||
|
class ClampConnection(Base):
|
||||||
|
__tablename__ = "clamp_connections"
|
||||||
|
|
||||||
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||||||
|
min_mm: Mapped[float | None] = mapped_column(Float, nullable=True, default=None)
|
||||||
|
max_mm: Mapped[float | None] = mapped_column(Float, nullable=True, default=None)
|
||||||
|
min_in: Mapped[float | None] = mapped_column(Float, nullable=True, default=None)
|
||||||
|
max_in: Mapped[float | None] = mapped_column(Float, nullable=True, default=None)
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
|
||||||
|
class ClampConnectionBase(BaseModel):
|
||||||
|
min_mm: float | None = None
|
||||||
|
max_mm: float | None = None
|
||||||
|
min_in: float | None = None
|
||||||
|
max_in: float | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class ClampConnectionCreate(ClampConnectionBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ClampConnectionUpdate(ClampConnectionBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ClampConnectionRead(ClampConnectionBase):
|
||||||
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
id: int
|
||||||
@@ -41,6 +41,9 @@
|
|||||||
{% if user.is_superuser or "static_connections:read" in user.permissions %}
|
{% if user.is_superuser or "static_connections:read" in user.permissions %}
|
||||||
<a href="/admin/static-connections">Static Connections</a>
|
<a href="/admin/static-connections">Static Connections</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if user.is_superuser or "clamp_connections:read" in user.permissions %}
|
||||||
|
<a href="/admin/clamp-connections">Clamp Connections</a>
|
||||||
|
{% endif %}
|
||||||
{% if user.is_superuser or "audit_log:read" in user.permissions %}
|
{% if user.is_superuser or "audit_log:read" in user.permissions %}
|
||||||
<a href="/admin/audit-log">Audit Log</a>
|
<a href="/admin/audit-log">Audit Log</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<tr id="clamp-connection-{{ cc.id }}">
|
||||||
|
<td>{{ cc.id }}</td>
|
||||||
|
<td>{{ cc.min_mm if cc.min_mm is not none else '—' }}</td>
|
||||||
|
<td>{{ cc.max_mm if cc.max_mm is not none else '—' }}</td>
|
||||||
|
<td>{{ cc.min_in if cc.min_in is not none else '—' }}</td>
|
||||||
|
<td>{{ cc.max_in if cc.max_in is not none else '—' }}</td>
|
||||||
|
<td class="row-actions">
|
||||||
|
<button class="btn btn-ghost"
|
||||||
|
hx-get="/admin/clamp-connections/{{ cc.id }}/edit"
|
||||||
|
hx-target="#clamp-connection-{{ cc.id }}"
|
||||||
|
hx-swap="outerHTML">Edit</button>
|
||||||
|
<button class="btn btn-danger"
|
||||||
|
hx-delete="/admin/clamp-connections/{{ cc.id }}"
|
||||||
|
hx-target="#clamp-connection-{{ cc.id }}"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
hx-confirm="Delete clamp connection #{{ cc.id }}?">Delete</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<tr id="clamp-connection-{{ cc.id }}">
|
||||||
|
<td colspan="6">
|
||||||
|
<form hx-post="/admin/clamp-connections/{{ cc.id }}"
|
||||||
|
hx-target="#clamp-connection-{{ cc.id }}"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
class="inline-edit">
|
||||||
|
<span class="muted">#{{ cc.id }}</span>
|
||||||
|
<label>Min (mm) <input type="number" name="min_mm" step="0.001" min="0"
|
||||||
|
value="{{ cc.min_mm if cc.min_mm is not none else '' }}"
|
||||||
|
placeholder="optional"></label>
|
||||||
|
<label>Max (mm) <input type="number" name="max_mm" step="0.001" min="0"
|
||||||
|
value="{{ cc.max_mm if cc.max_mm is not none else '' }}"
|
||||||
|
placeholder="optional"></label>
|
||||||
|
<label>Min (in) <input type="number" name="min_in" step="0.0001" min="0"
|
||||||
|
value="{{ cc.min_in if cc.min_in is not none else '' }}"
|
||||||
|
placeholder="optional"></label>
|
||||||
|
<label>Max (in) <input type="number" name="max_in" step="0.0001" min="0"
|
||||||
|
value="{{ cc.max_in if cc.max_in is not none else '' }}"
|
||||||
|
placeholder="optional"></label>
|
||||||
|
<div class="row-actions">
|
||||||
|
<button type="submit" class="btn btn-primary">Save</button>
|
||||||
|
<button type="button" class="btn btn-ghost"
|
||||||
|
hx-get="/admin/clamp-connections/{{ cc.id }}/row"
|
||||||
|
hx-target="#clamp-connection-{{ cc.id }}"
|
||||||
|
hx-swap="outerHTML">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<div id="clamp-connection-list" class="card">
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Min (mm)</th>
|
||||||
|
<th>Max (mm)</th>
|
||||||
|
<th>Min (in)</th>
|
||||||
|
<th>Max (in)</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for cc in clamp_connections %}
|
||||||
|
{% include "admin/_clamp_connection_row.html" %}
|
||||||
|
{% else %}
|
||||||
|
<tr><td colspan="6" class="muted">No clamp connections recorded.</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Clamp Connections · {{ app_name }}{% endblock %}
|
||||||
|
{% block body %}
|
||||||
|
{% include "_nav.html" %}
|
||||||
|
<main class="container">
|
||||||
|
<h1>Clamp Connections</h1>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h2>Add connection</h2>
|
||||||
|
<form hx-post="/admin/clamp-connections" hx-target="#clamp-connection-list" hx-swap="outerHTML" class="form-grid">
|
||||||
|
<label>Min (mm) <input type="number" name="min_mm" step="0.001" min="0" placeholder="optional"></label>
|
||||||
|
<label>Max (mm) <input type="number" name="max_mm" step="0.001" min="0" placeholder="optional"></label>
|
||||||
|
<label>Min (in) <input type="number" name="min_in" step="0.0001" min="0" placeholder="optional"></label>
|
||||||
|
<label>Max (in) <input type="number" name="max_in" step="0.0001" min="0" placeholder="optional"></label>
|
||||||
|
<button type="submit" class="btn btn-primary">Add</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% include "admin/_clamp_connections_table.html" %}
|
||||||
|
</main>
|
||||||
|
{% endblock %}
|
||||||
@@ -15,6 +15,7 @@ from app.crud import part_colour as part_colour_crud
|
|||||||
from app.crud import part_type as part_type_crud
|
from app.crud import part_type as part_type_crud
|
||||||
from app.crud import role as role_crud
|
from app.crud import role as role_crud
|
||||||
from app.crud import scope_model as scope_model_crud
|
from app.crud import scope_model as scope_model_crud
|
||||||
|
from app.crud import clamp_connection as clamp_connection_crud
|
||||||
from app.crud import static_connection as static_connection_crud
|
from app.crud import static_connection as static_connection_crud
|
||||||
from app.crud import sub_part_type as sub_part_type_crud
|
from app.crud import sub_part_type as sub_part_type_crud
|
||||||
from app.crud import unc_thread as unc_thread_crud
|
from app.crud import unc_thread as unc_thread_crud
|
||||||
@@ -1604,6 +1605,141 @@ async def delete_static_connection(
|
|||||||
return Response(status_code=status.HTTP_200_OK)
|
return Response(status_code=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
# --- Clamp Connections -------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/clamp-connections", response_class=HTMLResponse)
|
||||||
|
async def clamp_connections_page(
|
||||||
|
request: Request,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
user: User = Depends(web_require("clamp_connections:read")),
|
||||||
|
):
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
request,
|
||||||
|
"admin/clamp_connections.html",
|
||||||
|
{"user": user, "clamp_connections": await clamp_connection_crud.list_all(db)},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/clamp-connections", response_class=HTMLResponse)
|
||||||
|
async def create_clamp_connection(
|
||||||
|
request: Request,
|
||||||
|
min_mm: str = Form(""),
|
||||||
|
max_mm: str = Form(""),
|
||||||
|
min_in: str = Form(""),
|
||||||
|
max_in: str = Form(""),
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(web_require("clamp_connections:write")),
|
||||||
|
):
|
||||||
|
cc = await clamp_connection_crud.create(
|
||||||
|
db,
|
||||||
|
min_mm=float(min_mm) if min_mm else None,
|
||||||
|
max_mm=float(max_mm) if max_mm else None,
|
||||||
|
min_in=float(min_in) if min_in else None,
|
||||||
|
max_in=float(max_in) if max_in else None,
|
||||||
|
)
|
||||||
|
label = (
|
||||||
|
f"{cc.min_mm}–{cc.max_mm} mm" if cc.min_mm is not None
|
||||||
|
else f"{cc.min_in}–{cc.max_in} in"
|
||||||
|
)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="create", resource_type="ClampConnection",
|
||||||
|
resource_id=cc.id,
|
||||||
|
description=audit_crud.describe_create("ClampConnection", cc.id, label),
|
||||||
|
)
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
request,
|
||||||
|
"admin/_clamp_connections_table.html",
|
||||||
|
{"clamp_connections": await clamp_connection_crud.list_all(db)},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/clamp-connections/{clamp_connection_id}/edit", response_class=HTMLResponse)
|
||||||
|
async def edit_clamp_connection_row(
|
||||||
|
request: Request,
|
||||||
|
clamp_connection_id: int,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
_: User = Depends(web_require("clamp_connections:write")),
|
||||||
|
):
|
||||||
|
cc = await clamp_connection_crud.get(db, clamp_connection_id)
|
||||||
|
if cc is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Clamp connection not found")
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
request, "admin/_clamp_connection_row_edit.html", {"cc": cc}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/clamp-connections/{clamp_connection_id}/row", response_class=HTMLResponse)
|
||||||
|
async def clamp_connection_row(
|
||||||
|
request: Request,
|
||||||
|
clamp_connection_id: int,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
_: User = Depends(web_require("clamp_connections:read")),
|
||||||
|
):
|
||||||
|
cc = await clamp_connection_crud.get(db, clamp_connection_id)
|
||||||
|
if cc is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Clamp connection not found")
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
request, "admin/_clamp_connection_row.html", {"cc": cc}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/clamp-connections/{clamp_connection_id}", response_class=HTMLResponse)
|
||||||
|
async def update_clamp_connection(
|
||||||
|
request: Request,
|
||||||
|
clamp_connection_id: int,
|
||||||
|
min_mm: str = Form(""),
|
||||||
|
max_mm: str = Form(""),
|
||||||
|
min_in: str = Form(""),
|
||||||
|
max_in: str = Form(""),
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(web_require("clamp_connections:write")),
|
||||||
|
):
|
||||||
|
cc = await clamp_connection_crud.get(db, clamp_connection_id)
|
||||||
|
if cc is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Clamp connection not found")
|
||||||
|
changes = {
|
||||||
|
"min_mm": float(min_mm) if min_mm else None,
|
||||||
|
"max_mm": float(max_mm) if max_mm else None,
|
||||||
|
"min_in": float(min_in) if min_in else None,
|
||||||
|
"max_in": float(max_in) if max_in else None,
|
||||||
|
}
|
||||||
|
await clamp_connection_crud.update(db, cc, changes)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="update", resource_type="ClampConnection",
|
||||||
|
resource_id=clamp_connection_id,
|
||||||
|
description=audit_crud.describe_update(
|
||||||
|
"ClampConnection", clamp_connection_id, changes
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
request, "admin/_clamp_connection_row.html", {"cc": cc}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/clamp-connections/{clamp_connection_id}")
|
||||||
|
async def delete_clamp_connection(
|
||||||
|
clamp_connection_id: int,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(web_require("clamp_connections:delete")),
|
||||||
|
):
|
||||||
|
cc = await clamp_connection_crud.get(db, clamp_connection_id)
|
||||||
|
if cc is not None:
|
||||||
|
label = (
|
||||||
|
f"{cc.min_mm}–{cc.max_mm} mm" if cc.min_mm is not None
|
||||||
|
else f"{cc.min_in}–{cc.max_in} in"
|
||||||
|
)
|
||||||
|
await clamp_connection_crud.delete(db, cc)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="delete", resource_type="ClampConnection",
|
||||||
|
resource_id=clamp_connection_id,
|
||||||
|
description=audit_crud.describe_delete(
|
||||||
|
"ClampConnection", clamp_connection_id, label
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return Response(status_code=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
# --- Audit Log ---------------------------------------------------------------
|
# --- Audit Log ---------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -56,6 +56,9 @@ PERMISSIONS = [
|
|||||||
("static_connections:read", "View static connections"),
|
("static_connections:read", "View static connections"),
|
||||||
("static_connections:write", "Create and update static connections"),
|
("static_connections:write", "Create and update static connections"),
|
||||||
("static_connections:delete", "Delete static connections"),
|
("static_connections:delete", "Delete static connections"),
|
||||||
|
("clamp_connections:read", "View clamp connections"),
|
||||||
|
("clamp_connections:write", "Create and update clamp connections"),
|
||||||
|
("clamp_connections:delete", "Delete clamp connections"),
|
||||||
("augmented_parts:read", "View augmented parts"),
|
("augmented_parts:read", "View augmented parts"),
|
||||||
("augmented_parts:write", "Create and update augmented parts"),
|
("augmented_parts:write", "Create and update augmented parts"),
|
||||||
("augmented_parts:delete", "Delete augmented parts"),
|
("augmented_parts:delete", "Delete augmented parts"),
|
||||||
@@ -65,7 +68,7 @@ PERMISSIONS = [
|
|||||||
# Default roles -> permission names. "admin" gets everything.
|
# Default roles -> permission names. "admin" gets everything.
|
||||||
ROLES = {
|
ROLES = {
|
||||||
"admin": [name for name, _ in PERMISSIONS], # includes audit_log:read
|
"admin": [name for name, _ in PERMISSIONS], # includes audit_log:read
|
||||||
"user": ["users:read", "iso_threads:read", "unc_threads:read", "manufacturers:read", "scope_models:read", "part_colours:read", "part_types:read", "sub_part_types:read", "imported_parts:read", "static_connections:read", "augmented_parts:read"],
|
"user": ["users:read", "iso_threads:read", "unc_threads:read", "manufacturers:read", "scope_models:read", "part_colours:read", "part_types:read", "sub_part_types:read", "imported_parts:read", "static_connections:read", "clamp_connections:read", "augmented_parts:read"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user