pull/4185/head
tidusjar 4 years ago
parent 50af2b8482
commit 64c0fc17cc

@ -59,9 +59,9 @@ namespace Ombi.Core.Engine.Interfaces
var ruleResults = await Rules.StartSearchRules(model); var ruleResults = await Rules.StartSearchRules(model);
return ruleResults; return ruleResults;
} }
public async Task<RuleResult> RunSpecificRule(object model, SpecificRules rule) public async Task<RuleResult> RunSpecificRule(object model, SpecificRules rule, string requestOnBehalf)
{ {
var ruleResults = await Rules.StartSpecificRules(model, rule); var ruleResults = await Rules.StartSpecificRules(model, rule, requestOnBehalf);
return ruleResults; return ruleResults;
} }
} }

@ -71,7 +71,7 @@ namespace Ombi.Core.Engine
var canRequestOnBehalf = model.RequestOnBehalf.HasValue(); var canRequestOnBehalf = model.RequestOnBehalf.HasValue();
var isAdmin = await UserManager.IsInRoleAsync(userDetails, OmbiRoles.PowerUser) || await UserManager.IsInRoleAsync(userDetails, OmbiRoles.Admin); var isAdmin = await UserManager.IsInRoleAsync(userDetails, OmbiRoles.PowerUser) || await UserManager.IsInRoleAsync(userDetails, OmbiRoles.Admin);
if (model.RequestOnBehalf.HasValue() && !isAdmin) if (canRequestOnBehalf && !isAdmin)
{ {
return new RequestEngineResult return new RequestEngineResult
{ {
@ -703,7 +703,7 @@ namespace Ombi.Core.Engine
{ {
await MovieRepository.Add(model); await MovieRepository.Add(model);
var result = await RunSpecificRule(model, SpecificRules.CanSendNotification); var result = await RunSpecificRule(model, SpecificRules.CanSendNotification, requestOnBehalf);
if (result.Success) if (result.Success)
{ {
await NotificationHelper.NewRequest(model); await NotificationHelper.NewRequest(model);

@ -9,6 +9,6 @@ namespace Ombi.Core.Rule.Interfaces
{ {
Task<IEnumerable<RuleResult>> StartRequestRules(BaseRequest obj); Task<IEnumerable<RuleResult>> StartRequestRules(BaseRequest obj);
Task<IEnumerable<RuleResult>> StartSearchRules(SearchViewModel obj); Task<IEnumerable<RuleResult>> StartSearchRules(SearchViewModel obj);
Task<RuleResult> StartSpecificRules(object obj, SpecificRules selectedRule); Task<RuleResult> StartSpecificRules(object obj, SpecificRules selectedRule, string requestOnBehalf);
} }
} }

@ -5,7 +5,7 @@ namespace Ombi.Core.Rule.Interfaces
{ {
public interface ISpecificRule<T> where T : new() public interface ISpecificRule<T> where T : new()
{ {
Task<RuleResult> Execute(T obj); Task<RuleResult> Execute(T obj, string requestOnBehalf);
SpecificRules Rule { get; } SpecificRules Rule { get; }
} }
} }

@ -58,13 +58,13 @@ namespace Ombi.Core.Rule
return results; return results;
} }
public async Task<RuleResult> StartSpecificRules(object obj, SpecificRules selectedRule) public async Task<RuleResult> StartSpecificRules(object obj, SpecificRules selectedRule, string requestOnBehalf)
{ {
foreach (var rule in SpecificRules) foreach (var rule in SpecificRules)
{ {
if (selectedRule == rule.Rule) if (selectedRule == rule.Rule)
{ {
var result = await rule.Execute(obj); var result = await rule.Execute(obj, requestOnBehalf);
return result; return result;
} }
} }

@ -8,7 +8,7 @@ using Ombi.Store.Repository;
namespace Ombi.Core.Rule.Rules.Search namespace Ombi.Core.Rule.Rules.Search
{ {
public class LidarrArtistCacheRule : SpecificRule, ISpecificRule<object> public class LidarrArtistCacheRule : SpecificRule, IRules<object>
{ {
public LidarrArtistCacheRule(IExternalRepository<LidarrArtistCache> db) public LidarrArtistCacheRule(IExternalRepository<LidarrArtistCache> db)
{ {
@ -30,6 +30,7 @@ namespace Ombi.Core.Rule.Rules.Search
return Task.FromResult(Success()); return Task.FromResult(Success());
} }
public override SpecificRules Rule => SpecificRules.LidarrArtist; public override SpecificRules Rule => SpecificRules.LidarrArtist;
} }
} }

@ -22,11 +22,20 @@ namespace Ombi.Core.Rule.Rules.Specific
private OmbiUserManager UserManager { get; } private OmbiUserManager UserManager { get; }
private ISettingsService<OmbiSettings> Settings { get; } private ISettingsService<OmbiSettings> Settings { get; }
public async Task<RuleResult> Execute(object obj) public async Task<RuleResult> Execute(object obj, string requestOnBehalf)
{ {
var req = (BaseRequest)obj; var req = (BaseRequest)obj;
var canRequestonBehalf = requestOnBehalf.HasValue();
var settings = await Settings.GetSettingsAsync(); var settings = await Settings.GetSettingsAsync();
var sendNotification = true; var sendNotification = true;
if (settings.DoNotSendNotificationsForAutoApprove && canRequestonBehalf)
{
return new RuleResult
{
Success = false
};
}
var requestedUser = await UserManager.Users.FirstOrDefaultAsync(x => x.Id == req.RequestedUserId); var requestedUser = await UserManager.Users.FirstOrDefaultAsync(x => x.Id == req.RequestedUserId);
if (req.RequestType == RequestType.Movie) if (req.RequestType == RequestType.Movie)
{ {

Loading…
Cancel
Save