From 0b04fde471a8e39709638b4142e2c5ed350ac85f Mon Sep 17 00:00:00 2001
From: florimondmanca <florimond.manca@gmail.com>
Date: Sat, 30 Jun 2018 18:03:27 +0100
Subject: [PATCH] add project participation cancel endpoint

---
 projects/views.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/projects/views.py b/projects/views.py
index 18ccff6..8e82f19 100644
--- a/projects/views.py
+++ b/projects/views.py
@@ -39,7 +39,7 @@ class ProjectViewSet(viewsets.ReadOnlyModelViewSet):
                 "id": 1,
                 "url": "http://localhost:8000/api/projects/1/",
                 "name": "Oser la Prépa",
-                "description": "Oser la Prépa est un stage d'acclimatation aux Classes Préparatoires de deux semaines qui se déroule chaque été.",
+                "description": "Oser la Prépa est un stage d'acclimatation…",
                 "logo": null
             }
         ]
@@ -421,6 +421,19 @@ class ParticipationViewSet(mixins.CreateModelMixin, mixins.DestroyModelMixin,
     filter_backends = (filters.backends.DjangoFilterBackend,)
     filter_fields = ('user', 'state',)
 
+    @action(methods=['post'], detail=True)
+    def cancel(self, request, pk=None):
+        """Cancel a participation.
+
+        Note: the participation is not removed from the database,
+        it is only marked as cancelled.
+        Use [destroy](#project-participation-destroy) to delete it.
+        """
+        participation = self.get_object()
+        participation.state = Participation.STATE_CANCELLED
+        participation.save()
+        return Response(None, status=status.HTTP_204_NO_CONTENT)
+
     @action(methods=['get'], detail=True)
     def form_entry(self, request, pk=None):
         """Return the answers to the edition form for a participation.
-- 
GitLab