def get_playlists_collaborated_on_for_user(playlist_user_name): """ Fetch playlist metadata in JSPF format without recordings for which a user is a collaborator. If a playlist is private, it will only be returned if the caller is authorized to edit that playlist. :params count: The number of playlists to return (for pagination). Default :data:`~webserver.views.api.DEFAULT_NUMBER_OF_PLAYLISTS_PER_CALL` :params offset: The offset of into the list of playlists to return (for pagination) :statuscode 200: Yay, you have data! :statuscode 404: User not found :resheader Content-Type: *application/json* """ user = validate_auth_header(True) count = get_non_negative_param('count', DEFAULT_NUMBER_OF_PLAYLISTS_PER_CALL) offset = get_non_negative_param('offset', 0) playlist_user = db_user.get_by_mb_id(playlist_user_name) if playlist_user is None: raise APINotFound("Cannot find user: %s" % playlist_user_name) # TODO: This needs to be passed to the DB layer include_private = True if user and user["id"] == playlist_user[ "id"] else False playlists, playlist_count = db_playlist.get_playlists_collaborated_on( playlist_user["id"], include_private=include_private, load_recordings=False, count=count, offset=offset) return jsonify( serialize_playlists(playlists, playlist_count, count, offset))
def collaborations(user_name: str): """ Show playlists a user collaborates on """ if not current_app.config.get("FEATURE_PLAYLIST", False): raise NotFound() offset = request.args.get('offset', 0) try: offset = int(offset) except ValueError: raise BadRequest("Incorrect int argument offset: %s" % request.args.get("offset")) count = request.args.get("count", DEFAULT_NUMBER_OF_PLAYLISTS_PER_CALL) try: count = int(count) except ValueError: raise BadRequest("Incorrect int argument count: %s" % request.args.get("count")) user = _get_user(user_name) user_data = { "name": user.musicbrainz_id, "id": user.id, } current_user_data = {} if current_user.is_authenticated: current_user_data = { "id": current_user.id, "name": current_user.musicbrainz_id, "auth_token": current_user.auth_token, } include_private = current_user.is_authenticated and current_user.id == user.id playlists = [] colalborative_playlists, playlist_count = get_playlists_collaborated_on(user.id, include_private=include_private, load_recordings=False, count=count, offset=offset) for playlist in colalborative_playlists: playlists.append(serialize_jspf(playlist)) props = { "current_user": current_user_data, "api_url": current_app.config["API_URL"], "playlists": playlists, "user": user_data, "active_section": "collaborations", "playlist_count": playlist_count, } return render_template( "playlists/playlists.html", active_section="collaborations", props=ujson.dumps(props), user=user )