Apply review suggestions

pull/11220/head
Shadowghost 1 month ago
parent 2aaa9f669a
commit bff37ed13a

@ -526,9 +526,9 @@ namespace Emby.Server.Implementations.Playlists
{
// Update owner if shared
var rankedShares = playlist.Shares.OrderByDescending(x => x.CanEdit).ToArray();
if (rankedShares.Length > 0 && Guid.TryParse(rankedShares[0].UserId, out var guid))
if (rankedShares.Length > 0)
{
playlist.OwnerUserId = guid;
playlist.OwnerUserId = rankedShares[0].UserId;
playlist.Shares = rankedShares.Skip(1).ToArray();
await UpdatePlaylist(playlist).ConfigureAwait(false);
}
@ -556,11 +556,11 @@ namespace Emby.Server.Implementations.Playlists
await UpdatePlaylist(playlist).ConfigureAwait(false);
}
public async Task AddToShares(Guid playlistId, Guid userId, UserPermissions share)
public async Task AddToShares(Guid playlistId, Guid userId, PlaylistUserPermissions share)
{
var playlist = GetPlaylist(userId, playlistId);
var shares = playlist.Shares.ToList();
var existingUserShare = shares.FirstOrDefault(s => s.UserId.Equals(share.UserId, StringComparison.OrdinalIgnoreCase));
var existingUserShare = shares.FirstOrDefault(s => s.UserId.Equals(share.UserId));
if (existingUserShare is not null)
{
shares.Remove(existingUserShare);
@ -571,7 +571,7 @@ namespace Emby.Server.Implementations.Playlists
await UpdatePlaylist(playlist).ConfigureAwait(false);
}
public async Task RemoveFromShares(Guid playlistId, Guid userId, UserPermissions share)
public async Task RemoveFromShares(Guid playlistId, Guid userId, PlaylistUserPermissions share)
{
var playlist = GetPlaylist(userId, playlistId);
var shares = playlist.Shares.ToList();

@ -108,13 +108,13 @@ public class PlaylistsController : BaseJellyfinApiController
/// <response code="401">Unauthorized access.</response>
/// <response code="404">Playlist not found.</response>
/// <returns>
/// A list of <see cref="UserPermissions"/> objects.
/// A list of <see cref="PlaylistUserPermissions"/> objects.
/// </returns>
[HttpGet("{playlistId}/User")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult<IReadOnlyList<UserPermissions>> GetPlaylistUsers(
public ActionResult<IReadOnlyList<PlaylistUserPermissions>> GetPlaylistUsers(
[FromRoute, Required] Guid playlistId)
{
var userId = User.GetUserId();
@ -206,7 +206,7 @@ public class PlaylistsController : BaseJellyfinApiController
return Unauthorized("Unauthorized access");
}
await _playlistManager.AddToShares(playlistId, callingUserId, new UserPermissions(userId.ToString(), canEdit)).ConfigureAwait(false);
await _playlistManager.AddToShares(playlistId, callingUserId, new PlaylistUserPermissions(userId.ToString(), canEdit)).ConfigureAwait(false);
return NoContent();
}

@ -36,7 +36,7 @@ public class CreatePlaylistDto
/// <summary>
/// Gets or sets the playlist users.
/// </summary>
public IReadOnlyList<UserPermissions> Users { get; set; } = [];
public IReadOnlyList<PlaylistUserPermissions> Users { get; set; } = [];
/// <summary>
/// Gets or sets a value indicating whether the playlist is public.

@ -41,7 +41,7 @@ namespace MediaBrowser.Controller.Playlists
/// <param name="userId">The user identifier.</param>
/// <param name="share">The share.</param>
/// <returns>Task.</returns>
Task AddToShares(Guid playlistId, Guid userId, UserPermissions share);
Task AddToShares(Guid playlistId, Guid userId, PlaylistUserPermissions share);
/// <summary>
/// Rremoves a share from the playlist.
@ -50,7 +50,7 @@ namespace MediaBrowser.Controller.Playlists
/// <param name="userId">The user identifier.</param>
/// <param name="share">The share.</param>
/// <returns>Task.</returns>
Task RemoveFromShares(Guid playlistId, Guid userId, UserPermissions share);
Task RemoveFromShares(Guid playlistId, Guid userId, PlaylistUserPermissions share);
/// <summary>
/// Creates the playlist.

@ -40,7 +40,7 @@ namespace MediaBrowser.Controller.Playlists
public bool OpenAccess { get; set; }
public IReadOnlyList<UserPermissions> Shares { get; set; }
public IReadOnlyList<PlaylistUserPermissions> Shares { get; set; }
[JsonIgnore]
public bool IsFile => IsPlaylistFile(Path);

@ -519,7 +519,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
private void FetchFromSharesNode(XmlReader reader, IHasShares item)
{
var list = new List<UserPermissions>();
var list = new List<PlaylistUserPermissions>();
reader.MoveToContent();
reader.Read();
@ -830,7 +830,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
/// </summary>
/// <param name="reader">The xml reader.</param>
/// <returns>The share.</returns>
protected UserPermissions? GetShare(XmlReader reader)
protected PlaylistUserPermissions? GetShare(XmlReader reader)
{
reader.MoveToContent();
reader.Read();
@ -864,7 +864,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
// This is valid
if (!string.IsNullOrWhiteSpace(userId))
{
return new UserPermissions(userId, canEdit);
return new PlaylistUserPermissions(userId, canEdit);
}
return null;

@ -10,5 +10,5 @@ public interface IHasShares
/// <summary>
/// Gets or sets the shares.
/// </summary>
IReadOnlyList<UserPermissions> Shares { get; set; }
IReadOnlyList<PlaylistUserPermissions> Shares { get; set; }
}

@ -1,16 +1,18 @@
using System;
namespace MediaBrowser.Model.Entities;
/// <summary>
/// Class to hold data on user permissions for lists.
/// Class to hold data on user permissions for playlists.
/// </summary>
public class UserPermissions
public class PlaylistUserPermissions
{
/// <summary>
/// Initializes a new instance of the <see cref="UserPermissions"/> class.
/// Initializes a new instance of the <see cref="PlaylistUserPermissions"/> class.
/// </summary>
/// <param name="userId">The user id.</param>
/// <param name="canEdit">Edit permission.</param>
public UserPermissions(string userId, bool canEdit = false)
public PlaylistUserPermissions(Guid userId, bool canEdit = false)
{
UserId = userId;
CanEdit = canEdit;
@ -19,7 +21,7 @@ public class UserPermissions
/// <summary>
/// Gets or sets the user id.
/// </summary>
public string UserId { get; set; }
public Guid UserId { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the user has edit permissions.

@ -33,7 +33,7 @@ public class PlaylistCreationRequest
/// <summary>
/// Gets or sets the user permissions.
/// </summary>
public IReadOnlyList<UserPermissions> Users { get; set; } = [];
public IReadOnlyList<PlaylistUserPermissions> Users { get; set; } = [];
/// <summary>
/// Gets or sets a value indicating whether the playlist is public.

Loading…
Cancel
Save