Skip to content

Commit

Permalink
fix: project-wide refactoring to fix broken import links and failing …
Browse files Browse the repository at this point in the history
…server
  • Loading branch information
50-Course committed May 23, 2024
1 parent 3995d1e commit f41f7ae
Show file tree
Hide file tree
Showing 35 changed files with 92 additions and 19 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
DEBUG = os.environ.get("PAYCHECK_BACKEND_DEBUG", "off") == "on"

ALLOWED_HOSTS = ["127.0.0.1", "localhost", "0.0.0.0"]
ALLOWED_HOSTS += os.getenv("PAYCHECK_ALLOWED_HOSTS", "").split(",")
ALLOWED_HOSTS += os.getenv("PAYCHECK_EXTRA_ALLOWED_HOSTS", "").split(",")

# Application definition

Expand All @@ -44,7 +44,7 @@
"rest_framework",
]

LOCAL_APPS = []
LOCAL_APPS = ["core"]

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

Expand Down Expand Up @@ -132,3 +132,5 @@
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

APPEND_SLASH = False

AUTH_USER_MODEL = "core.BaseUser"
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions backend/paycheck_core/src/paycheck/core/auth/backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.contrib.auth.backends import BaseBackend
from django.http import HttpRequest


class PhoneEmailOrAccountNumberAuthBackend(BaseBackend):
"""
Authenticates a user into the platform using the user's assigned
unique account number, email address or phone number
"""

def authenticate(self, request, username, password, *args, **kwargs):
"""
Authenticate a user based on the username and password
"""
pass
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from uuid import uuid4
from django.contrib.auth import get_user_model
from django.db.models import Q

User = get_user_model()
from django.conf import settings


class BaseUser(AbstractUser):
Expand Down Expand Up @@ -96,7 +95,8 @@ class BaseUser(AbstractUser):
USERNAME_FIELD = "email"

class Meta:
abstract = True
verbose_name = _("user")
verbose_name_plural = _("users")

def __str__(self):
return self.username
Expand Down Expand Up @@ -181,7 +181,7 @@ class VerificationStatus(models.TextChoices):
("INTERNATIONAL_PASSPORT", "INTERNATIONAL_PASSPORT"),
]

user = models.OneToOneField(User, on_delete=models.CASCADE)
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
occupation = models.CharField(
_("occupation"),
max_length=100,
Expand Down Expand Up @@ -237,8 +237,7 @@ class VerificationStatus(models.TextChoices):
)

class Meta:
verbose_name = _("user")
verbose_name_plural = _("users")
verbose_name = _("user_profile")
indexes = [
models.Index(fields=["user"]),
models.Index(fields=["verification_status"]),
Expand All @@ -257,7 +256,7 @@ def is_verified(self, value: str) -> None:
self.verification_status = value


class Customer(User):
class Customer(BaseUser):
"""
A proxy model that represents a customer.
Expand All @@ -274,13 +273,14 @@ class Customer(User):
"""

user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
profile = models.OneToOneField(UserProfile, on_delete=models.CASCADE)

class Meta:
proxy = True

objects = models.Manager().filter(is_customer=True)


class Support(User):
class Support(BaseUser):
"""
A support user is essentially, the a member of the customer support team,
they can adminster and manage support tickets
Expand All @@ -292,15 +292,11 @@ class Meta:
def __str__(self):
return self.user.full_name()

objects = models.Manager().filter(is_staff=True)


class Admin(User):
class Admin(BaseUser):

class Meta:
proxy = True

def __str__(self):
return self.user.full_name()

objects = models.Manager().filter(Q(is_staff=True) & Q(is_superuser=True))
49 changes: 49 additions & 0 deletions backend/paycheck_core/src/paycheck/core/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from rest_framework import serializers
from django.conf import settings

User = settings.AUTH_USER_MODEL

from src.paycheck.core.models import UserProfile


class UserSerializer(serializers.ModelSerializer):

class Meta:
model = User


class UserProfileSerializer(serializers.ModelSerializer):
user_data = UserSerializer()

class Meta:
model = UserProfile
exclude = ("id",)


class WritableUserProfileSerializer(serializers.Serializer):
"""
This serializer is used to create or update a user profile.
Do not use this serializer in READ operation contexts for retrieving
user information as it may display sensitive information.
"""

user_data = UserSerializer()

def create(self, validated_data):
user_data = validated_data.pop("user_data")
user = User.objects.create(**user_data)
user_profile = UserProfile.objects.create(user=user, **validated_data)
return user_profile

def update(self, instance, validated_data):
user_data = validated_data.pop("user_data")
user = instance.user
user.username = user_data.get("username", user.username)
user.email = user_data.get("email", user.email)
user.save()
instance.__dict__.update(**validated_data)
instance.save()
return instance
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.shortcuts import render

# Create your views here.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@
"""Django's command-line utility for administrative tasks."""
import os
import sys
from pprint import pprint


def main():
"""Run administrative tasks."""
import pdb

project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
src_root = os.path.join(project_root, "src")

if src_root not in sys.path:
sys.path.append(src_root)

print(f"DJANGO_SETTINGS_MODULE: {os.environ.get('DJANGO_SETTINGS_MODULE')}")
print(f"sys.path: {sys.path}")

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.base")

try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
File renamed without changes.

0 comments on commit f41f7ae

Please sign in to comment.