mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-08 20:38:24 +02:00
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
|
using System.Threading.Tasks;
|
|||
|
using Jellyfin.Api.Auth.DownloadPolicy;
|
|||
|
using Jellyfin.Api.Extensions;
|
|||
|
using MediaBrowser.Controller.Library;
|
|||
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
|||
|
namespace Jellyfin.Api.Auth.UserPermissionPolicy
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Download authorization handler.
|
|||
|
/// </summary>
|
|||
|
public class UserPermissionHandler : AuthorizationHandler<UserPermissionRequirement>
|
|||
|
{
|
|||
|
private readonly IUserManager _userManager;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Initializes a new instance of the <see cref="UserPermissionHandler"/> class.
|
|||
|
/// </summary>
|
|||
|
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
|
|||
|
public UserPermissionHandler(IUserManager userManager)
|
|||
|
{
|
|||
|
_userManager = userManager;
|
|||
|
}
|
|||
|
|
|||
|
/// <inheritdoc />
|
|||
|
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, UserPermissionRequirement requirement)
|
|||
|
{
|
|||
|
var user = _userManager.GetUserById(context.User.GetUserId());
|
|||
|
if (user.HasPermission(requirement.RequiredPermission))
|
|||
|
{
|
|||
|
context.Succeed(requirement);
|
|||
|
}
|
|||
|
|
|||
|
return Task.CompletedTask;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|