Skip to content

Commit

Permalink
Merge branch 'master' into interact
Browse files Browse the repository at this point in the history
  • Loading branch information
jiisanda authored Dec 14, 2024
2 parents 1586073 + 9a82abd commit c471968
Show file tree
Hide file tree
Showing 33 changed files with 294 additions and 449 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Pylint

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --disable=E0401,C0116,C0114,C0115,C0301,R0913,R0914,R0917,R0903,C0103,E1101,W0611
39 changes: 39 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# - name: Test with pytest
# run: |
# pytest
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11.6
FROM python:3.12
LABEL authors="jiisanda"

WORKDIR /usr/src/app
Expand Down
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
Loading

0 comments on commit c471968

Please sign in to comment.