-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from chats.apps.projects.models import Project | ||
from chats.apps.sectors.models import Sector | ||
from chats.apps.queues.models import Queue | ||
|
||
from chats.apps.api.v1.internal.rest_clients.connect_rest_client import ( | ||
ConnectRESTClient, | ||
) | ||
from rest_framework import exceptions, status | ||
from chats.apps.api.v1.internal.rest_clients.flows_rest_client import FlowRESTClient | ||
|
||
|
||
class IntegratedTicketers: | ||
def integrate_ticketer(self, project): | ||
projects = Project.objects.filter(org=project.org).exclude( | ||
config__its_main=True | ||
) | ||
|
||
for secundary_project in projects: | ||
sectors = Sector.objects.filter( | ||
project=project, config__integration_token=secundary_project.uuid | ||
) | ||
|
||
for sector in sectors: | ||
content = { | ||
"project_uuid": str(secundary_project.uuid), | ||
"name": sector.name, | ||
"config": { | ||
"project_auth": str(sector.external_token.pk), | ||
"sector_uuid": str(sector.uuid), | ||
}, | ||
} | ||
connect = ConnectRESTClient() | ||
response = connect.create_ticketer(**content) | ||
if response.status_code not in [ | ||
status.HTTP_200_OK, | ||
status.HTTP_201_CREATED, | ||
]: | ||
raise exceptions.APIException( | ||
detail=f"[{response.status_code}] Error posting the sector/ticketer on flows. Exception: {response.content}" | ||
) | ||
|
||
def integrate_topic(self, project): | ||
projects = Project.objects.filter(org=project.org).exclude( | ||
config__its_main=True | ||
) | ||
for secundary_project in projects: | ||
queues = Queue.objects.filter( | ||
sector__project=project, | ||
sector__project__config__integration_token=secundary_project.uuid, | ||
) | ||
|
||
for queue in queues: | ||
content = { | ||
"uuid": str(queue.uuid), | ||
"name": queue.name, | ||
"sector_uuid": str(queue.sector.uuid), | ||
"project_uuid": str(secundary_project.uuid), | ||
} | ||
response = FlowRESTClient().create_queue(**content) | ||
if response.status_code not in [ | ||
status.HTTP_200_OK, | ||
status.HTTP_201_CREATED, | ||
]: | ||
raise exceptions.APIException( | ||
detail=f"[{response.status_code}] Error posting the queue on flows. Exception: {response.content}" | ||
) |