Rules changes and rework

This commit is contained in:
Jamie.Rees 2017-06-06 09:27:51 +01:00
parent d5ec429893
commit 9f4a8902f9
32 changed files with 2804 additions and 35 deletions

View file

@ -0,0 +1,34 @@
using Ombi.Core.Claims;
using Ombi.Core.Models.Requests;
using Ombi.Core.Rules;
using Ombi.Store.Entities;
using System.Security.Principal;
using Ombi.Core.Rule.Interfaces;
namespace Ombi.Core.Rule.Rules
{
public class AutoApproveRule : BaseRequestRule, IRequestRules<BaseRequestModel>
{
public AutoApproveRule(IPrincipal principal)
{
User = principal;
}
private IPrincipal User { get; }
public RuleResult Execute(BaseRequestModel obj)
{
if (User.IsInRole(OmbiClaims.Admin))
{
obj.Approved = true;
return Success();
}
if (obj.Type == RequestType.Movie && User.IsInRole(OmbiClaims.AutoApproveMovie))
obj.Approved = true;
if (obj.Type == RequestType.TvShow && User.IsInRole(OmbiClaims.AutoApproveTv))
obj.Approved = true;
return Success(); // We don't really care, we just don't set the obj to approve
}
}
}