Skip to content

Commit

Permalink
feature: verify if principal project already exists in org
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJaeger committed Feb 11, 2025
1 parent 37095f1 commit abad9a4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions chats/apps/api/v1/projects/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,17 @@ def partial_update(self, request, uuid=None):
def set_project_as_principal(self, request, *args, **kwargs):
project = self.get_object()

existing_principal = (
Project.objects.filter(org=project.org, config__its_principal=True)
.exclude(pk=project.pk)
.exists()
)
if existing_principal:
return Response(
{"detail": "Já existe um projeto principal nesta organização."},
status=status.HTTP_400_BAD_REQUEST,
)

config = project.config or {}
config["its_principal"] = True
project.config = config
Expand All @@ -486,11 +497,8 @@ def set_project_as_principal(self, request, *args, **kwargs):
def integrate_sectors(self, request, *args, **kwargs):
try:
project = Project.objects.get(uuid=request.query_params["project"])
print("projeto principal", project)
integrations = IntegratedTicketers()

print("classe de integracao", integrations)

integrations.integrate_ticketer(project)
integrations.integrate_topic(project)
except Exception as error:
Expand Down

0 comments on commit abad9a4

Please sign in to comment.