Adding AttachmentPointNames
This commit is contained in:
1 parent
ae50ec7049
commit
2767fb1c8e
14 files changed
+406
-3
No files matched your search
@@ -0,0 +1,29 @@
|
|||||||
|
"""add attachment_point_names
|
||||||
|
|
||||||
|
Revision ID: 70e48bda8829
|
||||||
|
Revises: c7882cedc9ae
|
||||||
|
Create Date: 2026-07-02 13:54:58.335394
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = '70e48bda8829'
|
||||||
|
down_revision: Union[str, None] = 'c7882cedc9ae'
|
||||||
|
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,92 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
from app.core.database import get_db
|
||||||
|
from app.crud import attachment_point_name as apn_crud
|
||||||
|
from app.crud import audit as audit_crud
|
||||||
|
from app.deps import require_permission
|
||||||
|
from app.models.user import User
|
||||||
|
from app.schemas.attachment_point_name import (
|
||||||
|
AttachmentPointNameCreate,
|
||||||
|
AttachmentPointNameRead,
|
||||||
|
AttachmentPointNameUpdate,
|
||||||
|
)
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("", response_model=list[AttachmentPointNameRead])
|
||||||
|
async def list_attachment_point_names(
|
||||||
|
skip: int = 0,
|
||||||
|
limit: int = 100,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
_: User = Depends(require_permission("attachment_point_names:read")),
|
||||||
|
):
|
||||||
|
return await apn_crud.list_all(db, skip=skip, limit=limit)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post(
|
||||||
|
"", response_model=AttachmentPointNameRead, status_code=status.HTTP_201_CREATED
|
||||||
|
)
|
||||||
|
async def create_attachment_point_name(
|
||||||
|
payload: AttachmentPointNameCreate,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(require_permission("attachment_point_names:write")),
|
||||||
|
):
|
||||||
|
apn = await apn_crud.create(db, name=payload.name)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="create", resource_type="AttachmentPointName",
|
||||||
|
resource_id=apn.id,
|
||||||
|
description=audit_crud.describe_create("AttachmentPointName", apn.id, apn.name),
|
||||||
|
)
|
||||||
|
return apn
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/{apn_id}", response_model=AttachmentPointNameRead)
|
||||||
|
async def get_attachment_point_name(
|
||||||
|
apn_id: int,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
_: User = Depends(require_permission("attachment_point_names:read")),
|
||||||
|
):
|
||||||
|
apn = await apn_crud.get(db, apn_id)
|
||||||
|
if apn is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Attachment point name not found")
|
||||||
|
return apn
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/{apn_id}", response_model=AttachmentPointNameRead)
|
||||||
|
async def update_attachment_point_name(
|
||||||
|
apn_id: int,
|
||||||
|
payload: AttachmentPointNameUpdate,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(require_permission("attachment_point_names:write")),
|
||||||
|
):
|
||||||
|
apn = await apn_crud.get(db, apn_id)
|
||||||
|
if apn is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Attachment point name not found")
|
||||||
|
changes = payload.model_dump(exclude_unset=True)
|
||||||
|
apn = await apn_crud.update(db, apn, changes)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="update", resource_type="AttachmentPointName",
|
||||||
|
resource_id=apn.id,
|
||||||
|
description=audit_crud.describe_update("AttachmentPointName", apn.id, changes),
|
||||||
|
)
|
||||||
|
return apn
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/{apn_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
|
async def delete_attachment_point_name(
|
||||||
|
apn_id: int,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(require_permission("attachment_point_names:delete")),
|
||||||
|
):
|
||||||
|
apn = await apn_crud.get(db, apn_id)
|
||||||
|
if apn is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Attachment point name not found")
|
||||||
|
name = apn.name
|
||||||
|
await apn_crud.delete(db, apn)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="delete", resource_type="AttachmentPointName",
|
||||||
|
resource_id=apn_id,
|
||||||
|
description=audit_crud.describe_delete("AttachmentPointName", apn_id, name),
|
||||||
|
)
|
||||||
+2
-1
@@ -1,6 +1,6 @@
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|
||||||
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
|
from app.api import attachment_point_names, 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"])
|
||||||
@@ -15,6 +15,7 @@ api_router.include_router(part_types.router, prefix="/part-types", tags=["part-t
|
|||||||
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(clamp_connections.router, prefix="/clamp-connections", tags=["clamp-connections"])
|
||||||
|
api_router.include_router(attachment_point_names.router, prefix="/attachment-point-names", tags=["attachment-point-names"])
|
||||||
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.attachment_point_name import AttachmentPointName
|
||||||
|
|
||||||
|
|
||||||
|
async def get(db: AsyncSession, apn_id: int) -> AttachmentPointName | None:
|
||||||
|
return await db.get(AttachmentPointName, apn_id)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_by_name(db: AsyncSession, name: str) -> AttachmentPointName | None:
|
||||||
|
result = await db.execute(
|
||||||
|
select(AttachmentPointName).where(AttachmentPointName.name == name)
|
||||||
|
)
|
||||||
|
return result.scalar_one_or_none()
|
||||||
|
|
||||||
|
|
||||||
|
async def list_all(
|
||||||
|
db: AsyncSession, skip: int = 0, limit: int = 100
|
||||||
|
) -> list[AttachmentPointName]:
|
||||||
|
result = await db.execute(
|
||||||
|
select(AttachmentPointName)
|
||||||
|
.order_by(AttachmentPointName.name)
|
||||||
|
.offset(skip)
|
||||||
|
.limit(limit)
|
||||||
|
)
|
||||||
|
return list(result.scalars().all())
|
||||||
|
|
||||||
|
|
||||||
|
async def create(db: AsyncSession, *, name: str) -> AttachmentPointName:
|
||||||
|
apn = AttachmentPointName(name=name)
|
||||||
|
db.add(apn)
|
||||||
|
await db.commit()
|
||||||
|
await db.refresh(apn)
|
||||||
|
return apn
|
||||||
|
|
||||||
|
|
||||||
|
async def update(
|
||||||
|
db: AsyncSession, apn: AttachmentPointName, data: dict
|
||||||
|
) -> AttachmentPointName:
|
||||||
|
for field, value in data.items():
|
||||||
|
setattr(apn, field, value)
|
||||||
|
await db.commit()
|
||||||
|
await db.refresh(apn)
|
||||||
|
return apn
|
||||||
|
|
||||||
|
|
||||||
|
async def delete(db: AsyncSession, apn: AttachmentPointName) -> None:
|
||||||
|
await db.delete(apn)
|
||||||
|
await db.commit()
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
"""Import all models so they register with ``Base.metadata``."""
|
"""Import all models so they register with ``Base.metadata``."""
|
||||||
|
|
||||||
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.attachment_point_name import AttachmentPointName
|
||||||
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.clamp_connection import ClampConnection
|
||||||
@@ -20,6 +21,7 @@ from app.models.unc_thread import UncThread
|
|||||||
from app.models.user import User
|
from app.models.user import User
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
"AttachmentPointName",
|
||||||
"AuditLog",
|
"AuditLog",
|
||||||
"AugmentedPart",
|
"AugmentedPart",
|
||||||
"ClampConnection",
|
"ClampConnection",
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
from sqlalchemy import UniqueConstraint
|
||||||
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
|
||||||
|
from app.core.database import Base
|
||||||
|
|
||||||
|
|
||||||
|
class AttachmentPointName(Base):
|
||||||
|
__tablename__ = "attachment_point_names"
|
||||||
|
__table_args__ = (UniqueConstraint("name"),)
|
||||||
|
|
||||||
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||||||
|
name: Mapped[str] = mapped_column(nullable=False)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
|
||||||
|
class AttachmentPointNameBase(BaseModel):
|
||||||
|
name: str
|
||||||
|
|
||||||
|
|
||||||
|
class AttachmentPointNameCreate(AttachmentPointNameBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class AttachmentPointNameUpdate(BaseModel):
|
||||||
|
name: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class AttachmentPointNameRead(AttachmentPointNameBase):
|
||||||
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
id: int
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
{% set p = user.permissions %}
|
{% set p = user.permissions %}
|
||||||
{% set can_admin = su or "users:read" in p or "roles:read" in p or "audit_log:read" in p %}
|
{% set can_admin = su or "users:read" in p or "roles:read" in p or "audit_log:read" in p %}
|
||||||
{% set can_connections = su or "clamp_connections:read" in p or "iso_threads:read" in p or "static_connections:read" in p or "unc_threads:read" in p %}
|
{% set can_connections = su or "clamp_connections:read" in p or "iso_threads:read" in p or "static_connections:read" in p or "unc_threads:read" in p %}
|
||||||
{% set can_labels = su or "manufacturers:read" in p or "part_colours:read" in p or "part_types:read" in p or "scope_models:read" in p or "sub_part_types:read" in p %}
|
{% set can_labels = su or "attachment_point_names:read" in p or "manufacturers:read" in p or "part_colours:read" in p or "part_types:read" in p or "scope_models:read" in p or "sub_part_types:read" in p %}
|
||||||
{% set can_database = su or "imported_parts:read" in p or "augmented_parts:read" in p %}
|
{% set can_database = su or "imported_parts:read" in p or "augmented_parts:read" in p %}
|
||||||
{% set can_parts = can_connections or can_labels or can_database %}
|
{% set can_parts = can_connections or can_labels or can_database %}
|
||||||
|
|
||||||
@@ -103,6 +103,10 @@
|
|||||||
<path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"/>
|
<path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"/>
|
||||||
<path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 0 3-3h7z"/>
|
<path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 0 3-3h7z"/>
|
||||||
</symbol>
|
</symbol>
|
||||||
|
<symbol id="icon-map-pin" viewBox="0 0 24 24">
|
||||||
|
<path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z"/>
|
||||||
|
<circle cx="12" cy="10" r="3"/>
|
||||||
|
</symbol>
|
||||||
</svg>
|
</svg>
|
||||||
|
|
||||||
{# ── Nav macro for DRY icon use ────────────────────────────────────────────── #}
|
{# ── Nav macro for DRY icon use ────────────────────────────────────────────── #}
|
||||||
@@ -159,6 +163,9 @@
|
|||||||
<div class="nav-group">
|
<div class="nav-group">
|
||||||
<span class="nav-label">{{ icon("tag") }} Labels <i class="nav-chevron">▶</i></span>
|
<span class="nav-label">{{ icon("tag") }} Labels <i class="nav-chevron">▶</i></span>
|
||||||
<div class="nav-dropdown">
|
<div class="nav-dropdown">
|
||||||
|
{% if su or "attachment_point_names:read" in p %}
|
||||||
|
<a href="/admin/attachment-point-names">{{ icon("map-pin") }} Attachment Point Names</a>
|
||||||
|
{% endif %}
|
||||||
{% if su or "manufacturers:read" in p %}
|
{% if su or "manufacturers:read" in p %}
|
||||||
<a href="/admin/manufacturers">{{ icon("building-2") }} Manufacturers</a>
|
<a href="/admin/manufacturers">{{ icon("building-2") }} Manufacturers</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<tr id="attachment-point-name-{{ apn.id }}">
|
||||||
|
<td>{{ apn.id }}</td>
|
||||||
|
<td>{{ apn.name }}</td>
|
||||||
|
<td class="row-actions">
|
||||||
|
<button class="btn btn-ghost"
|
||||||
|
hx-get="/admin/attachment-point-names/{{ apn.id }}/edit"
|
||||||
|
hx-target="#attachment-point-name-{{ apn.id }}"
|
||||||
|
hx-swap="outerHTML">Edit</button>
|
||||||
|
<button class="btn btn-danger"
|
||||||
|
hx-delete="/admin/attachment-point-names/{{ apn.id }}"
|
||||||
|
hx-target="#attachment-point-name-{{ apn.id }}"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
hx-confirm="Delete {{ apn.name }}?">Delete</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<tr id="attachment-point-name-{{ apn.id }}">
|
||||||
|
<td colspan="3">
|
||||||
|
<form hx-post="/admin/attachment-point-names/{{ apn.id }}"
|
||||||
|
hx-target="#attachment-point-name-{{ apn.id }}"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
class="inline-edit">
|
||||||
|
<span class="muted">#{{ apn.id }}</span>
|
||||||
|
<label>Name <input type="text" name="name" value="{{ apn.name }}" required></label>
|
||||||
|
<div class="row-actions">
|
||||||
|
<button type="submit" class="btn btn-primary">Save</button>
|
||||||
|
<button type="button" class="btn btn-ghost"
|
||||||
|
hx-get="/admin/attachment-point-names/{{ apn.id }}/row"
|
||||||
|
hx-target="#attachment-point-name-{{ apn.id }}"
|
||||||
|
hx-swap="outerHTML">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<div id="attachment-point-name-list" class="card">
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for apn in attachment_point_names %}
|
||||||
|
{% include "admin/_attachment_point_name_row.html" %}
|
||||||
|
{% else %}
|
||||||
|
<tr><td colspan="3" class="muted">No attachment point names recorded.</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Attachment Point Names · {{ app_name }}{% endblock %}
|
||||||
|
{% block body %}
|
||||||
|
{% include "_nav.html" %}
|
||||||
|
<main class="container">
|
||||||
|
<h1>Attachment Point Names</h1>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h2>Add attachment point name</h2>
|
||||||
|
<form hx-post="/admin/attachment-point-names"
|
||||||
|
hx-target="#attachment-point-name-list"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
class="form-grid">
|
||||||
|
<label>Name <input type="text" name="name" required></label>
|
||||||
|
<button type="submit" class="btn btn-primary">Add</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% include "admin/_attachment_point_names_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 attachment_point_name as apn_crud
|
||||||
from app.crud import clamp_connection as clamp_connection_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
|
||||||
@@ -1491,6 +1492,114 @@ async def delete_part_colour(
|
|||||||
return Response(status_code=status.HTTP_200_OK)
|
return Response(status_code=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
# --- Attachment Point Names ---------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/attachment-point-names", response_class=HTMLResponse)
|
||||||
|
async def attachment_point_names_page(
|
||||||
|
request: Request,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
user: User = Depends(web_require("attachment_point_names:read")),
|
||||||
|
):
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
request,
|
||||||
|
"admin/attachment_point_names.html",
|
||||||
|
{"user": user, "attachment_point_names": await apn_crud.list_all(db)},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/attachment-point-names", response_class=HTMLResponse)
|
||||||
|
async def create_attachment_point_name(
|
||||||
|
request: Request,
|
||||||
|
name: str = Form(...),
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(web_require("attachment_point_names:write")),
|
||||||
|
):
|
||||||
|
if not await apn_crud.get_by_name(db, name):
|
||||||
|
created = await apn_crud.create(db, name=name)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="create", resource_type="AttachmentPointName",
|
||||||
|
resource_id=created.id,
|
||||||
|
description=audit_crud.describe_create("AttachmentPointName", created.id, name),
|
||||||
|
)
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
request,
|
||||||
|
"admin/_attachment_point_names_table.html",
|
||||||
|
{"attachment_point_names": await apn_crud.list_all(db)},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/attachment-point-names/{apn_id}/edit", response_class=HTMLResponse)
|
||||||
|
async def edit_attachment_point_name_row(
|
||||||
|
request: Request,
|
||||||
|
apn_id: int,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
_: User = Depends(web_require("attachment_point_names:write")),
|
||||||
|
):
|
||||||
|
apn = await apn_crud.get(db, apn_id)
|
||||||
|
if apn is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Attachment point name not found")
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
request, "admin/_attachment_point_name_row_edit.html", {"apn": apn}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/attachment-point-names/{apn_id}/row", response_class=HTMLResponse)
|
||||||
|
async def attachment_point_name_row(
|
||||||
|
request: Request,
|
||||||
|
apn_id: int,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
_: User = Depends(web_require("attachment_point_names:read")),
|
||||||
|
):
|
||||||
|
apn = await apn_crud.get(db, apn_id)
|
||||||
|
if apn is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Attachment point name not found")
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
request, "admin/_attachment_point_name_row.html", {"apn": apn}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/attachment-point-names/{apn_id}", response_class=HTMLResponse)
|
||||||
|
async def update_attachment_point_name(
|
||||||
|
request: Request,
|
||||||
|
apn_id: int,
|
||||||
|
name: str = Form(...),
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(web_require("attachment_point_names:write")),
|
||||||
|
):
|
||||||
|
apn = await apn_crud.get(db, apn_id)
|
||||||
|
if apn is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Attachment point name not found")
|
||||||
|
changes = {"name": name}
|
||||||
|
await apn_crud.update(db, apn, changes)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="update", resource_type="AttachmentPointName",
|
||||||
|
resource_id=apn_id,
|
||||||
|
description=audit_crud.describe_update("AttachmentPointName", apn_id, changes),
|
||||||
|
)
|
||||||
|
return templates.TemplateResponse(
|
||||||
|
request, "admin/_attachment_point_name_row.html", {"apn": apn}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/attachment-point-names/{apn_id}")
|
||||||
|
async def delete_attachment_point_name(
|
||||||
|
apn_id: int,
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
actor: User = Depends(web_require("attachment_point_names:delete")),
|
||||||
|
):
|
||||||
|
apn = await apn_crud.get(db, apn_id)
|
||||||
|
if apn is not None:
|
||||||
|
name = apn.name
|
||||||
|
await apn_crud.delete(db, apn)
|
||||||
|
await audit_crud.log(
|
||||||
|
db, actor=actor, action="delete", resource_type="AttachmentPointName",
|
||||||
|
resource_id=apn_id,
|
||||||
|
description=audit_crud.describe_delete("AttachmentPointName", apn_id, name),
|
||||||
|
)
|
||||||
|
return Response(status_code=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
# --- Static Connections -------------------------------------------------------
|
# --- Static Connections -------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+12
-1
@@ -11,11 +11,14 @@ import asyncio
|
|||||||
|
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.database import AsyncSessionLocal, init_db
|
from app.core.database import AsyncSessionLocal, init_db
|
||||||
|
from app.crud import attachment_point_name as apn_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 sub_part_type as sub_part_type_crud
|
from app.crud import sub_part_type as sub_part_type_crud
|
||||||
from app.crud import user as user_crud
|
from app.crud import user as user_crud
|
||||||
|
|
||||||
|
ATTACHMENT_POINT_NAMES = ["Objective", "Occular"]
|
||||||
|
|
||||||
PART_TYPES = ["Flip Cover", "ARD", "Polarizer", "Adapter Ring", "Scope"]
|
PART_TYPES = ["Flip Cover", "ARD", "Polarizer", "Adapter Ring", "Scope"]
|
||||||
|
|
||||||
SUB_PART_TYPES = {
|
SUB_PART_TYPES = {
|
||||||
@@ -59,6 +62,9 @@ PERMISSIONS = [
|
|||||||
("clamp_connections:read", "View clamp connections"),
|
("clamp_connections:read", "View clamp connections"),
|
||||||
("clamp_connections:write", "Create and update clamp connections"),
|
("clamp_connections:write", "Create and update clamp connections"),
|
||||||
("clamp_connections:delete", "Delete clamp connections"),
|
("clamp_connections:delete", "Delete clamp connections"),
|
||||||
|
("attachment_point_names:read", "View attachment point names"),
|
||||||
|
("attachment_point_names:write", "Create and update attachment point names"),
|
||||||
|
("attachment_point_names:delete", "Delete attachment point names"),
|
||||||
("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"),
|
||||||
@@ -68,7 +74,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", "clamp_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", "attachment_point_names:read", "augmented_parts:read"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -99,6 +105,11 @@ async def seed() -> None:
|
|||||||
)
|
)
|
||||||
roles[role_name] = role
|
roles[role_name] = role
|
||||||
|
|
||||||
|
# Attachment point names
|
||||||
|
for apn_name in ATTACHMENT_POINT_NAMES:
|
||||||
|
if await apn_crud.get_by_name(db, apn_name) is None:
|
||||||
|
await apn_crud.create(db, name=apn_name)
|
||||||
|
|
||||||
# Part types
|
# Part types
|
||||||
for pt_name in PART_TYPES:
|
for pt_name in PART_TYPES:
|
||||||
if await part_type_crud.get_by_name(db, pt_name) is None:
|
if await part_type_crud.get_by_name(db, pt_name) is None:
|
||||||
|
|||||||
Reference in new issue
Block a user