Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions common/apps/organization/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 0 additions & 12 deletions common/apps/organization/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("organization_user", "0001_initial"),
]
Expand Down
1 change: 0 additions & 1 deletion common/apps/space/migrations/0002_space_is_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("space", "0001_initial"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("space_role", "0002_create_default_policies"),
]
Expand Down
31 changes: 31 additions & 0 deletions common/utils/custom_fields.py
Original file line number Diff line number Diff line change
@@ -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