mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 15:32:37 -07:00
Finished #556
This commit is contained in:
parent
2bd7ece9d0
commit
c5b65a335f
9 changed files with 66 additions and 65 deletions
|
@ -60,7 +60,6 @@
|
|||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="AuthenticationSettingsTests.cs" />
|
||||
<Compile Include="StatusCheckerTests.cs" />
|
||||
<Compile Include="NotificationMessageResolverTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<RequestedModel> modelChanged, string apiKey);
|
||||
Task NotifyUsers(RequestedModel modelChanged, string apiKey);
|
||||
Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, string apiKey, NotificationType type);
|
||||
Task NotifyUsers(RequestedModel modelChanged, string apiKey, NotificationType type);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace PlexRequests.Services.Notification
|
|||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private INotificationService Notification { get; }
|
||||
|
||||
public async Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, string apiKey)
|
||||
public async Task NotifyUsers(IEnumerable<RequestedModel> 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
|
||||
};
|
||||
|
|
|
@ -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<ISettingsService<EmailNotificationSettings>> _emailSettings;
|
||||
private Mock<IIssueService> _issueService;
|
||||
private Mock<ICacheProvider> _cache;
|
||||
private Mock<ITransientFaultQueue> _faultQueue;
|
||||
private Mock<IRepository<RequestLimit>> 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<IRepository<RequestLimit>>();
|
||||
_emailSettings = new Mock<ISettingsService<EmailNotificationSettings>>();
|
||||
_issueService = new Mock<IIssueService>();
|
||||
_faultQueue = new Mock<ITransientFaultQueue>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<CouchPotatoSettings> cpService, ICouchPotatoApi cpApi, ISonarrApi sonarrApi,
|
||||
ISettingsService<SonarrSettings> sonarrSettings, ISickRageApi srApi, ISettingsService<SickRageSettings> srSettings,
|
||||
ISettingsService<HeadphonesSettings> hpSettings, IHeadphonesApi hpApi, ISettingsService<PlexRequestSettings> pr) : base("approval", pr)
|
||||
ISettingsService<HeadphonesSettings> hpSettings, IHeadphonesApi hpApi, ISettingsService<PlexRequestSettings> 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}
|
||||
|
||||
/// <summary>
|
||||
/// Approves the specified request identifier.
|
||||
|
|
|
@ -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" });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue