Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
DangjeG committed Dec 23, 2023
2 parents fee4706 + accbaa8 commit 4a2c864
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
4 changes: 2 additions & 2 deletions backend/wiki/wiki_workspace/document/export/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ async def export_document(
ya_disk)
if export_type.DOCX:
res = converters.docx.convert(html)
headers = {"Content-Disposition": f'attachment; filename="{title}".docx'}
return Response(res, headers=headers, media_type="application/pdf")
headers = {"Content-Disposition": f'attachment; filename*=UTF-8\'\'"{title}"'}
return Response(res, headers=headers, media_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document")

raise Exception

Expand Down
24 changes: 19 additions & 5 deletions backend/wiki/wiki_workspace/document/repository.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional
from uuid import UUID

from sqlalchemy import select, and_
from sqlalchemy import select, and_, update
from starlette import status

from wiki.common.exceptions import WikiException, WikiErrorCode
Expand Down Expand Up @@ -41,13 +41,22 @@ async def _get_result_document_with_permission(self, user_id: UUID, *whereclause
*whereclause
)

async def get_documents_with_permission(self, user_id: UUID) -> list:
res = await self._get_result_document_with_permission(user_id)
async def get_documents_with_permission(self, user_id: UUID, is_only_existing: bool = True) -> list:
whereclause = []
if is_only_existing:
whereclause.append(Document.is_deleted == False)
res = await self._get_result_document_with_permission(user_id, *whereclause)
return res.all()

@menage_db_not_found_result_method(NotFoundResultMode.EXCEPTION, ex=document_not_found_exception)
async def get_document_with_permission_by_id(self, user_id: UUID, document_id: UUID):
res = await self._get_result_document_with_permission(user_id, Document.id == document_id)
async def get_document_with_permission_by_id(self,
user_id: UUID,
document_id: UUID,
is_only_existing: bool = True):
whereclause = [Document.id == document_id]
if is_only_existing:
whereclause.append(Document.is_deleted == False)
res = await self._get_result_document_with_permission(user_id, *whereclause)
return res.first()

@menage_db_not_found_result_method(NotFoundResultMode.EXCEPTION, ex=document_not_found_exception)
Expand Down Expand Up @@ -82,6 +91,11 @@ async def mark_document_delete(self, document_id: UUID):
document = await self.get_document_by_id(document_id)
document.is_deleted = True

query = (update(Document).where(Document.parent_document_id == document_id)
.values(parent_document_id=document.parent_document_id))

await self.session.execute(query)

self.session.add(document)

@menage_db_commit_method(CommitMode.FLUSH)
Expand Down
12 changes: 11 additions & 1 deletion backend/wiki/wiki_workspace/document/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ async def delete_document(
session: AsyncSession = Depends(get_db),
user: WikiUserHandlerData = Depends(BasePermission(responsibility=ResponsibilityType.VIEWER))
):
"""
## Deleted document by id
**You have to have a deletion permission or be an administrator.**
When a document is deleted, the hierarchy changes:
all child documents become child documents of the parent.
"""

document_repository: DocumentRepository = DocumentRepository(session)
if user.wiki_api_client.responsibility != ResponsibilityType.ADMIN:
document = await document_repository.get_document_with_permission_by_id(user.id, document_id)
Expand All @@ -186,7 +194,9 @@ async def delete_document(
else:
document = await document_repository.get_document_by_id(document_id)

await document_repository
await document_repository.mark_document_delete(document.id)

return BaseResponse(msg="Document deleted")


@document_router.post(
Expand Down
41 changes: 41 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2541,6 +2541,47 @@ paths:
summary: Get tree documents
tags:
- WorkspaceDocument
/api/v1/document/{document_id}:
delete:
description: '## Deleted document by id
**You have to have a deletion permission or be an administrator.**
When a document is deleted, the hierarchy changes:
all child documents become child documents of the parent.'
operationId: delete_document_api_v1_document__document_id__delete
parameters:
- in: path
name: document_id
required: true
schema:
format: uuid
title: Document Id
type: string
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/BaseResponse'
description: Successful Response
'422':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
description: Validation Error
security:
- WikiRootApiKey: []
- WikiApiKey: []
- WikiApiKey: []
- WikiAccessToken: []
- WikiBearer: []
summary: Delete document
tags:
- WorkspaceDocument
/api/v1/document/{document_id}/publish:
post:
description: '## Publish document
Expand Down

0 comments on commit 4a2c864

Please sign in to comment.