Skip to content

Commit

Permalink
🔥 pylint updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jiisanda committed Dec 14, 2024
1 parent 35bedb6 commit 7bf19cc
Show file tree
Hide file tree
Showing 29 changed files with 224 additions and 437 deletions.
4 changes: 2 additions & 2 deletions app/api/dependencies/auth_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from passlib.context import CryptContext

from app.core.config import settings
from app.core.exceptions import HTTP_401
from app.core.exceptions import http_401
from app.schemas.auth.bands import TokenData


Expand Down Expand Up @@ -62,7 +62,7 @@ def verify_access_token(token: str, credentials_exception):


def get_current_user(token: str = Depends(oauth2_scheme)):
credentials_exception = HTTP_401(
credentials_exception = http_401(
msg="Could not validate credentials",
headers={
"WWW-Authenticate": "Bearer"
Expand Down
4 changes: 2 additions & 2 deletions app/api/dependencies/mail_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from email.mime.text import MIMEText

from app.core.config import settings
from app.core.exceptions import HTTP_500
from app.core.exceptions import http_500


def mail_service(mail_to: str, subject: str, content: str, file_path: str = None) -> None:
Expand Down Expand Up @@ -50,6 +50,6 @@ def mail_service(mail_to: str, subject: str, content: str, file_path: str = None
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message.as_string())
except Exception as e:
raise HTTP_500(
raise http_500(
msg="There was some error sending email..."
) from e
26 changes: 15 additions & 11 deletions app/api/routes/documents/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from app.api.dependencies.auth_utils import get_current_user
from app.api.dependencies.repositories import get_repository
from app.core.exceptions import HTTP_400, HTTP_404
from app.core.exceptions import http_400, http_404
from app.db.repositories.auth.auth import AuthRepository
from app.db.repositories.documents.documents import DocumentRepository, perm_delete as perm_delete_file
from app.db.repositories.documents.documents_metadata import DocumentMetadataRepository
Expand All @@ -28,7 +28,9 @@ async def upload(
files: List[UploadFile] = File(...),
folder: Optional[str] = None,
repository: DocumentRepository = Depends(DocumentRepository),
metadata_repository: DocumentMetadataRepository = Depends(get_repository(DocumentMetadataRepository)),
metadata_repository: DocumentMetadataRepository = Depends(
get_repository(DocumentMetadataRepository)
),
user_repository: AuthRepository = Depends(get_repository(AuthRepository)),
user: TokenData = Depends(get_current_user)
) -> Union[List[DocumentMetadataRead], List[Dict[str, str]]]:
Expand All @@ -40,12 +42,14 @@ async def upload(
files (List[UploadFile]): The files to be uploaded.
folder (Optional[str]): The folder where the document will be stored. Defaults to None.
repository (DocumentRepository): The repository for managing documents.
metadata_repository (DocumentMetadataRepository): The repository for managing document metadata.
metadata_repository (DocumentMetadataRepository): The repository for managing document
metadata.
user_repository (AuthRepository): The repository for managing user authentication.
user (TokenData): The token data of the authenticated user.
Returns:
Union[DocumentMetadataRead, Dict[str, str]]: If the file is added, returns the uploaded document metadata.
Union[DocumentMetadataRead, Dict[str, str]]: If the file is added, returns the
uploaded document metadata.
If the file is updated, returns the patched document metadata.
Otherwise, returns a response dictionary.
Expand All @@ -54,7 +58,7 @@ async def upload(
"""

if not files:
raise HTTP_400(
raise http_400(
msg="No input files provided..."
)

Expand Down Expand Up @@ -110,15 +114,15 @@ async def download(
"""

if not file_name:
raise HTTP_400(
raise http_400(
msg="No file name..."
)
try:
get_document_metadata = dict(await metadata_repository.get(document=file_name, owner=user))

return await repository.download(s3_url=get_document_metadata["s3_url"], name=get_document_metadata["name"])
except Exception as e:
raise HTTP_404(
raise http_404(
msg=f"No file with {file_name}"
) from e

Expand Down Expand Up @@ -214,7 +218,7 @@ async def perm_delete(
)

except Exception as e:
raise HTTP_404(
raise http_404(
msg=f"No file with {file_name}"
) from e

Expand Down Expand Up @@ -301,17 +305,17 @@ async def get_document_preview(
"""

if not document:
raise HTTP_404(
raise http_404(
msg="Enter document id or name."
)
try:
get_document_metadata = dict(await metadata_repository.get(document=document, owner=user))
return await repository.preview(document=get_document_metadata)
except TypeError as e:
raise HTTP_404(
raise http_404(
msg="Document does not exists."
) from e
except ValueError as e:
raise HTTP_400(
raise http_400(
msg="File type is not supported for preview"
) from e
18 changes: 9 additions & 9 deletions app/api/routes/documents/document_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ async def search_document(
file_types (str, optional): The file types to filter documents by. Defaults to None.
doc_status (str, optional): The status of documents to filter by. Defaults to None.
repository (DocumentOrgRepository): The repository for managing document organization.
repository_metadata (DocumentMetadataRepository): The repository for managing document metadata.
repository_metadata (DocumentMetadataRepository): The repository for managing
document metadata.
user (TokenData): The token data of the authenticated user.
Returns:
Expand All @@ -50,11 +51,10 @@ async def search_document(
if tag is None and category is None and file_types is None and doc_status is None:
return doc_list

else:
return await repository.search_doc(
docs=doc_list,
tags=tag,
categories=category,
file_types=file_types,
status=doc_status
)
return await repository.search_doc(
docs=doc_list,
tags=tag,
categories=category,
file_types=file_types,
status=doc_status
)
60 changes: 38 additions & 22 deletions app/api/routes/documents/document_sharing.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Dict, Union
from typing import Union
from uuid import UUID

from fastapi import APIRouter, Depends, status
from fastapi.responses import RedirectResponse

from app.api.dependencies.auth_utils import get_current_user
from app.api.dependencies.repositories import get_repository, get_key
from app.core.exceptions import HTTP_404
from app.core.exceptions import http_404
from app.db.repositories.auth.auth import AuthRepository
from app.db.repositories.documents.documents import DocumentRepository
from app.db.repositories.documents.documents_metadata import DocumentMetadataRepository
Expand All @@ -28,8 +28,12 @@ async def share_link_document(
document: Union[str, UUID],
share_request: SharingRequest,
repository: DocumentSharingRepository = Depends(get_repository(DocumentSharingRepository)),
auth_repository: AuthRepository = Depends(get_repository(AuthRepository)),
metadata_repository: DocumentMetadataRepository = Depends(get_repository(DocumentMetadataRepository)),
auth_repository: AuthRepository = Depends(
get_repository(AuthRepository)
),
metadata_repository: DocumentMetadataRepository = Depends(
get_repository(DocumentMetadataRepository)
),
notify_repository: NotifyRepo = Depends(get_repository(NotifyRepo)),
user: TokenData = Depends(get_current_user)
):
Expand All @@ -39,10 +43,12 @@ async def share_link_document(
Args:
document (Union[str, UUID]): The ID or name of the document to be shared.
share_request (SharingRequest): The sharing request containing the details of the sharing operation.
share_request (SharingRequest): The sharing request containing the
details of the sharing operation.
repository (DocumentSharingRepository): The repository for managing document sharing.
auth_repository (AuthRepository): The repository for managing User-related queries.
metadata_repository (DocumentMetadataRepository): The repository for managing document metadata.
metadata_repository (DocumentMetadataRepository): The repository for managing
document metadata.
notify_repository (NotifyRepo): The repository for managing notification
user (TokenData): The token data of the authenticated user.
Expand Down Expand Up @@ -73,7 +79,9 @@ async def share_link_document(

# send a notification to the receiver
await notify_repository.notify(
user=user, receivers=share_to, filename=doc.__dict__["name"], auth_repo=auth_repository
user=user, receivers=share_to,
filename=doc.__dict__["name"],
auth_repo=auth_repository,
)

return {
Expand All @@ -82,15 +90,17 @@ async def share_link_document(
}

except KeyError as e:
raise HTTP_404(
raise http_404(
msg=f"No doc: {document}"
) from e


@router.get("/doc/{url_id}", tags=["Document Sharing"])
async def redirect_to_share(
url_id: str,
repository: DocumentSharingRepository = Depends(get_repository(DocumentSharingRepository)),
repository: DocumentSharingRepository = Depends(get_repository(
DocumentSharingRepository)
),
user: TokenData = Depends(get_current_user)
):

Expand Down Expand Up @@ -121,9 +131,13 @@ async def share_document(
document: Union[str, UUID],
share_request: SharingRequest,
notify: bool = True,
repository: DocumentSharingRepository = Depends(get_repository(DocumentSharingRepository)),
repository: DocumentSharingRepository = Depends(
get_repository(DocumentSharingRepository)
),
document_repo: DocumentRepository = Depends(DocumentRepository),
metadata_repo: DocumentMetadataRepository = Depends(get_repository(DocumentMetadataRepository)),
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),
Expand All @@ -133,15 +147,17 @@ async def share_document(
Share a document with other users, and notifies if notify is set to True (default).
Args:
document (Union[str, UUID]): The ID or UUID of the document to be shared.
share_request (SharingRequest): The sharing request containing the recipients and permissions.
notify (bool, optional): Whether to send notifications to the recipients. Defaults to True.
repository (DocumentSharingRepository, optional): The repository for document sharing operations.
document_repo (DocumentRepository, optional): The repository for document operations.
metadata_repo (DocumentMetadataRepository, optional): The repository for document metadata operations.
notify_repo (NotifyRepo, optional): The repository for notification operations.
auth_repo (AuthRepository, optional): The repository for authentication operations.
user (TokenData, optional): The authenticated user.
document (Union[str, UUID]): The ID or UUID of the document to be shared.
share_request (SharingRequest): The sharing request containing the recipients and permissions.
notify (bool, optional): Whether to send notifications to the recipients. Defaults to True.
repository (DocumentSharingRepository, optional): The repository for document sharing
operations.
document_repo (DocumentRepository, optional): The repository for document operations.
metadata_repo (DocumentMetadataRepository, optional): The repository for document metadata
operations.
notify_repo (NotifyRepo, optional): The repository for notification operations.
auth_repo (AuthRepository, optional): The repository for authentication operations.
user (TokenData, optional): The authenticated user.
Raises:
HTTP_404: If the document is not found.
Expand All @@ -151,7 +167,7 @@ async def share_document(
"""

if not document:
raise HTTP_404(
raise http_404(
msg="Enter document id or UUID."
)
try:
Expand All @@ -171,4 +187,4 @@ async def share_document(
auth_repo=auth_repo
)
except Exception as e:
raise HTTP_404() from e
raise http_404() from e
6 changes: 3 additions & 3 deletions app/api/routes/documents/documents_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from app.api.dependencies.repositories import get_repository
from app.api.dependencies.auth_utils import get_current_user
from app.core.exceptions import HTTP_404
from app.core.exceptions import http_404
from app.db.repositories.auth.auth import AuthRepository
from app.db.repositories.documents.documents_metadata import DocumentMetadataRepository
from app.schemas.auth.bands import TokenData
Expand Down Expand Up @@ -135,7 +135,7 @@ async def update_doc_metadata_details(
try:
await repository.get(document=document, owner=user)
except Exception as e:
raise HTTP_404(
raise http_404(
msg=f"No Document with: {document}"
) from e

Expand Down Expand Up @@ -177,7 +177,7 @@ async def delete_document_metadata(
try:
await repository.get(document=document, owner=user)
except Exception as e:
raise HTTP_404(
raise http_404(
msg=f"No document with the detail: {document}."
) from e

Expand Down
4 changes: 2 additions & 2 deletions app/api/routes/documents/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from app.api.dependencies.auth_utils import get_current_user
from app.api.dependencies.repositories import get_repository
from app.core.exceptions import HTTP_404
from app.core.exceptions import http_404
from app.db.repositories.documents.notify import NotifyRepo
from app.schemas.auth.bands import TokenData
from app.schemas.documents.bands import Notification, NotifyPatchStatus
Expand Down Expand Up @@ -71,7 +71,7 @@ async def patch_status(
elif notification_id:
return await repository.update_status(n_id=notification_id, updated_status=updated_status, user=user)
else:
raise HTTP_404(
raise http_404(
msg="Bad Request: Make sure to either flag mark_all "
"or enter notification_id along with correct status as payload."
)
Expand Down
7 changes: 5 additions & 2 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@


class GlobalConfig(BaseSettings):
"""
Global Configuration for the FastAPI application.
"""
title: str = os.environ.get("TITLE")
version: str = "1.0.0"
description: str = os.environ.get("DESCRIPTION")
Expand All @@ -15,13 +18,13 @@ class GlobalConfig(BaseSettings):
redoc_url: str = "/redoc"
openapi_url: str = "/openapi.json"
api_prefix: str = "/v2"
debug: bool = os.environ.get("DEBUG")
debug: bool = str(os.environ.get("DEBUG", "False")).lower() == "true"
postgres_user: str = os.environ.get("POSTGRES_USER")
postgres_password: str = os.environ.get("POSTGRES_PASSWORD")
postgres_hostname: str = os.environ.get("DATABASE_HOSTNAME")
postgres_port: int = int(os.environ.get("POSTGRES_PORT"))
postgres_db: str = os.environ.get("POSTGRES_DB")
db_echo_log: bool = True if os.environ.get("DEBUG") is True else False
db_echo_log: bool = str(os.environ.get("DEBUG", "False")).lower() == "true"
aws_access_key_id: str = os.environ.get("AWS_ACCESS_KEY_ID")
aws_secret_key: str = os.environ.get("AWS_SECRET_ACCESS_KEY")
aws_region: str = os.environ.get("AWS_REGION")
Expand Down
Loading

0 comments on commit 7bf19cc

Please sign in to comment.