From 5bea488181b561af8a1a43e9ee78edfc4376dc27 Mon Sep 17 00:00:00 2001 From: tanshu Date: Sat, 4 Sep 2021 13:08:46 +0530 Subject: [PATCH] Allow the renaming of the main section by temporal product permission. Allow deleting sections which do not have tables, but have associated section printers. --- barker/barker/routers/section.py | 12 +++++++++--- import.sh | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/barker/barker/routers/section.py b/barker/barker/routers/section.py index 804166a..c628fc8 100644 --- a/barker/barker/routers/section.py +++ b/barker/barker/routers/section.py @@ -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: diff --git a/import.sh b/import.sh index c9b6c7f..9ece624 100755 --- a/import.sh +++ b/import.sh @@ -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