From 9facaf404f6d18836f078822f106d8ea7bcfde81 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Dec 2021 10:20:54 -0800 Subject: [PATCH 01/13] Validates html in feed views --- bookwyrm/templates/feed/status.html | 2 +- bookwyrm/tests/views/test_feed.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bookwyrm/templates/feed/status.html b/bookwyrm/templates/feed/status.html index 8dcad088..e7b9280d 100644 --- a/bookwyrm/templates/feed/status.html +++ b/bookwyrm/templates/feed/status.html @@ -31,7 +31,7 @@ {% endif %} {% endfor %} -
+
{% include 'snippets/status/status.html' with status=status main=True %}
diff --git a/bookwyrm/tests/views/test_feed.py b/bookwyrm/tests/views/test_feed.py index 63264b80..475bebeb 100644 --- a/bookwyrm/tests/views/test_feed.py +++ b/bookwyrm/tests/views/test_feed.py @@ -13,6 +13,7 @@ from django.test.client import RequestFactory from bookwyrm import models from bookwyrm import views from bookwyrm.activitypub import ActivitypubResponse +from bookwyrm.tests.validate_html import validate_html @patch("bookwyrm.activitystreams.ActivityStream.get_activity_stream") @@ -58,7 +59,7 @@ class FeedViews(TestCase): request.user = self.local_user result = view(request, "home") self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_status_page(self, *_): @@ -72,7 +73,7 @@ class FeedViews(TestCase): is_api.return_value = False result = view(request, "mouse", status.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) with patch("bookwyrm.views.feed.is_api_request") as is_api: @@ -139,7 +140,7 @@ class FeedViews(TestCase): is_api.return_value = False result = view(request, "mouse", status.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) with patch("bookwyrm.views.feed.is_api_request") as is_api: @@ -159,7 +160,7 @@ class FeedViews(TestCase): is_api.return_value = False result = view(request, "mouse", status.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) with patch("bookwyrm.views.feed.is_api_request") as is_api: @@ -175,7 +176,7 @@ class FeedViews(TestCase): request.user = self.local_user result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_direct_messages_page_user(self, *_): @@ -185,7 +186,7 @@ class FeedViews(TestCase): request.user = self.local_user result = view(request, "nutria") self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) self.assertEqual(result.context_data["partner"], self.another_user) From 161532f8a8bb660b558a7c4b0a04473538cac006 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Dec 2021 10:37:21 -0800 Subject: [PATCH 02/13] Adds validate_html to announcement page tests --- bookwyrm/tests/views/admin/test_announcements.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bookwyrm/tests/views/admin/test_announcements.py b/bookwyrm/tests/views/admin/test_announcements.py index 44b5d5b6..fadd3d86 100644 --- a/bookwyrm/tests/views/admin/test_announcements.py +++ b/bookwyrm/tests/views/admin/test_announcements.py @@ -5,6 +5,7 @@ from django.test import TestCase from django.test.client import RequestFactory from bookwyrm import forms, models, views +from bookwyrm.tests.validate_html import validate_html class AnnouncementViews(TestCase): @@ -38,7 +39,7 @@ class AnnouncementViews(TestCase): result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_announcements_page_empty(self): @@ -51,7 +52,7 @@ class AnnouncementViews(TestCase): result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_announcement_page(self): @@ -68,7 +69,7 @@ class AnnouncementViews(TestCase): result = view(request, announcement.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_create_announcement(self): @@ -138,5 +139,5 @@ class AnnouncementViews(TestCase): result = view(request, self.local_user.localname) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) From 1e27b64af43b18fc89210b2b0f23d4af0ed86410 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Dec 2021 10:39:47 -0800 Subject: [PATCH 03/13] Valid dl html syntax on announcement page --- .../settings/announcements/announcement.html | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/bookwyrm/templates/settings/announcements/announcement.html b/bookwyrm/templates/settings/announcements/announcement.html index 37dba06f..8b49f4f4 100644 --- a/bookwyrm/templates/settings/announcements/announcement.html +++ b/bookwyrm/templates/settings/announcements/announcement.html @@ -31,35 +31,29 @@
-
-
{% trans "Visible:" %}
-
- {% if announcement in active_announcements %} - {% trans "True" %} - {% else %} - {% trans "False" %} - {% endif %} -
-
+
{% trans "Visible:" %}
+
+ + {% if announcement in active_announcements %} + {% trans "True" %} + {% else %} + {% trans "False" %} + {% endif %} + +
{% if announcement.start_date %} -
-
{% trans "Start date:" %}
-
{{ announcement.start_date|naturalday }}
-
+
{% trans "Start date:" %}
+
{{ announcement.start_date|naturalday }}
{% endif %} {% if announcement.end_date %} -
-
{% trans "End date:" %}
-
{{ announcement.end_date|naturalday }}
-
+
{% trans "End date:" %}
+
{{ announcement.end_date|naturalday }}
{% endif %} -
-
{% trans "Active:" %}
-
{{ announcement.active }}
-
+
{% trans "Active:" %}
+
{{ announcement.active }}
From 3770713e0714e5df502bb19da6529c1cd0a1d8d0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Dec 2021 10:44:04 -0800 Subject: [PATCH 04/13] Validate html in discover page tests --- bookwyrm/tests/views/test_discover.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bookwyrm/tests/views/test_discover.py b/bookwyrm/tests/views/test_discover.py index b2a82241..dcfc2bf2 100644 --- a/bookwyrm/tests/views/test_discover.py +++ b/bookwyrm/tests/views/test_discover.py @@ -4,8 +4,8 @@ from django.contrib.auth.models import AnonymousUser from django.test import TestCase from django.test.client import RequestFactory -from bookwyrm import models -from bookwyrm import views +from bookwyrm import models, views +from bookwyrm.tests.validate_html import validate_html class DiscoverViews(TestCase): @@ -39,7 +39,7 @@ class DiscoverViews(TestCase): result = view(request) self.assertEqual(mock.call_count, 1) self.assertEqual(result.status_code, 200) - result.render() + validate_html(result.render()) @patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async") @patch("bookwyrm.activitystreams.add_status_task.delay") @@ -67,7 +67,7 @@ class DiscoverViews(TestCase): result = view(request) self.assertEqual(mock.call_count, 1) self.assertEqual(result.status_code, 200) - result.render() + validate_html(result.render()) def test_discover_page_logged_out(self): """there are so many views, this just makes sure it LOADS""" From 8e89d020934f69b91758aa68ca32cb9d4709697b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Dec 2021 11:10:11 -0800 Subject: [PATCH 05/13] Fixes html form for editing lists --- bookwyrm/templates/lists/curate.html | 4 +- bookwyrm/templates/lists/form.html | 81 ++++++++++++++++++++++------ bookwyrm/tests/views/test_list.py | 31 +++++------ 3 files changed, 83 insertions(+), 33 deletions(-) diff --git a/bookwyrm/templates/lists/curate.html b/bookwyrm/templates/lists/curate.html index 638d86b8..13de89c1 100644 --- a/bookwyrm/templates/lists/curate.html +++ b/bookwyrm/templates/lists/curate.html @@ -54,13 +54,13 @@ {% csrf_token %} - +
{% csrf_token %} - +
diff --git a/bookwyrm/templates/lists/form.html b/bookwyrm/templates/lists/form.html index 25dc01e6..ae19e5db 100644 --- a/bookwyrm/templates/lists/form.html +++ b/bookwyrm/templates/lists/form.html @@ -18,24 +18,73 @@
{% trans "List curation:" %} - +
+ + +

+ {% trans "Only you can add and remove books to this list" %} +

+
- +
+ + +

+ {% trans "Anyone can suggest books, subject to your approval" %} +

+
- +
+ + +

+ {% trans "Anyone can add books to this list" %} +

+
+ +
+ + +

+ {% trans "Group members can add to and remove from this list" %} +

- +
diff --git a/bookwyrm/tests/views/test_list.py b/bookwyrm/tests/views/test_list.py index fd4d2d76..3d9b6d24 100644 --- a/bookwyrm/tests/views/test_list.py +++ b/bookwyrm/tests/views/test_list.py @@ -10,6 +10,7 @@ from django.test.client import RequestFactory from bookwyrm import models, views from bookwyrm.activitypub import ActivitypubResponse +from bookwyrm.tests.validate_html import validate_html # pylint: disable=unused-argument class ListViews(TestCase): @@ -84,14 +85,14 @@ class ListViews(TestCase): result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) request.user = self.anonymous_user result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_saved_lists_page(self): @@ -110,7 +111,7 @@ class ListViews(TestCase): result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) self.assertEqual(result.context_data["lists"].object_list, [booklist]) @@ -127,7 +128,7 @@ class ListViews(TestCase): result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) self.assertEqual(len(result.context_data["lists"].object_list), 0) @@ -188,7 +189,7 @@ class ListViews(TestCase): is_api.return_value = False result = view(request, self.list.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_list_page_sorted(self): @@ -210,7 +211,7 @@ class ListViews(TestCase): is_api.return_value = False result = view(request, self.list.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) request = self.factory.get("/?sort_by=title") @@ -219,7 +220,7 @@ class ListViews(TestCase): is_api.return_value = False result = view(request, self.list.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) request = self.factory.get("/?sort_by=rating") @@ -228,7 +229,7 @@ class ListViews(TestCase): is_api.return_value = False result = view(request, self.list.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) request = self.factory.get("/?sort_by=sdkfh") @@ -237,7 +238,7 @@ class ListViews(TestCase): is_api.return_value = False result = view(request, self.list.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_list_page_empty(self): @@ -250,7 +251,7 @@ class ListViews(TestCase): is_api.return_value = False result = view(request, self.list.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_list_page_logged_out(self): @@ -271,7 +272,7 @@ class ListViews(TestCase): is_api.return_value = False result = view(request, self.list.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_list_page_json_view(self): @@ -355,7 +356,7 @@ class ListViews(TestCase): result = view(request, self.list.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) request.user = self.anonymous_user @@ -375,7 +376,7 @@ class ListViews(TestCase): result = view(request, self.local_user.localname) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_user_lists_page_logged_out(self): @@ -404,7 +405,7 @@ class ListViews(TestCase): with patch("bookwyrm.views.list.is_api_request") as is_api: is_api.return_value = False with self.assertRaises(Http404): - result = view(request, self.list.id, "") + view(request, self.list.id, "") def test_embed_call_with_key(self): """there are so many views, this just makes sure it LOADS""" @@ -427,5 +428,5 @@ class ListViews(TestCase): result = view(request, self.list.id, embed_key) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) From 4e1b155c6c396aaabefb72fa2d44d3a80da46c45 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Dec 2021 11:21:21 -0800 Subject: [PATCH 06/13] Encode characters in iframe copy text --- bookwyrm/templates/lists/list.html | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index 836ca864..434ecd94 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -172,7 +172,7 @@
@@ -191,7 +191,16 @@ {% trans "Embed this list on a website" %}
- +
From 3e550a13adc32b0f3635ed8822752361563e2883 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Dec 2021 11:31:26 -0800 Subject: [PATCH 07/13] Unique names for shelve forms --- bookwyrm/templates/lists/list.html | 2 +- .../templates/snippets/reading_modals/finish_reading_modal.html | 2 +- .../snippets/reading_modals/progress_update_modal.html | 2 +- .../templates/snippets/reading_modals/start_reading_modal.html | 2 +- .../templates/snippets/reading_modals/want_to_read_modal.html | 2 +- .../snippets/shelve_button/shelve_button_dropdown_options.html | 2 +- .../templates/snippets/shelve_button/shelve_button_options.html | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index 434ecd94..8bf7c052 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -56,7 +56,7 @@
{{ book|book_description|to_markdown|default:""|safe|truncatewords_html:20 }}
- {% include 'snippets/shelve_button/shelve_button.html' %} + {% include 'snippets/shelve_button/shelve_button.html' with book=book %} {% endwith %} diff --git a/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html b/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html index a35ed9e0..fe35ee7e 100644 --- a/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html @@ -9,7 +9,7 @@ Finish "{{ book_title }}" {% endblock %} {% block modal-form-open %} - + {% csrf_token %} diff --git a/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html b/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html index 422f7056..3e0fd45e 100644 --- a/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html @@ -6,7 +6,7 @@ {% endblock %} {% block modal-form-open %} - + {% csrf_token %} {% endblock %} diff --git a/bookwyrm/templates/snippets/reading_modals/start_reading_modal.html b/bookwyrm/templates/snippets/reading_modals/start_reading_modal.html index 423f77eb..60c7a89e 100644 --- a/bookwyrm/templates/snippets/reading_modals/start_reading_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/start_reading_modal.html @@ -9,7 +9,7 @@ Start "{{ book_title }}" {% endblock %} {% block modal-form-open %} - + {% csrf_token %} diff --git a/bookwyrm/templates/snippets/reading_modals/want_to_read_modal.html b/bookwyrm/templates/snippets/reading_modals/want_to_read_modal.html index 2fb976bf..d6bc4d70 100644 --- a/bookwyrm/templates/snippets/reading_modals/want_to_read_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/want_to_read_modal.html @@ -9,7 +9,7 @@ Want to Read "{{ book_title }}" {% endblock %} {% block modal-form-open %} - + {% csrf_token %} diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html index 8c1881ce..d418b718 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html @@ -32,7 +32,7 @@ {% elif shelf.editable %} - + {% csrf_token %} - + + {% csrf_token %} +
+
+
- -
+
+ +
+
+ +
+ + {% endif %} + {% if list.user == request.user or list.curation == 'open' and item.user == request.user or list.group|is_member:request.user %} - From 6075a8843825ddfac0385063039703208ac3a615 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Dec 2021 11:45:07 -0800 Subject: [PATCH 09/13] Validate html in get started views tests --- bookwyrm/tests/views/test_get_started.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bookwyrm/tests/views/test_get_started.py b/bookwyrm/tests/views/test_get_started.py index 6d1819a4..9d022205 100644 --- a/bookwyrm/tests/views/test_get_started.py +++ b/bookwyrm/tests/views/test_get_started.py @@ -5,6 +5,7 @@ from django.test import TestCase from django.test.client import RequestFactory from bookwyrm import forms, models, views +from bookwyrm.tests.validate_html import validate_html @patch("bookwyrm.activitystreams.populate_stream_task.delay") @@ -40,7 +41,7 @@ class GetStartedViews(TestCase): result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @@ -72,7 +73,7 @@ class GetStartedViews(TestCase): result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_books_view_with_query(self, _): @@ -84,7 +85,7 @@ class GetStartedViews(TestCase): result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.rerank_suggestions_task.delay") @@ -117,7 +118,7 @@ class GetStartedViews(TestCase): result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) @patch("bookwyrm.suggested_users.SuggestedUsers.get_suggestions") @@ -130,5 +131,5 @@ class GetStartedViews(TestCase): result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) From 0968802fd30a2559c6da41b03fbebc71fbccaf85 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Dec 2021 11:45:17 -0800 Subject: [PATCH 10/13] Adds alt tag to logo --- bookwyrm/templates/get_started/layout.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bookwyrm/templates/get_started/layout.html b/bookwyrm/templates/get_started/layout.html index eef5a9e2..32db56d5 100644 --- a/bookwyrm/templates/get_started/layout.html +++ b/bookwyrm/templates/get_started/layout.html @@ -10,7 +10,12 @@