Skip to content
This repository has been archived by the owner on Aug 21, 2022. It is now read-only.

pr/custom user model #96

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
255c717
added custom fields to user model
ElijahAhianyo Dec 18, 2020
89f5966
added custom fields to user model
ElijahAhianyo Dec 18, 2020
b7f6c4d
added is_verfied property to user class
Dec 19, 2020
e3d5b51
MYC-180 #comment added custom fields to user mode
ElijahAhianyo Dec 20, 2020
4da3fd8
MYC-180 #comment corrected issue with line too long
ElijahAhianyo Dec 20, 2020
614d768
Update settings.py
ElijahAhianyo Dec 26, 2020
ae3902b
Merge remote-tracking branch 'upstream/pr/custom-user-model' into add…
milan-tom Dec 26, 2020
42ba57d
Update initial ideas for testing
milan-tom Dec 27, 2020
29ce774
Merge pull request #1 from milan-tom/pr/custom-user-model
ElijahAhianyo Dec 27, 2020
9ff589f
MYC-180 #comment resolved issue with phoneno field in migration
ElijahAhianyo Dec 27, 2020
5aa9b0a
Merge branch 'pr/custom-user-model' of github.com:ElijahAhianyo/covid…
ElijahAhianyo Dec 27, 2020
7c6669f
Merge remote-tracking branch 'upstream/pr/custom-user-model' into add…
milan-tom Dec 27, 2020
762d2f3
MYC-180 #comment added email_verified field
ElijahAhianyo Dec 27, 2020
d3c3072
Merge remote-tracking branch 'upstream/pr/custom-user-model' into add…
milan-tom Dec 27, 2020
9b97d15
MYC-180 #comment removed unnecessary whitespace
milan-tom Dec 29, 2020
db769ac
MYC-184 #comment Updated test for unverified user
milan-tom Dec 29, 2020
2bc31bd
MYC-184 #comment Added tests for partially verified users
milan-tom Dec 29, 2020
6050a61
MYC-184 #comment Added test for fully verified user
milan-tom Dec 29, 2020
e8374e5
Merge pull request #2 from milan-tom/add-test-cases
ElijahAhianyo Dec 30, 2020
4d279a6
MYC-184 #comment Incorporated verified arguments into create_user method
milan-tom Jan 1, 2021
f1d4cf6
MYC-184 #comment Loaded credentials from .ini file
milan-tom Jan 1, 2021
d4e825c
MYC-184 #comment Added newline at end of file
milan-tom Jan 1, 2021
bcf643c
MYC-184 #comment Added class to obtain credentials from .ini file
milan-tom Jan 2, 2021
fc15388
MYC-184 #comment Moved classes to obtain credentials to common directory
milan-tom Jan 13, 2021
454e6f8
MYC-184 #comment Added initial ideas for bytestream config file loader
milan-tom Jan 13, 2021
792bcb9
Merge pull request #3 from milan-tom/add-test-cases
ElijahAhianyo Jan 13, 2021
10eb3dd
MYC-184 #comment Moved non-standard import statement
milan-tom Jan 13, 2021
53b4d2c
MYC-184 #comment Removed trailing whitespace
milan-tom Jan 13, 2021
544a0e0
MYC-184 #comment Reformatted code
milan-tom Jan 14, 2021
ff1d7c0
MYC-184 #comment Removed trailing whitespace
milan-tom Jan 14, 2021
4ca9cf5
MYC-184 #comment Added docstrings to classes
milan-tom Jan 14, 2021
9ee5f3f
MYC-184 #comment Reformatted code
milan-tom Jan 14, 2021
9214508
MYC-184 #comment Reformatted code
milan-tom Jan 14, 2021
69baf7c
Updated gitignore and requirements_dev
milan-tom Jan 16, 2021
f803dc2
MYC-184 #comment Removed ConfigByteLoader, saving it for future pr
milan-tom Jan 16, 2021
ca65008
MYC-184 #comment Removed unnecessary import of io module
milan-tom Jan 16, 2021
5a5471a
MYC-184 #comment Moved config_file definition to new testing settings
milan-tom Jan 16, 2021
56096ab
MYC-184 #comment Removed unnecessary settings definition
milan-tom Jan 16, 2021
7392324
MYC-184 #comment Removed unused custom credentials class
milan-tom Jan 23, 2021
bfc5e78
MYC-184 #comment Resolved conflict with requirements_dev
milan-tom Jan 23, 2021
8feef55
Merge branch 'master' into pr/custom-user-model
milan-tom Jan 23, 2021
29c24f4
Merge branch 'master' of https://github.com/Xcov19/covidX into pr/cus…
milan-tom Jan 23, 2021
2a0b3cb
Merge branch 'master' of https://github.com/Xcov19/covidX into pr/cus…
milan-tom Jan 24, 2021
dba98d5
Merge branch 'pr/custom-user-model' of https://github.com/ElijahAhian…
milan-tom Jan 24, 2021
24d4971
Merge branch 'master' of https://github.com/Xcov19/covidX into pr/cus…
milan-tom Jan 24, 2021
6617ddc
Merge branch 'master' of https://github.com/Xcov19/covidX into pr/cus…
milan-tom Jan 24, 2021
4b875b1
Merge branch 'present-run' into pr/custom-user-model
codecakes Jan 24, 2021
beb7c60
MYC-184 #comment Moved config_file from dev.py and hardcoded it for now
milan-tom Jan 25, 2021
0deb71d
MYC-184 #comment Resolved merge conflicts
milan-tom Jan 25, 2021
1d0876c
MYC-184 #comment Merged with present-run
milan-tom Jan 25, 2021
99a9f6e
Merge remote-tracking branch 'upstream/present-run' into pr/custom-us…
milan-tom Jan 26, 2021
1fa0783
Merge branch 'present-run' of https://github.com/Xcov19/covidX into p…
milan-tom Jan 26, 2021
279951f
Merge branch 'master' of https://github.com/Xcov19/covidX into pr/cus…
milan-tom Jan 26, 2021
56fbb52
Merge remote-tracking branch 'upstream/codecakes-patch-fixes-improper…
milan-tom Feb 3, 2021
09fd3f8
Merge branch 'master' of https://github.com/Xcov19/covidX into pr/cus…
milan-tom Feb 3, 2021
3da0a46
MYC-184 #comment Reformatted migrations with black
milan-tom Feb 3, 2021
6a15f2b
Merge branch 'master' into pr/custom-user-model
codecakes Feb 4, 2021
de1e7dd
Fix the conflicts
codecakes Feb 6, 2021
90a4b08
This is not a feature branch
codecakes Feb 6, 2021
5bc82fa
not a feature or testing branch
codecakes Feb 6, 2021
0607807
Merge branch 'master' into present-run
codecakes Feb 6, 2021
07c2cc4
Merge remote-tracking branch 'upstream/present-run' into pr/custom-us…
milan-tom Feb 6, 2021
725273b
add back to resolve
codecakes Feb 7, 2021
0628ada
WIP fixes to BUILD for pr/custom-user-model
codecakes Feb 8, 2021
c5eec55
MYC-184 #comment Moved common into apps
milan-tom Feb 8, 2021
f3db20e
MYC-184 #comment Moved test_config.ini
milan-tom Feb 8, 2021
234e4ef
MYC-184 #comment Moved test_config.ini into apps/auth_zero/config/dat…
milan-tom Feb 8, 2021
be6289d
MYC-184 #comment Removed __init__.py file from config since it is not…
milan-tom Feb 8, 2021
d4ffef0
MYC-184 #comment Removed __init__.py file from common since it no lon…
milan-tom Feb 8, 2021
b460878
MYC-184 #comment Updated interfaces for loading files
milan-tom Feb 8, 2021
33b6355
copy cert/key after bazel build to save time on change
marcelloromani Feb 9, 2021
ae6fe69
Merge branch 'devops/copy_certs_after_bazel_build' of github.com:marc…
codecakes Feb 21, 2021
8e3bb4d
Updated docker
codecakes Feb 21, 2021
097fbdb
Added BUILD, refined dockerfile & up-script; fixed config.py;
codecakes Feb 21, 2021
fedd851
MYC-184 #comment Merge changes from Feature/docker custom user model
milan-tom Feb 21, 2021
1a8ec38
MYC-184 #comment Fixed gitpod glitch
milan-tom Feb 21, 2021
de7b57e
fix codacity static code analysis warning
marcelloromani Feb 24, 2021
4d478ab
Merge branch 'master' into pr/custom-user-model
marcelloromani Feb 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ venv.bak/
#Visual studio
.vscode/*
.vscode
.theia

#Idea Files
**/.idea/
Expand Down
3 changes: 2 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ buildifier(
)

