2020-06-15 23:15:59 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
|
|
using PluralKit.Core;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.API;
|
|
|
|
|
|
|
|
public class SystemPrivacyHandler: AuthorizationHandler<PrivacyRequirement<PKSystem>, PKSystem>
|
2020-06-15 23:15:59 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
|
|
|
|
PrivacyRequirement<PKSystem> requirement, PKSystem resource)
|
2020-06-15 23:15:59 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
var level = requirement.Mapper(resource);
|
|
|
|
var ctx = context.User.ContextFor(resource);
|
|
|
|
if (level.CanAccess(ctx))
|
|
|
|
context.Succeed(requirement);
|
|
|
|
return Task.CompletedTask;
|
2020-06-15 23:15:59 +00:00
|
|
|
}
|
|
|
|
}
|