diff options
| author | Shadowghost <Ghost_of_Stone@web.de> | 2024-04-03 16:14:06 +0200 |
|---|---|---|
| committer | Shadowghost <Ghost_of_Stone@web.de> | 2024-04-03 16:14:06 +0200 |
| commit | 04c5b9d6800d7790d08958b9d6700299ba0c8e74 (patch) | |
| tree | 4ebded65854e2d36d36366a0770fd240bcd32928 /Jellyfin.Api/Controllers/PlaylistsController.cs | |
| parent | 3e0b201688d6efeca5c65df11425001f73c8c9ec (diff) | |
Add endpoint to get user permissions
Diffstat (limited to 'Jellyfin.Api/Controllers/PlaylistsController.cs')
| -rw-r--r-- | Jellyfin.Api/Controllers/PlaylistsController.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Jellyfin.Api/Controllers/PlaylistsController.cs b/Jellyfin.Api/Controllers/PlaylistsController.cs index 4ced64ae7..567a27412 100644 --- a/Jellyfin.Api/Controllers/PlaylistsController.cs +++ b/Jellyfin.Api/Controllers/PlaylistsController.cs @@ -180,6 +180,40 @@ public class PlaylistsController : BaseJellyfinApiController } /// <summary> + /// Get a playlist users. + /// </summary> + /// <param name="playlistId">The playlist id.</param> + /// <param name="userId">The user id.</param> + /// <response code="200">Found shares.</response> + /// <response code="403">Access forbidden.</response> + /// <response code="404">Playlist not found.</response> + /// <returns> + /// <see cref="PlaylistUserPermissions"/>. + /// </returns> + [HttpGet("{playlistId}/User/{userId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public ActionResult<PlaylistUserPermissions?> GetPlaylistUser( + [FromRoute, Required] Guid playlistId, + [FromRoute, Required] Guid userId) + { + var callingUserId = User.GetUserId(); + + var playlist = _playlistManager.GetPlaylistForUser(playlistId, callingUserId); + if (playlist is null) + { + return NotFound("Playlist not found"); + } + + var isPermitted = playlist.OwnerUserId.Equals(userId) + || playlist.Shares.Any(s => s.CanEdit && s.UserId.Equals(callingUserId)) + || userId.Equals(callingUserId); + + return isPermitted ? playlist.Shares.FirstOrDefault(s => s.UserId.Equals(userId)) : Forbid(); + } + + /// <summary> /// Modify a user to a playlist's users. /// </summary> /// <param name="playlistId">The playlist id.</param> |
