From 23e4611c5ee023677733cc19cbf2d4251dbdb749 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Sun, 7 Sep 2025 01:30:03 +0300 Subject: [PATCH] Features: 1) Add `readonly_fields` for `uuid`, `modified`, and `created` in `CustomerRelationshipManagementProvider`; 2) Add additional `readonly_fields` for `OrderCrmLink`; Fixes: 1) Fix email validation to properly handle `self.instance` checks in serializers; Extra: 1) Remove unnecessary blank lines and reformat code for better readability; 2) Consolidate migration field definitions to a single line for cleaner diff; --- core/admin.py | 8 +++++++- ...ustomerrelationshipmanagementprovider_ordercrmlink.py | 9 ++------- ...ter_customerrelationshipmanagementprovider_options.py | 1 - vibes_auth/serializers.py | 7 ++++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/admin.py b/core/admin.py index c188b2fa..2cf9bc3e 100644 --- a/core/admin.py +++ b/core/admin.py @@ -519,6 +519,7 @@ class CustomerRelationshipManagementProviderAdmin(FieldsetsMixin, ModelAdmin): model = CustomerRelationshipManagementProvider # type: ignore [misc] list_display = ("name", "default") search_fields = ("name",) + readonly_fields = ("uuid", "modified", "created") general_fields = [ "is_active", @@ -538,6 +539,12 @@ class OrderCrmLinkAdmin(FieldsetsMixin, ModelAdmin): model = OrderCrmLink # type: ignore [misc] list_display = ("crm_lead_id",) search_fields = ("crm_lead_id",) + readonly_fields = ( + "uuid", + "modified", + "created", + "crm_lead_id", + ) general_fields = [ "is_active", @@ -547,7 +554,6 @@ class OrderCrmLinkAdmin(FieldsetsMixin, ModelAdmin): "order", "crm", ] - readonly_fields = ("crm_lead_id",) # Constance configuration diff --git a/core/migrations/0040_customerrelationshipmanagementprovider_ordercrmlink.py b/core/migrations/0040_customerrelationshipmanagementprovider_ordercrmlink.py index cd240f0f..e3275ef5 100644 --- a/core/migrations/0040_customerrelationshipmanagementprovider_ordercrmlink.py +++ b/core/migrations/0040_customerrelationshipmanagementprovider_ordercrmlink.py @@ -8,7 +8,6 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ ("core", "0039_alter_product_sku"), ] @@ -58,15 +57,11 @@ class Migration(migrations.Migration): ), ( "integration_url", - models.URLField( - blank=True, help_text="URL of the integration", null=True - ), + models.URLField(blank=True, help_text="URL of the integration", null=True), ), ( "authentication", - models.JSONField( - blank=True, help_text="authentication credentials", null=True - ), + models.JSONField(blank=True, help_text="authentication credentials", null=True), ), ( "attributes", diff --git a/core/migrations/0041_alter_customerrelationshipmanagementprovider_options.py b/core/migrations/0041_alter_customerrelationshipmanagementprovider_options.py index cf581e7d..da348d60 100644 --- a/core/migrations/0041_alter_customerrelationshipmanagementprovider_options.py +++ b/core/migrations/0041_alter_customerrelationshipmanagementprovider_options.py @@ -4,7 +4,6 @@ from django.db import migrations class Migration(migrations.Migration): - dependencies = [ ("core", "0040_customerrelationshipmanagementprovider_ordercrmlink"), ] diff --git a/vibes_auth/serializers.py b/vibes_auth/serializers.py index 98006117..793a8f49 100644 --- a/vibes_auth/serializers.py +++ b/vibes_auth/serializers.py @@ -115,9 +115,10 @@ class UserSerializer(ModelSerializer): raise ValidationError(_(f"malformed phone number: {phone_number}")) if "email" in attrs: validate_email(attrs["email"]) - if User.objects.filter(email=attrs["email"]).exclude(uuid=self.instance.uuid).exists(): - email = attrs["email"] - raise ValidationError(_(f"malformed email: {email}")) + if self.instance: + if User.objects.filter(email=attrs["email"]).exclude(uuid=self.instance.uuid).exists(): + email = attrs["email"] + raise ValidationError(_(f"malformed email: {email}")) return attrs