From a04d94e458bbd7f3a51a9ecdd434a6ffe937a2c6 Mon Sep 17 00:00:00 2001 From: AlanJaeger Date: Tue, 4 Feb 2025 14:41:23 -0300 Subject: [PATCH] feature: new endpoint to set principal projects --- chats/apps/api/v1/projects/viewsets.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/chats/apps/api/v1/projects/viewsets.py b/chats/apps/api/v1/projects/viewsets.py index 0e284b2d..815959ee 100644 --- a/chats/apps/api/v1/projects/viewsets.py +++ b/chats/apps/api/v1/projects/viewsets.py @@ -518,3 +518,26 @@ def update_access(self, request, *args, **kwargs): status.HTTP_401_UNAUTHORIZED, ) return Response(serialized_data.data, status=status.HTTP_200_OK) + + @action( + detail=True, + methods=["post"], + url_path="set-project-principal", + ) + def set_project_as_principal(self, request, *args, **kwargs): + project = self.get_object() + + config = project.config or {} + config["its_principal"] = True + project.config = config + project.save() + + org_projects = Project.objects.filter(org=project.org).exclude(pk=project.pk) + org_projects.update(config={"its_secundary": True}) + + return Response( + { + "detail": "Project set as principal and other projects in the same org set as secondary." + }, + status=status.HTTP_200_OK, + )