Skip to content

Commit

Permalink
feature: new endpoint to set principal projects
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJaeger committed Feb 4, 2025
1 parent cdeb223 commit a04d94e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions chats/apps/api/v1/projects/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit a04d94e

Please sign in to comment.