yavsc/Yavsc/ViewModels/Auth/EstimateViewHandler.cs

26 lines
No EOL
924 B
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Security.Claims;
using Microsoft.AspNet.Authorization;
using Yavsc.Models.Billing;
namespace Yavsc.ViewModels.Auth
{
public class EstimateViewHandler : AuthorizationHandler<ViewRequirement, Estimate>
{
protected override void Handle(AuthorizationContext context, ViewRequirement requirement, Estimate resource)
{
if (context.User.IsInRole("Moderator"))
context.Succeed(requirement);
else if (!context.User.Identity.IsAuthenticated)
context.Fail();
else {
var uid = context.User.GetUserId();
if (resource.OwnerId == uid || resource.Query.ClientId == uid)
context.Succeed(requirement);
else
// TODO && ( resource.Circles == null || context.User belongs to resource.Circles )
context.Fail();
}
}
}
}