Allow the renaming of the main section by temporal product permission.
Allow deleting sections which do not have tables, but have associated section printers.
This commit is contained in:
parent
63dfe05044
commit
5bea488181
@ -5,12 +5,13 @@ from typing import List
|
||||
import barker.schemas.section as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import delete, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from ..core.security import get_current_active_user as get_user
|
||||
from ..db.session import SessionFuture
|
||||
from ..models.section import Section
|
||||
from ..models.section_printer import SectionPrinter
|
||||
from ..schemas.user_token import UserToken
|
||||
|
||||
|
||||
@ -44,7 +45,7 @@ def update_route(
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
item: Section = db.execute(select(Section).where(Section.id == id_)).scalar_one()
|
||||
if item.is_fixture:
|
||||
if item.is_fixture and "temporal-products" not in user.permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_423_LOCKED,
|
||||
detail=f"{item.name} is a fixture and cannot be edited or deleted.",
|
||||
@ -72,7 +73,12 @@ def delete_route(
|
||||
status_code=status.HTTP_423_LOCKED,
|
||||
detail=f"{item.name} is a fixture and cannot be edited or deleted.",
|
||||
)
|
||||
db.delete(item)
|
||||
db.execute(
|
||||
delete(SectionPrinter)
|
||||
.where(SectionPrinter.section_id == id_)
|
||||
.execution_options(synchronize_session=False)
|
||||
)
|
||||
db.execute(delete(Section).where(Section.id == id_).execution_options(synchronize_session=False))
|
||||
db.commit()
|
||||
return section_blank()
|
||||
except SQLAlchemyError as e:
|
||||
|
@ -87,10 +87,14 @@ then
|
||||
docker start "$doname" || exit
|
||||
docker exec -it "$doname" poetry run alembic upgrade 48bc1c7c07ce || exit
|
||||
docker exec -it "$doname" poetry run alembic upgrade e5e8acfc6495 || exit
|
||||
docker exec -it "$doname" poetry run alembic upgrade c123dbf9c659 || exit
|
||||
docker exec -it "$doname" poetry run alembic upgrade 81d94c5223a7 || exit
|
||||
else
|
||||
cd "$parent_path"/barker || exit
|
||||
alembic upgrade 48bc1c7c07ce || exit
|
||||
alembic upgrade e5e8acfc6495 || exit
|
||||
alembic upgrade c123dbf9c659 || exit
|
||||
alembic upgrade 81d94c5223a7 || exit
|
||||
fi
|
||||
|
||||
rm -f "$parent_path"/csv/*.csv "$parent_path"/csv/csv.tar.zip || exit
|
||||
|
Loading…
Reference in New Issue
Block a user