Self hosted FLOSS fitness/workout, nutrition and weight tracker
Require a login to add gallery images
Roland Geider3336876bdaec
diff --git a/wger/gallery/tests/test_gallery_image.py b/wger/gallery/tests/test_gallery_image.pyindex 520cf1aa4..b047254d0 100644--- a/wger/gallery/tests/test_gallery_image.py+++ b/wger/gallery/tests/test_gallery_image.py@@ -15,10 +15,15 @@# Standard Libraryimport datetime+# Django+from django.conf import settings+from django.urls import reverse+# wgerfrom wger.core.tests.base_testcase import (WgerAddTestCase,WgerDeleteTestCase,+ WgerTestCase,)from wger.gallery.models import Image@@ -105,3 +110,27 @@ class DeleteGalleryImageTestCase(WgerDeleteTestCase):# 'user': 2,# 'description': 'Everything going well',# 'image': open('wger/exercises/tests/protestschwein.jpg', 'rb')}+++class AddGalleryImageAnonymousTestCase(WgerTestCase):+ """+ Anonymous visitors are sent to the login page instead of the upload form+ """++ def test_get(self):+ response = self.client.get(reverse('gallery:images:add'))++ self.assertEqual(response.status_code, 302)+ self.assertTrue(response['Location'].startswith(f'{settings.LOGIN_URL}?next='))++ def test_post(self):+ count_before = Image.objects.count()++ with open('wger/exercises/tests/protestschwein.jpg', 'rb') as image:+ response = self.client.post(+ reverse('gallery:images:add'),+ {'date': datetime.date(2021, 5, 1), 'user': 1, 'image': image},+ )++ self.assertEqual(response.status_code, 302)+ self.assertEqual(Image.objects.count(), count_before)diff --git a/wger/gallery/views/images.py b/wger/gallery/views/images.pyindex 43e8071fa..269dd8332 100644--- a/wger/gallery/views/images.py+++ b/wger/gallery/views/images.py@@ -53,7 +53,7 @@ def overview(request):return render(request, 'images/overview.html', context)-class ImageAddView(WgerFormMixin, CreateView):+class ImageAddView(WgerFormMixin, LoginRequiredMixin, CreateView):"""Generic view to add a new weight entry"""