Skip to content

Commit

Permalink
Fix playlist API bugs (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
piazzatron committed Oct 9, 2020
1 parent ea1d12c commit 8c6fdbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
6 changes: 2 additions & 4 deletions discovery-provider/src/api/v1/playlists.py
Expand Up @@ -38,8 +38,6 @@ def get_playlist(playlist_id, current_user_id):
def get_tracks_for_playlist(playlist_id, current_user_id=None):
args = {"playlist_id": playlist_id, "with_users": True, "current_user_id": current_user_id}
playlist_tracks = get_playlist_tracks(args)
if not playlist_tracks:
abort_not_found(playlist_id, ns)
tracks = list(map(extend_track, playlist_tracks))
return tracks

Expand Down Expand Up @@ -210,7 +208,7 @@ def get(self, playlist_id):
decoded_id = decode_with_abort(playlist_id, full_ns)
limit = get_default_max(args.get('limit'), 10, 100)
offset = get_default_max(args.get('offset'), 0)

current_user_id = None
if args.get("user_id"):
current_user_id = decode_string_id(args["user_id"])
Expand Down Expand Up @@ -253,7 +251,7 @@ def get(self, playlist_id):
decoded_id = decode_with_abort(playlist_id, full_ns)
limit = get_default_max(args.get('limit'), 10, 100)
offset = get_default_max(args.get('offset'), 0)

current_user_id = None
if args.get("user_id"):
current_user_id = decode_string_id(args["user_id"])
Expand Down
15 changes: 7 additions & 8 deletions discovery-provider/src/queries/get_playlists.py
Expand Up @@ -37,7 +37,6 @@ def get_playlists(args):
db = get_db_read_replica()
with db.scoped_session() as session:
def get_unpopulated_playlists():
filter_out_private_playlists = True
playlist_query = (
session.query(Playlist)
.filter(Playlist.is_current == True)
Expand All @@ -58,13 +57,8 @@ def get_unpopulated_playlists():
Playlist.playlist_owner_id == user_id
)

# if the current user is the same as the user passed in through the query param then we're trying
# to get playlists for, check if the users are the same. if they are the same, the current user is
# trying to request their own playlists, so allow them to see private playlists
if current_user_id and user_id and (int(current_user_id) == int(user_id)):
filter_out_private_playlists = False

if filter_out_private_playlists:
# If no current_user_id, never show hidden playlists
if not current_user_id:
playlist_query = playlist_query.filter(
Playlist.is_private == False
)
Expand All @@ -79,6 +73,11 @@ def get_unpopulated_playlists():
playlists = paginate_query(playlist_query).all()
playlists = helpers.query_result_to_list(playlists)

# if we passed in a current_user_id, filter out all privte playlists where
# the owner_id doesn't match the current_user_id
if current_user_id:
playlists = list(filter(lambda playlist: (not playlist["is_private"]) or playlist["playlist_owner_id"] == current_user_id, playlists))

# retrieve playlist ids list
playlist_ids = list(map(lambda playlist: playlist["playlist_id"], playlists))

Expand Down

0 comments on commit 8c6fdbf

Please sign in to comment.