Skip to content

Commit

Permalink
google oAuth2 integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazarii committed Mar 21, 2024
1 parent 0b4ccbc commit 7fcb62c
Show file tree
Hide file tree
Showing 69 changed files with 1,190 additions and 366 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ redis-*.tgz
db.sqlite3
.secrets.env
*.spec
.secrets.env
171 changes: 171 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#!/bin/bash


help() {
echo ""
echo "Usage: build.sh [--linter <string>] [--build <string>] [--test]"
echo "-l, --linter <string> Linter to run (black, isort, flake8)"
echo "-b, --build <string> Build type (frontend, backend)"
echo "-h, --help <string> Print this help message"
echo "-t, --test <string> Test type (backend)"
echo
}

install_dependencies() {
pip install -r requirements.txt
}

run_black() {
echo "Running Black..."
black --check --diff .
}

run_isort() {
echo "Running isort..."
isort --check --diff .
}

run_flake8() {
echo "Running Flake8..."
flake8 .
}


validate_image_args() {
IMAGE_NAME=${IMAGE_NAME:-$CI_REGISTRY_IMAGE} # "registry.gitlab.com/mds7060534/naivebayes_app/backend"
APP_VERSION=${APP_VERSION:-$CI_COMMIT_REF_SLUG}
PROJECT_PATH=${build_path}

if [ -z "${IMAGE_NAME}" ]; then
echo "Docker image not specified. Please provide -i | --image-name"
echo "Supported env vars: DOCKER_IMAGE | CI_REGISTRY_IMAGE"
exit 1
fi

if [ -z "${APP_VERSION}" ]; then
echo "Docker image not specified. Please provide -v | --version"
echo "Supported env vars: APP_VERSION | CI_COMMIT_REF_SLUG"
exit 1
fi

IMAGE=${IMAGE_NAME}/${PROJECT_PATH}:${APP_VERSION}

echo "Image Name: ${IMAGE_NAME}"
echo "App Version: ${APP_VERSION}"
echo "Project Path: ${PROJECT_PATH}"
echo "Image: ${IMAGE}"
}

run_build() {

validate_image_args

CI_PROJECT_DIR=$(pwd)
DOCKERFILE_PATH="./Dockerfile"
CONTEXT="${CI_PROJECT_DIR}/${PROJECT_PATH}"

/kaniko/executor --context "${CONTEXT}" --dockerfile "${DOCKERFILE_PATH}" --destination "${IMAGE_NAME}"
}

run_test() {
validate_image_args

docker pull $IMAGE
docker run --entrypoint="" --rm --name $PROJECT_PATH $IMAGE python -m coverage run -m unittest discover -s tests -p *_test.py
}

# Main function to execute linting tasks based on the specified linter

if [ $# -eq 0 ]; then
echo "No arguments provided. Usage: ./build.sh --help"
exit 1
fi


main() {
while [[ $# -gt 0 ]]; do
key="$1"
case "$key" in
-l|--linter)
linter="$2"
shift; shift;
;;
-b|--build)
build="$2"
build_path="$2"
shift; shift;
;;
-t|--test)
test="$2"
build_path="$2"
shift; shift;
;;
-h|--help)
help
exit 0;
;;
-i|--image-name)
IMAGE_NAME="$2"
shift; shift;
;;
-v|--version)
APP_VERSION="$2"
shift; shift;
;;
*)
echo "Invalid argument: $key"
help
exit 1
;;
esac
done
}


main "$@"


if [ "$linter" ]; then
case "$linter" in
black)
run_black "$@"
;;
isort)
run_isort "$@"
;;
flake8)
run_flake8 "$@"
;;
*)
echo "Invalid linter: $linter"
exit 1
;;
esac
fi

if [ "$build" ]; then
case "$build" in
frontend)
run_build "$@"
;;
backend)
run_build "$@"
;;
*)
echo "Invalid build: $build"
exit 1
;;
esac
fi

if [ "$test" ]; then
case "$test" in
backend)
run_test "$@"
;;
*)
echo "Invalid test: $test"
exit 1
;;
esac
fi
2 changes: 1 addition & 1 deletion docker/dev/env/.email.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EMAIL_HOST=gateway-host
EMAIL_HOST=host.docker.internal
EMAIL_PORT=1025
EMAIL_USE_TLS=0
EMAIL_USE_SSL=0
Expand Down
6 changes: 3 additions & 3 deletions docker/dev/env/.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ HEALTH_CHECK_URL=/application/health/
ENABLE_SILK=1
ENABLE_DEBUG_TOOLBAR=0
ENABLE_SENTRY=0
FRONTEND_URL=http://192.168.59.111:8008
BACKEND_URL=http://192.168.59.111:8008
FRONTEND_URL=http://localhost:8008
BACKEND_URL=http://localhost:8008

CHAT_PROXY=http://192.168.59.111:8005/init/
CHAT_PROXY=http://localhost:8005/init/
19 changes: 19 additions & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
* Install dependencies
```shell
pipenv install -r docs/requirements.txt --dev
```

* doc8 style checks
```shell
doc8 docs/source/ --config web/pyproject.toml
```

* Generate documentation
```shell
make -C docs html
```

* Check spelling
```shell
make -C docs spelling
```
Empty file.
72 changes: 72 additions & 0 deletions web/api/email_service/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Optional, TypedDict

from django.contrib.auth import get_user_model
from django.utils.translation import get_language

from main.tasks import send_information_email

if TYPE_CHECKING:
from main.models import UserType


User: 'UserType' = get_user_model()


class EmailSendData(TypedDict):
subject: str
template_name: str
language: str
to_email: str
context: dict
from_email: Optional[str]
file_path_attachments: Optional[str]


class BaseEmailService(ABC):
def __init__(self, user: Optional[User] = None, language: Optional[str] = None, from_email: Optional[str] = None):
self._user = user
self._locale: str = language or get_language()
self.from_email = from_email

@property
def locale(self) -> str:
return self._locale

@property
def user(self) -> User:
assert self._user, 'User object were not provided'
return self._user

@property
@abstractmethod
def template_name(self) -> str:
"""Template email path"""

@property
def to_email(self) -> str:
return self.user.email

def email_context(self, **kwargs) -> dict:
"""Provide dict with data for email template rendering"""
return {}

@property
@abstractmethod
def email_subject(self) -> str:
"""Provide email subject"""

def get_email_data(self, **kwargs) -> EmailSendData:
return {
'subject': self.email_subject,
'template_name': self.template_name,
'language': self.locale,
'to_email': self.to_email,
'context': self.email_context(**kwargs),
'from_email': self.from_email,
'file_path_attachments': None,
}

def send_email(self, **kwargs):
kwargs: dict = self.get_email_data(**kwargs)
return send_information_email.apply_async(kwargs=kwargs)
18 changes: 18 additions & 0 deletions web/api/email_service/password_reset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.conf import settings
from django.utils.translation import gettext_lazy as _

from api.email_service.base import BaseEmailService


class PasswordResetService(BaseEmailService):
template_name = 'emails/password_reset.html'

@property
def email_subject(self) -> str:
return _('Blog password reset')

def email_context(self, reset_url: str, **kwargs) -> dict:
return {
'full_name': self.user.full_name,
'reset_url': reset_url,
}
17 changes: 17 additions & 0 deletions web/api/email_service/sign_up.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.utils.translation import gettext_lazy as _

from api.email_service.base import BaseEmailService


class SignUpEmailService(BaseEmailService):
template_name = 'emails/verify_email.html'

@property
def email_subject(self) -> str:
return _('Blog register confirmation email')

def email_context(self, activate_url: str, **kwargs) -> dict:
return {
'full_name': self.user.full_name,
'activate_url': activate_url,
}
38 changes: 0 additions & 38 deletions web/api/email_services.py

This file was deleted.

2 changes: 0 additions & 2 deletions web/api/v1/actions/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class FollowSerializer(serializers.Serializer):


class UserFollowSerializer(serializers.ModelSerializer):
"""For list of user following and followers"""

profile_url = serializers.URLField(source='get_absolute_url')

follow = serializers.BooleanField()
Expand Down
Loading

0 comments on commit 7fcb62c

Please sign in to comment.