From 7ee8e02b297e5cfa36a93a1d4378d2be1e5243e3 Mon Sep 17 00:00:00 2001
From: Kuba Orlik <kontakt@kuba-orlik.name>
Date: Thu, 22 Oct 2020 15:06:28 +0200
Subject: [PATCH] Fix feed formatting so it passes w3c validation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Feeds generated by Funkwhale do not pass validation with the [w3c
validator](https://validator.w3.org/feed/check.cgi?url=https%3A%2F%2Fpodcast.midline.pl%2Fapi%2Fv1%2Fchannels%2FMidline%2Frss).
This commit addresses the problems identified during validation:

1. The `isPermalink` is not recognized -> changed it to
   `isPermaLink` (capital "L")

2. `itunes:summary` and `itunes:subtitle` are 256 characters after
   truncating, but the maximum is 255. The truncating function trims the
   text to 255 chars, but then adds `…`, so the text is one character
   too long

3. The tags within `itunes:keywords` are now separated with commas
   instead of spaces (https://validator.w3.org/feed/docs/warning/InvalidKeywords.html)
---
 api/funkwhale_api/audio/serializers.py | 8 ++++----
 api/funkwhale_api/users/adapters.py    | 3 +++
 api/requirements/base.txt              | 2 +-
 api/tests/audio/test_serializers.py    | 6 +++---
 changes/changelog.d/1250.bugfix        | 1 +
 5 files changed, 12 insertions(+), 8 deletions(-)
 create mode 100644 changes/changelog.d/1250.bugfix

diff --git a/api/funkwhale_api/audio/serializers.py b/api/funkwhale_api/audio/serializers.py
index fd57ed374e..e15325d8c3 100644
--- a/api/funkwhale_api/audio/serializers.py
+++ b/api/funkwhale_api/audio/serializers.py
@@ -818,7 +818,7 @@ def rss_serialize_item(upload):
     data = {
         "title": [{"value": upload.track.title}],
         "itunes:title": [{"value": upload.track.title}],
-        "guid": [{"cdata_value": str(upload.uuid), "isPermalink": "false"}],
+        "guid": [{"cdata_value": str(upload.uuid), "isPermaLink": "false"}],
         "pubDate": [{"value": rfc822_date(upload.creation_date)}],
         "itunes:duration": [{"value": rss_duration(upload.duration)}],
         "itunes:explicit": [{"value": "no"}],
@@ -841,7 +841,7 @@ def rss_serialize_item(upload):
         ],
     }
     if upload.track.description:
-        data["itunes:subtitle"] = [{"value": upload.track.description.truncate(255)}]
+        data["itunes:subtitle"] = [{"value": upload.track.description.truncate(254)}]
         data["itunes:summary"] = [{"cdata_value": upload.track.description.rendered}]
         data["description"] = [{"value": upload.track.description.as_plain_text}]
 
@@ -853,7 +853,7 @@ def rss_serialize_item(upload):
     tagged_items = getattr(upload.track, "_prefetched_tagged_items", [])
     if tagged_items:
         data["itunes:keywords"] = [
-            {"value": " ".join([ti.tag.name for ti in tagged_items])}
+            {"value": ",".join([ti.tag.name for ti in tagged_items])}
         ]
 
     return data
@@ -903,7 +903,7 @@ def rss_serialize_channel(channel):
         data["itunes:category"] = [node]
 
     if channel.artist.description:
-        data["itunes:subtitle"] = [{"value": channel.artist.description.truncate(255)}]
+        data["itunes:subtitle"] = [{"value": channel.artist.description.truncate(254)}]
         data["itunes:summary"] = [{"cdata_value": channel.artist.description.rendered}]
         data["description"] = [{"value": channel.artist.description.as_plain_text}]
 
diff --git a/api/funkwhale_api/users/adapters.py b/api/funkwhale_api/users/adapters.py
index e52892bd98..436ed2d774 100644
--- a/api/funkwhale_api/users/adapters.py
+++ b/api/funkwhale_api/users/adapters.py
@@ -26,6 +26,9 @@ class FunkwhaleAccountAdapter(DefaultAccountAdapter):
     def get_login_redirect_url(self, request):
         return "noop"
 
+    def get_signup_redirect_url(self, request):
+        return "noop"
+
     def add_message(self, *args, **kwargs):
         # disable message sending
         return
diff --git a/api/requirements/base.txt b/api/requirements/base.txt
index 602ec8f46c..0b6234d8a6 100644
--- a/api/requirements/base.txt
+++ b/api/requirements/base.txt
@@ -6,7 +6,7 @@ django-environ~=0.4
 # Images
 Pillow~=7.0
 
-django-allauth~=0.42
+django-allauth~=0.42.0
 
 psycopg2-binary~=2.8
 
diff --git a/api/tests/audio/test_serializers.py b/api/tests/audio/test_serializers.py
index fbcd28a1a0..5f0c1226f6 100644
--- a/api/tests/audio/test_serializers.py
+++ b/api/tests/audio/test_serializers.py
@@ -300,13 +300,13 @@ def test_rss_item_serializer(factories):
     expected = {
         "title": [{"value": upload.track.title}],
         "itunes:title": [{"value": upload.track.title}],
-        "itunes:subtitle": [{"value": description.truncate(255)}],
+        "itunes:subtitle": [{"value": description.truncate(254)}],
         "itunes:summary": [{"cdata_value": description.rendered}],
         "description": [{"value": description.as_plain_text}],
-        "guid": [{"cdata_value": str(upload.uuid), "isPermalink": "false"}],
+        "guid": [{"cdata_value": str(upload.uuid), "isPermaLink": "false"}],
         "pubDate": [{"value": serializers.rfc822_date(upload.creation_date)}],
         "itunes:duration": [{"value": serializers.rss_duration(upload.duration)}],
-        "itunes:keywords": [{"value": "pop rock"}],
+        "itunes:keywords": [{"value": "pop,rock"}],
         "itunes:explicit": [{"value": "no"}],
         "itunes:episodeType": [{"value": "full"}],
         "itunes:season": [{"value": upload.track.disc_number}],
diff --git a/changes/changelog.d/1250.bugfix b/changes/changelog.d/1250.bugfix
new file mode 100644
index 0000000000..4d4cbddf2b
--- /dev/null
+++ b/changes/changelog.d/1250.bugfix
@@ -0,0 +1 @@
+Make the generated RSS feed more conformant with w3c specification (#1250)
-- 
GitLab