Skip to content

Commit

Permalink
Merge branch 'main' into four
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis authored Jun 30, 2024
2 parents 3e9a0e2 + ded83cb commit 87eeb18
Show file tree
Hide file tree
Showing 155 changed files with 3,948 additions and 1,880 deletions.
7 changes: 7 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ DATABASE_PASSWORD="postgres"

SECRET_KEY='secret'
DEBUG='1'

ACTIVIST_EMAIL="[email protected]"
EMAIL_HOST="smtp.activist.org"
EMAIl_PORT="587"
EMAIL_HOST_USER="[email protected]"
EMAIL_HOST_PASSWORD="activist123!?"
EMAIL_USE_TLS="True"
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Community discussion channels
- name: 👋 Community discussion channels
url: https://matrix.to/#/#activist_community:matrix.org
about: Join us in our public Matrix chat rooms!
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
hooks:
Expand All @@ -15,11 +23,3 @@ repos:
# additional_dependencies:
# - prettier
# - prettier-plugin-tailwindcss

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
2 changes: 1 addition & 1 deletion STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Please define all routes for images and icons in the respective [url registry ut

activist uses [nuxt-icon](https://github.com/nuxt-modules/icon) for all icons. Icons are defined via `<Icon :name="IconMap.ICON_REF"/>` components, with [Icônes](https://icones.js.org/) being a good place to look for [Iconify](https://iconify.design/) based files to import. The `<Icon/>` component also has a `size` argument that `em` based arguments can be passed to. There's also a `color` argument, but colors are handled with Tailwind CSS via the `text-COLOR` class argument.

Custom icons for activist can further be found in the [Icon directory of the frontend components](https://github.com/activist-org/activist/tree/main/frontend/components/Icon). These icons can also be referenced via the `<Icon>` component via their file name (ex: `<Icon name="IconSupport">` for the grasped hands we use). For Tailwind coloration note that we need to use `fill-COLOR` for the custom activist icons rather than `text-COLOR`.
Custom icons for activist can further be found in the [Icon directory of the frontend components](https://github.com/activist-org/activist/tree/main/frontend/components/icon). These icons can also be referenced via the `<Icon>` component via their file name (ex: `<Icon name="IconSupport">` for the grasped hands we use). For Tailwind coloration note that we need to use `fill-COLOR` for the custom activist icons rather than `text-COLOR`.

<a id="tab-size"></a>

Expand Down
29 changes: 18 additions & 11 deletions backend/authentication/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
UserTopic,
)

# MARK: Main Tables

# Remove default Group.
admin.site.unregister(Group)
admin.site.register(Support)

# MARK: Bridge Tables

admin.site.register(UserResource)
admin.site.register(UserTask)
admin.site.register(UserTopic)
admin.site.register(SupportEntityType)

# MARK: Methods


class UserCreationForm(forms.ModelForm[UserModel]):
"""
Expand Down Expand Up @@ -81,10 +96,9 @@ class UserAdmin(BaseUserAdmin):
"fields": [
"username",
"description",
"private",
"high_risk",
"user_icon",
"social_accounts",
"is_private",
"is_high_risk",
"verfied",
]
},
),
Expand Down Expand Up @@ -115,12 +129,5 @@ class UserAdmin(BaseUserAdmin):
filter_horizontal = []


# Remove default Group
admin.site.unregister(Group)
admin.site.register(UserResource)
admin.site.register(UserTask)
admin.site.register(UserTopic)
admin.site.register(SupportEntityType)
admin.site.register(Support)
# Now register the new UserAdmin...
admin.site.register(UserModel, UserAdmin)
20 changes: 20 additions & 0 deletions backend/authentication/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Enums for the authentication app.
More details about Enums can be found in schema section on Figma.
"""

from enum import Enum


class StatusTypes(Enum):
PENDING = 1
ACTIVE = 2
SUSPENDED = 3
BANNED = 4


class SupportEntityTypes(Enum):
ORGANIZATION = 1
GROUP = 2
EVENT = 3
USER = 4
7 changes: 6 additions & 1 deletion backend/authentication/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
UserTopic,
)

# MARK: Main Tables


class SupportEntityTypeFactory(factory.django.DjangoModelFactory):
class Meta:
Expand Down Expand Up @@ -39,12 +41,12 @@ class Meta:
description = factory.Faker("text", max_nb_chars=500)
verified = factory.Faker("boolean")
verification_method = factory.Faker("word")
verifictaion_code = factory.Faker("uuid4")
email = factory.Faker("email")
social_links = factory.List([factory.Faker("user_name") for _ in range(3)])
is_private = factory.Faker("boolean")
is_high_risk = factory.Faker("boolean")
creation_date = factory.Faker("date_time_this_decade", before_now=True)
deletion_date = factory.Faker("date_time_this_decade", before_now=False)
plaintext_password = factory.PostGenerationMethodCall("set_password", "password")

# Workaround for the build method
Expand All @@ -61,6 +63,9 @@ def verification_partner(
pass


# MARK: Bridge Tables


class UserResourceFactory(factory.django.DjangoModelFactory):
class Meta:
model = UserResource
Expand Down
84 changes: 46 additions & 38 deletions backend/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,23 @@
Models for the authentication app.
"""

from __future__ import annotations

from typing import Any
from uuid import uuid4

from django.contrib.auth.models import (
AbstractUser,
BaseUserManager,
PermissionsMixin,
User,
)
from django.contrib.postgres.fields import ArrayField
from django.db import models


class SupportEntityType(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=255)

def __str__(self) -> str:
return self.name
# MARK: Main Tables


class Support(models.Model):
supporter_type = models.ForeignKey(
"SupportEntityType", on_delete=models.CASCADE, related_name="supporter"
)
supporter_entity = models.ForeignKey(
"entities.Organization", on_delete=models.CASCADE, related_name="supporter"
)
supported_type = models.ForeignKey(
"SupportEntityType", on_delete=models.CASCADE, related_name="supported"
)
supported_entity = models.ForeignKey(
"entities.Organization", on_delete=models.CASCADE, related_name="supported"
)
creation_date = models.DateTimeField(auto_now_add=True)

def __str__(self) -> str:
return f"{self.id}"


class CustomAccountManager(BaseUserManager[User]):
class CustomAccountManager(BaseUserManager["UserModel"]):
def create_superuser(
self,
email: str,
Expand All @@ -59,25 +35,53 @@ def create_superuser(
if other_fields.get("is_superuser") is not True:
raise ValueError("Superuser must be assigned to is_superuser=True.")

return self.create_user(email, username, password, **other_fields)
return self.create_user(
email=email, username=username, password=password, **other_fields
)

def create_user(
self,
email: str,
username: str,
password: str,
**other_fields: bool,
) -> User:
if not email:
raise ValueError(("You must provide an email address"))
**other_fields: Any,
) -> UserModel:
if email != "":
email = self.normalize_email(email)

email = self.normalize_email(email)
user: User = self.model(email=email, username=username, **other_fields)
user = self.model(email=email, username=username, **other_fields)
user.set_password(password)
user.save()
return user


class SupportEntityType(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=255)

def __str__(self) -> str:
return self.name


class Support(models.Model):
supporter_type = models.ForeignKey(
"SupportEntityType", on_delete=models.CASCADE, related_name="supporter"
)
supporter_entity = models.ForeignKey(
"entities.Organization", on_delete=models.CASCADE, related_name="supporter"
)
supported_type = models.ForeignKey(
"SupportEntityType", on_delete=models.CASCADE, related_name="supported"
)
supported_entity = models.ForeignKey(
"entities.Organization", on_delete=models.CASCADE, related_name="supported"
)
creation_date = models.DateTimeField(auto_now_add=True)

def __str__(self) -> str:
return f"{self.id}"


class UserModel(AbstractUser, PermissionsMixin):
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
username = models.CharField(max_length=255, unique=True)
Expand All @@ -92,7 +96,9 @@ class UserModel(AbstractUser, PermissionsMixin):
icon_url = models.ForeignKey(
"content.Image", on_delete=models.SET_NULL, blank=True, null=True
)
email = models.EmailField(unique=True)
verification_code = models.UUIDField(blank=True, null=True)
email = models.EmailField(blank=True)
is_confirmed = models.BooleanField(default=False)
social_links = ArrayField(models.CharField(max_length=255), blank=True, null=True)
is_private = models.BooleanField(default=False)
is_high_risk = models.BooleanField(default=False)
Expand All @@ -102,15 +108,17 @@ class UserModel(AbstractUser, PermissionsMixin):
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

objects = CustomAccountManager() # type: ignore
objects: CustomAccountManager = CustomAccountManager() # type: ignore

USERNAME_FIELD = "username"
REQUIRED_FIELDS = ["email"]

def __str__(self) -> str:
return self.username


# MARK: Bridge Tables


class UserResource(models.Model):
user_id = models.ForeignKey(UserModel, on_delete=models.CASCADE)
resource_id = models.ForeignKey("content.Resource", on_delete=models.CASCADE)
Expand Down
Loading

0 comments on commit 87eeb18

Please sign in to comment.