#1914 for the issue resolved notification

This commit is contained in:
Jamie 2018-01-22 08:31:50 +00:00
parent 2551175867
commit 48ec5d700c
12 changed files with 149 additions and 20 deletions

View file

@ -4,9 +4,9 @@
{ {
NewRequest, NewRequest,
Issue, Issue,
IssueResolved,
RequestAvailable, RequestAvailable,
RequestApproved, RequestApproved,
AdminNote,
Test, Test,
RequestDeclined, RequestDeclined,
ItemAddedToFaultQueue, ItemAddedToFaultQueue,

View file

@ -68,7 +68,7 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task Issue(NotificationOptions model, DiscordNotificationSettings settings) protected override async Task NewIssue(NotificationOptions model, DiscordNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.Issue, model); var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.Issue, model);
if (parsed.Disabled) if (parsed.Disabled)
@ -84,6 +84,22 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, DiscordNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Discord, NotificationType.IssueResolved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Discord}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
}
protected override async Task AddedToRequestQueue(NotificationOptions model, DiscordNotificationSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, DiscordNotificationSettings settings)
{ {
var user = string.Empty; var user = string.Empty;

View file

@ -92,7 +92,7 @@ namespace Ombi.Notifications.Agents
await Send(message, settings); await Send(message, settings);
} }
protected override async Task Issue(NotificationOptions model, EmailNotificationSettings settings) protected override async Task NewIssue(NotificationOptions model, EmailNotificationSettings settings)
{ {
var message = await LoadTemplate(NotificationType.Issue, model, settings); var message = await LoadTemplate(NotificationType.Issue, model, settings);
if (message == null) if (message == null)
@ -109,6 +109,23 @@ namespace Ombi.Notifications.Agents
await Send(message, settings); await Send(message, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, EmailNotificationSettings settings)
{
var message = await LoadTemplate(NotificationType.IssueResolved, model, settings);
if (message == null)
{
return;
}
var plaintext = await LoadPlainTextMessage(NotificationType.IssueResolved, model, settings);
message.Other.Add("PlainTextBody", plaintext);
// Issues should be sent to admin
message.To = settings.AdminEmail;
await Send(message, settings);
}
protected override async Task AddedToRequestQueue(NotificationOptions model, EmailNotificationSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, EmailNotificationSettings settings)
{ {
var email = new EmailBasicTemplate(); var email = new EmailBasicTemplate();

View file

@ -63,7 +63,7 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task Issue(NotificationOptions model, MattermostNotificationSettings settings) protected override async Task NewIssue(NotificationOptions model, MattermostNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.Issue, model); var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.Issue, model);
if (parsed.Disabled) if (parsed.Disabled)
@ -79,6 +79,22 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, MattermostNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Mattermost, NotificationType.IssueResolved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Mattermost}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
}
protected override async Task AddedToRequestQueue(NotificationOptions model, MattermostNotificationSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, MattermostNotificationSettings settings)
{ {
var user = string.Empty; var user = string.Empty;

View file

@ -58,7 +58,7 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task Issue(NotificationOptions model, PushbulletSettings settings) protected override async Task NewIssue(NotificationOptions model, PushbulletSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.Issue, model); var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.Issue, model);
if (parsed.Disabled) if (parsed.Disabled)
@ -73,6 +73,21 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, PushbulletSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushbullet, NotificationType.IssueResolved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Pushbullet}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
}
protected override async Task AddedToRequestQueue(NotificationOptions model, PushbulletSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, PushbulletSettings settings)
{ {
string user; string user;

View file

@ -59,7 +59,7 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task Issue(NotificationOptions model, PushoverSettings settings) protected override async Task NewIssue(NotificationOptions model, PushoverSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.Issue, model); var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.Issue, model);
if (parsed.Disabled) if (parsed.Disabled)
@ -74,6 +74,21 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, PushoverSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Pushover, NotificationType.IssueResolved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Pushover}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
}
protected override async Task AddedToRequestQueue(NotificationOptions model, PushoverSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, PushoverSettings settings)
{ {
string user; string user;

View file

@ -69,7 +69,7 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task Issue(NotificationOptions model, SlackNotificationSettings settings) protected override async Task NewIssue(NotificationOptions model, SlackNotificationSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.Issue, model); var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.Issue, model);
if (parsed.Disabled) if (parsed.Disabled)
@ -85,6 +85,22 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, SlackNotificationSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Slack, NotificationType.IssueResolved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Slack}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
notification.Other.Add("image", parsed.Image);
await Send(notification, settings);
}
protected override async Task AddedToRequestQueue(NotificationOptions model, SlackNotificationSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, SlackNotificationSettings settings)
{ {
var user = string.Empty; var user = string.Empty;

View file

@ -52,7 +52,7 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task Issue(NotificationOptions model, TelegramSettings settings) protected override async Task NewIssue(NotificationOptions model, TelegramSettings settings)
{ {
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.Issue, model); var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.Issue, model);
if (parsed.Disabled) if (parsed.Disabled)
@ -67,6 +67,21 @@ namespace Ombi.Notifications.Agents
await Send(notification, settings); await Send(notification, settings);
} }
protected override async Task IssueResolved(NotificationOptions model, TelegramSettings settings)
{
var parsed = await LoadTemplate(NotificationAgent.Telegram, NotificationType.IssueResolved, model);
if (parsed.Disabled)
{
Logger.LogInformation($"Template {NotificationType.IssueResolved} is disabled for {NotificationAgent.Telegram}");
return;
}
var notification = new NotificationMessage
{
Message = parsed.Message,
};
await Send(notification, settings);
}
protected override async Task AddedToRequestQueue(NotificationOptions model, TelegramSettings settings) protected override async Task AddedToRequestQueue(NotificationOptions model, TelegramSettings settings)
{ {
var user = string.Empty; var user = string.Empty;

View file

@ -76,7 +76,7 @@ namespace Ombi.Notifications.Interfaces
await NewRequest(model, notificationSettings); await NewRequest(model, notificationSettings);
break; break;
case NotificationType.Issue: case NotificationType.Issue:
await Issue(model, notificationSettings); await NewIssue(model, notificationSettings);
break; break;
case NotificationType.RequestAvailable: case NotificationType.RequestAvailable:
await AvailableRequest(model, notificationSettings); await AvailableRequest(model, notificationSettings);
@ -84,9 +84,6 @@ namespace Ombi.Notifications.Interfaces
case NotificationType.RequestApproved: case NotificationType.RequestApproved:
await RequestApproved(model, notificationSettings); await RequestApproved(model, notificationSettings);
break; break;
case NotificationType.AdminNote:
throw new NotImplementedException();
case NotificationType.Test: case NotificationType.Test:
await Test(model, notificationSettings); await Test(model, notificationSettings);
break; break;
@ -96,6 +93,9 @@ namespace Ombi.Notifications.Interfaces
case NotificationType.ItemAddedToFaultQueue: case NotificationType.ItemAddedToFaultQueue:
await AddedToRequestQueue(model, notificationSettings); await AddedToRequestQueue(model, notificationSettings);
break; break;
case NotificationType.IssueResolved:
await IssueResolved(model, notificationSettings);
break;
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
@ -173,7 +173,8 @@ namespace Ombi.Notifications.Interfaces
protected abstract bool ValidateConfiguration(T settings); protected abstract bool ValidateConfiguration(T settings);
protected abstract Task NewRequest(NotificationOptions model, T settings); protected abstract Task NewRequest(NotificationOptions model, T settings);
protected abstract Task Issue(NotificationOptions model, T settings); protected abstract Task NewIssue(NotificationOptions model, T settings);
protected abstract Task IssueResolved(NotificationOptions model, T settings);
protected abstract Task AddedToRequestQueue(NotificationOptions model, T settings); protected abstract Task AddedToRequestQueue(NotificationOptions model, T settings);
protected abstract Task RequestDeclined(NotificationOptions model, T settings); protected abstract Task RequestDeclined(NotificationOptions model, T settings);
protected abstract Task RequestApproved(NotificationOptions model, T settings); protected abstract Task RequestApproved(NotificationOptions model, T settings);

View file

@ -102,10 +102,6 @@ namespace Ombi.Store.Context
//Check if templates exist //Check if templates exist
var templates = NotificationTemplates.ToList(); var templates = NotificationTemplates.ToList();
//if (templates.Any())
//{
// return;
//}
var allAgents = Enum.GetValues(typeof(NotificationAgent)).Cast<NotificationAgent>().ToList(); var allAgents = Enum.GetValues(typeof(NotificationAgent)).Cast<NotificationAgent>().ToList();
var allTypes = Enum.GetValues(typeof(NotificationType)).Cast<NotificationType>().ToList(); var allTypes = Enum.GetValues(typeof(NotificationType)).Cast<NotificationType>().ToList();
@ -162,8 +158,6 @@ namespace Ombi.Store.Context
Enabled = true, Enabled = true,
}; };
break; break;
case NotificationType.AdminNote:
continue;
case NotificationType.Test: case NotificationType.Test:
continue; continue;
case NotificationType.RequestDeclined: case NotificationType.RequestDeclined:
@ -188,6 +182,16 @@ namespace Ombi.Store.Context
Enabled = true, Enabled = true,
}; };
break; break;
case NotificationType.IssueResolved:
notificationToAdd = new NotificationTemplates
{
NotificationType = notificationType,
Message = "Hello {RequestedUser} Your issue for {Title} has now been resolved.",
Subject = "{ApplicationName}: Issue has been resolved for {Title}!",
Agent = agent,
Enabled = true,
};
break;
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }

