PluralKit/PluralKit.API/Authorization/MemberOwnerHandler.cs

20 lines
679 B
C#
Raw Normal View History

2021-08-27 15:03:47 +00:00
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using PluralKit.Core;
namespace PluralKit.API
{
2021-08-27 15:03:47 +00:00
public class MemberOwnerHandler: AuthorizationHandler<OwnSystemRequirement, PKMember>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
OwnSystemRequirement requirement, PKMember resource)
{
if (!context.User.Identity.IsAuthenticated) return Task.CompletedTask;
if (resource.System == context.User.CurrentSystem())
context.Succeed(requirement);
return Task.CompletedTask;
}
}
}