Skip to content

Commit

Permalink
🔔📨 notify of mail
Browse files Browse the repository at this point in the history
  • Loading branch information
jiisanda committed Dec 11, 2023
1 parent 6d96e23 commit 6a0f92d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
13 changes: 11 additions & 2 deletions api/routes/documents/document_sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ async def share_document(
repository: DocumentSharingRepository = Depends(get_repository(DocumentSharingRepository)),
document_repo: DocumentRepository = Depends(DocumentRepository),
metadata_repo: DocumentMetadataRepository = Depends(get_repository(DocumentMetadataRepository)),
notify_repo: NotifyRepo = Depends(get_repository(NotifyRepo)),
auth_repo: AuthRepository = Depends(get_repository(AuthRepository)),
user: TokenData = Depends(get_current_user),
) -> Dict[str, str]:
) -> None:

if not document:
raise HTTP_404(
Expand All @@ -139,7 +141,14 @@ async def share_document(
print("Here here")

return await repository.share_document(
document_key=key, file=file, share_request=share_request, notify=notify, owner=user
filename=get_document_metadata["name"],
document_key=key,
file=file,
share_request=share_request,
notify=notify,
owner=user,
notify_repo=notify_repo,
auth_repo=auth_repo
)
except Exception as e:
raise HTTP_404() from e
18 changes: 13 additions & 5 deletions db/repositories/documents/document_sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from core.exceptions import HTTP_404, HTTP_500
from db.tables.auth.auth import User
from db.tables.documents.document_sharing import DocumentSharing
from db.repositories.auth.auth import AuthRepository
from db.repositories.documents.notify import NotifyRepo
from schemas.auth.bands import TokenData
from schemas.documents.document_sharing import SharingRequest

Expand Down Expand Up @@ -195,8 +197,15 @@ async def confirm_access(self, user: TokenData, url_id: str | None) -> bool:
) from e

async def share_document(
self, document_key: str, file: Any, share_request: SharingRequest, notify: bool, owner: TokenData
) -> Dict[str, str]:
self, filename: str,
document_key: str,
file: Any,
share_request: SharingRequest,
notify: bool,
owner: TokenData,
notify_repo: NotifyRepo,
auth_repo: AuthRepository,
) -> None:

user_mail = await self.get_user_mail(owner)
share_to = share_request.share_to
Expand All @@ -223,6 +232,5 @@ async def share_document(
print(f"mail to {mails}")
mail_service(mail_to=mails, subject=subject, content=content, file_path=temp_path)

return {
"response": "Mails were sent successfully."
}
if notify:
return await notify_repo.notify(user=owner, receivers=share_to, filename=filename, auth_repo=auth_repo)
2 changes: 1 addition & 1 deletion db/repositories/documents/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def notify(self, user: TokenData, receivers: List[str], filename: str, aut
except Exception as e:
raise HTTP_404(
msg="The user does not exists, make sure the user has an account on docflow..."
)
) from e

async def get_notification_by_id(self, n_id: UUID, user: TokenData) -> Notification:
"""
Expand Down

0 comments on commit 6a0f92d

Please sign in to comment.