From 0cf1aa50e12ce2fd8614e37783231825b71f4233 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Wed, 27 Sep 2017 16:27:46 +0100 Subject: [PATCH] Made a lot of changes around the notifcations to support the custom app name also started on the welcome email ##1456 --- src/Ombi.DependencyInjection/IocExtensions.cs | 1 + src/Ombi.Helpers/NotificationType.cs | 3 +- .../EmailBasicTemplate.cs | 6 +- .../IEmailBasicTemplate.cs | 2 +- .../Agents/DiscordNotification.cs | 3 +- .../Agents/EmailNotification.cs | 52 ++++++--------- .../Agents/MattermostNotification.cs | 4 +- .../Agents/PushbulletNotification.cs | 4 +- .../Agents/PushoverNotification.cs | 4 +- .../Agents/SlackNotification.cs | 4 +- .../GenericEmailProvider.cs | 8 ++- .../Interfaces/BaseNotification.cs | 16 +++-- .../NotificationMessageCurlys.cs | 16 ++++- src/Ombi.Schedule/Jobs/Ombi/IWelcomeEmail.cs | 10 +++ src/Ombi.Schedule/Jobs/Ombi/WelcomeEmail.cs | 64 +++++++++++++++++++ src/Ombi.Store/Context/OmbiContext.cs | 22 +++++-- .../app/interfaces/INotificationSettings.ts | 1 + .../app/services/identity.service.ts | 4 ++ .../notificationtemplate.component.ts | 1 + .../usermanagement.component.ts | 16 +++-- src/Ombi/Controllers/IdentityController.cs | 20 +++++- 21 files changed, 199 insertions(+), 62 deletions(-) create mode 100644 src/Ombi.Schedule/Jobs/Ombi/IWelcomeEmail.cs create mode 100644 src/Ombi.Schedule/Jobs/Ombi/WelcomeEmail.cs diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index e4f434087..b6f9f6108 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -144,6 +144,7 @@ namespace Ombi.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } diff --git a/src/Ombi.Helpers/NotificationType.cs b/src/Ombi.Helpers/NotificationType.cs index 08d57cfad..493ca5506 100644 --- a/src/Ombi.Helpers/NotificationType.cs +++ b/src/Ombi.Helpers/NotificationType.cs @@ -9,6 +9,7 @@ AdminNote, Test, RequestDeclined, - ItemAddedToFaultQueue + ItemAddedToFaultQueue, + WelcomeEmail } } diff --git a/src/Ombi.Notifications.Templates/EmailBasicTemplate.cs b/src/Ombi.Notifications.Templates/EmailBasicTemplate.cs index b1eb504d1..64740fb43 100644 --- a/src/Ombi.Notifications.Templates/EmailBasicTemplate.cs +++ b/src/Ombi.Notifications.Templates/EmailBasicTemplate.cs @@ -11,7 +11,7 @@ namespace Ombi.Notifications.Templates get { #if DEBUG - return Path.Combine(Directory.GetCurrentDirectory(), "bin", "Debug", "netcoreapp1.1", "Templates", "BasicTemplate.html"); + return Path.Combine(Directory.GetCurrentDirectory(), "bin", "Debug", "netcoreapp2.0", "Templates", "BasicTemplate.html"); #else return Path.Combine(Directory.GetCurrentDirectory(), "Templates","BasicTemplate.html"); #endif @@ -22,9 +22,9 @@ namespace Ombi.Notifications.Templates private const string BodyKey = "{@BODY}"; private const string ImgSrc = "{@IMGSRC}"; private const string DateKey = "{@DATENOW}"; - private const string Logo = "{@DATENOW}"; + private const string Logo = "{@LOGO}"; - public string LoadTemplate(string subject, string body, string img, string logo) + public string LoadTemplate(string subject, string body, string img = default(string), string logo = default(string)) { var sb = new StringBuilder(File.ReadAllText(TemplateLocation)); sb.Replace(SubjectKey, subject); diff --git a/src/Ombi.Notifications.Templates/IEmailBasicTemplate.cs b/src/Ombi.Notifications.Templates/IEmailBasicTemplate.cs index 6b90c796a..99d7c881a 100644 --- a/src/Ombi.Notifications.Templates/IEmailBasicTemplate.cs +++ b/src/Ombi.Notifications.Templates/IEmailBasicTemplate.cs @@ -2,7 +2,7 @@ { public interface IEmailBasicTemplate { - string LoadTemplate(string subject, string body, string img, string logo); + string LoadTemplate(string subject, string body, string img = default(string), string logo = default(string)); string TemplateLocation { get; } } } \ No newline at end of file diff --git a/src/Ombi.Notifications/Agents/DiscordNotification.cs b/src/Ombi.Notifications/Agents/DiscordNotification.cs index 47cbcf23e..9e48e771e 100644 --- a/src/Ombi.Notifications/Agents/DiscordNotification.cs +++ b/src/Ombi.Notifications/Agents/DiscordNotification.cs @@ -8,6 +8,7 @@ using Ombi.Core.Settings; using Ombi.Helpers; using Ombi.Notifications.Interfaces; using Ombi.Notifications.Models; +using Ombi.Settings.Settings.Models; using Ombi.Settings.Settings.Models.Notifications; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -17,7 +18,7 @@ namespace Ombi.Notifications.Agents { public class DiscordNotification : BaseNotification, IDiscordNotification { - public DiscordNotification(IDiscordApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t) : base(sn, r, m, t) + public DiscordNotification(IDiscordApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, ISettingsService s) : base(sn, r, m, t,s) { Api = api; Logger = log; diff --git a/src/Ombi.Notifications/Agents/EmailNotification.cs b/src/Ombi.Notifications/Agents/EmailNotification.cs index f702807d2..29cce3ff1 100644 --- a/src/Ombi.Notifications/Agents/EmailNotification.cs +++ b/src/Ombi.Notifications/Agents/EmailNotification.cs @@ -17,13 +17,11 @@ namespace Ombi.Notifications.Agents { public class EmailNotification : BaseNotification, IEmailNotification { - public EmailNotification(ISettingsService settings, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, IEmailProvider prov, ISettingsService c) : base(settings, r, m, t) + public EmailNotification(ISettingsService settings, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, IEmailProvider prov, ISettingsService c) : base(settings, r, m, t, c) { EmailProvider = prov; - CustomizationSettings = c; } private IEmailProvider EmailProvider { get; } - private ISettingsService CustomizationSettings { get; } public override string NotificationName => nameof(EmailNotification); protected override bool ValidateConfiguration(EmailNotificationSettings settings) @@ -51,10 +49,8 @@ namespace Ombi.Notifications.Agents { var parsed = await LoadTemplate(NotificationAgent.Email, type, model); - var customization = await CustomizationSettings.GetSettingsAsync(); - var email = new EmailBasicTemplate(); - var html = email.LoadTemplate(parsed.Subject, parsed.Message,parsed.Image, customization.Logo); + var html = email.LoadTemplate(parsed.Subject, parsed.Message,parsed.Image, Customization.Logo); var message = new NotificationMessage @@ -67,8 +63,6 @@ namespace Ombi.Notifications.Agents return message; } - - protected override async Task NewRequest(NotificationOptions model, EmailNotificationSettings settings) { var message = await LoadTemplate(NotificationType.NewRequest, model, settings); @@ -76,9 +70,7 @@ namespace Ombi.Notifications.Agents { return; } - - //message.Other.Add("PlainTextBody", $"Hello! The user '{model.RequestedUser}' has requested the {model.RequestType} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime:f}"); - + await Send(message, settings); } @@ -89,9 +81,7 @@ namespace Ombi.Notifications.Agents { return; } - - //message.Other.Add("PlainTextBody", $"Hello! The user '{model.RequestedUser}' has reported a new issue {model.Body} for the title {model.Title}!"); - + await Send(message, settings); } @@ -114,21 +104,17 @@ namespace Ombi.Notifications.Agents img = TvRequest.ParentRequest.PosterPath; } - var customization = await CustomizationSettings.GetSettingsAsync(); var html = email.LoadTemplate( - "Ombi: A request could not be added.", - $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying", img, customization.Logo); + $"{Customization.ApplicationName}: A request could not be added.", + $"Hello! The user '{user}' has requested {title} but it could not be added. This has been added into the requests queue and will keep retrying", img, Customization.Logo); var message = new NotificationMessage { Message = html, - Subject = $"Ombi: A request could not be added", + Subject = $"{Customization.ApplicationName}: A request could not be added", To = settings.AdminEmail, }; - - //message.Other.Add("PlainTextBody", $"Hello! The user '{model.RequestedUser}' 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); } @@ -139,10 +125,9 @@ namespace Ombi.Notifications.Agents { return; } - - //message.Other.Add("PlainTextBody", $"Hello! Your request for {model.Title} has been declined, Sorry!"); - - + message.To = model.RequestType == RequestType.Movie + ? MovieRequest.RequestedUser.Email + : TvRequest.RequestedUser.Email; await Send(message, settings); } @@ -153,9 +138,9 @@ namespace Ombi.Notifications.Agents { return; } - - //message.Other.Add("PlainTextBody", $"Hello! Your request for {model.Title} has been approved!"); - + message.To = model.RequestType == RequestType.Movie + ? MovieRequest.RequestedUser.Email + : TvRequest.RequestedUser.Email; await Send(message, settings); } @@ -166,9 +151,9 @@ namespace Ombi.Notifications.Agents { return; } - - //message.Other.Add("PlainTextBody", $"Hello! You requested {model.Title} on Ombi! This is now available on Plex! :)"); - + message.To = model.RequestType == RequestType.Movie + ? MovieRequest.RequestedUser.Email + : TvRequest.RequestedUser.Email; await Send(message, settings); } @@ -180,10 +165,9 @@ namespace Ombi.Notifications.Agents protected override async Task Test(NotificationOptions model, EmailNotificationSettings settings) { var email = new EmailBasicTemplate(); - var customization = await CustomizationSettings.GetSettingsAsync(); var html = email.LoadTemplate( "Test Message", - "This is just a test! Success!", "", customization.Logo); + "This is just a test! Success!", "", Customization.Logo); var message = new NotificationMessage { Message = html, diff --git a/src/Ombi.Notifications/Agents/MattermostNotification.cs b/src/Ombi.Notifications/Agents/MattermostNotification.cs index 683fd4084..8d627c5b8 100644 --- a/src/Ombi.Notifications/Agents/MattermostNotification.cs +++ b/src/Ombi.Notifications/Agents/MattermostNotification.cs @@ -10,6 +10,7 @@ using Ombi.Core.Settings; using Ombi.Helpers; using Ombi.Notifications.Interfaces; using Ombi.Notifications.Models; +using Ombi.Settings.Settings.Models; using Ombi.Settings.Settings.Models.Notifications; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -19,7 +20,8 @@ namespace Ombi.Notifications.Agents { public class MattermostNotification : BaseNotification, IMattermostNotification { - public MattermostNotification(IMattermostApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t) : base(sn, r, m, t) + public MattermostNotification(IMattermostApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, + ISettingsService s) : base(sn, r, m, t,s) { Api = api; Logger = log; diff --git a/src/Ombi.Notifications/Agents/PushbulletNotification.cs b/src/Ombi.Notifications/Agents/PushbulletNotification.cs index ea8b97b42..d16a6e6b5 100644 --- a/src/Ombi.Notifications/Agents/PushbulletNotification.cs +++ b/src/Ombi.Notifications/Agents/PushbulletNotification.cs @@ -6,6 +6,7 @@ using Ombi.Core.Settings; using Ombi.Helpers; using Ombi.Notifications.Interfaces; using Ombi.Notifications.Models; +using Ombi.Settings.Settings.Models; using Ombi.Settings.Settings.Models.Notifications; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -15,7 +16,8 @@ namespace Ombi.Notifications.Agents { public class PushbulletNotification : BaseNotification, IPushbulletNotification { - public PushbulletNotification(IPushbulletApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t) : base(sn, r, m, t) + public PushbulletNotification(IPushbulletApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, + ISettingsService s) : base(sn, r, m, t,s) { Api = api; Logger = log; diff --git a/src/Ombi.Notifications/Agents/PushoverNotification.cs b/src/Ombi.Notifications/Agents/PushoverNotification.cs index 3e3ae20e2..0c5c8414b 100644 --- a/src/Ombi.Notifications/Agents/PushoverNotification.cs +++ b/src/Ombi.Notifications/Agents/PushoverNotification.cs @@ -7,6 +7,7 @@ using Ombi.Core.Settings; using Ombi.Helpers; using Ombi.Notifications.Interfaces; using Ombi.Notifications.Models; +using Ombi.Settings.Settings.Models; using Ombi.Settings.Settings.Models.Notifications; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -16,7 +17,8 @@ namespace Ombi.Notifications.Agents { public class PushoverNotification : BaseNotification, IPushoverNotification { - public PushoverNotification(IPushoverApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t) : base(sn, r, m, t) + public PushoverNotification(IPushoverApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, + ISettingsService s) : base(sn, r, m, t, s) { Api = api; Logger = log; diff --git a/src/Ombi.Notifications/Agents/SlackNotification.cs b/src/Ombi.Notifications/Agents/SlackNotification.cs index d02a19ba0..6321ed3ae 100644 --- a/src/Ombi.Notifications/Agents/SlackNotification.cs +++ b/src/Ombi.Notifications/Agents/SlackNotification.cs @@ -7,6 +7,7 @@ using Ombi.Core.Settings; using Ombi.Helpers; using Ombi.Notifications.Interfaces; using Ombi.Notifications.Models; +using Ombi.Settings.Settings.Models; using Ombi.Settings.Settings.Models.Notifications; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -16,7 +17,8 @@ namespace Ombi.Notifications.Agents { public class SlackNotification : BaseNotification, ISlackNotification { - public SlackNotification(ISlackApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t) : base(sn, r, m, t) + public SlackNotification(ISlackApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, + ISettingsService s) : base(sn, r, m, t, s) { Api = api; Logger = log; diff --git a/src/Ombi.Notifications/GenericEmailProvider.cs b/src/Ombi.Notifications/GenericEmailProvider.cs index de20886c3..ec6160e12 100644 --- a/src/Ombi.Notifications/GenericEmailProvider.cs +++ b/src/Ombi.Notifications/GenericEmailProvider.cs @@ -17,11 +17,17 @@ namespace Ombi.Notifications CustomizationSettings = s; } private ISettingsService CustomizationSettings { get; } + + /// + /// This will load up the Email template and generate the HTML + /// + /// + /// + /// public async Task SendAdHoc(NotificationMessage model, EmailNotificationSettings settings) { try { - var email = new EmailBasicTemplate(); var customization = await CustomizationSettings.GetSettingsAsync(); diff --git a/src/Ombi.Notifications/Interfaces/BaseNotification.cs b/src/Ombi.Notifications/Interfaces/BaseNotification.cs index 5627afc63..e908ae300 100644 --- a/src/Ombi.Notifications/Interfaces/BaseNotification.cs +++ b/src/Ombi.Notifications/Interfaces/BaseNotification.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Ombi.Core.Settings; using Ombi.Helpers; using Ombi.Notifications.Models; +using Ombi.Settings.Settings.Models; using Ombi.Store.Entities; using Ombi.Store.Entities.Requests; using Ombi.Store.Repository; @@ -13,19 +14,24 @@ namespace Ombi.Notifications.Interfaces { public abstract class BaseNotification : INotification where T : Settings.Settings.Models.Settings, new() { - protected BaseNotification(ISettingsService settings, INotificationTemplatesRepository templateRepo, IMovieRequestRepository movie, ITvRequestRepository tv) + protected BaseNotification(ISettingsService settings, INotificationTemplatesRepository templateRepo, IMovieRequestRepository movie, ITvRequestRepository tv, + ISettingsService customization) { Settings = settings; TemplateRepository = templateRepo; MovieRepository = movie; TvRepository = tv; + CustomizationSettings = customization; } protected ISettingsService Settings { get; } protected INotificationTemplatesRepository TemplateRepository { get; } protected IMovieRequestRepository MovieRepository { get; } protected ITvRequestRepository TvRepository { get; } - + protected CustomizationSettings Customization { get; set; } + private ISettingsService CustomizationSettings { get; } + + protected ChildRequests TvRequest { get; set; } protected MovieRequests MovieRequest { get; set; } @@ -54,6 +60,8 @@ namespace Ombi.Notifications.Interfaces { await LoadRequest(model.RequestId, model.RequestType); } + + Customization = await CustomizationSettings.GetSettingsAsync(); try { switch (model.NotificationType) @@ -129,11 +137,11 @@ namespace Ombi.Notifications.Interfaces var curlys = new NotificationMessageCurlys(); if (model.RequestType == RequestType.Movie) { - curlys.Setup(MovieRequest); + curlys.Setup(MovieRequest, Customization); } else { - curlys.Setup(TvRequest); + curlys.Setup(TvRequest, Customization); } var parsed = resolver.ParseMessage(template, curlys); diff --git a/src/Ombi.Notifications/NotificationMessageCurlys.cs b/src/Ombi.Notifications/NotificationMessageCurlys.cs index 5e26d503e..63f94eae5 100644 --- a/src/Ombi.Notifications/NotificationMessageCurlys.cs +++ b/src/Ombi.Notifications/NotificationMessageCurlys.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using Ombi.Settings.Settings.Models; +using Ombi.Store.Entities; using Ombi.Store.Entities.Requests; namespace Ombi.Notifications @@ -7,8 +9,9 @@ namespace Ombi.Notifications public class NotificationMessageCurlys { - public void Setup(FullBaseRequest req) + public void Setup(FullBaseRequest req, CustomizationSettings s) { + ApplicationName = string.IsNullOrEmpty(s.ApplicationName) ? "Ombi" : s.ApplicationName; RequestedUser = string.IsNullOrEmpty(req.RequestedUser.Alias) ? req.RequestedUser.UserName : req.RequestedUser.Alias; @@ -20,8 +23,9 @@ namespace Ombi.Notifications PosterImage = req.PosterPath; } - public void Setup(ChildRequests req) + public void Setup(ChildRequests req, CustomizationSettings s) { + ApplicationName = string.IsNullOrEmpty(s.ApplicationName) ? "Ombi" : s.ApplicationName; RequestedUser = string.IsNullOrEmpty(req.RequestedUser.Alias) ? req.RequestedUser.UserName : req.RequestedUser.Alias; @@ -33,6 +37,12 @@ namespace Ombi.Notifications PosterImage = req.ParentRequest.PosterPath; // DO Episode and Season Lists } + + public void Setup(OmbiUser user, CustomizationSettings s) + { + ApplicationName = string.IsNullOrEmpty(s.ApplicationName) ? "Ombi" : s.ApplicationName; + RequestedUser = user.UserName; + } // User Defined public string RequestedUser { get; set; } @@ -45,6 +55,7 @@ namespace Ombi.Notifications public string EpisodesList { get; set; } public string SeasonsList { get; set; } public string PosterImage { get; set; } + public string ApplicationName { get; set; } // System Defined private string LongDate => DateTime.Now.ToString("D"); @@ -68,6 +79,7 @@ namespace Ombi.Notifications {nameof(EpisodesList),EpisodesList}, {nameof(SeasonsList),SeasonsList}, {nameof(PosterImage),PosterImage}, + {nameof(ApplicationName),ApplicationName}, }; } } \ No newline at end of file diff --git a/src/Ombi.Schedule/Jobs/Ombi/IWelcomeEmail.cs b/src/Ombi.Schedule/Jobs/Ombi/IWelcomeEmail.cs new file mode 100644 index 000000000..b4be7cbef --- /dev/null +++ b/src/Ombi.Schedule/Jobs/Ombi/IWelcomeEmail.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; +using Ombi.Store.Entities; + +namespace Ombi.Schedule.Jobs.Ombi +{ + public interface IWelcomeEmail + { + Task SendEmail(OmbiUser user); + } +} \ No newline at end of file diff --git a/src/Ombi.Schedule/Jobs/Ombi/WelcomeEmail.cs b/src/Ombi.Schedule/Jobs/Ombi/WelcomeEmail.cs new file mode 100644 index 000000000..63e27d85b --- /dev/null +++ b/src/Ombi.Schedule/Jobs/Ombi/WelcomeEmail.cs @@ -0,0 +1,64 @@ +using System.Threading.Tasks; +using Ombi.Core.Settings; +using Ombi.Helpers; +using Ombi.Notifications; +using Ombi.Notifications.Models; +using Ombi.Settings.Settings.Models; +using Ombi.Settings.Settings.Models.Notifications; +using Ombi.Store.Entities; +using Ombi.Store.Repository; + +namespace Ombi.Schedule.Jobs.Ombi +{ + public class WelcomeEmail : IWelcomeEmail + { + public WelcomeEmail(ISettingsService email, INotificationTemplatesRepository template, ISettingsService c, + IEmailProvider provider) + { + _emailSettings = email; + _email = provider; + _templates = template; + _customizationSettings = c; + } + + private readonly ISettingsService _emailSettings; + private readonly ISettingsService _customizationSettings; + private readonly INotificationTemplatesRepository _templates; + private readonly IEmailProvider _email; + + public async Task SendEmail(OmbiUser user) + { + var settings = await _emailSettings.GetSettingsAsync(); + if (!settings.Enabled) + { + return; + } + var template = await _templates.GetTemplate(NotificationAgent.Email, NotificationType.WelcomeEmail); + if (!template.Enabled) + { + return; + } + + var cs = await _customizationSettings.GetSettingsAsync(); + var parsed = Parse(user, template, cs); + + var message = new NotificationMessage + { + Message = parsed.Message, + Subject = parsed.Subject, + To = user.Email, + }; + await _email.SendAdHoc(message, settings); + } + + private NotificationMessageContent Parse(OmbiUser u, NotificationTemplates template, CustomizationSettings cs) + { + var resolver = new NotificationMessageResolver(); + var curlys = new NotificationMessageCurlys(); + curlys.Setup(u, cs); + var parsed = resolver.ParseMessage(template, curlys); + + return parsed; + } + } +} \ No newline at end of file diff --git a/src/Ombi.Store/Context/OmbiContext.cs b/src/Ombi.Store/Context/OmbiContext.cs index 5df010ef8..d38213cd3 100644 --- a/src/Ombi.Store/Context/OmbiContext.cs +++ b/src/Ombi.Store/Context/OmbiContext.cs @@ -115,7 +115,7 @@ namespace Ombi.Store.Context { NotificationType = notificationType, Message = "Hello! The user '{RequestedUser}' has requested the {Type} '{Title}'! Please log in to approve this request. Request Date: {RequestedDate}", - Subject = "Ombi: New {Type} request for {Title}!", + Subject = "{ApplicationName}: New {Type} request for {Title}!", Agent = agent, Enabled = true, }; @@ -125,7 +125,7 @@ namespace Ombi.Store.Context { NotificationType = notificationType, Message = "Hello! The user '{RequestedUser}' has reported a new issue for the title {Title}!
{Issue}", - Subject = "Ombi: New issue for {Title}!", + Subject = "{ApplicationName}: New issue for {Title}!", Agent = agent, Enabled = true, }; @@ -134,8 +134,8 @@ namespace Ombi.Store.Context notificationToAdd = new NotificationTemplates { NotificationType = notificationType, - Message = "Hello! You requested {Title} on Ombi! This is now available! :)", - Subject = "Ombi: {Title} is now available!", + Message = "Hello! You requested {Title} on {ApplicationName}! This is now available! :)", + Subject = "{ApplicationName}: {Title} is now available!", Agent = agent, Enabled = true, }; @@ -145,7 +145,7 @@ namespace Ombi.Store.Context { NotificationType = notificationType, Message = "Hello! Your request for {Title} has been approved!", - Subject = "Ombi: your request has been approved", + Subject = "{ApplicationName}: your request has been approved", Agent = agent, Enabled = true, }; @@ -159,13 +159,23 @@ namespace Ombi.Store.Context { NotificationType = notificationType, Message = "Hello! Your request for {Title} has been declined, Sorry!", - Subject = "Ombi: your request has been declined", + Subject = "{ApplicationName}: your request has been declined", Agent = agent, Enabled = true, }; break; case NotificationType.ItemAddedToFaultQueue: continue; + case NotificationType.WelcomeEmail: + notificationToAdd = new NotificationTemplates + { + NotificationType = notificationType, + Message = "Hello! You have been invited to use {ApplicationName}!", + Subject = "Invite to {ApplicationName}", + Agent = agent, + Enabled = true, + }; + break; default: throw new ArgumentOutOfRangeException(); } diff --git a/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts b/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts index 598dd0b05..270de2a9e 100644 --- a/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts +++ b/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts @@ -41,6 +41,7 @@ export enum NotificationType { Test, RequestDeclined, ItemAddedToFaultQueue, + WelcomeEmail, } export interface IDiscordNotifcationSettings extends INotificationSettings { diff --git a/src/Ombi/ClientApp/app/services/identity.service.ts b/src/Ombi/ClientApp/app/services/identity.service.ts index 81ea5ac29..b8b4231ac 100644 --- a/src/Ombi/ClientApp/app/services/identity.service.ts +++ b/src/Ombi/ClientApp/app/services/identity.service.ts @@ -54,6 +54,10 @@ export class IdentityService extends ServiceAuthHelpers { return this.regularHttp.post(this.url + "resetpassword", JSON.stringify(token), { headers: this.headers }).map(this.extractData); } + public sendWelcomeEmail(user: IUser): Observable { + return this.http.post(`${this.url}welcomeEmail`, JSON.stringify(user), { headers: this.headers }).map(this.extractData); + } + public hasRole(role: string): boolean { const roles = localStorage.getItem("roles") as string[] | null; if (roles) { diff --git a/src/Ombi/ClientApp/app/settings/notifications/notificationtemplate.component.ts b/src/Ombi/ClientApp/app/settings/notifications/notificationtemplate.component.ts index cfa366f0b..8b6a4b25a 100644 --- a/src/Ombi/ClientApp/app/settings/notifications/notificationtemplate.component.ts +++ b/src/Ombi/ClientApp/app/settings/notifications/notificationtemplate.component.ts @@ -20,6 +20,7 @@ export class NotificationTemplate { {EpisodesList} : A comma seperated list of Episodes requested
{SeasonsList} : A comma seperated list of seasons requested
{PosterImage} : The requested poster image link
+{ApplicationName} : The Application Name from the Customization Settings {LongDate} : 15 June 2017
{ShortDate} : 15/06/2017
{LongTime} : 16:02:34
diff --git a/src/Ombi/ClientApp/app/usermanagement/usermanagement.component.ts b/src/Ombi/ClientApp/app/usermanagement/usermanagement.component.ts index 286c2970a..2149884be 100644 --- a/src/Ombi/ClientApp/app/usermanagement/usermanagement.component.ts +++ b/src/Ombi/ClientApp/app/usermanagement/usermanagement.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from "@angular/core"; -import { IUser } from "../interfaces"; -import { IdentityService } from "../services"; +import { IEmailNotificationSettings, IUser } from "../interfaces"; +import { IdentityService, NotificationService, SettingsService } from "../services"; @Component({ templateUrl: "./usermanagement.component.html", @@ -10,8 +10,11 @@ export class UserManagementComponent implements OnInit { public users: IUser[]; public checkAll = false; + public emailSettings: IEmailNotificationSettings; - constructor(private identityService: IdentityService) { } + constructor(private identityService: IdentityService, + private settingsService: SettingsService, + private notificationService: NotificationService) { } public ngOnInit() { this.users = []; @@ -19,10 +22,15 @@ export class UserManagementComponent implements OnInit { this.users = x; }); + this.settingsService.getEmailNotificationSettings().subscribe(x => this.emailSettings = x); } public welcomeEmail(user: IUser) { - // todo + if (!this.emailSettings.enabled) { + this.notificationService.error("Email", "Email Notifications are not setup, cannot send welcome email"); + return; + } + this.identityService.sendWelcomeEmail(user).subscribe(); } public checkAllBoxes() { diff --git a/src/Ombi/Controllers/IdentityController.cs b/src/Ombi/Controllers/IdentityController.cs index c234c3186..a5a59f964 100644 --- a/src/Ombi/Controllers/IdentityController.cs +++ b/src/Ombi/Controllers/IdentityController.cs @@ -5,6 +5,7 @@ using System.Net; using System.Threading.Tasks; using AutoMapper; +using Hangfire; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; @@ -18,13 +19,16 @@ using Ombi.Core.Claims; using Ombi.Core.Helpers; using Ombi.Core.Models.UI; using Ombi.Core.Settings; +using Ombi.Helpers; using Ombi.Models; using Ombi.Models.Identity; using Ombi.Notifications; using Ombi.Notifications.Models; +using Ombi.Schedule.Jobs.Ombi; using Ombi.Settings.Settings.Models; using Ombi.Settings.Settings.Models.Notifications; using Ombi.Store.Entities; +using Ombi.Store.Repository; using OmbiIdentityResult = Ombi.Models.Identity.IdentityResult; namespace Ombi.Controllers @@ -40,7 +44,8 @@ namespace Ombi.Controllers public IdentityController(UserManager user, IMapper mapper, RoleManager rm, IEmailProvider prov, ISettingsService s, ISettingsService c, - IOptions userSettings) + IOptions userSettings, + IWelcomeEmail welcome) { UserManager = user; Mapper = mapper; @@ -49,6 +54,7 @@ namespace Ombi.Controllers EmailSettings = s; CustomizationSettings = c; UserSettings = userSettings; + WelcomeEmail = welcome; } private UserManager UserManager { get; } @@ -58,6 +64,7 @@ namespace Ombi.Controllers private ISettingsService EmailSettings { get; } private ISettingsService CustomizationSettings { get; } private IOptions UserSettings { get; } + private IWelcomeEmail WelcomeEmail { get; } /// /// This is what the Wizard will call when creating the user for the very first time. @@ -517,6 +524,17 @@ namespace Ombi.Controllers }; } + [HttpPost("welcomeEmail")] + public void SendWelcomeEmail([FromBody] UserViewModel user) + { + var ombiUser = new OmbiUser + { + Email = user.EmailAddress, + UserName = user.Username + }; + BackgroundJob.Enqueue(() => WelcomeEmail.SendEmail(ombiUser)); + } + private async Task> AddRoles(IEnumerable roles, OmbiUser ombiUser) { var roleResult = new List();