diff --git a/PlexRequests.Core.Tests/PlexRequests.Core.Tests.csproj b/PlexRequests.Core.Tests/PlexRequests.Core.Tests.csproj
index 0e6f4d3e0..5002e3c21 100644
--- a/PlexRequests.Core.Tests/PlexRequests.Core.Tests.csproj
+++ b/PlexRequests.Core.Tests/PlexRequests.Core.Tests.csproj
@@ -60,7 +60,6 @@
-
diff --git a/PlexRequests.Core.Tests/StatusCheckerTests.cs b/PlexRequests.Core.Tests/StatusCheckerTests.cs
deleted file mode 100644
index 38b9b4674..000000000
--- a/PlexRequests.Core.Tests/StatusCheckerTests.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-#region Copyright
-// /************************************************************************
-// Copyright (c) 2016 Jamie Rees
-// File: AuthenticationSettingsTests.cs
-// Created By: Jamie Rees
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-// ************************************************************************/
-#endregion
-
-using System;
-using NUnit.Framework;
-
-namespace PlexRequests.Core.Tests
-{
- [TestFixture]
- public class StatusCheckerTests
- {
- [Test]
- [Ignore("API Limit")]
- public void CheckStatusTest()
- {
- var checker = new StatusChecker();
- var status = checker.GetStatus();
-
- Assert.That(status, Is.Not.Null);
- }
- }
-}
diff --git a/PlexRequests.Services/Interfaces/INotificationEngine.cs b/PlexRequests.Services/Interfaces/INotificationEngine.cs
index ba53eb9bf..5a4198d00 100644
--- a/PlexRequests.Services/Interfaces/INotificationEngine.cs
+++ b/PlexRequests.Services/Interfaces/INotificationEngine.cs
@@ -27,13 +27,14 @@
using System.Collections.Generic;
using System.Threading.Tasks;
+using PlexRequests.Core.Models;
using PlexRequests.Store;
namespace PlexRequests.Services.Interfaces
{
public interface INotificationEngine
{
- Task NotifyUsers(IEnumerable modelChanged, string apiKey);
- Task NotifyUsers(RequestedModel modelChanged, string apiKey);
+ Task NotifyUsers(IEnumerable modelChanged, string apiKey, NotificationType type);
+ Task NotifyUsers(RequestedModel modelChanged, string apiKey, NotificationType type);
}
}
\ No newline at end of file
diff --git a/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs b/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs
index 161ea0ec3..a0d3ed85a 100644
--- a/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs
+++ b/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs
@@ -153,7 +153,7 @@ namespace PlexRequests.Services.Jobs
if (modifiedModel.Any())
{
- NotificationEngine.NotifyUsers(modifiedModel, plexSettings.PlexAuthToken);
+ NotificationEngine.NotifyUsers(modifiedModel, plexSettings.PlexAuthToken, NotificationType.RequestAvailable);
RequestService.BatchUpdate(modifiedModel);
}
diff --git a/PlexRequests.Services/Notification/EmailMessageNotification.cs b/PlexRequests.Services/Notification/EmailMessageNotification.cs
index 52727dba8..cc22155f2 100644
--- a/PlexRequests.Services/Notification/EmailMessageNotification.cs
+++ b/PlexRequests.Services/Notification/EmailMessageNotification.cs
@@ -79,8 +79,8 @@ namespace PlexRequests.Services.Notification
await EmailAvailableRequest(model, emailSettings);
break;
case NotificationType.RequestApproved:
- throw new NotImplementedException();
-
+ await EmailRequestApproved(model, emailSettings);
+ break;
case NotificationType.AdminNote:
throw new NotImplementedException();
@@ -88,8 +88,8 @@ namespace PlexRequests.Services.Notification
await EmailTest(model, emailSettings);
break;
case NotificationType.RequestDeclined:
- throw new NotImplementedException();
-
+ await EmailRequestDeclined(model, emailSettings);
+ break;
case NotificationType.ItemAddedToFaultQueue:
await EmailAddedToRequestQueue(model, emailSettings);
break;
@@ -193,6 +193,48 @@ namespace PlexRequests.Services.Notification
await Send(message, settings);
}
+ private async Task EmailRequestDeclined(NotificationModel model, EmailNotificationSettings settings)
+ {
+ var email = new EmailBasicTemplate();
+ var html = email.LoadTemplate(
+ "Plex Requests: Your request has been declined",
+ $"Hello! Your request for {model.Title} has been declined, Sorry!",
+ model.ImgSrc);
+ var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! Your request for {model.Title} has been declined, Sorry!", };
+
+ var message = new MimeMessage
+ {
+ Body = body.ToMessageBody(),
+ Subject = $"Plex Requests: Your request has been declined"
+ };
+ message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
+ message.To.Add(new MailboxAddress(model.UserEmail, model.UserEmail));
+
+
+ await Send(message, settings);
+ }
+
+ private async Task EmailRequestApproved(NotificationModel model, EmailNotificationSettings settings)
+ {
+ var email = new EmailBasicTemplate();
+ var html = email.LoadTemplate(
+ "Plex Requests: Your request has been approved!",
+ $"Hello! Your request for {model.Title} has been approved!",
+ model.ImgSrc);
+ var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! Your request for {model.Title} has been approved!", };
+
+ var message = new MimeMessage
+ {
+ Body = body.ToMessageBody(),
+ Subject = $"Plex Requests: Your request has been approved!"
+ };
+ message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
+ message.To.Add(new MailboxAddress(model.UserEmail, model.UserEmail));
+
+
+ await Send(message, settings);
+ }
+
private async Task EmailAvailableRequest(NotificationModel model, EmailNotificationSettings settings)
{
if (!settings.EnableUserEmailNotifications)
diff --git a/PlexRequests.Services/Notification/NotificationEngine.cs b/PlexRequests.Services/Notification/NotificationEngine.cs
index 50dc4fc49..f0ba5bec5 100644
--- a/PlexRequests.Services/Notification/NotificationEngine.cs
+++ b/PlexRequests.Services/Notification/NotificationEngine.cs
@@ -55,7 +55,7 @@ namespace PlexRequests.Services.Notification
private static Logger Log = LogManager.GetCurrentClassLogger();
private INotificationService Notification { get; }
- public async Task NotifyUsers(IEnumerable modelChanged, string apiKey)
+ public async Task NotifyUsers(IEnumerable modelChanged, string apiKey, NotificationType type)
{
try
{
@@ -75,7 +75,7 @@ namespace PlexRequests.Services.Notification
if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase))
{
Log.Info("This user is the Plex server owner");
- await PublishUserNotification(userAccount.Username, userAccount.Email, model.Title, model.PosterPath);
+ await PublishUserNotification(userAccount.Username, userAccount.Email, model.Title, model.PosterPath, type);
return;
}
@@ -88,7 +88,7 @@ namespace PlexRequests.Services.Notification
}
Log.Info("Sending notification to: {0} at: {1}, for title: {2}", email.Username, email.Email, model.Title);
- await PublishUserNotification(email.Username, email.Email, model.Title, model.PosterPath);
+ await PublishUserNotification(email.Username, email.Email, model.Title, model.PosterPath, type);
}
}
}
@@ -98,7 +98,7 @@ namespace PlexRequests.Services.Notification
}
}
- public async Task NotifyUsers(RequestedModel model, string apiKey)
+ public async Task NotifyUsers(RequestedModel model, string apiKey, NotificationType type)
{
try
{
@@ -117,7 +117,7 @@ namespace PlexRequests.Services.Notification
if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase))
{
Log.Info("This user is the Plex server owner");
- await PublishUserNotification(userAccount.Username, userAccount.Email, model.Title, model.PosterPath);
+ await PublishUserNotification(userAccount.Username, userAccount.Email, model.Title, model.PosterPath, type);
return;
}
@@ -130,7 +130,7 @@ namespace PlexRequests.Services.Notification
}
Log.Info("Sending notification to: {0} at: {1}, for title: {2}", email.Username, email.Email, model.Title);
- await PublishUserNotification(email.Username, email.Email, model.Title, model.PosterPath);
+ await PublishUserNotification(email.Username, email.Email, model.Title, model.PosterPath, type);
}
}
catch (Exception e)
@@ -139,13 +139,13 @@ namespace PlexRequests.Services.Notification
}
}
- private async Task PublishUserNotification(string username, string email, string title, string img)
+ private async Task PublishUserNotification(string username, string email, string title, string img, NotificationType type)
{
var notificationModel = new NotificationModel
{
User = username,
UserEmail = email,
- NotificationType = NotificationType.RequestAvailable,
+ NotificationType = type,
Title = title,
ImgSrc = img
};
diff --git a/PlexRequests.UI.Tests/SearchModuleTests.cs b/PlexRequests.UI.Tests/SearchModuleTests.cs
index cffa9487d..08c1ddfdd 100644
--- a/PlexRequests.UI.Tests/SearchModuleTests.cs
+++ b/PlexRequests.UI.Tests/SearchModuleTests.cs
@@ -33,6 +33,7 @@ using NUnit.Framework;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Plex;
using PlexRequests.Core;
+using PlexRequests.Core.Queue;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Helpers.Analytics;
@@ -73,6 +74,7 @@ namespace PlexRequests.UI.Tests
private Mock> _emailSettings;
private Mock _issueService;
private Mock _cache;
+ private Mock _faultQueue;
private Mock> RequestLimitRepo { get; set; }
private SearchModule Search { get; set; }
private readonly Fixture F = new Fixture();
@@ -145,6 +147,7 @@ namespace PlexRequests.UI.Tests
RequestLimitRepo = new Mock>();
_emailSettings = new Mock>();
_issueService = new Mock();
+ _faultQueue = new Mock();
CreateModule();
}
@@ -155,7 +158,7 @@ namespace PlexRequests.UI.Tests
_sickRageSettingsMock.Object, _cpApi.Object, _srApi.Object, _notificationService.Object,
_music.Object, _hpAPi.Object, _headphonesSettings.Object, _cpCache.Object, _sonarrCache.Object,
_srCache.Object, _plexApi.Object, _plexSettingsMock.Object, _authMock.Object,
- _userRepo.Object, _emailSettings.Object, _issueService.Object, _analytics.Object, RequestLimitRepo.Object);
+ _userRepo.Object, _emailSettings.Object, _issueService.Object, _analytics.Object, RequestLimitRepo.Object, _faultQueue.Object);
}
diff --git a/PlexRequests.UI/Modules/ApprovalModule.cs b/PlexRequests.UI/Modules/ApprovalModule.cs
index e0ba7314d..09ceef150 100644
--- a/PlexRequests.UI/Modules/ApprovalModule.cs
+++ b/PlexRequests.UI/Modules/ApprovalModule.cs
@@ -37,6 +37,7 @@ using NLog;
using PlexRequests.Api;
using PlexRequests.Api.Interfaces;
using PlexRequests.Core;
+using PlexRequests.Core.Queue;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Store;
@@ -50,7 +51,7 @@ namespace PlexRequests.UI.Modules
public ApprovalModule(IRequestService service, ISettingsService cpService, ICouchPotatoApi cpApi, ISonarrApi sonarrApi,
ISettingsService sonarrSettings, ISickRageApi srApi, ISettingsService srSettings,
- ISettingsService hpSettings, IHeadphonesApi hpApi, ISettingsService pr) : base("approval", pr)
+ ISettingsService hpSettings, IHeadphonesApi hpApi, ISettingsService pr, ITransientFaultQueue faultQueue) : base("approval", pr)
{
this.RequiresAnyClaim(UserClaims.Admin, UserClaims.PowerUser);
@@ -85,6 +86,7 @@ namespace PlexRequests.UI.Modules
private ISickRageApi SickRageApi { get; }
private ICouchPotatoApi CpApi { get; }
private IHeadphonesApi HeadphoneApi { get; }
+ private ITransientFaultQueue FaultQueue { get}
///
/// Approves the specified request identifier.
diff --git a/PlexRequests.UI/Modules/RequestsModule.cs b/PlexRequests.UI/Modules/RequestsModule.cs
index 13aecdc03..068c3de16 100644
--- a/PlexRequests.UI/Modules/RequestsModule.cs
+++ b/PlexRequests.UI/Modules/RequestsModule.cs
@@ -386,7 +386,7 @@ namespace PlexRequests.UI.Modules
var result = await Service.UpdateRequestAsync(originalRequest);
var plexService = await PlexSettings.GetSettingsAsync();
- await NotificationEngine.NotifyUsers(originalRequest, plexService.PlexAuthToken);
+ await NotificationEngine.NotifyUsers(originalRequest, plexService.PlexAuthToken, available ? NotificationType.RequestAvailable : NotificationType.RequestDeclined);
return Response.AsJson(result
? new { Result = true, Available = available, Message = string.Empty }
: new { Result = false, Available = false, Message = "Could not update the availability, please try again or check the logs" });