REQS = [
"django",
"python-dotenv",
"social-auth-app-django",
"social-auth-core",
Expand All @@ -23,7 +24,7 @@ REQS = [
]

DEPS = [
"//covidX/settings:dev",
"//covidX:settings",
"//covidX:urls",
"//covidX:asgi",
"//covidX:wsgi",
Expand Down
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ ENV DEBUG_ENV=1
ENV SECRET_KEY=dskaj343
ENV CPPFLAGS="$(pg_config --cppflags)"
ENV LDFLAGS="$(pg_config --ldflags)"
COPY privateKey.key /privateKey.key
COPY certificate /certificate
ENV BAZEL_CACHE="/bazel-cache"

#build
RUN CPPFLAGS="$(pg_config --cppflags)" LDFLAGS="$(pg_config --ldflags)" bazel build :manage --watchfs --spawn_strategy=standalone --copt --aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements --verbose_failures=true --show_timestamps=true --python_version=PY3 --build_python_zip --sandbox_debug --color=yes --curses=yes --jobs=2000 --loading_phase_threads=HOST_CPUS --action_env=LDFLAGS --action_env=CPPFLAGS --action_env=DEBUG_ENV --action_env=SECRET_KEY
RUN mkdir -p $BAZEL_CACHE
RUN CPPFLAGS="$(pg_config --cppflags)" LDFLAGS="$(pg_config --ldflags)" bazel build :manage --watchfs --spawn_strategy=standalone --copt --aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements --verbose_failures=true --show_timestamps=true --python_version=PY3 --build_python_zip --sandbox_debug --color=yes --curses=yes --jobs=2000 --loading_phase_threads=HOST_CPUS --action_env=LDFLAGS --action_env=CPPFLAGS --action_env=DEBUG_ENV --action_env=SECRET_KEY --action_env=$BAZEL_CACHE --disk_cache=$BAZEL_CACHE

COPY privateKey.key /privateKey.key
COPY certificate /certificate

COPY pre-start.sh /pre-start.sh
COPY up-script.sh /up-script.sh
Expand Down
16 changes: 16 additions & 0 deletions apps/auth_zero/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ py_library(
],
)

py_test(
name = "test",
srcs = [
"tests.py",
],
# TODO(codecakes): include common in deps module once moved to apps/
deps = [
requirement("django"),
],
# TODO(codecakes): include data to include data folder
# that has config/test_config.ini
data = [],
main = "tests.py",
srcs_version = "PY3"
)

filegroup(
name = "auth_zero_tmpl",
srcs = glob([
Expand Down
21 changes: 21 additions & 0 deletions apps/auth_zero/config/data/test/test_config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[DEFAULT]
PASSWORD = testPass
EMAIL = [email protected]
otp_verified = False
email_verified = False

[fully_unverified]
USERNAME = fullyUnverifiedUser

[only_otp_verified]
USERNAME = onlyOTPVerifiedUser
otp_verified=True

[only_email_verified]
USERNAME = onlyEmailVerifiedUser
email_verified=True

[fully_verified]
USERNAME = fullyVerifiedUser
otp_verified = True
email_verified = True
31 changes: 31 additions & 0 deletions apps/auth_zero/migrations/0004_auto_20201227_1514.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 3.0.7 on 2020-12-27 15:14

from django.db import migrations, models
import phonenumber_field.modelfields


class Migration(migrations.Migration):

dependencies = [
("auth_zero", "0003_auto_20201211_1219"),
]

operations = [
migrations.AddField(
model_name="user",
name="last_otp",
field=models.CharField(max_length=20, null=True),
),
migrations.AddField(
model_name="user",
name="mobile",
field=phonenumber_field.modelfields.PhoneNumberField(
blank=True, max_length=128, region=None
),
),
migrations.AddField(
model_name="user",
name="otp_verified",
field=models.BooleanField(default=False),
),
]
18 changes: 18 additions & 0 deletions apps/auth_zero/migrations/0005_user_email_verified.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-12-27 16:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("auth_zero", "0004_auto_20201227_1514"),
]

operations = [
migrations.AddField(
model_name="user",
name="email_verified",
field=models.BooleanField(default=False),
),
]
10 changes: 10 additions & 0 deletions apps/auth_zero/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from django.db import transaction
from django.db.models import Q

from phonenumber_field.modelfields import PhoneNumberField

UserTypes_T = TypeVar("UserTypes_T", bound="UserTypes")
User_T = TypeVar("User_T", bound="User")
AccountTypes_T = TypeVar("AccountTypes_T", bound="AccountType")
Expand All @@ -26,10 +28,18 @@ class User(AbstractUser):
"""Custom Auth User model."""

default_user_type = UserTypes.PATIENT
mobile = PhoneNumberField(blank=True)
last_otp = models.CharField(blank=False, null=True, max_length=20)
otp_verified = models.BooleanField(default=False)
email_verified = models.BooleanField(default=False)

class Meta:
app_label = "auth_zero"

@property
def is_verified(self):
return self.otp_verified and self.email_verified

@property
def user_types(self):
return self.account_types # pylint: disable=no-member
Expand Down
33 changes: 33 additions & 0 deletions apps/auth_zero/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.contrib.auth import get_user_model
from django.test import TestCase

from apps.common.config import ConfigFileLoader
from apps.common.config import CredentialsLoader


class UserTestCase(TestCase):
def setUp(self):
self.user_model = get_user_model()
config_file = "apps/auth_zero/config/data/test/test_config.ini"
self.creds_obj = CredentialsLoader(config_file, ConfigFileLoader)
self.users = {
verification_status: self.user_model.objects.create_user(
**self.creds_obj.loader_class.read_config(verification_status)
)
for verification_status in [
"fully_unverified",
"only_otp_verified",
"only_email_verified",
"fully_verified",
]
}

def test_fully_unverified_user(self):
self.assertFalse(self.users["fully_unverified"].is_verified)

def test_partially_verfied_users(self):
self.assertFalse(self.users["only_otp_verified"].is_verified)
self.assertFalse(self.users["only_email_verified"].is_verified)

def test_fully_verified_user(self):
self.assertTrue(self.users["fully_verified"].is_verified)
61 changes: 61 additions & 0 deletions apps/common/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import abc
from configparser import ConfigParser
from typing import TypeVar

from django.utils.encoding import force_text


class InterfaceConfigLoader(metaclass=abc.ABCMeta):
"""Enforce abstract interface for class capability."""

impl_methods = ("read_config",)

@classmethod
def __subclasshook__(cls, subclass: object):
"""A subclass hooks to methods in impl_methods or NotImplemented."""
return all(map(cls.get_implementation, cls.impl_methods)) or NotImplemented

@staticmethod
def get_implementation(subclass, attr_name: str) -> bool:
"""Fetch an implemented method."""
return hasattr(subclass, attr_name)

@abc.abstractmethod
def read_config(self, verification_status: str) -> dict:
raise NotImplementedError


IConfigLoader_T = TypeVar("IConfigLoader_T", bound=InterfaceConfigLoader)


class CredentialsLoader:
"""Loads credentials from config file using custom loader class"""

def __init__(
self, config_file: str, loader_class: TypeVar("ConfigFileLoader")
) -> IConfigLoader_T:
"""Initialises custom loader class."""
self.__loader_class = loader_class(config_file)

@property
def loader_class(self):
return self.__loader_class


class ConfigFileLoader(InterfaceConfigLoader):
"""Loads data from .ini file"""

def __init__(self, config_file: str):
"""Initialises ConfigParser instance and reads inputted config file."""
self.config = ConfigParser()
self.config.read(config_file)

def read_config(self, verification_status: str) -> dict:
config_settings = self.config[verification_status]
return dict(
username=force_text(config_settings["username"]),
password=force_text(config_settings["password"]),
email=force_text(config_settings["email"]),
otp_verified=config_settings.getboolean("otp_verified"),
email_verified=config_settings.getboolean("email_verified"),
)
25 changes: 4 additions & 21 deletions covidX/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,11 @@ py_library(

py_library(
name = "settings",
srcs = ["settings.py"],
srcs = [
"//covidX/settings:base",
"//covidX/settings:dev",
],
deps = [
requirement("django-extensions"),
requirement("social-auth-core"),
requirement("social-auth-app-django"),
requirement("graphene-django"),
requirement("django-guardian"),
requirement("djangorestframework"),
requirement("drf-jwt"),
requirement("django-debug-toolbar"),
":gae_settings",
":schema",
":utils",
"//apps/apihealth:__init__",
"//apps/apihealth:apps",
"//apps/hrm:__init__",
"//apps/hrm:apps",
"//apps/hrm:models",
"//apps/auth_zero:__init__",
"//apps/auth_zero:apps",
"//apps/auth_zero:models",
"//apps/auth_zero:auth0backend",
"//:__init__",
],
srcs_version="PY3",
Expand Down
2 changes: 2 additions & 0 deletions covidX/settings/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ py_library(
],
srcs_version="PY3",
data = ["//:static",],
visibility=["//visibility:public"],
)

py_library(
Expand All @@ -43,4 +44,5 @@ py_library(
":base",
],
srcs_version="PY3",
visibility=["//visibility:public"],
)
Empty file added covidX/settings/__init__.py
Empty file.
1 change: 1 addition & 0 deletions covidX/settings/dev.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint:disable=E0611
from covidX.settings.base import *

CONFIG_FILE = "apps/auth_zero/config/test_config.ini"
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ services:
- redis
volumes:
- ./django-api:/app
- ./bazel-cache:/bazel-cache
hostname: django-api
env_file: .env
environment:
Expand All @@ -53,5 +54,6 @@ services:

volumes:
django-api:
bazel-cache:
pgdata:
redisdata:
6 changes: 3 additions & 3 deletions up-script.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
echo "=====migrate & runserver_plus====="
CPPFLAGS="$(pg_config --cppflags)" LDFLAGS="$(pg_config --ldflags)" bazel run :manage --watchfs --spawn_strategy=standalone --copt --aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements --verbose_failures=true --show_timestamps=true --python_version=PY3 --build_python_zip --sandbox_debug --color=yes --curses=yes --jobs=2000 --loading_phase_threads=HOST_CPUS --action_env=LDFLAGS --action_env=CPPFLAGS --action_env=DEBUG_ENV --action_env=SECRET_KEY -- collectstatic --noinput
CPPFLAGS="$(pg_config --cppflags)" LDFLAGS="$(pg_config --ldflags)" bazel run :manage --watchfs --spawn_strategy=standalone --copt --aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements --verbose_failures=true --show_timestamps=true --python_version=PY3 --build_python_zip --sandbox_debug --color=yes --curses=yes --jobs=2000 --loading_phase_threads=HOST_CPUS --action_env=LDFLAGS --action_env=CPPFLAGS --action_env=DEBUG_ENV --action_env=SECRET_KEY -- migrate;
CPPFLAGS="$(pg_config --cppflags)" LDFLAGS="$(pg_config --ldflags)" bazel run :manage --watchfs --spawn_strategy=standalone --copt --aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements --verbose_failures=true --show_timestamps=true --python_version=PY3 --build_python_zip --sandbox_debug --color=yes --curses=yes --jobs=2000 --loading_phase_threads=HOST_CPUS --action_env=LDFLAGS --action_env=CPPFLAGS --action_env=DEBUG_ENV --action_env=SECRET_KEY -- runserver_plus --cert-file ./certificate 0.0.0.0:8000;
CPPFLAGS="$(pg_config --cppflags)" LDFLAGS="$(pg_config --ldflags)" bazel run :manage --watchfs --spawn_strategy=standalone --copt --aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements --verbose_failures=true --show_timestamps=true --python_version=PY3 --build_python_zip --sandbox_debug --color=yes --curses=yes --jobs=2000 --loading_phase_threads=HOST_CPUS --action_env=LDFLAGS --action_env=CPPFLAGS --action_env=DEBUG_ENV --action_env=SECRET_KEY --action_env=BAZEL_CACHE --disk_cache="$BAZEL_CACHE" -- collectstatic --noinput
CPPFLAGS="$(pg_config --cppflags)" LDFLAGS="$(pg_config --ldflags)" bazel run :manage --watchfs --spawn_strategy=standalone --copt --aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements --verbose_failures=true --show_timestamps=true --python_version=PY3 --build_python_zip --sandbox_debug --color=yes --curses=yes --jobs=2000 --loading_phase_threads=HOST_CPUS --action_env=LDFLAGS --action_env=CPPFLAGS --action_env=DEBUG_ENV --action_env=SECRET_KEY --action_env=BAZEL_CACHE --disk_cache="$BAZEL_CACHE" -- migrate;
CPPFLAGS="$(pg_config --cppflags)" LDFLAGS="$(pg_config --ldflags)" bazel run :manage --watchfs --spawn_strategy=standalone --copt --aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements --verbose_failures=true --show_timestamps=true --python_version=PY3 --build_python_zip --sandbox_debug --color=yes --curses=yes --jobs=2000 --loading_phase_threads=HOST_CPUS --action_env=LDFLAGS --action_env=CPPFLAGS --action_env=DEBUG_ENV --action_env=SECRET_KEY --action_env=BAZEL_CACHE --disk_cache="$BAZEL_CACHE" -- runserver_plus --cert-file ./certificate 0.0.0.0:8000;