-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement api crud for auth pages and email #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ngovinh2k2
merged 1 commit into
dev
from
feat/implement-api-crud-for-auth-pages-and-email
Jul 2, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class CustomPageConfig(AppConfig): | ||
| default_auto_field = "django.db.models.BigAutoField" | ||
| name = "apps.custom_page" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from django.db import models | ||
|
|
||
|
|
||
| class PageTypes(models.TextChoices): | ||
| SIGN_IN = "sign_in" | ||
| SIGN_UP = "sign_up" | ||
| FORGET_PASSWORD = "forget_password" # nosec B105 | ||
| CHANGE_PASSWORD = "change_password" # nosec B105 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Generated by Django 5.0.6 on 2026-05-27 09:20 | ||
|
|
||
| import django.db.models.deletion | ||
| import uuid | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| ("organization", "0004_alter_organization_template"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="CustomPage", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.UUIDField( | ||
| default=uuid.uuid4, | ||
| editable=False, | ||
| primary_key=True, | ||
| serialize=False, | ||
| unique=True, | ||
| ), | ||
| ), | ||
| ("created_at", models.DateTimeField(auto_now_add=True)), | ||
| ("updated_at", models.DateTimeField(auto_now=True)), | ||
| ( | ||
| "page_type", | ||
| models.CharField( | ||
| choices=[ | ||
| ("sign_in", "Sign In"), | ||
| ("sign_up", "Sign Up"), | ||
| ("forget_password", "Forget Password"), | ||
| ("change_password", "Change Password"), | ||
| ], | ||
| max_length=255, | ||
| ), | ||
| ), | ||
| ("title", models.CharField(max_length=255)), | ||
| ("subtitle", models.CharField(blank=True, max_length=255, null=True)), | ||
| ("metadata", models.JSONField(blank=True, default=dict)), | ||
| ("theme_colors", models.JSONField(blank=True, default=dict)), | ||
| ( | ||
| "background_image", | ||
| models.CharField(blank=True, default="", max_length=500), | ||
| ), | ||
| ("show_logo", models.BooleanField(default=True)), | ||
| ( | ||
| "organization", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="organization_custom_page", | ||
| to="organization.organization", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "db_table": "custom_pages", | ||
| "ordering": ["-created_at"], | ||
| }, | ||
| ), | ||
| ] |
50 changes: 50 additions & 0 deletions
50
apps/custom_page/migrations/0002_backfill_default_custom_pages.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| from django.db import migrations | ||
|
|
||
| from apps.custom_page.service import get_default_pages | ||
|
|
||
|
|
||
| def backfill_default_custom_pages(apps, schema_editor): | ||
| CustomPage = apps.get_model("custom_page", "CustomPage") | ||
| Organization = apps.get_model("organization", "Organization") | ||
|
|
||
| pages_to_create = [] | ||
| existing_pages = {} | ||
| for org_id, page_type in CustomPage.objects.values_list( | ||
| "organization_id", "page_type" | ||
| ): | ||
| if org_id not in existing_pages: | ||
| existing_pages[org_id] = set() | ||
| existing_pages[org_id].add(page_type) | ||
|
|
||
| for organization in Organization.objects.all().iterator(): | ||
| existing_page_types = existing_pages.get(organization.id, set()) | ||
|
|
||
| for page in get_default_pages(): | ||
| if page["page_type"] in existing_page_types: | ||
| continue | ||
|
|
||
| pages_to_create.append( | ||
| CustomPage( | ||
| organization_id=organization.id, | ||
| page_type=page["page_type"], | ||
| title=page["title"], | ||
| subtitle=page["subtitle"], | ||
| metadata=page["metadata"], | ||
| theme_colors=page["theme_colors"], | ||
| background_image=page["background_image"], | ||
| show_logo=page["show_logo"], | ||
| ) | ||
| ) | ||
|
|
||
| if pages_to_create: | ||
| CustomPage.objects.bulk_create(pages_to_create, batch_size=50) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("custom_page", "0001_initial"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(backfill_default_custom_pages, migrations.RunPython.noop), | ||
| ] |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from common.models.base_model import BaseModel | ||
| from django.db import models | ||
|
|
||
| from apps.custom_page.constants import PageTypes | ||
| from apps.organization.models import Organization | ||
|
|
||
|
|
||
| class CustomPage(BaseModel): | ||
| organization = models.ForeignKey( | ||
| Organization, | ||
| on_delete=models.CASCADE, | ||
| related_name="organization_custom_page", | ||
| ) | ||
| page_type = models.CharField(max_length=255, choices=PageTypes.choices) | ||
| title = models.CharField(max_length=255) | ||
| subtitle = models.CharField(max_length=255, null=True, blank=True) | ||
| metadata = models.JSONField(default=dict, blank=True) | ||
| theme_colors = models.JSONField(default=dict, blank=True) | ||
| background_image = models.CharField(max_length=500, blank=True, default="") | ||
| show_logo = models.BooleanField(default=True) | ||
|
|
||
| class Meta: | ||
| db_table = "custom_pages" | ||
| ordering = ["-created_at"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| from common.apps.upload_file.service import get_presigned_url | ||
| from django.conf import settings | ||
| from rest_framework import serializers | ||
|
|
||
| from apps.custom_page.models import CustomPage | ||
|
|
||
|
|
||
| class CustomPageSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = CustomPage | ||
| fields = [ | ||
| "id", | ||
| "page_type", | ||
| "title", | ||
| "subtitle", | ||
| "metadata", | ||
| "theme_colors", | ||
| "background_image", | ||
| "show_logo", | ||
| "created_at", | ||
| "updated_at", | ||
| ] | ||
| extra_kwargs = { | ||
| "id": {"read_only": True}, | ||
| "background_image": {"write_only": True}, | ||
| "created_at": {"read_only": True}, | ||
| "updated_at": {"read_only": True}, | ||
| } | ||
|
|
||
| def validate_background_image(self, value): | ||
| return value or "" | ||
|
|
||
| def to_representation(self, instance): | ||
| data = super().to_representation(instance) | ||
| if instance.background_image: | ||
| data["url_background_image"] = get_presigned_url( | ||
| settings.AWS_S3.get("AWS_STORAGE_BUCKET_NAME"), | ||
| f"uploads/{instance.background_image}", | ||
| ) | ||
| return data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| from apps.custom_page.constants import PageTypes | ||
| from apps.custom_page.models import CustomPage | ||
|
|
||
|
|
||
| def get_default_pages(): | ||
| return [ | ||
| { | ||
| "page_type": PageTypes.SIGN_IN, | ||
| "title": "Sign in to SpaceDF", | ||
| "subtitle": "Sign in to manage your IoT devices", | ||
| "metadata": {}, | ||
| "theme_colors": {}, | ||
| "background_image": "", | ||
| "show_logo": True, | ||
| }, | ||
| { | ||
| "page_type": PageTypes.SIGN_UP, | ||
| "title": "Sign up to SpaceDF", | ||
| "subtitle": "Sign up to manage your IoT devices", | ||
| "metadata": {}, | ||
| "theme_colors": {}, | ||
| "background_image": "", | ||
| "show_logo": True, | ||
| }, | ||
| { | ||
| "page_type": PageTypes.FORGET_PASSWORD, | ||
| "title": "Forgot Your Password?", | ||
| "subtitle": "Enter your email address and we will send you instructions to reset your password.", | ||
| "metadata": {}, | ||
| "theme_colors": { | ||
| "background_color": "#FFFFFF", | ||
| }, | ||
| "background_image": "", | ||
| "show_logo": True, | ||
| }, | ||
| { | ||
| "page_type": PageTypes.CHANGE_PASSWORD, | ||
| "title": "Create New Password", | ||
| "subtitle": "Create your new password. If you forget it, then you have to do forget password", | ||
| "metadata": {}, | ||
| "theme_colors": { | ||
| "background_color": "#FFFFFF", | ||
| }, | ||
| "background_image": "", | ||
| "show_logo": True, | ||
| }, | ||
| ] | ||
|
|
||
|
|
||
| def create_default_pages(organization): | ||
| default_pages = get_default_pages() | ||
| list_data = [ | ||
| CustomPage( | ||
| organization=organization, | ||
| page_type=page.get("page_type"), | ||
| title=page.get("title"), | ||
| subtitle=page.get("subtitle"), | ||
| metadata=page.get("metadata"), | ||
| theme_colors=page.get("theme_colors"), | ||
| background_image=page.get("background_image"), | ||
| show_logo=page.get("show_logo"), | ||
| ) | ||
| for page in default_pages | ||
| ] | ||
| CustomPage.objects.bulk_create(list_data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from django.urls import path | ||
|
|
||
| from apps.custom_page.views import ListCustomPageView | ||
|
|
||
| app_name = "custom_page" | ||
|
|
||
| urlpatterns = [ | ||
| path("custom-pages", ListCustomPageView.as_view(), name="custom-pages-list"), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from common.pagination.base_pagination import BasePagination | ||
| from django_filters.rest_framework import DjangoFilterBackend | ||
| from rest_framework.filters import OrderingFilter | ||
|
|
||
| from apps.custom_page.models import CustomPage | ||
| from apps.custom_page.serializers import CustomPageSerializer | ||
| from utils.views import OrganizationListAPIView | ||
|
|
||
|
|
||
| class ListCustomPageView(OrganizationListAPIView): | ||
| serializer_class = CustomPageSerializer | ||
| queryset = CustomPage.objects.select_related("organization").all() | ||
| organization_field = "organization" | ||
| pagination_class = BasePagination | ||
| filter_backends = [DjangoFilterBackend, OrderingFilter] | ||
| ordering = ["-created_at"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.