Jamie 7 years ago
parent 8cbf2ab707
commit b2d5996d52

@ -54,7 +54,11 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, DiscordNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.NewRequest, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -67,7 +71,11 @@ namespace Ombi.Notifications.Agents
protected override async Task Issue(NotificationOptions model, DiscordNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.Issue, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -105,7 +113,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestDeclined(NotificationOptions model, DiscordNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.RequestDeclined, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -117,7 +129,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestApproved(NotificationOptions model, DiscordNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.RequestApproved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -130,7 +146,11 @@ namespace Ombi.Notifications.Agents
protected override async Task AvailableRequest(NotificationOptions model, DiscordNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.RequestAvailable, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,

@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using MailKit.Net.Smtp;
using Microsoft.Extensions.Logging;
using MimeKit;
using Ombi.Core.Settings;
using Ombi.Helpers;
@ -17,11 +18,14 @@ namespace Ombi.Notifications.Agents
{
public class EmailNotification : BaseNotification<EmailNotificationSettings>, IEmailNotification
{
public EmailNotification(ISettingsService<EmailNotificationSettings> settings, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, IEmailProvider prov, ISettingsService<CustomizationSettings> c) : base(settings, r, m, t, c)
public EmailNotification(ISettingsService<EmailNotificationSettings> settings, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, IEmailProvider prov, ISettingsService<CustomizationSettings> c,
ILogger<EmailNotification> log) : base(settings, r, m, t, c)
{
EmailProvider = prov;
Logger = log;
}
private IEmailProvider EmailProvider { get; }
private ILogger<EmailNotification> Logger { get; }
public override string NotificationName => nameof(EmailNotification);
protected override bool ValidateConfiguration(EmailNotificationSettings settings)
@ -48,7 +52,11 @@ namespace Ombi.Notifications.Agents
private async Task<NotificationMessage> LoadTemplate(NotificationType type, NotificationOptions model, EmailNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Email, type, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {type} is disabled for {NotificationAgent.Email}");
return null;
}
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(parsed.Subject, parsed.Message,parsed.Image, Customization.Logo);

@ -49,7 +49,11 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, MattermostNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.NewRequest, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -62,7 +66,11 @@ namespace Ombi.Notifications.Agents
protected override async Task Issue(NotificationOptions model, MattermostNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.Issue, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -100,7 +108,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestDeclined(NotificationOptions model, MattermostNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.RequestDeclined, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -112,7 +124,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestApproved(NotificationOptions model, MattermostNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.RequestApproved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -125,7 +141,11 @@ namespace Ombi.Notifications.Agents
protected override async Task AvailableRequest(NotificationOptions model, MattermostNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.RequestAvailable, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,

@ -45,7 +45,11 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, PushbulletSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.NewRequest, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -57,7 +61,11 @@ namespace Ombi.Notifications.Agents
protected override async Task Issue(NotificationOptions model, PushbulletSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.Issue, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -90,7 +98,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestDeclined(NotificationOptions model, PushbulletSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.RequestDeclined, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -101,7 +113,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestApproved(NotificationOptions model, PushbulletSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.RequestApproved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -113,7 +129,11 @@ namespace Ombi.Notifications.Agents
protected override async Task AvailableRequest(NotificationOptions model, PushbulletSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.RequestAvailable, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,

@ -46,7 +46,11 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, PushoverSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.NewRequest, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -58,7 +62,11 @@ namespace Ombi.Notifications.Agents
protected override async Task Issue(NotificationOptions model, PushoverSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.Issue, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -91,7 +99,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestDeclined(NotificationOptions model, PushoverSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.RequestDeclined, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -102,7 +114,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestApproved(NotificationOptions model, PushoverSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.RequestApproved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -114,6 +130,11 @@ namespace Ombi.Notifications.Agents
protected override async Task AvailableRequest(NotificationOptions model, PushoverSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.RequestAvailable, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{

@ -55,7 +55,11 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, SlackNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.NewRequest, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -68,7 +72,11 @@ namespace Ombi.Notifications.Agents
protected override async Task Issue(NotificationOptions model, SlackNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.Issue, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -102,7 +110,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestDeclined(NotificationOptions model, SlackNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.RequestDeclined, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -114,7 +126,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestApproved(NotificationOptions model, SlackNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.RequestApproved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -127,7 +143,11 @@ namespace Ombi.Notifications.Agents
protected override async Task AvailableRequest(NotificationOptions model, SlackNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.RequestAvailable, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,

@ -39,7 +39,11 @@ namespace Ombi.Notifications.Agents
protected override async Task NewRequest(NotificationOptions model, TelegramSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.NewRequest, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.NewRequest} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -51,7 +55,11 @@ namespace Ombi.Notifications.Agents
protected override async Task Issue(NotificationOptions model, TelegramSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.Issue, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.Issue} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -87,7 +95,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestDeclined(NotificationOptions model, TelegramSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.RequestDeclined, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestDeclined} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -98,7 +110,11 @@ namespace Ombi.Notifications.Agents
protected override async Task RequestApproved(NotificationOptions model, TelegramSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.RequestApproved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestApproved} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message ?? string.Empty,
@ -110,7 +126,11 @@ namespace Ombi.Notifications.Agents
protected override async Task AvailableRequest(NotificationOptions model, TelegramSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.RequestAvailable, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.RequestAvailable} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
@ -122,7 +142,6 @@ namespace Ombi.Notifications.Agents
{
try
{
await Api.Send(model.Message, settings.BotApi, settings.ChatId, settings.ParseMode);
}
catch (Exception e)

@ -0,0 +1,17 @@
using System;
namespace Ombi.Notifications.Exceptions
{
public class TemplateMissingException : Exception
{
public TemplateMissingException() : base()
{
}
public TemplateMissingException(string msg) : base(msg)
{
}
}
}

@ -3,6 +3,7 @@ using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Settings;
using Ombi.Helpers;
using Ombi.Notifications.Exceptions;
using Ombi.Notifications.Models;
using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities;
@ -134,9 +135,13 @@ namespace Ombi.Notifications.Interfaces
protected virtual async Task<NotificationMessageContent> LoadTemplate(NotificationAgent agent, NotificationType type, NotificationOptions model)
{
var template = await TemplateRepository.GetTemplate(agent, type);
if (template == null)
{
throw new TemplateMissingException($"The template for {agent} and type {type} is missing");
}
if (!template.Enabled)
{
return null;
return new NotificationMessageContent {Disabled = true};
}
var parsed = Parse(model, template);

@ -2,6 +2,7 @@
{
public class NotificationMessageContent
{
public bool Disabled { get; set; }
public string Subject { get; set; }
public string Message { get; set; }
public string Image { get; set; }

Loading…
Cancel
Save