You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ombi/src/Ombi.Core/Engine/Interfaces/BaseEngine.cs

57 lines
1.7 KiB

using Ombi.Core.Claims;
using Ombi.Core.Rule;
using System.Collections.Generic;
using System.Security.Principal;
using System.Threading.Tasks;
using Ombi.Core.Models.Search;
using Ombi.Core.Rule.Interfaces;
using Ombi.Store.Entities.Requests;
namespace Ombi.Core.Engine.Interfaces
{
public abstract class BaseEngine
{
protected BaseEngine(IPrincipal user, IRuleEvaluator rules)
{
User = user;
Rules = rules;
}
protected IPrincipal User { get; }
protected IRuleEvaluator Rules { get; }
protected string Username => User.Identity.Name;
protected bool HasRole(string roleName)
{
return User.IsInRole(roleName);
}
protected bool ShouldSendNotification(BaseRequest req)
{
var sendNotification = !req.Approved; /*|| !prSettings.IgnoreNotifyForAutoApprovedRequests;*/
if (HasRole(OmbiClaims.Admin))
sendNotification = false; // Don't bother sending a notification if the user is an admin
return sendNotification;
}
public async Task<IEnumerable<RuleResult>> RunRequestRules(BaseRequest model)
{
var ruleResults = await Rules.StartRequestRules(model);
return ruleResults;
}
public async Task<IEnumerable<RuleResult>> RunSearchRules(SearchViewModel model)
{
var ruleResults = await Rules.StartSearchRules(model);
return ruleResults;
}
public async Task<RuleResult> RunSpecificRule(object model, SpecificRules rule)
{
var ruleResults = await Rules.StartSpecificRules(model, rule);
return ruleResults;
}
}
}