-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add UUID to user model (#4488)
- Loading branch information
1 parent
9382908
commit 32be7c0
Showing
8 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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,22 @@ | ||
from django.urls import reverse | ||
from rest_framework import status | ||
from rest_framework.test import APIClient | ||
|
||
from users.models import FFAdminUser | ||
|
||
|
||
def test_get_current_user(staff_user: FFAdminUser, staff_client: APIClient) -> None: | ||
# Given | ||
url = reverse("api-v1:custom_auth:ffadminuser-me") | ||
|
||
# When | ||
response = staff_client.get(url) | ||
|
||
# Then | ||
assert response.status_code == status.HTTP_200_OK | ||
|
||
response_json = response.json() | ||
assert response_json["email"] == staff_user.email | ||
assert response_json["first_name"] == staff_user.first_name | ||
assert response_json["last_name"] == staff_user.last_name | ||
assert response_json["uuid"] == str(staff_user.uuid) |
This file contains 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 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 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,37 @@ | ||
# Generated by Django 3.2.25 on 2024-08-12 14:21 | ||
from django.apps.registry import Apps | ||
from django.db import migrations, models | ||
import uuid | ||
|
||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor | ||
|
||
|
||
def set_default_uuids(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None: | ||
user_model = apps.get_model("users", "FFAdminUser") | ||
|
||
users = list(user_model.objects.all()) | ||
for user in users: | ||
user.uuid = uuid.uuid4() | ||
|
||
user_model.objects.bulk_update(users, fields=["uuid"]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('users', '0036_create_hubspot_lead'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='ffadminuser', | ||
name='uuid', | ||
field=models.UUIDField(default=uuid.uuid4), | ||
), | ||
migrations.RunPython(set_default_uuids, reverse_code=migrations.RunPython.noop), | ||
migrations.AlterField( | ||
model_name='ffadminuser', | ||
name='uuid', | ||
field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True), | ||
), | ||
] |
This file contains 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 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