Skip to content

Commit

Permalink
commit merge for eda project create and template type verification
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJaeger committed Sep 21, 2023
2 parents 8be6419 + f94605b commit 89c17e3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 39 deletions.
9 changes: 0 additions & 9 deletions chats/apps/api/v1/queues/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ def perform_create(self, serializer):
"name": instance.name,
"sector_uuid": str(instance.sector.uuid),
}
if settings.USE_EDA:
FlowsEDAClient().request_queue(action="", content=content)
return
if not settings.USE_WENI_FLOWS:
return super().perform_create(serializer)
response = FlowRESTClient().create_queue(**content)
Expand All @@ -77,9 +74,6 @@ def perform_update(self, serializer):
"name": instance.name,
"sector_uuid": str(instance.sector.uuid),
}
if settings.USE_EDA:
FlowsEDAClient().request_queue(action="", content=content)
return

if not settings.USE_WENI_FLOWS:
return super().perform_create(serializer)
Expand All @@ -97,9 +91,6 @@ def perform_destroy(self, instance):
"sector_uuid": str(instance.sector.uuid),
}

if settings.USE_EDA:
FlowsEDAClient().request_queue(action="", content=content)
return super().perform_destroy(instance)
if not settings.USE_WENI_FLOWS:
return super().perform_destroy(instance)

Expand Down
3 changes: 0 additions & 3 deletions chats/apps/api/v1/sectors/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ def perform_create(self, serializer):
"sector_uuid": str(instance.uuid),
},
}
if settings.USE_EDA:
FlowsEDAClient().request_ticketer(content=content)
return
if settings.USE_WENI_FLOWS:
connect = ConnectRESTClient()
response = connect.create_ticketer(**content)
Expand Down
5 changes: 2 additions & 3 deletions chats/apps/projects/consumers/project_consumer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import amqp
from django.conf import settings

from chats.apps.event_driven.consumers import pyamqp_call_dlx_when_error
from chats.apps.event_driven.consumers import EDAConsumer
from chats.apps.event_driven.consumers import EDAConsumer, pyamqp_call_dlx_when_error
from chats.apps.event_driven.parsers.json_parser import JSONParser
from chats.apps.projects.usecases.project_creation import (
ProjectCreationDTO,
Expand Down Expand Up @@ -32,7 +31,7 @@ def consume(message: amqp.Message):
date_format=body.get("date_format"),
template_type_uuid=body.get("template_type_uuid"),
timezone=body.get("timezone"),
authorizations=body.get("authorizations"),
authorizations=body.get("authorizations", []),
)

sector_setup_handler = SectorSetupHandlerUseCase()
Expand Down
3 changes: 1 addition & 2 deletions chats/apps/projects/consumers/template_type_consumer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import amqp
from django.conf import settings

from chats.apps.event_driven.consumers import pyamqp_call_dlx_when_error
from chats.apps.event_driven.consumers import EDAConsumer
from chats.apps.event_driven.consumers import EDAConsumer, pyamqp_call_dlx_when_error
from chats.apps.event_driven.parsers.json_parser import JSONParser
from chats.apps.projects.usecases import TemplateTypeCreation

Expand Down
42 changes: 22 additions & 20 deletions chats/apps/projects/usecases/project_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.contrib.auth import get_user_model

from ..models import Project, TemplateType, ProjectPermission
from ..models import Project, ProjectPermission, TemplateType
from .exceptions import InvalidProjectData

User = get_user_model()
Expand All @@ -17,7 +17,7 @@ class ProjectCreationDTO:
date_format: str
timezone: str
template_type_uuid: str
authorizations: dict
authorizations: list


class ProjectCreationUseCase:
Expand Down Expand Up @@ -50,25 +50,27 @@ def create_project(self, project_dto: ProjectCreationDTO):

if Project.objects.filter(uuid=project_dto.uuid).exists():
raise InvalidProjectData(f"The project `{project_dto.uuid}` already exist!")
else:
project = Project.objects.create(
uuid=project_dto.uuid,
name=project_dto.name,
is_template=project_dto.is_template,
date_format=project_dto.date_format,
timezone=project_dto.timezone,
)

for permission in project_dto.authorizations:
permission_user = User.objects.get_or_create(
email=permission.get("user_email")
)[0]
permission = project.permissions.create(
user=permission_user,
role=1 if permission.get("role") == 3 else 2,
)

creator_permission = ProjectPermission.objects.get(user=user, project=project)
project = Project.objects.create(
uuid=project_dto.uuid,
name=project_dto.name,
is_template=project_dto.is_template,
date_format=project_dto.date_format,
timezone=project_dto.timezone,
)

creator_permission, _ = ProjectPermission.objects.get_or_create(
user=user, project=project, role=1
)

for permission in project_dto.authorizations:
permission_user = User.objects.get_or_create(
email=permission.get("user_email")
)[0]
project.permissions.get_or_create(
user=permission_user,
defaults={"role": 1 if permission.get("role") == 3 else 2},
)

if project_dto.is_template:
self.__sector_setup_handler.setup_sectors_in_project(
Expand Down
2 changes: 0 additions & 2 deletions chats/apps/projects/usecases/sector_setup_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from chats.apps.queues.models import QueueAuthorization
from chats.apps.sectors.models import SectorAuthorization

from .exceptions import InvalidTemplateTypeData


class SectorSetupHandlerUseCase:
def __init__(self):
Expand Down

0 comments on commit 89c17e3

Please sign in to comment.