Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Sep 26, 2024
2 parents 9f80739 + b7093b0 commit b1acf15
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 16 deletions.
14 changes: 14 additions & 0 deletions Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4203,6 +4203,15 @@ private List<string> GetWhereClauses(InternalItemsQuery query, SqliteCommand? st
OR (select CleanValue from ItemValues where ItemId=ParentId and Type=6 and CleanValue in ({includedTags})) is not null)
""");
}

// A playlist should be accessible to its owner regardless of allowed tags.
else if (includeTypes.Length == 1 && includeTypes.FirstOrDefault() is BaseItemKind.Playlist)
{
whereClauses.Add($"""
((select CleanValue from ItemValues where ItemId=Guid and Type=6 and CleanValue in ({includedTags})) is not null
OR data like @PlaylistOwnerUserId)
""");
}
else
{
whereClauses.Add("((select CleanValue from ItemValues where ItemId=Guid and Type=6 and cleanvalue in (" + includedTags + ")) is not null)");
Expand All @@ -4214,6 +4223,11 @@ private List<string> GetWhereClauses(InternalItemsQuery query, SqliteCommand? st
{
statement.TryBind(paramName + index, GetCleanValue(query.IncludeInheritedTags[index]));
}

if (query.User is not null)
{
statement.TryBind("@PlaylistOwnerUserId", $"""%"OwnerUserId":"{query.User.Id.ToString("N")}"%""");
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion Emby.Server.Implementations/Localization/Core/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,10 @@
"TaskCleanCollectionsAndPlaylists": "コレクションとプレイリストをクリーンアップ",
"TaskAudioNormalization": "音声の正規化",
"TaskAudioNormalizationDescription": "音声の正規化データのためにファイルをスキャンします。",
"TaskCleanCollectionsAndPlaylistsDescription": "在しなくなったコレクションやプレイリストからアイテムを削除します。"
"TaskCleanCollectionsAndPlaylistsDescription": "在しなくなったコレクションやプレイリストからアイテムを削除します。",
"TaskDownloadMissingLyricsDescription": "歌詞をダウンロード",
"TaskExtractMediaSegments": "メディアセグメントを読み取る",
"TaskMoveTrickplayImages": "Trickplayの画像を移動",
"TaskMoveTrickplayImagesDescription": "ライブラリ設定によりTrickplayのファイルを移動。",
"TaskDownloadMissingLyrics": "記録されていない歌詞をダウンロード"
}
52 changes: 37 additions & 15 deletions Jellyfin.Api/Controllers/PlaylistsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,37 @@ await _playlistManager.UpdatePlaylist(new PlaylistUpdateRequest
return NoContent();
}

/// <summary>
/// Get a playlist.
/// </summary>
/// <param name="playlistId">The playlist id.</param>
/// <response code="200">The playlist.</response>
/// <response code="404">Playlist not found.</response>
/// <returns>
/// A <see cref="Playlist"/> objects.
/// </returns>
[HttpGet("{playlistId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult<PlaylistDto> GetPlaylist(
[FromRoute, Required] Guid playlistId)
{
var userId = User.GetUserId();

var playlist = _playlistManager.GetPlaylistForUser(playlistId, userId);
if (playlist is null)
{
return NotFound("Playlist not found");
}

return new PlaylistDto()
{
Shares = playlist.Shares,
OpenAccess = playlist.OpenAccess,
ItemIds = playlist.GetManageableItems().Select(t => t.Item2.Id).ToList()
};
}

/// <summary>
/// Get a playlist's users.
/// </summary>
Expand Down Expand Up @@ -467,32 +498,23 @@ public ActionResult<QueryResult<BaseItemDto>> GetPlaylistItems(
[FromQuery] int? imageTypeLimit,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
{
userId = RequestHelpers.GetUserId(User, userId);
var playlist = _playlistManager.GetPlaylistForUser(playlistId, userId.Value);
var callingUserId = userId ?? User.GetUserId();
var playlist = _playlistManager.GetPlaylistForUser(playlistId, callingUserId);
if (playlist is null)
{
return NotFound("Playlist not found");
}

var isPermitted = playlist.OpenAccess
|| playlist.OwnerUserId.Equals(userId.Value)
|| playlist.Shares.Any(s => s.UserId.Equals(userId.Value));
|| playlist.OwnerUserId.Equals(callingUserId)
|| playlist.Shares.Any(s => s.UserId.Equals(callingUserId));

if (!isPermitted)
{
return Forbid();
}

var user = userId.IsNullOrEmpty()
? null
: _userManager.GetUserById(userId.Value);
var item = _libraryManager.GetItemById<Playlist>(playlistId, user);
if (item is null)
{
return NotFound();
}

var items = item.GetManageableItems().ToArray();
var items = playlist.GetManageableItems().ToArray();
var count = items.Length;
if (startIndex.HasValue)
{
Expand All @@ -507,7 +529,7 @@ public ActionResult<QueryResult<BaseItemDto>> GetPlaylistItems(
var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(User)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);

var user = _userManager.GetUserById(callingUserId);
var dtos = _dtoService.GetBaseItemDtos(items.Select(i => i.Item2).ToList(), dtoOptions, user);
for (int index = 0; index < dtos.Count; index++)
{
Expand Down
26 changes: 26 additions & 0 deletions MediaBrowser.Model/Dto/PlaylistDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Entities;

namespace MediaBrowser.Model.Dto;

/// <summary>
/// DTO for playlists.
/// </summary>
public class PlaylistDto
{
/// <summary>
/// Gets or sets a value indicating whether the playlist is publicly readable.
/// </summary>
public bool OpenAccess { get; set; }

/// <summary>
/// Gets or sets the share permissions.
/// </summary>
public required IReadOnlyList<PlaylistUserPermissions> Shares { get; set; }

/// <summary>
/// Gets or sets the item ids.
/// </summary>
public required IReadOnlyList<Guid> ItemIds { get; set; }
}

0 comments on commit b1acf15

Please sign in to comment.