#1914 for the issue resolved notification

pull/1925/head
Jamie 6 years ago
parent 2551175867
commit 48ec5d700c

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

@ -68,7 +68,7 @@ namespace Ombi.Notifications.Agents
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);
if (parsed.Disabled)
@ -84,6 +84,22 @@ namespace Ombi.Notifications.Agents
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)
{
var user = string.Empty;

@ -92,7 +92,7 @@ namespace Ombi.Notifications.Agents
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);
if (message == null)
@ -109,6 +109,23 @@ namespace Ombi.Notifications.Agents
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)
{
var email = new EmailBasicTemplate();

@ -63,7 +63,7 @@ namespace Ombi.Notifications.Agents
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);
if (parsed.Disabled)
@ -79,6 +79,22 @@ namespace Ombi.Notifications.Agents
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)
{
var user = string.Empty;

@ -58,7 +58,7 @@ namespace Ombi.Notifications.Agents
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);
if (parsed.Disabled)
@ -73,6 +73,21 @@ namespace Ombi.Notifications.Agents
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)
{
string user;

@ -59,7 +59,7 @@ namespace Ombi.Notifications.Agents
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);
if (parsed.Disabled)
@ -74,6 +74,21 @@ namespace Ombi.Notifications.Agents
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)
{
string user;

@ -69,7 +69,7 @@ namespace Ombi.Notifications.Agents
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);
if (parsed.Disabled)
@ -85,6 +85,22 @@ namespace Ombi.Notifications.Agents
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)
{
var user = string.Empty;

@ -52,7 +52,7 @@ namespace Ombi.Notifications.Agents
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);
if (parsed.Disabled)
@ -67,6 +67,21 @@ namespace Ombi.Notifications.Agents
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)
{
var user = string.Empty;

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

@ -102,10 +102,6 @@ namespace Ombi.Store.Context
//Check if templates exist
var templates = NotificationTemplates.ToList();
//if (templates.Any())
//{
// return;
//}
var allAgents = Enum.GetValues(typeof(NotificationAgent)).Cast<NotificationAgent>().ToList();
var allTypes = Enum.GetValues(typeof(NotificationType)).Cast<NotificationType>().ToList();
@ -162,8 +158,6 @@ namespace Ombi.Store.Context
Enabled = true,
};
break;
case NotificationType.AdminNote:
continue;
case NotificationType.Test:
continue;
case NotificationType.RequestDeclined:
@ -188,6 +182,16 @@ namespace Ombi.Store.Context
Enabled = true,
};
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:
throw new ArgumentOutOfRangeException();
}

@ -82,7 +82,7 @@ namespace Ombi.Tests
_userManager = _serviceProvider.GetRequiredService<OmbiUserManager>();
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;

@ -16,6 +16,7 @@ using Ombi.Helpers;
using Ombi.Models;
using Ombi.Notifications.Models;
using Ombi.Store.Entities;
using StackExchange.Profiling.Helpers;
namespace Ombi.Controllers
{
@ -213,6 +214,19 @@ namespace Ombi.Controllers
issue.Status = model.Status;
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;
}
}

Loading…
Cancel
Save