fix(plus): smart playlist display inaccessible songs

This commit is contained in:
Phan An 2024-01-22 23:33:16 +01:00
parent 9dc23f319e
commit 69368bfbd8
3 changed files with 7 additions and 0 deletions

View file

@ -22,6 +22,7 @@ class SmartPlaylistService
$query = Song::query()
->withMetaFor($user ?? $playlist->user)
->when(License::isPlus(), static fn (SongBuilder $query) => $query->accessibleBy($user))
->when(
$playlist->own_songs_only && License::isPlus(),
static fn (SongBuilder $query) => $query->where('songs.owner_id', $playlist->user_id)

View file

@ -31,6 +31,7 @@ class PlaylistSongTest extends PlusTestCase
public function testGetSongsInCollaborativePlaylist(): void
{
/** @var Playlist $playlist */
$playlist = Playlist::factory()->create();
$playlist->addSongs(Song::factory()->public()->count(3)->create());
@ -45,6 +46,7 @@ class PlaylistSongTest extends PlusTestCase
public function testPrivateSongsDoNotShowUpInCollaborativePlaylist(): void
{
/** @var Playlist $playlist */
$playlist = Playlist::factory()->create();
$playlist->addSongs(Song::factory()->public()->count(3)->create());
@ -64,6 +66,7 @@ class PlaylistSongTest extends PlusTestCase
public function testCollaboratorCanAddSongs(): void
{
/** @var Playlist $playlist */
$playlist = Playlist::factory()->create();
$collaborator = create_user();
$playlist->addCollaborator($collaborator);
@ -77,6 +80,7 @@ class PlaylistSongTest extends PlusTestCase
public function testCollaboratorCanRemoveSongs(): void
{
/** @var Playlist $playlist */
$playlist = Playlist::factory()->create();
$collaborator = create_user();
$playlist->addCollaborator($collaborator);

View file

@ -15,6 +15,8 @@ class SongTest extends PlusTestCase
$user = create_user();
Song::factory(2)->public()->create();
/** @var Collection<Song>|array<array-key, Song> $ownSongs */
$ownSongs = Song::factory(3)->for($user, 'owner')->create();
$this->getAs('api/songs?own_songs_only=true', $user)