mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
commit
32dffd09cb
22 changed files with 590 additions and 519 deletions
|
@ -185,7 +185,6 @@ namespace Ombi.Api
|
|||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
|
||||
var info = new EmbyInformation();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
|
|
@ -32,6 +32,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using Ombi.Api;
|
||||
using Ombi.Api.Interfaces;
|
||||
|
@ -77,7 +78,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public string GetNewsletterHtml(bool test)
|
||||
public Newsletter GetNewsletter(bool test)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -86,7 +87,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return string.Empty;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,11 +98,12 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
public List<EmbyEpisodeInformation> EpisodeInformation { get; set; }
|
||||
}
|
||||
|
||||
private string GetHtml(bool test)
|
||||
private Newsletter GetHtml(bool test)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var embySettings = EmbySettings.GetSettings();
|
||||
var newsletter = new Newsletter();
|
||||
|
||||
var embySettings = EmbySettings.GetSettings();
|
||||
var embyContent = Content.GetAll().ToList();
|
||||
|
||||
var series = embyContent.Where(x => x.Type == EmbyMediaType.Series).ToList();
|
||||
|
@ -115,7 +117,6 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
var filteredMovies = movie.Where(m => recentlyAdded.All(x => x.ProviderId != m.ProviderId)).ToList();
|
||||
var filteredEp = episodes.Where(m => recentlyAdded.All(x => x.ProviderId != m.ProviderId)).ToList();
|
||||
|
||||
|
||||
var info = new List<EmbyRecentlyAddedModel>();
|
||||
foreach (var m in filteredMovies)
|
||||
{
|
||||
|
@ -129,32 +130,47 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
});
|
||||
}
|
||||
GenerateMovieHtml(info, sb);
|
||||
newsletter.MovieCount = info.Count;
|
||||
|
||||
info.Clear();
|
||||
foreach (var t in series)
|
||||
{
|
||||
var i = Api.GetInformation(t.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Series,
|
||||
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
||||
var ep = filteredEp.Where(x => x.ParentId == t.EmbyId);
|
||||
|
||||
if (ep.Any())
|
||||
var ep = filteredEp.Where(x => x.ParentId == t.EmbyId).ToList();
|
||||
var item = new EmbyRecentlyAddedModel
|
||||
{
|
||||
var episodeList = new List<EmbyEpisodeInformation>();
|
||||
foreach (var embyEpisodese in ep)
|
||||
EmbyContent = t,
|
||||
EmbyInformation = i,
|
||||
};
|
||||
if (ep.Any() && embySettings.EnableEpisodeSearching)
|
||||
{
|
||||
try
|
||||
{
|
||||
var epInfo = Api.GetInformation(embyEpisodese.EmbyId, Ombi.Api.Models.Emby.EmbyMediaType.Episode,
|
||||
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
||||
episodeList.Add(epInfo.EpisodeInformation);
|
||||
var episodeList = new List<EmbyEpisodeInformation>();
|
||||
foreach (var embyEpisodese in ep)
|
||||
{
|
||||
var epInfo = Api.GetInformation(embyEpisodese.EmbyId,
|
||||
Ombi.Api.Models.Emby.EmbyMediaType.Episode,
|
||||
embySettings.ApiKey, embySettings.AdministratorId, embySettings.FullUri);
|
||||
episodeList.Add(epInfo.EpisodeInformation);
|
||||
Thread.Sleep(200); // Let's not try and overload the server
|
||||
}
|
||||
item.EpisodeInformation = episodeList;
|
||||
}
|
||||
info.Add(new EmbyRecentlyAddedModel
|
||||
catch (JsonReaderException)
|
||||
{
|
||||
EmbyContent = t,
|
||||
EmbyInformation = i,
|
||||
EpisodeInformation = episodeList
|
||||
});
|
||||
Log.Error(
|
||||
"Failed getting episode information, we may have overloaded Emby's api... Waiting and we will skip this one and go to the next");
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
info.Add(item);
|
||||
}
|
||||
GenerateTvHtml(info, sb);
|
||||
newsletter.TvCount = info.Count;
|
||||
|
||||
|
||||
var template = new RecentlyAddedTemplate();
|
||||
var html = template.LoadTemplate(sb.ToString());
|
||||
|
@ -180,9 +196,12 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
var escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
return escapedHtml;
|
||||
newsletter.Html = escapedHtml;
|
||||
return newsletter;
|
||||
|
||||
}
|
||||
|
||||
private void GenerateMovieHtml(IEnumerable<EmbyRecentlyAddedModel> recentlyAddedMovies, StringBuilder sb)
|
||||
|
@ -272,11 +291,12 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
{
|
||||
var seriesItem = t.EmbyInformation.SeriesInformation;
|
||||
var relatedEpisodes = t.EpisodeInformation;
|
||||
|
||||
var endLoop = false;
|
||||
|
||||
try
|
||||
{
|
||||
var info = TvApi.ShowLookupByTheTvDbId(int.Parse(seriesItem.ProviderIds.Tvdb));
|
||||
if(info == null)continue;
|
||||
|
||||
var banner = info.image?.original;
|
||||
if (!string.IsNullOrEmpty(banner))
|
||||
|
@ -295,30 +315,33 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
Header(sb, 3, title);
|
||||
EndTag(sb, "a");
|
||||
|
||||
var results = relatedEpisodes.GroupBy(p => p.ParentIndexNumber,
|
||||
(key, g) => new
|
||||
{
|
||||
ParentIndexNumber = key,
|
||||
IndexNumber = g.ToList()
|
||||
}
|
||||
);
|
||||
// Group the episodes
|
||||
foreach (var embyEpisodeInformation in results.OrderBy(x => x.ParentIndexNumber))
|
||||
if (relatedEpisodes != null)
|
||||
{
|
||||
var epSb = new StringBuilder();
|
||||
for (var i = 0; i < embyEpisodeInformation.IndexNumber.Count; i++)
|
||||
var results = relatedEpisodes.GroupBy(p => p.ParentIndexNumber,
|
||||
(key, g) => new
|
||||
{
|
||||
ParentIndexNumber = key,
|
||||
IndexNumber = g.ToList()
|
||||
}
|
||||
);
|
||||
// Group the episodes
|
||||
foreach (var embyEpisodeInformation in results.OrderBy(x => x.ParentIndexNumber))
|
||||
{
|
||||
var ep = embyEpisodeInformation.IndexNumber[i];
|
||||
if (i < embyEpisodeInformation.IndexNumber.Count)
|
||||
var epSb = new StringBuilder();
|
||||
for (var i = 0; i < embyEpisodeInformation.IndexNumber.Count; i++)
|
||||
{
|
||||
epSb.Append($"{ep.IndexNumber},");
|
||||
}
|
||||
else
|
||||
{
|
||||
epSb.Append(ep);
|
||||
var ep = embyEpisodeInformation.IndexNumber[i];
|
||||
if (i < embyEpisodeInformation.IndexNumber.Count)
|
||||
{
|
||||
epSb.Append($"{ep.IndexNumber},");
|
||||
}
|
||||
else
|
||||
{
|
||||
epSb.Append(ep);
|
||||
}
|
||||
}
|
||||
AddParagraph(sb, $"Season: {embyEpisodeInformation.ParentIndexNumber}, Episode: {epSb}");
|
||||
}
|
||||
AddParagraph(sb, $"Season: {embyEpisodeInformation.ParentIndexNumber}, Episode: {epSb}");
|
||||
}
|
||||
|
||||
if (info.genres.Any())
|
||||
|
@ -327,6 +350,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
}
|
||||
|
||||
AddParagraph(sb, string.IsNullOrEmpty(seriesItem.Overview) ? info.summary : seriesItem.Overview);
|
||||
endLoop = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -334,7 +358,8 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
}
|
||||
finally
|
||||
{
|
||||
EndLoopHtml(sb);
|
||||
if(endLoop)
|
||||
EndLoopHtml(sb);
|
||||
}
|
||||
}
|
||||
sb.Append("</table><br /><br />");
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
{
|
||||
public interface IEmbyAddedNewsletter
|
||||
{
|
||||
string GetNewsletterHtml(bool test);
|
||||
Newsletter GetNewsletter(bool test);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,6 @@
|
|||
{
|
||||
public interface IPlexNewsletter
|
||||
{
|
||||
string GetNewsletterHtml(bool test);
|
||||
Newsletter GetNewsletter(bool test);
|
||||
}
|
||||
}
|
37
Ombi.Services/Jobs/RecentlyAddedNewsletter/Newsletter.cs
Normal file
37
Ombi.Services/Jobs/RecentlyAddedNewsletter/Newsletter.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: Newsletter.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
|
||||
namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
||||
{
|
||||
public class Newsletter
|
||||
{
|
||||
public string Html { get; set; }
|
||||
public int MovieCount { get; set; }
|
||||
public int TvCount { get; set; }
|
||||
|
||||
public bool Send => MovieCount > 0 || TvCount > 0;
|
||||
}
|
||||
}
|
|
@ -42,11 +42,9 @@ using Ombi.Core.SettingModels;
|
|||
using Ombi.Helpers;
|
||||
using Ombi.Services.Jobs.Templates;
|
||||
using Ombi.Store.Models;
|
||||
using Ombi.Store.Models.Emby;
|
||||
using Ombi.Store.Models.Plex;
|
||||
using Ombi.Store.Repository;
|
||||
using TMDbLib.Objects.Exceptions;
|
||||
using EmbyMediaType = Ombi.Store.Models.Plex.EmbyMediaType;
|
||||
using PlexMediaType = Ombi.Store.Models.Plex.PlexMediaType;
|
||||
|
||||
namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
||||
|
@ -81,7 +79,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public string GetNewsletterHtml(bool test)
|
||||
public Newsletter GetNewsletter(bool test)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -90,7 +88,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
return string.Empty;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,9 +98,10 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
public PlexContent Content { get; set; }
|
||||
}
|
||||
|
||||
private string GetHtml(bool test)
|
||||
private Newsletter GetHtml(bool test)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var newsletter = new Newsletter();
|
||||
var plexSettings = PlexSettings.GetSettings();
|
||||
|
||||
var plexContent = Content.GetAll().ToList();
|
||||
|
@ -134,6 +133,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
});
|
||||
}
|
||||
GenerateMovieHtml(info, sb);
|
||||
newsletter.MovieCount = info.Count;
|
||||
|
||||
info.Clear();
|
||||
foreach (var t in filteredSeries)
|
||||
|
@ -168,6 +168,7 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
//}
|
||||
}
|
||||
GenerateTvHtml(info, sb);
|
||||
newsletter.TvCount = info.Count;
|
||||
|
||||
var template = new RecentlyAddedTemplate();
|
||||
var html = template.LoadTemplate(sb.ToString());
|
||||
|
@ -203,7 +204,8 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
|
||||
var escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
return escapedHtml;
|
||||
newsletter.Html = escapedHtml;
|
||||
return newsletter;
|
||||
}
|
||||
|
||||
private void GenerateMovieHtml(IEnumerable<PlexRecentlyAddedModel> recentlyAddedMovies, StringBuilder sb)
|
||||
|
|
|
@ -137,22 +137,26 @@ namespace Ombi.Services.Jobs.RecentlyAddedNewsletter
|
|||
var embySettings = EmbySettings.GetSettings();
|
||||
if (embySettings.Enable)
|
||||
{
|
||||
var html = EmbyNewsletter.GetNewsletterHtml(testEmail);
|
||||
|
||||
var escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
SendNewsletter(newletterSettings, escapedHtml, testEmail, "New Content On Emby!");
|
||||
var letter = EmbyNewsletter.GetNewsletter(testEmail) ?? new Newsletter();
|
||||
if (letter.Send)
|
||||
{
|
||||
SendNewsletter(newletterSettings, letter.Html, testEmail, "New Content On Emby!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("There is no new content to send the newsletter");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var plexSettings = PlexSettings.GetSettings();
|
||||
if (plexSettings.Enable)
|
||||
{
|
||||
var html = PlexNewsletter.GetNewsletterHtml(testEmail);
|
||||
|
||||
var escapedHtml = new string(html.Where(c => !char.IsControl(c)).ToArray());
|
||||
Log.Debug(escapedHtml);
|
||||
SendNewsletter(newletterSettings, html, testEmail);
|
||||
var letter = PlexNewsletter.GetNewsletter(testEmail) ?? new Newsletter();
|
||||
if (letter.Send)
|
||||
{
|
||||
SendNewsletter(newletterSettings, letter.Html, testEmail);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ using Ombi.Services.Interfaces;
|
|||
|
||||
namespace Ombi.Services.Notification
|
||||
{
|
||||
public abstract class BaseNotification<T,U> : INotification where T : Settings, new() where U : new()
|
||||
public abstract class BaseNotification<T> : INotification where T : Settings, new()
|
||||
{
|
||||
protected BaseNotification(ISettingsService<T> settings)
|
||||
{
|
||||
|
@ -63,34 +63,41 @@ namespace Ombi.Services.Notification
|
|||
return;
|
||||
}
|
||||
|
||||
switch (model.NotificationType)
|
||||
try
|
||||
{
|
||||
case NotificationType.NewRequest:
|
||||
await EmailNewRequest(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.Issue:
|
||||
await EmailIssue(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.RequestAvailable:
|
||||
await EmailAvailableRequest(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.RequestApproved:
|
||||
await EmailRequestApproved(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.AdminNote:
|
||||
throw new NotImplementedException();
|
||||
switch (model.NotificationType)
|
||||
{
|
||||
case NotificationType.NewRequest:
|
||||
await NewRequest(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.Issue:
|
||||
await Issue(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.RequestAvailable:
|
||||
await AvailableRequest(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.RequestApproved:
|
||||
await RequestApproved(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.AdminNote:
|
||||
throw new NotImplementedException();
|
||||
|
||||
case NotificationType.Test:
|
||||
await EmailTest(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.RequestDeclined:
|
||||
await EmailRequestDeclined(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.ItemAddedToFaultQueue:
|
||||
await EmailAddedToRequestQueue(model, notificationSettings);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
case NotificationType.Test:
|
||||
await Test(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.RequestDeclined:
|
||||
await RequestDeclined(model, notificationSettings);
|
||||
break;
|
||||
case NotificationType.ItemAddedToFaultQueue:
|
||||
await AddedToRequestQueue(model, notificationSettings);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
catch (NotImplementedException)
|
||||
{
|
||||
// Do nothing, it's not implimented meaning it might not be ready or even used
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -103,14 +110,14 @@ namespace Ombi.Services.Notification
|
|||
|
||||
|
||||
protected abstract bool ValidateConfiguration(T settings);
|
||||
protected abstract Task EmailNewRequest(NotificationModel model, T settings);
|
||||
protected abstract Task EmailIssue(NotificationModel model, T settings);
|
||||
protected abstract Task EmailAddedToRequestQueue(NotificationModel model, T settings);
|
||||
protected abstract Task EmailRequestDeclined(NotificationModel model, T settings);
|
||||
protected abstract Task EmailRequestApproved(NotificationModel model, T settings);
|
||||
protected abstract Task EmailAvailableRequest(NotificationModel model, T settings);
|
||||
protected abstract Task Send(U message, T settings);
|
||||
protected abstract Task EmailTest(NotificationModel model, T settings);
|
||||
protected abstract Task NewRequest(NotificationModel model, T settings);
|
||||
protected abstract Task Issue(NotificationModel model, T settings);
|
||||
protected abstract Task AddedToRequestQueue(NotificationModel model, T settings);
|
||||
protected abstract Task RequestDeclined(NotificationModel model, T settings);
|
||||
protected abstract Task RequestApproved(NotificationModel model, T settings);
|
||||
protected abstract Task AvailableRequest(NotificationModel model, T settings);
|
||||
protected abstract Task Send(NotificationMessage model, T settings);
|
||||
protected abstract Task Test(NotificationModel model, T settings);
|
||||
|
||||
}
|
||||
}
|
|
@ -29,118 +29,24 @@ using System;
|
|||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Api.Models.Notifications;
|
||||
using Ombi.Core;
|
||||
using Ombi.Core.Models;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Services.Interfaces;
|
||||
|
||||
namespace Ombi.Services.Notification
|
||||
{
|
||||
public class DiscordNotification : INotification
|
||||
public class DiscordNotification : BaseNotification<DiscordNotificationSettings>
|
||||
{
|
||||
public DiscordNotification(IDiscordApi api, ISettingsService<DiscordNotificationSettings> sn)
|
||||
public DiscordNotification(IDiscordApi api, ISettingsService<DiscordNotificationSettings> sn) : base(sn)
|
||||
{
|
||||
Api = api;
|
||||
Settings = sn;
|
||||
}
|
||||
|
||||
public string NotificationName => "DiscordNotification";
|
||||
public override string NotificationName => "DiscordNotification";
|
||||
|
||||
private IDiscordApi Api { get; }
|
||||
private ISettingsService<DiscordNotificationSettings> Settings { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
||||
public async Task NotifyAsync(NotificationModel model)
|
||||
{
|
||||
var settings = Settings.GetSettings();
|
||||
|
||||
await NotifyAsync(model, settings);
|
||||
}
|
||||
|
||||
public async Task NotifyAsync(NotificationModel model, Settings settings)
|
||||
{
|
||||
if (settings == null) await NotifyAsync(model);
|
||||
|
||||
var pushSettings = (DiscordNotificationSettings)settings;
|
||||
if (!ValidateConfiguration(pushSettings))
|
||||
{
|
||||
Log.Error("Settings for Slack was not correct, we cannot push a notification");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (model.NotificationType)
|
||||
{
|
||||
case NotificationType.NewRequest:
|
||||
await PushNewRequestAsync(model, pushSettings);
|
||||
break;
|
||||
case NotificationType.Issue:
|
||||
await PushIssueAsync(model, pushSettings);
|
||||
break;
|
||||
case NotificationType.RequestAvailable:
|
||||
break;
|
||||
case NotificationType.RequestApproved:
|
||||
break;
|
||||
case NotificationType.AdminNote:
|
||||
break;
|
||||
case NotificationType.Test:
|
||||
await PushTest(pushSettings);
|
||||
break;
|
||||
case NotificationType.RequestDeclined:
|
||||
await PushRequestDeclinedAsync(model, pushSettings);
|
||||
break;
|
||||
case NotificationType.ItemAddedToFaultQueue:
|
||||
await PushFaultQueue(model, pushSettings);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PushNewRequestAsync(NotificationModel model, DiscordNotificationSettings settings)
|
||||
{
|
||||
var message = $"{model.Title} has been requested by user: {model.User}";
|
||||
await Push(settings, message);
|
||||
}
|
||||
|
||||
private async Task PushRequestDeclinedAsync(NotificationModel model, DiscordNotificationSettings settings)
|
||||
{
|
||||
var message = $"Hello! Your request for {model.Title} has been declined, Sorry!";
|
||||
await Push(settings, message);
|
||||
}
|
||||
|
||||
private async Task PushIssueAsync(NotificationModel model, DiscordNotificationSettings settings)
|
||||
{
|
||||
var message = $"A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
|
||||
await Push(settings, message);
|
||||
}
|
||||
|
||||
private async Task PushTest(DiscordNotificationSettings settings)
|
||||
{
|
||||
var message = $"This is a test from Ombi, if you can see this then we have successfully pushed a notification!";
|
||||
await Push(settings, message);
|
||||
}
|
||||
|
||||
private async Task PushFaultQueue(NotificationModel model, DiscordNotificationSettings settings)
|
||||
{
|
||||
var message = $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying";
|
||||
await Push(settings, message);
|
||||
}
|
||||
|
||||
private async Task Push(DiscordNotificationSettings config, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Api.SendMessageAsync(message, config.WebookId, config.Token, config.Username);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ValidateConfiguration(DiscordNotificationSettings settings)
|
||||
protected override bool ValidateConfiguration(DiscordNotificationSettings settings)
|
||||
{
|
||||
if (!settings.Enabled)
|
||||
{
|
||||
|
@ -161,5 +67,78 @@ namespace Ombi.Services.Notification
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override async Task NewRequest(NotificationModel model, DiscordNotificationSettings settings)
|
||||
{
|
||||
var message = $"{model.Title} has been requested by user: {model.User}";
|
||||
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
protected override async Task Issue(NotificationModel model, DiscordNotificationSettings settings)
|
||||
{
|
||||
var message = $"A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
protected override async Task AddedToRequestQueue(NotificationModel model, DiscordNotificationSettings settings)
|
||||
{
|
||||
var message = $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying";
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
protected override async Task RequestDeclined(NotificationModel model, DiscordNotificationSettings settings)
|
||||
{
|
||||
var message = $"Hello! Your request for {model.Title} has been declined, Sorry!";
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
protected override Task RequestApproved(NotificationModel model, DiscordNotificationSettings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override Task AvailableRequest(NotificationModel model, DiscordNotificationSettings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override async Task Send(NotificationMessage model, DiscordNotificationSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Api.SendMessageAsync(model.Message, settings.WebookId, settings.Token, settings.Username);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task Test(NotificationModel model, DiscordNotificationSettings settings)
|
||||
{
|
||||
var message = $"This is a test from Ombi, if you can see this then we have successfully pushed a notification!";
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ using SmtpClient = MailKit.Net.Smtp.SmtpClient;
|
|||
|
||||
namespace Ombi.Services.Notification
|
||||
{
|
||||
public class EmailMessageNotification : BaseNotification<EmailNotificationSettings, MimeMessage>
|
||||
public class EmailMessageNotification : BaseNotification<EmailNotificationSettings>
|
||||
{
|
||||
public EmailMessageNotification(ISettingsService<EmailNotificationSettings> settings) : base(settings)
|
||||
{
|
||||
|
@ -63,135 +63,150 @@ namespace Ombi.Services.Notification
|
|||
return true;
|
||||
}
|
||||
|
||||
protected override async Task EmailNewRequest(NotificationModel model, EmailNotificationSettings settings)
|
||||
protected override async Task NewRequest(NotificationModel model, EmailNotificationSettings settings)
|
||||
{
|
||||
var email = new EmailBasicTemplate();
|
||||
var html = email.LoadTemplate(
|
||||
$"Ombi: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!",
|
||||
$"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}",
|
||||
model.ImgSrc);
|
||||
var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}" };
|
||||
|
||||
|
||||
var message = new MimeMessage
|
||||
var message = new NotificationMessage
|
||||
{
|
||||
Body = body.ToMessageBody(),
|
||||
Subject = $"Ombi: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!"
|
||||
Message = html,
|
||||
Subject = $"Ombi: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!",
|
||||
To = model.UserEmail,
|
||||
};
|
||||
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
|
||||
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));
|
||||
|
||||
message.Other.Add("PlainTextBody", $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}");
|
||||
|
||||
await Send(message, settings);
|
||||
}
|
||||
|
||||
protected override async Task EmailIssue(NotificationModel model, EmailNotificationSettings settings)
|
||||
protected override async Task Issue(NotificationModel model, EmailNotificationSettings settings)
|
||||
{
|
||||
var email = new EmailBasicTemplate();
|
||||
var html = email.LoadTemplate(
|
||||
$"Ombi: New issue for {model.Title}!",
|
||||
$"Hello! The user '{model.User}' has reported a new issue {model.Body} for the title {model.Title}!",
|
||||
model.ImgSrc);
|
||||
var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! The user '{model.User}' has reported a new issue {model.Body} for the title {model.Title}!"};
|
||||
|
||||
var message = new MimeMessage
|
||||
var message = new NotificationMessage
|
||||
{
|
||||
Body = body.ToMessageBody(),
|
||||
Subject = $"Ombi: New issue for {model.Title}!"
|
||||
Message = html,
|
||||
Subject = $"Ombi: New issue for {model.Title}!",
|
||||
To = model.UserEmail,
|
||||
};
|
||||
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
|
||||
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));
|
||||
|
||||
message.Other.Add("PlainTextBody", $"Hello! The user '{model.User}' has reported a new issue {model.Body} for the title {model.Title}!");
|
||||
|
||||
|
||||
|
||||
await Send(message, settings);
|
||||
}
|
||||
|
||||
protected override async Task EmailAddedToRequestQueue(NotificationModel model, EmailNotificationSettings settings)
|
||||
protected override async Task AddedToRequestQueue(NotificationModel model, EmailNotificationSettings settings)
|
||||
{
|
||||
var email = new EmailBasicTemplate();
|
||||
var html = email.LoadTemplate(
|
||||
"Ombi: A request could not be added.",
|
||||
$"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying",
|
||||
model.ImgSrc);
|
||||
var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying" };
|
||||
|
||||
var message = new MimeMessage
|
||||
var message = new NotificationMessage
|
||||
{
|
||||
Body = body.ToMessageBody(),
|
||||
Subject = $"Ombi: A request could not be added"
|
||||
Message = html,
|
||||
Subject = $"Ombi: A request could not be added",
|
||||
To = model.UserEmail,
|
||||
};
|
||||
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
|
||||
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));
|
||||
|
||||
message.Other.Add("PlainTextBody", $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying");
|
||||
|
||||
|
||||
await Send(message, settings);
|
||||
}
|
||||
|
||||
protected override async Task EmailRequestDeclined(NotificationModel model, EmailNotificationSettings settings)
|
||||
protected override async Task RequestDeclined(NotificationModel model, EmailNotificationSettings settings)
|
||||
{
|
||||
var email = new EmailBasicTemplate();
|
||||
var html = email.LoadTemplate(
|
||||
"Ombi: 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
|
||||
var message = new NotificationMessage
|
||||
{
|
||||
Body = body.ToMessageBody(),
|
||||
Subject = $"Ombi: Your request has been declined"
|
||||
Message = html,
|
||||
Subject = $"Ombi: Your request has been declined",
|
||||
To = model.UserEmail,
|
||||
};
|
||||
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
|
||||
message.To.Add(new MailboxAddress(model.UserEmail, model.UserEmail));
|
||||
|
||||
message.Other.Add("PlainTextBody", $"Hello! Your request for {model.Title} has been declined, Sorry!");
|
||||
|
||||
|
||||
await Send(message, settings);
|
||||
}
|
||||
|
||||
protected override async Task EmailRequestApproved(NotificationModel model, EmailNotificationSettings settings)
|
||||
protected override async Task RequestApproved(NotificationModel model, EmailNotificationSettings settings)
|
||||
{
|
||||
var email = new EmailBasicTemplate();
|
||||
var html = email.LoadTemplate(
|
||||
"Ombi: 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
|
||||
var message = new NotificationMessage
|
||||
{
|
||||
Body = body.ToMessageBody(),
|
||||
Subject = $"Ombi: Your request has been approved!"
|
||||
Message = html,
|
||||
Subject = $"Ombi: Your request has been approved!",
|
||||
To = model.UserEmail,
|
||||
};
|
||||
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
|
||||
message.To.Add(new MailboxAddress(model.UserEmail, model.UserEmail));
|
||||
|
||||
message.Other.Add("PlainTextBody", $"Hello! Your request for {model.Title} has been approved!");
|
||||
|
||||
await Send(message, settings);
|
||||
}
|
||||
|
||||
protected override async Task EmailAvailableRequest(NotificationModel model, EmailNotificationSettings settings)
|
||||
protected override async Task AvailableRequest(NotificationModel model, EmailNotificationSettings settings)
|
||||
{
|
||||
var email = new EmailBasicTemplate();
|
||||
var html = email.LoadTemplate(
|
||||
$"Ombi: {model.Title} is now available!",
|
||||
$"Hello! You requested {model.Title} on Ombi! This is now available on Plex! :)",
|
||||
model.ImgSrc);
|
||||
var body = new BodyBuilder { HtmlBody = html, TextBody = $"Hello! You requested {model.Title} on Ombi! This is now available on Plex! :)" };
|
||||
|
||||
var message = new MimeMessage
|
||||
|
||||
var message = new NotificationMessage
|
||||
{
|
||||
Body = body.ToMessageBody(),
|
||||
Subject = $"Ombi: {model.Title} is now available!"
|
||||
Message = html,
|
||||
Subject = $"Ombi: {model.Title} is now available!",
|
||||
To = model.UserEmail,
|
||||
};
|
||||
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
|
||||
message.To.Add(new MailboxAddress(model.UserEmail, model.UserEmail));
|
||||
|
||||
message.Other.Add("PlainTextBody", $"Hello! You requested {model.Title} on Ombi! This is now available on Plex! :)");
|
||||
|
||||
await Send(message, settings);
|
||||
}
|
||||
|
||||
protected override async Task Send(MimeMessage message, EmailNotificationSettings settings)
|
||||
protected override async Task Send(NotificationMessage model, EmailNotificationSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
var body = new BodyBuilder
|
||||
{
|
||||
HtmlBody = model.Message,
|
||||
TextBody = model.Other["PlainTextBody"]
|
||||
};
|
||||
|
||||
var message = new MimeMessage
|
||||
{
|
||||
Body = body.ToMessageBody(),
|
||||
Subject = model.Subject
|
||||
};
|
||||
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
|
||||
message.To.Add(new MailboxAddress(model.To, model.To));
|
||||
|
||||
using (var client = new SmtpClient())
|
||||
{
|
||||
client.Connect(settings.EmailHost, settings.EmailPort); // Let MailKit figure out the correct SecureSocketOptions.
|
||||
|
@ -215,20 +230,21 @@ namespace Ombi.Services.Notification
|
|||
}
|
||||
}
|
||||
|
||||
protected override async Task EmailTest(NotificationModel model, EmailNotificationSettings settings)
|
||||
protected override async Task Test(NotificationModel model, EmailNotificationSettings settings)
|
||||
{
|
||||
var email = new EmailBasicTemplate();
|
||||
var html = email.LoadTemplate(
|
||||
"Test Message",
|
||||
"This is just a test! Success!",
|
||||
model.ImgSrc);
|
||||
var body = new BodyBuilder { HtmlBody = html, };
|
||||
var message = new MimeMessage
|
||||
var message = new NotificationMessage
|
||||
{
|
||||
Body = body.ToMessageBody()
|
||||
Message = html,
|
||||
Subject = $"Ombi: Test",
|
||||
To = model.UserEmail,
|
||||
};
|
||||
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
|
||||
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));
|
||||
|
||||
message.Other.Add("PlainTextBody", "This is just a test! Success!");
|
||||
|
||||
await Send(message, settings);
|
||||
}
|
||||
|
|
40
Ombi.Services/Notification/NotificationMessage.cs
Normal file
40
Ombi.Services/Notification/NotificationMessage.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: NotificationMessage.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.Collections.Generic;
|
||||
|
||||
namespace Ombi.Services.Notification
|
||||
{
|
||||
public class NotificationMessage
|
||||
{
|
||||
public string Subject { get; set; }
|
||||
public string Message { get; set; }
|
||||
public string To { get; set; }
|
||||
|
||||
public Dictionary<string,string> Other { get; set; } = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
|
@ -30,67 +30,24 @@ using System.Threading.Tasks;
|
|||
using NLog;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Core;
|
||||
using Ombi.Core.Models;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Services.Interfaces;
|
||||
using Ombi.Store;
|
||||
|
||||
namespace Ombi.Services.Notification
|
||||
{
|
||||
public class PushbulletNotification : INotification
|
||||
public class PushbulletNotification : BaseNotification<PushbulletNotificationSettings>
|
||||
{
|
||||
public PushbulletNotification(IPushbulletApi pushbulletApi, ISettingsService<PushbulletNotificationSettings> settings)
|
||||
public PushbulletNotification(IPushbulletApi pushbulletApi, ISettingsService<PushbulletNotificationSettings> settings) : base(settings)
|
||||
{
|
||||
PushbulletApi = pushbulletApi;
|
||||
SettingsService = settings;
|
||||
}
|
||||
private IPushbulletApi PushbulletApi { get; }
|
||||
private ISettingsService<PushbulletNotificationSettings> SettingsService { get; }
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
public string NotificationName => "PushbulletNotification";
|
||||
public async Task NotifyAsync(NotificationModel model)
|
||||
{
|
||||
var configuration = GetSettings();
|
||||
await NotifyAsync(model, configuration);
|
||||
}
|
||||
|
||||
public async Task NotifyAsync(NotificationModel model, Settings settings)
|
||||
{
|
||||
if (settings == null) await NotifyAsync(model);
|
||||
|
||||
var pushSettings = (PushbulletNotificationSettings)settings;
|
||||
|
||||
if (!ValidateConfiguration(pushSettings)) return;
|
||||
|
||||
switch (model.NotificationType)
|
||||
{
|
||||
case NotificationType.NewRequest:
|
||||
await PushNewRequestAsync(model, pushSettings);
|
||||
break;
|
||||
case NotificationType.Issue:
|
||||
await PushIssueAsync(model, pushSettings);
|
||||
break;
|
||||
case NotificationType.RequestAvailable:
|
||||
break;
|
||||
case NotificationType.RequestApproved:
|
||||
break;
|
||||
case NotificationType.AdminNote:
|
||||
break;
|
||||
case NotificationType.Test:
|
||||
await PushTestAsync(pushSettings);
|
||||
break;
|
||||
case NotificationType.RequestDeclined:
|
||||
break;
|
||||
case NotificationType.ItemAddedToFaultQueue:
|
||||
await PushFaultQueue(model, pushSettings);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private bool ValidateConfiguration(PushbulletNotificationSettings settings)
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
public override string NotificationName => "PushbulletNotification";
|
||||
|
||||
protected override bool ValidateConfiguration(PushbulletNotificationSettings settings)
|
||||
{
|
||||
if (!settings.Enabled)
|
||||
{
|
||||
|
@ -103,44 +60,64 @@ namespace Ombi.Services.Notification
|
|||
return true;
|
||||
}
|
||||
|
||||
private PushbulletNotificationSettings GetSettings()
|
||||
{
|
||||
return SettingsService.GetSettings();
|
||||
}
|
||||
|
||||
private async Task PushNewRequestAsync(NotificationModel model, PushbulletNotificationSettings settings)
|
||||
protected override async Task NewRequest(NotificationModel model, PushbulletNotificationSettings settings)
|
||||
{
|
||||
var message = $"The {model.RequestType.GetString()?.ToLower()} '{model.Title}' has been requested by user: {model.User}";
|
||||
var pushTitle = $"Ombi: The {model.RequestType.GetString()?.ToLower()} {model.Title} has been requested!";
|
||||
await Push(settings, message, pushTitle);
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
Subject = pushTitle
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
|
||||
private async Task PushIssueAsync(NotificationModel model, PushbulletNotificationSettings settings)
|
||||
protected override async Task Issue(NotificationModel model, PushbulletNotificationSettings settings)
|
||||
{
|
||||
var message = $"A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
|
||||
var pushTitle = $"Ombi: A new issue has been reported for {model.Title}";
|
||||
await Push(settings, message, pushTitle);
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
Subject = pushTitle
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
private async Task PushTestAsync(PushbulletNotificationSettings settings)
|
||||
protected override async Task AddedToRequestQueue(NotificationModel model, PushbulletNotificationSettings settings)
|
||||
{
|
||||
var message = "This is just a test! Success!";
|
||||
var pushTitle = "Ombi: Test Message!";
|
||||
await Push(settings, message, pushTitle);
|
||||
|
||||
var message = $"Hello!The user '{model.User}' has requested { model.Title} but it could not be added. This has been added into the requests queue and will keep retrying";
|
||||
var pushTitle = $"Ombi: A request could not be added.";
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
Subject = pushTitle
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
private async Task PushFaultQueue(NotificationModel model, PushbulletNotificationSettings settings)
|
||||
protected override Task RequestDeclined(NotificationModel model, PushbulletNotificationSettings settings)
|
||||
{
|
||||
var message = $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying";
|
||||
var pushTitle = $"Ombi: The {model.RequestType.GetString()?.ToLower()} {model.Title} has been requested but could not be added!";
|
||||
await Push(settings, message, pushTitle);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private async Task Push(PushbulletNotificationSettings settings, string message, string title)
|
||||
protected override Task RequestApproved(NotificationModel model, PushbulletNotificationSettings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override Task AvailableRequest(NotificationModel model, PushbulletNotificationSettings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override async Task Send(NotificationMessage model, PushbulletNotificationSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await PushbulletApi.PushAsync(settings.AccessToken, title, message, settings.DeviceIdentifier);
|
||||
var result = await PushbulletApi.PushAsync(settings.AccessToken, model.Subject, model.Message, settings.DeviceIdentifier);
|
||||
if (result != null)
|
||||
{
|
||||
Log.Error("Pushbullet api returned a null value, the notification did not get pushed");
|
||||
|
@ -151,5 +128,17 @@ namespace Ombi.Services.Notification
|
|||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task Test(NotificationModel model, PushbulletNotificationSettings settings)
|
||||
{
|
||||
var message = "This is just a test! Success!";
|
||||
var pushTitle = "Ombi: Test Message!";
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
Subject = pushTitle
|
||||
};
|
||||
await Send(notification,settings);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,67 +30,24 @@ using System.Threading.Tasks;
|
|||
using NLog;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Core;
|
||||
using Ombi.Core.Models;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Services.Interfaces;
|
||||
using Ombi.Store;
|
||||
|
||||
namespace Ombi.Services.Notification
|
||||
{
|
||||
public class PushoverNotification : INotification
|
||||
public class PushoverNotification : BaseNotification<PushoverNotificationSettings>
|
||||
{
|
||||
public PushoverNotification(IPushoverApi pushoverApi, ISettingsService<PushoverNotificationSettings> settings)
|
||||
public PushoverNotification(IPushoverApi pushoverApi, ISettingsService<PushoverNotificationSettings> settings) : base(settings)
|
||||
{
|
||||
PushoverApi = pushoverApi;
|
||||
SettingsService = settings;
|
||||
}
|
||||
private IPushoverApi PushoverApi { get; }
|
||||
private ISettingsService<PushoverNotificationSettings> SettingsService { get; }
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
public string NotificationName => "PushoverNotification";
|
||||
public async Task NotifyAsync(NotificationModel model)
|
||||
{
|
||||
var configuration = GetSettings();
|
||||
await NotifyAsync(model, configuration);
|
||||
}
|
||||
public override string NotificationName => "PushoverNotification";
|
||||
|
||||
public async Task NotifyAsync(NotificationModel model, Settings settings)
|
||||
{
|
||||
if (settings == null) await NotifyAsync(model);
|
||||
|
||||
var pushSettings = (PushoverNotificationSettings)settings;
|
||||
|
||||
if (!ValidateConfiguration(pushSettings)) return;
|
||||
|
||||
switch (model.NotificationType)
|
||||
{
|
||||
case NotificationType.NewRequest:
|
||||
await PushNewRequestAsync(model, pushSettings);
|
||||
break;
|
||||
case NotificationType.Issue:
|
||||
await PushIssueAsync(model, pushSettings);
|
||||
break;
|
||||
case NotificationType.RequestAvailable:
|
||||
break;
|
||||
case NotificationType.RequestApproved:
|
||||
break;
|
||||
case NotificationType.AdminNote:
|
||||
break;
|
||||
case NotificationType.Test:
|
||||
await PushTestAsync(model, pushSettings);
|
||||
break;
|
||||
case NotificationType.RequestDeclined:
|
||||
break;
|
||||
case NotificationType.ItemAddedToFaultQueue:
|
||||
await PushFaultQueue(model, pushSettings);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private bool ValidateConfiguration(PushoverNotificationSettings settings)
|
||||
protected override bool ValidateConfiguration(PushoverNotificationSettings settings)
|
||||
{
|
||||
if (!settings.Enabled)
|
||||
{
|
||||
|
@ -103,40 +60,57 @@ namespace Ombi.Services.Notification
|
|||
return true;
|
||||
}
|
||||
|
||||
private PushoverNotificationSettings GetSettings()
|
||||
{
|
||||
return SettingsService.GetSettings();
|
||||
}
|
||||
|
||||
private async Task PushNewRequestAsync(NotificationModel model, PushoverNotificationSettings settings)
|
||||
protected override async Task NewRequest(NotificationModel model, PushoverNotificationSettings settings)
|
||||
{
|
||||
var message = $"Ombi: The {model.RequestType.GetString()?.ToLower()} '{model.Title}' has been requested by user: {model.User}";
|
||||
await Push(settings, message);
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
private async Task PushIssueAsync(NotificationModel model, PushoverNotificationSettings settings)
|
||||
protected override async Task Issue(NotificationModel model, PushoverNotificationSettings settings)
|
||||
{
|
||||
var message = $"Ombi: A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
|
||||
await Push(settings, message);
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
private async Task PushTestAsync(NotificationModel model, PushoverNotificationSettings settings)
|
||||
{
|
||||
var message = $"Ombi: Test Message!";
|
||||
await Push(settings, message);
|
||||
}
|
||||
|
||||
private async Task PushFaultQueue(NotificationModel model, PushoverNotificationSettings settings)
|
||||
protected override async Task AddedToRequestQueue(NotificationModel model, PushoverNotificationSettings settings)
|
||||
{
|
||||
var message = $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying";
|
||||
await Push(settings, message);
|
||||
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
private async Task Push(PushoverNotificationSettings settings, string message)
|
||||
protected override Task RequestDeclined(NotificationModel model, PushoverNotificationSettings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override Task RequestApproved(NotificationModel model, PushoverNotificationSettings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override Task AvailableRequest(NotificationModel model, PushoverNotificationSettings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override async Task Send(NotificationMessage model, PushoverNotificationSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await PushoverApi.PushAsync(settings.AccessToken, message, settings.UserToken);
|
||||
var result = await PushoverApi.PushAsync(settings.AccessToken, model.Message, settings.UserToken);
|
||||
if (result?.status != 1)
|
||||
{
|
||||
Log.Error("Pushover api returned a status that was not 1, the notification did not get pushed");
|
||||
|
@ -147,5 +121,16 @@ namespace Ombi.Services.Notification
|
|||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task Test(NotificationModel model, PushoverNotificationSettings settings)
|
||||
{
|
||||
|
||||
var message = $"Ombi: Test Message!";
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,116 +31,24 @@ using NLog;
|
|||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Api.Models.Notifications;
|
||||
using Ombi.Core;
|
||||
using Ombi.Core.Models;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Services.Interfaces;
|
||||
|
||||
namespace Ombi.Services.Notification
|
||||
{
|
||||
public class SlackNotification : INotification
|
||||
public class SlackNotification : BaseNotification<SlackNotificationSettings>
|
||||
{
|
||||
public SlackNotification(ISlackApi api, ISettingsService<SlackNotificationSettings> sn)
|
||||
public SlackNotification(ISlackApi api, ISettingsService<SlackNotificationSettings> sn) : base(sn)
|
||||
{
|
||||
Api = api;
|
||||
Settings = sn;
|
||||
}
|
||||
|
||||
public string NotificationName => "SlackNotification";
|
||||
public override string NotificationName => "SlackNotification";
|
||||
|
||||
private ISlackApi Api { get; }
|
||||
private ISettingsService<SlackNotificationSettings> Settings { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
||||
public async Task NotifyAsync(NotificationModel model)
|
||||
{
|
||||
var settings = Settings.GetSettings();
|
||||
|
||||
await NotifyAsync(model, settings);
|
||||
}
|
||||
|
||||
public async Task NotifyAsync(NotificationModel model, Settings settings)
|
||||
{
|
||||
if (settings == null) await NotifyAsync(model);
|
||||
|
||||
var pushSettings = (SlackNotificationSettings)settings;
|
||||
if (!ValidateConfiguration(pushSettings))
|
||||
{
|
||||
Log.Error("Settings for Slack was not correct, we cannot push a notification");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (model.NotificationType)
|
||||
{
|
||||
case NotificationType.NewRequest:
|
||||
await PushNewRequestAsync(model, pushSettings);
|
||||
break;
|
||||
case NotificationType.Issue:
|
||||
await PushIssueAsync(model, pushSettings);
|
||||
break;
|
||||
case NotificationType.RequestAvailable:
|
||||
break;
|
||||
case NotificationType.RequestApproved:
|
||||
break;
|
||||
case NotificationType.AdminNote:
|
||||
break;
|
||||
case NotificationType.Test:
|
||||
await PushTest(pushSettings);
|
||||
break;
|
||||
case NotificationType.RequestDeclined:
|
||||
break;
|
||||
case NotificationType.ItemAddedToFaultQueue:
|
||||
await PushFaultQueue(model, pushSettings);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PushNewRequestAsync(NotificationModel model, SlackNotificationSettings settings)
|
||||
{
|
||||
var message = $"{model.Title} has been requested by user: {model.User}";
|
||||
await Push(settings, message);
|
||||
}
|
||||
|
||||
private async Task PushIssueAsync(NotificationModel model, SlackNotificationSettings settings)
|
||||
{
|
||||
var message = $"A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
|
||||
await Push(settings, message);
|
||||
}
|
||||
|
||||
private async Task PushTest(SlackNotificationSettings settings)
|
||||
{
|
||||
var message = $"This is a test from Ombi, if you can see this then we have successfully pushed a notification!";
|
||||
await Push(settings, message);
|
||||
}
|
||||
|
||||
private async Task PushFaultQueue(NotificationModel model, SlackNotificationSettings settings)
|
||||
{
|
||||
var message = $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying";
|
||||
await Push(settings, message);
|
||||
}
|
||||
|
||||
private async Task Push(SlackNotificationSettings config, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
var notification = new SlackNotificationBody { username = config.Username, channel = config.Channel ?? string.Empty, text = message };
|
||||
|
||||
var result = await Api.PushAsync(config.Team, config.Token, config.Service, notification);
|
||||
if (!result.Equals("ok"))
|
||||
{
|
||||
Log.Error("Slack returned a message that was not 'ok', the notification did not get pushed");
|
||||
Log.Error($"Message that slack returned: {result}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ValidateConfiguration(SlackNotificationSettings settings)
|
||||
protected override bool ValidateConfiguration(SlackNotificationSettings settings)
|
||||
{
|
||||
if (!settings.Enabled)
|
||||
{
|
||||
|
@ -162,5 +70,80 @@ namespace Ombi.Services.Notification
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override async Task NewRequest(NotificationModel model, SlackNotificationSettings settings)
|
||||
{
|
||||
var message = $"{model.Title} has been requested by user: {model.User}";
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
protected override async Task Issue(NotificationModel model, SlackNotificationSettings settings)
|
||||
{
|
||||
var message = $"A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
protected override async Task AddedToRequestQueue(NotificationModel model, SlackNotificationSettings settings)
|
||||
{
|
||||
var message = $"Hello! The user '{model.User}' has requested {model.Title} but it could not be added. This has been added into the requests queue and will keep retrying";
|
||||
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
|
||||
protected override Task RequestDeclined(NotificationModel model, SlackNotificationSettings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override Task RequestApproved(NotificationModel model, SlackNotificationSettings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override Task AvailableRequest(NotificationModel model, SlackNotificationSettings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override async Task Send(NotificationMessage model, SlackNotificationSettings config)
|
||||
{
|
||||
try
|
||||
{
|
||||
var notification = new SlackNotificationBody { username = config.Username, channel = config.Channel ?? string.Empty, text = model.Message };
|
||||
|
||||
var result = await Api.PushAsync(config.Team, config.Token, config.Service, notification);
|
||||
if (!result.Equals("ok"))
|
||||
{
|
||||
Log.Error("Slack returned a message that was not 'ok', the notification did not get pushed");
|
||||
Log.Error($"Message that slack returned: {result}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task Test(NotificationModel model, SlackNotificationSettings settings)
|
||||
{
|
||||
var message = $"This is a test from Ombi, if you can see this then we have successfully pushed a notification!";
|
||||
var notification = new NotificationMessage
|
||||
{
|
||||
Message = message,
|
||||
};
|
||||
await Send(notification, settings);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -108,6 +108,7 @@
|
|||
<Compile Include="Jobs\EmbyEpisodeCacher.cs" />
|
||||
<Compile Include="Jobs\EmbyUserChecker.cs" />
|
||||
<Compile Include="Jobs\RadarrCacher.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\Newsletter.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\PlexRecentlyAddedNewsletter.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\EmbyRecentlyAddedNewsletter.cs" />
|
||||
<Compile Include="Jobs\RecentlyAddedNewsletter\IPlexNewsletter.cs" />
|
||||
|
@ -147,6 +148,7 @@
|
|||
<Compile Include="Notification\BaseNotification.cs" />
|
||||
<Compile Include="Notification\EmailMessageNotification.cs" />
|
||||
<Compile Include="Notification\EmbyNotificationEngine.cs" />
|
||||
<Compile Include="Notification\NotificationMessage.cs" />
|
||||
<Compile Include="Notification\PlexNotificationEngine.cs" />
|
||||
<Compile Include="Notification\NotificationModel.cs" />
|
||||
<Compile Include="Notification\NotificationService.cs" />
|
||||
|
|
|
@ -175,14 +175,6 @@ namespace Ombi.UI.Modules
|
|||
isOwner = true;
|
||||
userId = GetOwnerId(plexSettings.PlexAuthToken, username);
|
||||
}
|
||||
UsersModel dbUser = await IsDbuser(username);
|
||||
if (dbUser != null) // in the db?
|
||||
{
|
||||
var perms = (Permissions) dbUser.Permissions;
|
||||
authenticated = true;
|
||||
isOwner = perms.HasFlag(Permissions.Administrator);
|
||||
userId = dbUser.UserGuid;
|
||||
}
|
||||
Log.Debug("Friends list result = {0}", authenticated);
|
||||
}
|
||||
else if (!settings.UserAuthentication) // No auth, let them pass!
|
||||
|
@ -207,14 +199,6 @@ namespace Ombi.UI.Modules
|
|||
authenticated = true;
|
||||
isOwner = true;
|
||||
}
|
||||
UsersModel dbUser = await IsDbuser(username);
|
||||
if (dbUser != null) // in the db?
|
||||
{
|
||||
var perms = (Permissions)dbUser.Permissions;
|
||||
authenticated = true;
|
||||
isOwner = perms.HasFlag(Permissions.Administrator);
|
||||
userId = dbUser.UserGuid;
|
||||
}
|
||||
Log.Debug("Friends list result = {0}", authenticated);
|
||||
}
|
||||
else if (!settings.UserAuthentication) // No auth, let them pass!
|
||||
|
@ -222,6 +206,16 @@ namespace Ombi.UI.Modules
|
|||
authenticated = true;
|
||||
}
|
||||
}
|
||||
|
||||
UsersModel dbUser = await IsDbuser(username);
|
||||
if (dbUser != null) // in the db?
|
||||
{
|
||||
var perms = (Permissions)dbUser.Permissions;
|
||||
authenticated = true;
|
||||
isOwner = perms.HasFlag(Permissions.Administrator);
|
||||
userId = dbUser.UserGuid;
|
||||
}
|
||||
|
||||
if (settings.UsePassword || isOwner || Security.HasPermissions(username, Permissions.Administrator))
|
||||
{
|
||||
Session[SessionKeys.UserLoginName] = username;
|
||||
|
|
|
@ -78,19 +78,21 @@ namespace Ombi.UI.Modules
|
|||
|
||||
private async Task<Response> LoadUsers()
|
||||
{
|
||||
|
||||
var model = new List<UserManagementUsersViewModel>();
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
var embySettings = await EmbySettings.GetSettingsAsync();
|
||||
if (plexSettings.Enable)
|
||||
{
|
||||
return await LoadPlexUsers();
|
||||
model.AddRange(await LoadPlexUsers());
|
||||
}
|
||||
if (embySettings.Enable)
|
||||
{
|
||||
return await LoadEmbyUsers();
|
||||
model.AddRange(await LoadEmbyUsers());
|
||||
}
|
||||
|
||||
return null;
|
||||
model.AddRange(await LoadLocalUsers());
|
||||
|
||||
return Response.AsJson(model);
|
||||
}
|
||||
|
||||
private async Task<Response> CreateUser()
|
||||
|
@ -547,19 +549,26 @@ namespace Ombi.UI.Modules
|
|||
return retVal;
|
||||
}
|
||||
|
||||
private async Task<Response> LoadPlexUsers()
|
||||
private async Task<IEnumerable<UserManagementUsersViewModel>> LoadLocalUsers()
|
||||
{
|
||||
var localUsers = await UserMapper.GetUsersAsync();
|
||||
var plexDbUsers = await PlexUsersRepository.GetAllAsync();
|
||||
|
||||
var localUsers = await UserMapper.GetUsersAsync(); var userLogins = UserLoginsRepo.GetAll().ToList();
|
||||
|
||||
var model = new List<UserManagementUsersViewModel>();
|
||||
|
||||
var userLogins = UserLoginsRepo.GetAll().ToList();
|
||||
|
||||
foreach (var user in localUsers)
|
||||
{
|
||||
var userDb = userLogins.FirstOrDefault(x => x.UserId == user.UserGuid);
|
||||
model.Add(MapLocalUser(user, userDb?.LastLoggedIn ?? DateTime.MinValue));
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<UserManagementUsersViewModel>> LoadPlexUsers()
|
||||
{
|
||||
var plexDbUsers = await PlexUsersRepository.GetAllAsync();
|
||||
var model = new List<UserManagementUsersViewModel>();
|
||||
|
||||
var userLogins = UserLoginsRepo.GetAll().ToList();
|
||||
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
if (!string.IsNullOrEmpty(plexSettings.PlexAuthToken))
|
||||
|
@ -595,23 +604,16 @@ namespace Ombi.UI.Modules
|
|||
model.Add(MapPlexAdmin(account, dbUser, userDb?.LastLoggedIn ?? DateTime.MinValue));
|
||||
}
|
||||
}
|
||||
return Response.AsJson(model);
|
||||
return model;
|
||||
}
|
||||
|
||||
private async Task<Response> LoadEmbyUsers()
|
||||
private async Task<IEnumerable<UserManagementUsersViewModel>> LoadEmbyUsers()
|
||||
{
|
||||
var localUsers = await UserMapper.GetUsersAsync();
|
||||
var embyDbUsers = await EmbyRepository.GetAllAsync();
|
||||
var model = new List<UserManagementUsersViewModel>();
|
||||
|
||||
var userLogins = UserLoginsRepo.GetAll().ToList();
|
||||
|
||||
foreach (var user in localUsers)
|
||||
{
|
||||
var userDb = userLogins.FirstOrDefault(x => x.UserId == user.UserGuid);
|
||||
model.Add(MapLocalUser(user, userDb?.LastLoggedIn ?? DateTime.MinValue));
|
||||
}
|
||||
|
||||
var embySettings = await EmbySettings.GetSettingsAsync();
|
||||
if (!string.IsNullOrEmpty(embySettings.ApiKey))
|
||||
{
|
||||
|
@ -631,7 +633,7 @@ namespace Ombi.UI.Modules
|
|||
}
|
||||
}
|
||||
}
|
||||
return Response.AsJson(model);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,9 @@
|
|||
|
||||
<div class="form-group">
|
||||
<div>
|
||||
<button id="recentlyAddedBtn" class="btn btn-primary-outline">Send test email to Admin <div id="testEmailSpinner"></div></button>
|
||||
|
||||
<button id="recentlyAddedBtn" class="btn btn-primary-outline">Send test email to Admin @Html.ToolTip("Note: nothing will send if there is no new content...")
|
||||
<div id="testEmailSpinner"></div></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -84,6 +86,8 @@
|
|||
|
||||
$('#recentlyAddedBtn').click(function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
generateNotify("This could take some time depending on if you have episode searching enabled and also how many new items have been added!", "info");
|
||||
var base = '@Html.GetBaseUrl()';
|
||||
var url = createBaseUrl(base, '/admin/testnewsletteradminemail');
|
||||
$('#testEmailSpinner').attr("class", "fa fa-spinner fa-spin");
|
||||
|
@ -94,11 +98,11 @@
|
|||
success: function (response) {
|
||||
if (response) {
|
||||
generateNotify(response.message, "success");
|
||||
$('#testSendMassEmailSpinner').attr("class", "fa fa-check");
|
||||
$('#testEmailSpinner').attr("class", "fa fa-check");
|
||||
} else {
|
||||
|
||||
generateNotify(response.message, "danger");
|
||||
$('#testSendMassEmailSpinner').attr("class", "fa fa-times");
|
||||
$('#testEmailSpinner').attr("class", "fa fa-times");
|
||||
}
|
||||
},
|
||||
error: function (e) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@using Ombi.UI.Helpers
|
||||
@using Ombi.UI.Helpers
|
||||
@Html.Partial("Shared/Partial/_Sidebar")
|
||||
@{
|
||||
int port;
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
{
|
||||
rootFolder = Model.RootPath.Replace("/", "//");
|
||||
rootFolder = rootFolder.Replace(@"\", @"\\");
|
||||
}
|
||||
}
|
||||
<div class="col-sm-8 col-sm-push-1">
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
{
|
||||
rootFolder = Model.RootPath.Replace("/", "//");
|
||||
rootFolder = rootFolder.Replace(@"\", @"\\");
|
||||
}
|
||||
}
|
||||
<div class="col-sm-8 col-sm-push-1">
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
{
|
||||
title = customName;
|
||||
}
|
||||
var isAdmin = Html.IsAdmin();
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,11 +42,11 @@
|
|||
@Html.GetNavbarUrl(Context, "/search", UI.Layout_Search, "search")
|
||||
@Html.GetNavbarUrl(Context, "/requests", UI.Layout_Requests, "plus-circle")
|
||||
@Html.GetNavbarUrl(Context, "/issues", UI.Layout_Issues, "exclamation", "<span id=\"issueCount\"></span>")
|
||||
@if (Html.IsAdmin())
|
||||
@if (isAdmin)
|
||||
{
|
||||
@Html.GetNavbarUrl(Context, "/usermanagement", UI.Layout_Usermanagement, "users")
|
||||
}
|
||||
@if (Html.IsAdmin())
|
||||
@if (isAdmin)
|
||||
{
|
||||
<li><a id="donate" href="https://www.paypal.me/PlexRequestsNet" target="_blank"><i class="fa fa-heart" style="color: red"></i> @UI.Layout_Donate</a></li>
|
||||
}
|
||||
|
@ -55,7 +56,7 @@
|
|||
<a id="gravatarImg" class="navbar-brand" href="#">
|
||||
|
||||
</a>
|
||||
@if (Html.IsAdmin())
|
||||
@if (isAdmin)
|
||||
{
|
||||
<li><a>@UI.Layout_Welcome @Context.CurrentUser.UserName</a></li>
|
||||
<li class="dropdown">
|
||||
|
@ -121,7 +122,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var base = '@Html.GetBaseUrl()';
|
||||
var base = '@baseUrl';
|
||||
var url = createBaseUrl(base, '/customDonation');
|
||||
$.ajax({
|
||||
url: url,
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>(ROBOCOPY "$(ProjectDir)bin\$(ConfigurationName)\UpdateService" "$(SolutionDir)Ombi.UI\bin\$(ConfigurationName)\UpdateService" "*")^& IF %25ERRORLEVEL%25 GEQ 16 exit 1
|
||||
<PostBuildEvent>(ROBOCOPY "$(ProjectDir)bin\$(ConfigurationName)\UpdateService" "$(SolutionDir)Ombi.UI\bin\$(ConfigurationName)\UpdateService" "*")^& IF %25ERRORLEVEL%25 LEQ 2 exit 0
|
||||
exit 0</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue