|
|
@ -2,7 +2,9 @@
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using Ombi.Core.Authentication;
|
|
|
|
using Ombi.Core.Authentication;
|
|
|
|
using Ombi.Core.Rule.Interfaces;
|
|
|
|
using Ombi.Core.Rule.Interfaces;
|
|
|
|
|
|
|
|
using Ombi.Core.Settings;
|
|
|
|
using Ombi.Helpers;
|
|
|
|
using Ombi.Helpers;
|
|
|
|
|
|
|
|
using Ombi.Settings.Settings.Models;
|
|
|
|
using Ombi.Store.Entities;
|
|
|
|
using Ombi.Store.Entities;
|
|
|
|
using Ombi.Store.Entities.Requests;
|
|
|
|
using Ombi.Store.Entities.Requests;
|
|
|
|
|
|
|
|
|
|
|
@ -10,33 +12,42 @@ namespace Ombi.Core.Rule.Rules.Specific
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class SendNotificationRule : SpecificRule, ISpecificRule<object>
|
|
|
|
public class SendNotificationRule : SpecificRule, ISpecificRule<object>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public SendNotificationRule(OmbiUserManager um)
|
|
|
|
public SendNotificationRule(OmbiUserManager um, ISettingsService<OmbiSettings> settings)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UserManager = um;
|
|
|
|
UserManager = um;
|
|
|
|
|
|
|
|
Settings = settings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override SpecificRules Rule => SpecificRules.CanSendNotification;
|
|
|
|
public override SpecificRules Rule => SpecificRules.CanSendNotification;
|
|
|
|
private OmbiUserManager UserManager { get; }
|
|
|
|
private OmbiUserManager UserManager { get; }
|
|
|
|
|
|
|
|
private ISettingsService<OmbiSettings> Settings { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<RuleResult> Execute(object obj)
|
|
|
|
public async Task<RuleResult> Execute(object obj)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var req = (BaseRequest)obj;
|
|
|
|
var req = (BaseRequest)obj;
|
|
|
|
var sendNotification = !req.Approved; /*|| !prSettings.IgnoreNotifyForAutoApprovedRequests;*/
|
|
|
|
var settings = await Settings.GetSettingsAsync();
|
|
|
|
|
|
|
|
var sendNotification = true;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sendNotification = !await UserManager.IsInRoleAsync(requestedUser, OmbiRoles.AutoApproveMovie);
|
|
|
|
if (settings.DoNotSendNotificationsForAutoApprove)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sendNotification = !await UserManager.IsInRoleAsync(requestedUser, OmbiRoles.AutoApproveMovie);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(req.RequestType == RequestType.TvShow)
|
|
|
|
else if (req.RequestType == RequestType.TvShow)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sendNotification = !await UserManager.IsInRoleAsync(requestedUser, OmbiRoles.AutoApproveTv);
|
|
|
|
if (settings.DoNotSendNotificationsForAutoApprove)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sendNotification = !await UserManager.IsInRoleAsync(requestedUser, OmbiRoles.AutoApproveTv);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (await UserManager.IsInRoleAsync(requestedUser, OmbiRoles.Admin))
|
|
|
|
if (await UserManager.IsInRoleAsync(requestedUser, OmbiRoles.Admin))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sendNotification = false; // Don't bother sending a notification if the user is an admin
|
|
|
|
sendNotification = false; // Don't bother sending a notification if the user is an admin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new RuleResult
|
|
|
|
return new RuleResult
|
|
|
|
{
|
|
|
|
{
|