Doing a relayout of permissions to make it a bit easier to navigate

This commit is contained in:
Ian Roddis committed 2026-06-25 16:06:36 -03:00
1 parent 1549971a13
commit eba7896893
5 files changed
+138 -24

No files matched your search

+27 -14
View File
@@ -9,17 +9,17 @@ from app.crud import audit as audit_crud
from app.crud import imported_part as imported_part_crud
from app.crud import imported_part_config as imported_part_config_crud
from app.crud import iso_thread as iso_thread_crud
from app.crud import sub_part_type as sub_part_type_crud
from app.services import odata as odata_service
from app.crud import manufacturer as manufacturer_crud
from app.crud import part_type as part_type_crud
from app.crud import role as role_crud
from app.crud import scope_model as scope_model_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 user as user_crud
from app.deps import get_current_web_user
from app.models.unc_thread import UncSeries
from app.models.user import User
from app.services import odata as odata_service
from app.web.templates import templates
router = APIRouter(prefix="/admin", include_in_schema=False)
@@ -39,6 +39,18 @@ def web_require(*perms: str):
return checker
async def _role_perm_ctx(db: AsyncSession) -> dict:
all_perms = await role_crud.list_permissions(db)
scopes = sorted({p.name.split(":")[0] for p in all_perms})
perm_map = {p.name: p for p in all_perms}
return {
"permissions": all_perms,
"scopes": scopes,
"perm_map": perm_map,
"actions": ["read", "write", "delete"],
}
@router.get("", response_class=HTMLResponse)
async def admin_home():
return RedirectResponse(url="/admin/users", status_code=status.HTTP_302_FOUND)
@@ -190,11 +202,7 @@ async def roles_page(
return templates.TemplateResponse(
request,
"admin/roles.html",
{
"user": user,
"roles": await role_crud.list_roles(db),
"permissions": await role_crud.list_permissions(db),
},
{"user": user, "roles": await role_crud.list_roles(db), **(await _role_perm_ctx(db))},
)
@@ -222,10 +230,7 @@ async def create_role(
return templates.TemplateResponse(
request,
"admin/_roles_table.html",
{
"roles": await role_crud.list_roles(db),
"permissions": await role_crud.list_permissions(db),
},
{"roles": await role_crud.list_roles(db), **(await _role_perm_ctx(db))},
)
@@ -242,7 +247,7 @@ async def edit_role_row(
return templates.TemplateResponse(
request,
"admin/_role_row_edit.html",
{"r": role, "permissions": await role_crud.list_permissions(db)},
{"r": role, **(await _role_perm_ctx(db))},
)
@@ -256,7 +261,11 @@ async def role_row(
role = await role_crud.get(db, role_id)
if role is None:
raise HTTPException(status_code=404, detail="Role not found")
return templates.TemplateResponse(request, "admin/_role_row.html", {"r": role})
return templates.TemplateResponse(
request,
"admin/_role_row.html",
{"r": role, **(await _role_perm_ctx(db))},
)
@router.post("/roles/{role_id}", response_class=HTMLResponse)
@@ -277,7 +286,11 @@ async def update_role(
resource_id=role_id,
description=audit_crud.describe_update("Role", role_id, changes),
)
return templates.TemplateResponse(request, "admin/_role_row.html", {"r": role})
return templates.TemplateResponse(
request,
"admin/_role_row.html",
{"r": role, **(await _role_perm_ctx(db))},
)
@router.delete("/roles/{role_id}")