From 697ea24b794b1accb309c36e1ff51a42bacd6ccb Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Sun, 24 Jun 2018 14:33:58 +0200 Subject: [PATCH 1/2] Fix #302: Include user's current private playlists on playlist list --- api/funkwhale_api/common/fields.py | 6 +++--- api/funkwhale_api/playlists/views.py | 4 +++- api/tests/common/test_fields.py | 3 ++- changes/changelog.d/302.bugfix | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 changes/changelog.d/302.bugfix diff --git a/api/funkwhale_api/common/fields.py b/api/funkwhale_api/common/fields.py index 190576efa..890aee425 100644 --- a/api/funkwhale_api/common/fields.py +++ b/api/funkwhale_api/common/fields.py @@ -17,13 +17,13 @@ def get_privacy_field(): ) -def privacy_level_query(user, lookup_field="privacy_level"): +def privacy_level_query(user, lookup_field="privacy_level", user_field="user"): if user.is_anonymous: return models.Q(**{lookup_field: "everyone"}) return models.Q( - **{"{}__in".format(lookup_field): ["followers", "instance", "everyone"]} - ) + **{"{}__in".format(lookup_field): ["instance", "everyone"]} + ) | models.Q(**{lookup_field: "me", user_field: user}) class SearchFilter(django_filters.CharFilter): diff --git a/api/funkwhale_api/playlists/views.py b/api/funkwhale_api/playlists/views.py index d5d19df74..21e35f50a 100644 --- a/api/funkwhale_api/playlists/views.py +++ b/api/funkwhale_api/playlists/views.py @@ -110,7 +110,9 @@ class PlaylistTrackViewSet( def get_queryset(self): return self.queryset.filter( fields.privacy_level_query( - self.request.user, lookup_field="playlist__privacy_level" + self.request.user, + lookup_field="playlist__privacy_level", + user_field="playlist__user", ) ) diff --git a/api/tests/common/test_fields.py b/api/tests/common/test_fields.py index d26923148..72aa8b4c3 100644 --- a/api/tests/common/test_fields.py +++ b/api/tests/common/test_fields.py @@ -12,7 +12,8 @@ from funkwhale_api.users.factories import UserFactory (AnonymousUser(), Q(privacy_level="everyone")), ( UserFactory.build(pk=1), - Q(privacy_level__in=["followers", "instance", "everyone"]), + Q(privacy_level__in=["instance", "everyone"]) + | Q(privacy_level="me", user=UserFactory.build(pk=1)), ), ], ) diff --git a/changes/changelog.d/302.bugfix b/changes/changelog.d/302.bugfix new file mode 100644 index 000000000..66c9dea0b --- /dev/null +++ b/changes/changelog.d/302.bugfix @@ -0,0 +1 @@ +Include user's current private playlists on playlist list (#302) From c371fe36452d66c630848eda41603b9e82ea8682 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Sun, 24 Jun 2018 14:34:27 +0200 Subject: [PATCH 2/2] Fixed random stuff (redirection and broken absoluteURl) --- front/src/store/instance.js | 3 +++ front/src/views/playlists/Detail.vue | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/front/src/store/instance.js b/front/src/store/instance.js index dfd6a9db8..95de94171 100644 --- a/front/src/store/instance.js +++ b/front/src/store/instance.js @@ -71,6 +71,9 @@ export default { if (relativeUrl.startsWith('http')) { return relativeUrl } + if (state.instanceUrl.endsWith('/') && relativeUrl.startsWith('/')) { + relativeUrl = relativeUrl.slice(1) + } return state.instanceUrl + relativeUrl } }, diff --git a/front/src/views/playlists/Detail.vue b/front/src/views/playlists/Detail.vue index 61968c2e7..7a378fa67 100644 --- a/front/src/views/playlists/Detail.vue +++ b/front/src/views/playlists/Detail.vue @@ -93,7 +93,7 @@ export default { let url = 'playlists/' + this.id + '/' axios.get(url).then((response) => { self.playlist = response.data - axios.get(url + 'tracks').then((response) => { + axios.get(url + 'tracks/').then((response) => { self.updatePlts(response.data.results) }).then(() => { self.isLoading = false