Skip to content

Commit

Permalink
Merge pull request #3843 from Roardom/fix-private-playlist-id-search
Browse files Browse the repository at this point in the history
(Fix) Exclude private playlists from torrent search
  • Loading branch information
HDVinnie committed May 21, 2024
2 parents 702cfbe + 418f141 commit 57f7fb6
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/Traits/TorrentFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,23 @@ public function scopeOfMal(Builder $query, int $malId): void
/**
* @param Builder<Torrent> $query
*/
public function scopeOfPlaylist(Builder $query, int $playlistId): void
public function scopeOfPlaylist(Builder $query, int $playlistId, ?User $authenticatedUser = null): void
{
$query->whereIn('id', PlaylistTorrent::select('torrent_id')->where('playlist_id', '=', $playlistId));
$authenticatedUser ??= auth()->user();

$query->whereIn(
'id',
PlaylistTorrent::select('torrent_id')
->where('playlist_id', '=', $playlistId)
->when(
$authenticatedUser === null,
fn ($query) => $query->where('is_private', '=', false),
fn ($query) => $query->when(
! $authenticatedUser->group->is_modo,
fn ($query) => $query->where(fn ($query) => $query->where('is_private', '=', false)->orWhere('user_id', '=', $authenticatedUser->id))
)
)
);
}

/**
Expand Down

0 comments on commit 57f7fb6

Please sign in to comment.