mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-06-29 10:23:36 +02:00
Fix playlist access checks
This commit is contained in:
parent
f453746e2c
commit
f9f263a481
|
@ -22,7 +22,6 @@ using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
using MediaBrowser.Model.Playlists;
|
using MediaBrowser.Model.Playlists;
|
||||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PlaylistsNET.Content;
|
using PlaylistsNET.Content;
|
||||||
|
@ -68,8 +67,14 @@ namespace Emby.Server.Implementations.Playlists
|
||||||
public IEnumerable<Playlist> GetPlaylists(Guid userId)
|
public IEnumerable<Playlist> GetPlaylists(Guid userId)
|
||||||
{
|
{
|
||||||
var user = _userManager.GetUserById(userId);
|
var user = _userManager.GetUserById(userId);
|
||||||
|
return _libraryManager.GetItemList(new InternalItemsQuery
|
||||||
return GetPlaylistsFolder(userId).GetChildren(user, true).OfType<Playlist>();
|
{
|
||||||
|
IncludeItemTypes = [BaseItemKind.Playlist],
|
||||||
|
Recursive = true,
|
||||||
|
DtoOptions = new DtoOptions(false)
|
||||||
|
})
|
||||||
|
.Cast<Playlist>()
|
||||||
|
.Where(p => p.IsVisible(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PlaylistCreationResult> CreatePlaylist(PlaylistCreationRequest request)
|
public async Task<PlaylistCreationResult> CreatePlaylist(PlaylistCreationRequest request)
|
||||||
|
@ -162,6 +167,13 @@ namespace Emby.Server.Implementations.Playlists
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Playlist> GetUserPlaylists(Guid userId)
|
||||||
|
{
|
||||||
|
var user = _userManager.GetUserById(userId);
|
||||||
|
|
||||||
|
return GetPlaylistsFolder(userId).GetChildren(user, true).OfType<Playlist>().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
private static string GetTargetPath(string path)
|
private static string GetTargetPath(string path)
|
||||||
{
|
{
|
||||||
while (Directory.Exists(path))
|
while (Directory.Exists(path))
|
||||||
|
@ -227,7 +239,7 @@ namespace Emby.Server.Implementations.Playlists
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the playlist in the repository
|
// Update the playlist in the repository
|
||||||
playlist.LinkedChildren = [..playlist.LinkedChildren, ..childrenToAdd];
|
playlist.LinkedChildren = [.. playlist.LinkedChildren, .. childrenToAdd];
|
||||||
|
|
||||||
await UpdatePlaylistInternal(playlist).ConfigureAwait(false);
|
await UpdatePlaylistInternal(playlist).ConfigureAwait(false);
|
||||||
|
|
||||||
|
@ -501,11 +513,13 @@ namespace Emby.Server.Implementations.Playlists
|
||||||
return relativePath;
|
return relativePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public Folder GetPlaylistsFolder()
|
public Folder GetPlaylistsFolder()
|
||||||
{
|
{
|
||||||
return GetPlaylistsFolder(Guid.Empty);
|
return GetPlaylistsFolder(Guid.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public Folder GetPlaylistsFolder(Guid userId)
|
public Folder GetPlaylistsFolder(Guid userId)
|
||||||
{
|
{
|
||||||
const string TypeName = "PlaylistsFolder";
|
const string TypeName = "PlaylistsFolder";
|
||||||
|
@ -517,7 +531,7 @@ namespace Emby.Server.Implementations.Playlists
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task RemovePlaylistsAsync(Guid userId)
|
public async Task RemovePlaylistsAsync(Guid userId)
|
||||||
{
|
{
|
||||||
var playlists = GetPlaylists(userId);
|
var playlists = GetUserPlaylists(userId);
|
||||||
foreach (var playlist in playlists)
|
foreach (var playlist in playlists)
|
||||||
{
|
{
|
||||||
// Update owner if shared
|
// Update owner if shared
|
||||||
|
@ -555,9 +569,9 @@ namespace Emby.Server.Implementations.Playlists
|
||||||
|
|
||||||
var user = _userManager.GetUserById(request.UserId);
|
var user = _userManager.GetUserById(request.UserId);
|
||||||
await AddToPlaylistInternal(request.Id, request.Ids, user, new DtoOptions(false)
|
await AddToPlaylistInternal(request.Id, request.Ids, user, new DtoOptions(false)
|
||||||
{
|
{
|
||||||
EnableImages = true
|
EnableImages = true
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
playlist = GetPlaylistForUser(request.Id, request.UserId);
|
playlist = GetPlaylistForUser(request.Id, request.UserId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,6 +221,11 @@ public class PlaylistsController : BaseJellyfinApiController
|
||||||
return userPermission;
|
return userPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (playlist.OwnerUserId.Equals(callingUserId))
|
||||||
|
{
|
||||||
|
return new PlaylistUserPermissions(callingUserId, true);
|
||||||
|
}
|
||||||
|
|
||||||
return NotFound("User permissions not found");
|
return NotFound("User permissions not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace MediaBrowser.Controller.Playlists
|
||||||
Task UpdatePlaylist(PlaylistUpdateRequest request);
|
Task UpdatePlaylist(PlaylistUpdateRequest request);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the playlists.
|
/// Gets all playlists a user has access to.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">The user identifier.</param>
|
/// <param name="userId">The user identifier.</param>
|
||||||
/// <returns>IEnumerable<Playlist>.</returns>
|
/// <returns>IEnumerable<Playlist>.</returns>
|
||||||
|
|
Loading…
Reference in a new issue