Skip to content

Commit

Permalink
Merge pull request #55 from AnimalFoodBank:feature/20231204-volunteer…
Browse files Browse the repository at this point in the history
…-onboarding

Feature/20231204-volunteer-onboarding
  • Loading branch information
delano authored Jan 24, 2024
2 parents 3232917 + 79312fc commit fbd9c84
Show file tree
Hide file tree
Showing 17 changed files with 237 additions and 118 deletions.
1 change: 0 additions & 1 deletion .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# This is a basic GitHub Actions workflow for running CI tests on a Django project.
# It runs on Ubuntu 22.04 with 4 parallel jobs, caches system packages and Python dependencies,
# and checks out the repository with a fetch depth of 1. The build job sets the Python version to 3.10
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Temporary Items

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
__pycache__
*.py[cod]
*$py.class

Expand Down
26 changes: 0 additions & 26 deletions .ruff.toml

This file was deleted.

2 changes: 0 additions & 2 deletions .trunk/configs/.isort.cfg

This file was deleted.

5 changes: 0 additions & 5 deletions .trunk/configs/ruff.toml

This file was deleted.

18 changes: 10 additions & 8 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.17.2
version: 1.18.0
plugins:
sources:
- id: trunk
Expand All @@ -12,7 +12,7 @@ runtimes:
enabled:
- [email protected]
- [email protected]
- [email protected].8
- [email protected].9
lint:
enabled:
- [email protected]
Expand All @@ -21,17 +21,19 @@ lint:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- git-diff-check
- [email protected]
- [email protected]
- osv-scanner@1.4.3
- osv-scanner@1.5.0
- [email protected]
- [email protected].6
- trivy@0.47.0
- [email protected]-rc0
- [email protected].7
- trivy@0.48.0
- [email protected]
- [email protected]
disabled:
- black
- isort
- autoflake
actions:
disabled:
- trunk-announce
Expand Down
25 changes: 16 additions & 9 deletions apps/api/afbcore/models/users/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

from django.db import models
from phonenumber_field.modelfields import PhoneNumberField
import uuid
from django.urls import reverse

from .role import Role
from .user import User # Profile depends on User and not the other way around
from .role import Role # noqa: F401

# Profile depends on User and not the other way around
from .user import User # noqa: F401

from ..base import BaseAbstractModel

Expand Down Expand Up @@ -108,12 +109,18 @@ class Profile(BaseAbstractModel):
# Via Client
#

# Address - If address is duplicate to another clients, both accounts need to be placed on hold and manually reviewed/approved bc people are scammers.
# Has to be a validated address (google?) and not permitted to be overwritten. The last amount of free form text entry as possible.
# You'd be amazed how many clients don't know their postal code and we route by postal code sooooo

# Postal/Zip Code - Has to be a validated address (google?) and not permitted to be overwritten. The last amount of free form text entry as possible.
# You'd be amazed how many clients don't know their postal code and we route by postal code sooooo
# Address - If address is duplicate to another clients, both accounts
# need to be placed on hold and manually reviewed/approved bc people
# are scammers. Has to be a validated address (google?) and not
# permitted to be overwritten. The last amount of free form text
# entry as possible. You'd be amazed how many clients don't know
# their postal code and we route by postal code sooooo
#
# Postal/Zip Code - Has to be a validated address (google?) and not
# permitted to be overwritten. The last amount of free form text
# entry as possible. You'd be amazed how many clients don't know
# their postal code and we route by postal code sooooo
#
validated_postal_code = models.CharField(max_length=20, null=True)

# Country - I don't know if we need this but google addresses populate country too. It may be useful for analytics
Expand Down
12 changes: 5 additions & 7 deletions apps/api/afbcore/models/users/role.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from ..base import BaseAbstractModel, BaseAbstractQuerySet, BaseAbstractModelManager
from django.core.exceptions import ValidationError
from ..base import BaseAbstractModel, BaseAbstractModelManager, BaseAbstractQuerySet
from django.db import models


class RoleQuerySet(BaseAbstractQuerySet):
Expand All @@ -18,9 +18,9 @@ class Role(BaseAbstractModel):
A model representing a user role.
Attributes:
name (str): The name of the role.
name (str): A human-readable name for the role. e.g. "Volunteer".
level (int): The level of the role between 0 and 100. 0 is the lowest
level and 99 is the highest level.
and 99 is the highest level.
"""

objects = RoleManager.from_queryset(RoleQuerySet)()
Expand All @@ -32,6 +32,7 @@ class Role(BaseAbstractModel):
def save(self, *args, **kwargs):
if not self.name:
raise ValueError("Name cannot be empty")

super().save(*args, **kwargs)

def clean(self):
Expand All @@ -40,6 +41,3 @@ def clean(self):

def __str__(self):
return self.name

def __str__(self):
return self.name
33 changes: 18 additions & 15 deletions apps/api/afbcore/models/users/user.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""
AFB Core API User Model
NOTE: We don't need to define a custom manager for this model because
Django's built-in UserManager already provides the functionality we need.
It's also a bit of a pain to implement properly.
NOTE: We define a custom manager for this model in order to provide
create_user and create_superuser methods. We could have implemented
these methods in the model itself, but it's better to keep the model
as simple as possible. Otherwise, the rest of the functionality
comes from Django's built-in UserManager.
NOTE 2: However, that means we need to be careful wuth regards to soft
detletes. If we use the delete method provided by the default manager,
Expand All @@ -13,16 +15,11 @@
"""
import logging

