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