Merge pull request 'vsp-fix-back: фикс багов по всп' (#43) from vsp-fix-back into test
Reviewed-on: #43 Reviewed-by: Raykov-MS <RaykovMS@avt.rshb.ru>
This commit is contained in:
commit
8ef3b1cca1
@ -24,9 +24,18 @@ from src.services.user_service import UserService
|
||||
router = APIRouter(prefix="/users", tags=["users"])
|
||||
|
||||
|
||||
@router.get("/me", response_model=UserSchema)
|
||||
async def get_current_user_info(current_user: AppUser = Depends(get_current_active_user)):
|
||||
return current_user
|
||||
@router.get("/me", response_model=UserAdminListResponse)
|
||||
async def get_current_user_info(
|
||||
current_user: AppUser = Depends(get_current_active_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
load_orgs: bool = False,
|
||||
):
|
||||
if load_orgs:
|
||||
user_service = UserService(db)
|
||||
result = await user_service.get(user_id=current_user.id, load_orgs=True)
|
||||
return UserAdminListResponse.model_validate(result)
|
||||
else:
|
||||
return current_user
|
||||
|
||||
|
||||
@router.get("/")
|
||||
|
||||
@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from datetime import date, datetime
|
||||
|
||||
from sqlalchemy import Boolean, Date, DateTime, ForeignKey, Integer, Numeric, String, Text, func
|
||||
from sqlalchemy import Boolean, CheckConstraint, Date, DateTime, ForeignKey, Integer, Numeric, String, Text, UniqueConstraint, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from src.db.base import Base
|
||||
@ -10,7 +10,17 @@ from src.db.base import Base
|
||||
|
||||
class Vsp(Base):
|
||||
__tablename__ = "vsp"
|
||||
__table_args__ = {"schema": "v3"}
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"reg_number", name="vsp_reg_number_unique",
|
||||
),
|
||||
CheckConstraint(
|
||||
"closed_at IS NULL OR opened_at IS NULL OR closed_at >= opened_at",
|
||||
name="chk_closed_after_opened",
|
||||
),
|
||||
|
||||
{"schema": "v3"},
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
branch_id: Mapped[int] = mapped_column(Integer, ForeignKey("v3.org_unit.id"))
|
||||
|
||||
@ -39,7 +39,7 @@ class VSPService:
|
||||
return vsp
|
||||
|
||||
ssp_ids = await self._get_scoped_ssp_ids(user=user)
|
||||
if not ssp_ids or vsp.ssp_id not in set(ssp_ids):
|
||||
if not ssp_ids or vsp.branch_id not in set(ssp_ids):
|
||||
raise AccessDeniedException()
|
||||
return vsp
|
||||
|
||||
@ -129,6 +129,11 @@ class VSPService:
|
||||
)
|
||||
return created
|
||||
except IntegrityError as exc:
|
||||
message = str(getattr(exc, "orig", exc) or exc).strip()
|
||||
if "vsp_reg_number_unique" in message:
|
||||
raise ValidationException(description="Указанный номер уже существует")
|
||||
if "chk_closed_after_opened" in message:
|
||||
raise ValidationException(description="Дата закрытия не может быть меньше даты открытия")
|
||||
raise ValidationException(description="Некорректные данные для записи ВСП") from exc
|
||||
|
||||
async def export_xlsx(
|
||||
@ -232,7 +237,7 @@ class VSPService:
|
||||
|
||||
if user.role_id != UserRoleEnum.ADMIN:
|
||||
ssp_ids = await self._get_scoped_ssp_ids(user=user)
|
||||
if not ssp_ids or vsp.ssp_id not in set(ssp_ids):
|
||||
if not ssp_ids or vsp.branch_id not in set(ssp_ids):
|
||||
raise AccessDeniedException()
|
||||
if not set(data.keys()).issubset(self.EXECUTOR_EDITABLE_FIELDS):
|
||||
raise AccessDeniedException()
|
||||
@ -246,6 +251,11 @@ class VSPService:
|
||||
vsp=vsp, data=data, updated_by=user.id, load_org_unit=load_org_unit,
|
||||
)
|
||||
except IntegrityError as exc:
|
||||
message = str(getattr(exc, "orig", exc) or exc).strip()
|
||||
if "vsp_reg_number_unique" in message:
|
||||
raise ValidationException(description="Указанный номер уже существует")
|
||||
if "chk_closed_after_opened" in message:
|
||||
raise ValidationException(description="Дата закрытия не может быть меньше даты открытия")
|
||||
raise ValidationException(description="Некорректные данные для записи ВСП") from exc
|
||||
|
||||
async def logical_delete(self, vsp_id: int, user: AppUser) -> bool:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user