View file

@ -82,7 +82,7 @@ namespace Ombi.Tests
_userManager = _serviceProvider.GetRequiredService<OmbiUserManager>(); _userManager = _serviceProvider.GetRequiredService<OmbiUserManager>();
Controller = new IdentityController(_userManager, _mapper.Object, _serviceProvider.GetService<RoleManager<IdentityRole>>(), _emailProvider.Object, Controller = new IdentityController(_userManager, _mapper.Object, _serviceProvider.GetService<RoleManager<IdentityRole>>(), _emailProvider.Object,
_emailSettings.Object, _customizationSettings.Object,_welcomeEmail.Object, null, null, null, null, null); _emailSettings.Object, _customizationSettings.Object,_welcomeEmail.Object, null, null, null, null, null, null, null, null);
} }
private OmbiUserManager _userManager; private OmbiUserManager _userManager;

View file

@ -16,6 +16,7 @@ using Ombi.Helpers;
using Ombi.Models; using Ombi.Models;
using Ombi.Notifications.Models; using Ombi.Notifications.Models;
using Ombi.Store.Entities; using Ombi.Store.Entities;
using StackExchange.Profiling.Helpers;
namespace Ombi.Controllers namespace Ombi.Controllers
{ {
@ -213,6 +214,19 @@ namespace Ombi.Controllers
issue.Status = model.Status; issue.Status = model.Status;
await _issues.SaveChangesAsync(); await _issues.SaveChangesAsync();
var notificationModel = new NotificationOptions
{
RequestId = 0,
DateTime = DateTime.Now,
NotificationType = NotificationType.Issue,
RequestType = issue.RequestType,
Recipient = !string.IsNullOrEmpty(issue.UserReported?.Email) ? issue.UserReported.Email : string.Empty,
AdditionalInformation = $"{issue.Subject} | {issue.Description}"
};
BackgroundJob.Enqueue(() => _notification.Publish(notificationModel));
return true; return true;
} }
} }