Apply review suggestions

pull/11220/head
Shadowghost 2 months ago
parent 2aaa9f669a
commit bff37ed13a

@ -526,9 +526,9 @@ namespace Emby.Server.Implementations.Playlists
{ {
// Update owner if shared // Update owner if shared
var rankedShares = playlist.Shares.OrderByDescending(x => x.CanEdit).ToArray(); 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(); playlist.Shares = rankedShares.Skip(1).ToArray();
await UpdatePlaylist(playlist).ConfigureAwait(false); await UpdatePlaylist(playlist).ConfigureAwait(false);
} }
@ -556,11 +556,11 @@ namespace Emby.Server.Implementations.Playlists
await UpdatePlaylist(playlist).ConfigureAwait(false); 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 playlist = GetPlaylist(userId, playlistId);
var shares = playlist.Shares.ToList(); 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) if (existingUserShare is not null)
{ {
shares.Remove(existingUserShare); shares.Remove(existingUserShare);
@ -571,7 +571,7 @@ namespace Emby.Server.Implementations.Playlists
await UpdatePlaylist(playlist).ConfigureAwait(false); 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 playlist = GetPlaylist(userId, playlistId);
var shares = playlist.Shares.ToList(); var shares = playlist.Shares.ToList();

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

@ -36,7 +36,7 @@ public class CreatePlaylistDto
/// <summary> /// <summary>
/// Gets or sets the playlist users. /// Gets or sets the playlist users.
/// </summary> /// </summary>
public IReadOnlyList<UserPermissions> Users { get; set; } = []; public IReadOnlyList<PlaylistUserPermissions> Users { get; set; } = [];
/// <summary> /// <summary>
/// Gets or sets a value indicating whether the playlist is public. /// 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="userId">The user identifier.</param>
/// <param name="share">The share.</param> /// <param name="share">The share.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
Task AddToShares(Guid playlistId, Guid userId, UserPermissions share); Task AddToShares(Guid playlistId, Guid userId, PlaylistUserPermissions share);
/// <summary> /// <summary>
/// Rremoves a share from the playlist. /// Rremoves a share from the playlist.
@ -50,7 +50,7 @@ namespace MediaBrowser.Controller.Playlists
/// <param name="userId">The user identifier.</param> /// <param name="userId">The user identifier.</param>
/// <param name="share">The share.</param> /// <param name="share">The share.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
Task RemoveFromShares(Guid playlistId, Guid userId, UserPermissions share); Task RemoveFromShares(Guid playlistId, Guid userId, PlaylistUserPermissions share);
/// <summary> /// <summary>
/// Creates the playlist. /// Creates the playlist.

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

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

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

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

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

Loading…
Cancel
Save