Add soft delete API for signups
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 2.1.5 on 2020-11-07 18:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('webapp', '0073_auto_20201107_1916'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='signup',
|
||||
name='deleted',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
||||
+2
-2
@@ -125,7 +125,7 @@ class SignupForm(models.Model):
|
||||
|
||||
class Signup(models.Model):
|
||||
"""
|
||||
In
|
||||
Actual signup into any SignupForm. Deletes are soft.
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
@@ -140,6 +140,7 @@ class Signup(models.Model):
|
||||
email = models.EmailField(blank=True, null=True)
|
||||
# Random unique identifier. Used for signup editing by the user.
|
||||
uuid = models.UUIDField(default=uuid4, editable=False)
|
||||
deleted = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.signupForm}: {self.list_name} ({self.pk})"
|
||||
@@ -147,7 +148,6 @@ class Signup(models.Model):
|
||||
|
||||
@receiver(post_save, sender=Signup)
|
||||
def email_on_signup(sender, instance, created, **kwargs):
|
||||
"""Send email validation."""
|
||||
if created and instance.email:
|
||||
# TODO: Possible bug due to many-to-many relationship with events and forms.
|
||||
# TODO: Subject field crashes with lazy loaded translations.
|
||||
|
||||
@@ -56,6 +56,15 @@ class SignupTestCase(APITestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertEqual(Signup.objects.count(), 3)
|
||||
|
||||
def test_delete_as_admin(self):
|
||||
id = self.signup1.id
|
||||
no_auth_response = self.client.delete(f"{URL}{id}/", format="json")
|
||||
self.assertEqual(no_auth_response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
self.client.force_authenticate(user=self.authClient)
|
||||
response = self.client.delete(f"{URL}{id}/", format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(Signup.objects.get(id=id).deleted, True)
|
||||
|
||||
@skip("NotImplemented")
|
||||
def test_get_hidden_forms_admin(self):
|
||||
pass
|
||||
|
||||
+10
-1
@@ -106,7 +106,7 @@ class SignupFormViewSet(ModelViewSet):
|
||||
|
||||
|
||||
class SignupViewSet(ModelViewSet):
|
||||
queryset = Signup.objects.all()
|
||||
queryset = Signup.objects.filter(deleted=False)
|
||||
serializer_class = SignupSerializer
|
||||
permission_classes = [SignupPermission]
|
||||
|
||||
@@ -156,6 +156,15 @@ class SignupViewSet(ModelViewSet):
|
||||
else:
|
||||
return JsonResponse(status=404, data={"error": f"SignupForm {id} not found"})
|
||||
|
||||
def destroy(self, request, pk=None, *args, **kwargs):
|
||||
try:
|
||||
signup = self.get_object()
|
||||
signup.deleted = True
|
||||
signup.save()
|
||||
return JsonResponse(status=200, data={"message": "OK"})
|
||||
except ObjectDoesNotExist:
|
||||
return JsonResponse(status=404, data={"error": f"Signup {pk} not found"})
|
||||
|
||||
|
||||
class SavedQuestionsViewSet(ModelViewSet):
|
||||
queryset = TemplateQuestion.objects.all()
|
||||
|
||||
Reference in New Issue
Block a user