plugged share_list() FBV ability for user to share list w. self as recipient
This commit is contained in:
@@ -2,6 +2,7 @@ import lxml.html
|
||||
from unittest import skip
|
||||
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import html
|
||||
|
||||
from apps.dashboard.forms import (
|
||||
@@ -210,3 +211,11 @@ class ShareListTest(TestCase):
|
||||
data={"recipient": "nobody@example.com"},
|
||||
)
|
||||
self.assertRedirects(response, f"/apps/dashboard/{our_list.id}/")
|
||||
|
||||
def test_share_list_does_not_add_owner_as_recipient(self):
|
||||
owner = User.objects.create(email="owner@example.com")
|
||||
our_list = List.objects.create(owner=owner)
|
||||
self.client.force_login(owner)
|
||||
self.client.post(reverse("share_list", args=[our_list.id]),
|
||||
data={"recipient": "owner@example.com"})
|
||||
self.assertNotIn(owner, our_list.shared_with.all())
|
||||
|
||||
@@ -44,6 +44,8 @@ def share_list(request, list_id):
|
||||
our_list = List.objects.get(id=list_id)
|
||||
try:
|
||||
recipient = User.objects.get(email=request.POST["recipient"])
|
||||
if recipient == request.user:
|
||||
return redirect(our_list)
|
||||
our_list.shared_with.add(recipient)
|
||||
except User.DoesNotExist:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user