Crear Asunto funciona
This commit is contained in:
@@ -589,7 +589,6 @@ async def get_ticket_issues(
|
||||
async def create_ticket_issue(
|
||||
ticket_id: str,
|
||||
issue: IssueCreate,
|
||||
file: Optional[UploadFile] = File(None),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
current_tenant: Tenant = Depends(get_current_tenant),
|
||||
@@ -633,21 +632,11 @@ async def create_ticket_issue(
|
||||
detail=f"Usuarios no encontrados: {missing}",
|
||||
)
|
||||
|
||||
attachment_path = None
|
||||
attachment_filename = None
|
||||
attachment_mime_type = None
|
||||
if file and file.filename:
|
||||
file_metadata = await file_handler.save_upload(file, current_tenant.id, ticket_uuid)
|
||||
attachment_path = file_metadata["file_path"]
|
||||
attachment_filename = file_metadata["original_filename"]
|
||||
attachment_mime_type = file_metadata["mime_type"]
|
||||
|
||||
new_issue = TicketIssue(
|
||||
id=uuid.uuid4(), ticket_id=ticket_uuid,
|
||||
tenant_id=current_user.tenant_id, created_by=current_user.id,
|
||||
tenant_id=ticket_obj.tenant_id, created_by=current_user.id,
|
||||
content=issue.content, priority=TicketPriority[issue.priority],
|
||||
attachment_path=attachment_path, attachment_filename=attachment_filename,
|
||||
attachment_mime_type=attachment_mime_type,
|
||||
attachment_path=None, attachment_filename=None, attachment_mime_type=None,
|
||||
created_at=datetime.utcnow(), updated_at=datetime.utcnow(),
|
||||
)
|
||||
new_issue.tagged_users = tagged_users
|
||||
@@ -677,4 +666,47 @@ async def create_ticket_issue(
|
||||
attachment_filename=new_issue.attachment_filename,
|
||||
attachment_mime_type=new_issue.attachment_mime_type,
|
||||
created_at=new_issue.created_at, updated_at=new_issue.updated_at,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@router.post("/{ticket_id}/issues/{issue_id}/attachment", status_code=status.HTTP_200_OK)
|
||||
async def upload_issue_attachment(
|
||||
ticket_id: str,
|
||||
issue_id: str,
|
||||
file: UploadFile = File(...),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
current_tenant: Tenant = Depends(get_current_tenant),
|
||||
):
|
||||
"""Subir adjunto a un asunto existente."""
|
||||
ticket_uuid = validate_uuid_param(ticket_id, "ticket ID")
|
||||
issue_uuid = validate_uuid_param(issue_id, "issue ID")
|
||||
|
||||
result = await db.execute(
|
||||
select(TicketIssue).where(
|
||||
TicketIssue.id == issue_uuid,
|
||||
TicketIssue.ticket_id == ticket_uuid,
|
||||
)
|
||||
)
|
||||
db_issue = result.scalars().first()
|
||||
if not db_issue:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Asunto no encontrado")
|
||||
|
||||
if db_issue.created_by != current_user.id and not current_user.role.is_global:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Sin permisos")
|
||||
|
||||
upload_tenant_id = db_issue.tenant_id
|
||||
file_metadata = await file_handler.save_upload(file, upload_tenant_id, ticket_uuid)
|
||||
|
||||
db_issue.attachment_path = file_metadata["file_path"]
|
||||
db_issue.attachment_filename = file_metadata["original_filename"]
|
||||
db_issue.attachment_mime_type = file_metadata["mime_type"]
|
||||
db_issue.updated_at = datetime.utcnow()
|
||||
|
||||
await db.commit()
|
||||
|
||||
return {
|
||||
"message": "Adjunto subido correctamente",
|
||||
"attachment_filename": db_issue.attachment_filename,
|
||||
"attachment_mime_type": db_issue.attachment_mime_type,
|
||||
}
|
||||
Reference in New Issue
Block a user