diff --git a/gpodder/tests.py b/gpodder/tests.py new file mode 100644 index 0000000..2080c1c --- /dev/null +++ b/gpodder/tests.py @@ -0,0 +1,36 @@ +import base64 +import json + +from django.contrib.auth.models import User +from django.test import TestCase + +from podcasts.models import EpisodeProgress, PodcastEpisode, PodcastFeed + + +class EpisodeActionTests(TestCase): + """Play positions from a gPodder client (AntennaPod sync) land on the user's own episode.""" + + def setUp(self): + self.alice = User.objects.create_user(username='alice', password='pw12345678') + bob = User.objects.create_user(username='bob', password='pw12345678') + url = 'https://example.org/feed' + audio = 'https://example.org/e1.mp3' + # Bob subscribed first: his copy of the episode has the lower id. + bobs_feed = PodcastFeed.objects.create(user=bob, rss_url=url, title='Feed') + self.bobs_ep = PodcastEpisode.objects.create(feed=bobs_feed, guid='e1', title='E1', audio_url=audio, + duration_seconds=1000) + alices_feed = PodcastFeed.objects.create(user=self.alice, rss_url=url, title='Feed') + self.alices_ep = PodcastEpisode.objects.create(feed=alices_feed, guid='e1', title='E1', audio_url=audio, + duration_seconds=1000) + self.auth = 'Basic ' + base64.b64encode(b'alice:pw12345678').decode() + + def test_position_goes_to_own_episode(self): + actions = [{'podcast': 'https://example.org/feed', 'episode': 'https://example.org/e1.mp3', + 'action': 'play', 'position': 300, 'total': 1000}] + r = self.client.post('/api/2/episodes/alice.json', json.dumps(actions), content_type='application/json', + HTTP_AUTHORIZATION=self.auth) + self.assertEqual(r.status_code, 200, r.content) + progress = EpisodeProgress.objects.get(user=self.alice) + self.assertEqual(progress.episode, self.alices_ep) + self.assertEqual(progress.position_seconds, 300) + self.assertFalse(EpisodeProgress.objects.filter(episode=self.bobs_ep).exists()) diff --git a/gpodder/views.py b/gpodder/views.py index a4e3b79..913d64b 100644 --- a/gpodder/views.py +++ b/gpodder/views.py @@ -230,7 +230,8 @@ def episode_actions(request, username): # Sync playback position to EpisodeProgress if action == 'play' and a.get('position') is not None: try: - ep = PodcastEpisode.objects.filter(audio_url=episode_url).first() + # Only this user's subscriptions: several users can have the same feed. + ep = PodcastEpisode.objects.filter(audio_url=episode_url, feed__user=request.user).first() if ep: pos = int(a['position']) dur = ep.duration_seconds or 0