diff --git a/common/apps/organization/handler.py b/common/apps/organization/handler.py index eb2be3e..3cbf2c7 100644 --- a/common/apps/organization/handler.py +++ b/common/apps/organization/handler.py @@ -14,17 +14,3 @@ def __init__(self, organization, owner): @abstractmethod def handle(self): pass - - -class DeleteOrganizationHandlerBase: - """ - The base class for Delete Organization Handler - Use by set DELETE_ORGANIZATION_HANDLER in Django setting file - """ - - def __init__(self, organization): - self._organization = organization - - @abstractmethod - def handle(self): - pass diff --git a/common/apps/organization/tasks.py b/common/apps/organization/tasks.py index 2c13c78..b695092 100644 --- a/common/apps/organization/tasks.py +++ b/common/apps/organization/tasks.py @@ -51,15 +51,3 @@ def create_organization(id, name, slug_name, is_active, owner, created_at, updat if NewOrganizationHandler is not None: NewOrganizationHandler(organization, owner).handle() - - -@task(name="spacedf.tasks.delete_organization", max_retries=3) -@transaction.atomic -def delete_organization(slug_name): - logger.info(f"delete_organization({slug_name})") - DeleteOrganizationHandler = get_delete_organization_handler() - - organization = Organization.objects.get(schema_name=slug_name) - if DeleteOrganizationHandler is not None: - DeleteOrganizationHandler(organization).handle() - organization.delete(force_drop=True) diff --git a/common/apps/organization_user/migrations/0002_organizationuser_avatar_and_more.py b/common/apps/organization_user/migrations/0002_organizationuser_avatar_and_more.py index 7f6b020..b0d3775 100644 --- a/common/apps/organization_user/migrations/0002_organizationuser_avatar_and_more.py +++ b/common/apps/organization_user/migrations/0002_organizationuser_avatar_and_more.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [ ("organization_user", "0001_initial"), ] diff --git a/common/apps/space/migrations/0002_space_is_default.py b/common/apps/space/migrations/0002_space_is_default.py index 092c874..ec961ad 100644 --- a/common/apps/space/migrations/0002_space_is_default.py +++ b/common/apps/space/migrations/0002_space_is_default.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("space", "0001_initial"), ] diff --git a/common/apps/space_role/migrations/0003_spaceroleuser_is_default.py b/common/apps/space_role/migrations/0003_spaceroleuser_is_default.py index 1adcdf7..85ebade 100644 --- a/common/apps/space_role/migrations/0003_spaceroleuser_is_default.py +++ b/common/apps/space_role/migrations/0003_spaceroleuser_is_default.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("space_role", "0002_create_default_policies"), ] diff --git a/common/utils/custom_fields.py b/common/utils/custom_fields.py new file mode 100644 index 0000000..a2767f1 --- /dev/null +++ b/common/utils/custom_fields.py @@ -0,0 +1,31 @@ +import re + +from rest_framework import serializers +from rest_framework.validators import UniqueValidator + + +class HexCharField(serializers.CharField): + def __init__(self, length, unique=False, **kwargs): + self.length = length + self.format = re.compile(rf"^[a-fA-F0-9]{{{length}}}$") + self.unique = unique + super().__init__(**kwargs) + + def bind(self, field_name, parent): + super().bind(field_name, parent) + if self.unique and hasattr(parent.Meta, "model"): + model = parent.Meta.model + self.validators.append( + UniqueValidator( + queryset=model.objects.all(), + message=f"Device with this {field_name} already exists.", + ) + ) + + def to_internal_value(self, data): + value = super().to_internal_value(data) + if value and not self.format.fullmatch(value): + raise serializers.ValidationError( + f"Value must be {self.length} hex characters" + ) + return value