from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.contrib.auth.models import UserManager as DefaultUserManager
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils.translation import gettext_lazy as _
from model_utils.models import (
TimeStampedModel,
UUIDModel,
)

from django.contrib.auth.models import BaseUserManager
from model_utils.models import TimeStampedModel, UUIDModel

logger = logging.getLogger(__name__)

Expand All @@ -32,23 +29,28 @@ def is_a_truly_unique(self, field_name, value):
"""
Check the given value against the database.
Used by VueformUniqueValidatorView.
Used by VueformUniqueValidatorView for checking uniqueness
of email field.
"""
logger.debug(f"UserManager.is_a_truly_unique - {field_name}: {value}")

# Fast fail on bad input.
if value is None or value == "":
logger.info(f"UserManager.is_a_truly_unique - value is None or empty")
return False

# Assume pessimistically that the value is not unique.
is_unique = False

try:
record = User.objects.get(**{field_name: value})
logger.info(f"UserManager.is_a_truly_unique - record: {record.pk}")

except User.DoesNotExist:
logger.info(f"UserManager.is_a_truly_unique - DoesNotExist")
return True
is_unique = True

return False
return is_unique

def create_user(self, email, name, password=None):
"""
Expand Down Expand Up @@ -88,8 +90,6 @@ class User(UUIDModel, TimeStampedModel, AbstractUser):
A custom user model that extends Django's built-in AbstractUser model.
Fields inherited from AbstractUser:
- name
- email
- password
- groups
- user_permissions
Expand Down Expand Up @@ -118,8 +118,11 @@ class User(UUIDModel, TimeStampedModel, AbstractUser):
"name",
]

# Override the email field from AbstractUser to make it unique.
email = models.EmailField(_("email address"), unique=True)

# Add a single name field which we'll use instead of the default
# first_name and last_name fields.
name = models.CharField(_("name"), max_length=255)

terms_agreement = models.BooleanField(
Expand Down
5 changes: 5 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"@trunkio/launcher": "^1.2.7"
}
}
17 changes: 17 additions & 0 deletions apps/api/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 27 additions & 13 deletions apps/api/requirements.in
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
##
# Requirements file for afb-requests.
#
# Requirements file for afb-requests. Modify this file to
# include the packages you want to install. Then, run:
# NOTE: DO NOT EDIT requirements.txt DIRECTLY. Edit this file
# instead, and use the pip-compile command to generate it.
#
# pip-compile --output-file requirements.txt requirements.in
#
# This will generate a new requirements.txt file with the
# latest versions of the packages listed here.
# USAGE
#
# You can also run:
# After modifying this file to include the packages you
# want to install for this project, run the following to
# generate the requirements.txt file:
#
# pip-compile --upgrade --output-file requirements.txt requirements.in
# $ pip-compile --output-file requirements.txt --upgrade --strip-extras requirements.in
#
# to upgrade all packages to their latest versions.
# Using other flags:
#
# To install the packages in the requirements.txt file, run:
# `--upgrade` to upgrade all packages to their latest versions.
# `--skip-extras` to skip installing optional dependencies.
# `--generate-hashes` to generate hashes for all packages.
#
# pip install -r requirements.txt
# Install dependencies as you normally would:
#
# See: https://github.com/jazzband/pip-tools
# $ pip install -r requirements.txt
#
#
# MORE INFO
#
# https://github.com/jazzband/pip-tools
#
# To resolve warnings in Django (important to do before upgrading):
#
# python -Wa manage.py test
# $ python -Wa manage.py test
#
# See: https://docs.djangoproject.com/en/4.2/howto/upgrade-version/#upgrade-packages-individually
#


#
#
# Django 4.0 introduces several new features and improvements over
# Django 3.x and 2.x. Here are some key differences:
#
Expand Down Expand Up @@ -106,3 +116,7 @@ pytest-django
coverage
ipdb
Werkzeug

# Specific version to avoid python deprecation warning ("torchsde 0.2.5
# has a non-standard dependency specifier numpy>=1.19.*").
torchsde>=0.2.6
Loading

0 comments on commit fbd9c84

Please sign in to comment.