Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: verify if principal project already exists in org #459

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 13 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,19 @@ 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": "There is already a principal project in this organization."
},
status=status.HTTP_400_BAD_REQUEST,
)

config = project.config or {}
config["its_principal"] = True
project.config = config
Expand All @@ -486,11 +499,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
Loading