mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
Added the Rules Engine Pattern and the Auto approve and request rules #865
This commit is contained in:
parent
7f2cfdafd1
commit
d10b0f7081
11 changed files with 238 additions and 48 deletions
38
src/Ombi.Core/Rule/Rules/AutoApproveRule.cs
Normal file
38
src/Ombi.Core/Rule/Rules/AutoApproveRule.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using Ombi.Core.Claims;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Rules;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
|
||||
namespace Ombi.Core.Rule.Rules
|
||||
{
|
||||
public class AutoApproveRule : BaseRule, 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 == Store.Entities.RequestType.Movie && User.IsInRole(OmbiClaims.AutoApproveMovie))
|
||||
{
|
||||
obj.Approved = true;
|
||||
}
|
||||
if (obj.Type == Store.Entities.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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue