Merge pull request #9466 from Shadowghost/playlist-fix
commit
9c500bdca3
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Playlists;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Server.Migrations.Routines;
|
||||
|
||||
/// <summary>
|
||||
/// Properly set playlist owner.
|
||||
/// </summary>
|
||||
internal class FixPlaylistOwner : IMigrationRoutine
|
||||
{
|
||||
private readonly ILogger<RemoveDuplicateExtras> _logger;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IPlaylistManager _playlistManager;
|
||||
|
||||
public FixPlaylistOwner(
|
||||
ILogger<RemoveDuplicateExtras> logger,
|
||||
ILibraryManager libraryManager,
|
||||
IPlaylistManager playlistManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_libraryManager = libraryManager;
|
||||
_playlistManager = playlistManager;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Guid Id => Guid.Parse("{615DFA9E-2497-4DBB-A472-61938B752C5B}");
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => "FixPlaylistOwner";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool PerformOnNewInstall => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Perform()
|
||||
{
|
||||
var playlists = _libraryManager.GetItemList(new InternalItemsQuery
|
||||
{
|
||||
IncludeItemTypes = new[] { BaseItemKind.Playlist }
|
||||
})
|
||||
.Cast<Playlist>()
|
||||
.Where(x => x.OwnerUserId.Equals(Guid.Empty))
|
||||
.ToArray();
|
||||
|
||||
if (playlists.Length > 0)
|
||||
{
|
||||
foreach (var playlist in playlists)
|
||||
{
|
||||
var shares = playlist.Shares;
|
||||
var firstEditShare = shares.First(x => x.CanEdit);
|
||||
if (firstEditShare is not null && Guid.TryParse(firstEditShare.UserId, out var guid))
|
||||
{
|
||||
playlist.OwnerUserId = guid;
|
||||
playlist.Shares = shares.Where(x => x != firstEditShare).ToArray();
|
||||
|
||||
_playlistManager.UpdatePlaylistAsync(playlist).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#nullable disable
|
||||
|
||||
#pragma warning disable CS1591
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
public class Share
|
||||
{
|
||||
public string UserId { get; set; }
|
||||
|
||||
public bool CanEdit { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
namespace MediaBrowser.Model.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Class to hold data on sharing permissions.
|
||||
/// </summary>
|
||||
public class Share
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
public string? UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the user has edit permissions.
|
||||
/// </summary>
|
||||
public bool CanEdit { get; set; }
|
||||
}
|
@ -1,19 +1,36 @@
|
||||
#nullable disable
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Model.Playlists;
|
||||
|
||||
namespace MediaBrowser.Model.Playlists
|
||||
/// <summary>
|
||||
/// A playlist creation request.
|
||||
/// </summary>
|
||||
public class PlaylistCreationRequest
|
||||
{
|
||||
public class PlaylistCreationRequest
|
||||
{
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of items.
|
||||
/// </summary>
|
||||
public IReadOnlyList<Guid> ItemIdList { get; set; } = Array.Empty<Guid>();
|
||||
|
||||
public IReadOnlyList<Guid> ItemIdList { get; set; } = Array.Empty<Guid>();
|
||||
/// <summary>
|
||||
/// Gets or sets the media type.
|
||||
/// </summary>
|
||||
public string? MediaType { get; set; }
|
||||
|
||||
public string MediaType { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
public Guid UserId { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets the shares.
|
||||
/// </summary>
|
||||
public Share[]? Shares { get; set; }
|
||||
}
|
||||
|
Loading…
Reference in new issue