diff --git a/PlexRequests.Core/PlexRequests.Core.csproj b/PlexRequests.Core/PlexRequests.Core.csproj index 055061291..143508e1e 100644 --- a/PlexRequests.Core/PlexRequests.Core.csproj +++ b/PlexRequests.Core/PlexRequests.Core.csproj @@ -91,6 +91,7 @@ + diff --git a/PlexRequests.Core/SettingModels/NewsletterSettings.cs b/PlexRequests.Core/SettingModels/NewsletterSettings.cs new file mode 100644 index 000000000..775c06571 --- /dev/null +++ b/PlexRequests.Core/SettingModels/NewsletterSettings.cs @@ -0,0 +1,38 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: NewsletterSettings.cs +// Created By: Jim MacKenzie +// +// 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; +using PlexRequests.Core.Models; +using PlexRequests.Core.Notification; + +namespace PlexRequests.Core.SettingModels +{ + public class NewletterSettings : Settings + { + public bool SendRecentlyAddedEmail { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Core/SettingModels/PlexRequestSettings.cs b/PlexRequests.Core/SettingModels/PlexRequestSettings.cs index 65afd1559..5c7e6ddf5 100644 --- a/PlexRequests.Core/SettingModels/PlexRequestSettings.cs +++ b/PlexRequests.Core/SettingModels/PlexRequestSettings.cs @@ -58,8 +58,8 @@ namespace PlexRequests.Core.SettingModels public bool Wizard { get; set; } public bool DisableTvRequestsByEpisode { get; set; } public bool DisableTvRequestsBySeason { get; set; } + [Obsolete("Moved to NewsLetterSettings")] public bool SendRecentlyAddedEmail { get; set; } - public string CustomDonationUrl { get; set; } public bool EnableCustomDonationUrl { get; set; } public string CustomDonationMessage { get; set; } diff --git a/PlexRequests.Core/Setup.cs b/PlexRequests.Core/Setup.cs index dac15a731..e16613161 100644 --- a/PlexRequests.Core/Setup.cs +++ b/PlexRequests.Core/Setup.cs @@ -72,6 +72,10 @@ namespace PlexRequests.Core { MigrateToVersion1910(); } + if (version > 1943 && version <= 1945) + { + MigrateToVersion1945(); + } } return Db.DbConnection().ConnectionString; @@ -275,5 +279,31 @@ namespace PlexRequests.Core Log.Error(e); } } + + + /// + /// Migrates to version1945 + /// + public void MigrateToVersion1945() + { + try + { + var settings = new SettingsServiceV2(new SettingsJsonRepository(Db, new MemoryCacheProvider())); + var plex = settings.GetSettings(); + var newsLetterSettings = new SettingsServiceV2(new SettingsJsonRepository(Db, new MemoryCacheProvider())); + var newsLetter = newsLetterSettings.GetSettings(); + if (plex.SendRecentlyAddedEmail) + { + newsLetter.SendRecentlyAddedEmail = plex.SendRecentlyAddedEmail; + plex.SendRecentlyAddedEmail = false; + settings.SaveSettings(plex); + newsLetterSettings.SaveSettings(newsLetter); + } + } + catch (Exception e) + { + Log.Error(e); + } + } } } diff --git a/PlexRequests.Services/Jobs/RecentlyAdded.cs b/PlexRequests.Services/Jobs/RecentlyAdded.cs index 13cf02e51..0755baafa 100644 --- a/PlexRequests.Services/Jobs/RecentlyAdded.cs +++ b/PlexRequests.Services/Jobs/RecentlyAdded.cs @@ -53,7 +53,7 @@ namespace PlexRequests.Services.Jobs public RecentlyAdded(IPlexApi api, ISettingsService plexSettings, ISettingsService email, ISettingsService scheduledService, IJobRecord rec, - ISettingsService plexRequest, + ISettingsService newsletter, IPlexReadOnlyDatabase db) { JobRecord = rec; @@ -61,7 +61,7 @@ namespace PlexRequests.Services.Jobs PlexSettings = plexSettings; EmailSettings = email; ScheduledJobsSettings = scheduledService; - PlexRequestSettings = plexRequest; + NewsletterSettings = newsletter; PlexDb = db; } @@ -72,7 +72,7 @@ namespace PlexRequests.Services.Jobs private const int MetadataTypeMovie = 1; private ISettingsService PlexSettings { get; } private ISettingsService EmailSettings { get; } - private ISettingsService PlexRequestSettings { get; } + private ISettingsService NewsletterSettings { get; } private ISettingsService ScheduledJobsSettings { get; } private IJobRecord JobRecord { get; } private IPlexReadOnlyDatabase PlexDb { get; } @@ -83,7 +83,7 @@ namespace PlexRequests.Services.Jobs { try { - var settings = PlexRequestSettings.GetSettings(); + var settings = NewsletterSettings.GetSettings(); if (!settings.SendRecentlyAddedEmail) { return; diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index fba7e8a95..d583168df 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -80,6 +80,7 @@ namespace PlexRequests.UI.Modules private ISettingsService PushbulletService { get; } private ISettingsService PushoverService { get; } private ISettingsService HeadphonesService { get; } + private ISettingsService NewsLetterService { get; } private ISettingsService LogService { get; } private IPlexApi PlexApi { get; } private ISonarrApi SonarrApi { get; } @@ -112,6 +113,7 @@ namespace PlexRequests.UI.Modules PushbulletApi pbApi, ICouchPotatoApi cpApi, ISettingsService pushoverSettings, + ISettingsService newsletter, IPushoverApi pushoverApi, IRepository logsRepo, INotificationService notify, @@ -139,6 +141,7 @@ namespace PlexRequests.UI.Modules PushoverApi = pushoverApi; NotificationService = notify; HeadphonesService = headphones; + NewsLetterService = newsletter; LogService = logs; Cache = cache; SlackSettings = slackSettings; @@ -200,6 +203,9 @@ namespace PlexRequests.UI.Modules Get["/headphones"] = _ => Headphones(); Post["/headphones"] = _ => SaveHeadphones(); + Get["/newsletter"] = _ => Newsletter(); + Post["/newsletter"] = _ => SaveNewsletter(); + Post["/createapikey"] = x => CreateApiKey(); Post["/autoupdate"] = x => AutoUpdate(); @@ -814,6 +820,33 @@ namespace PlexRequests.UI.Modules : new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." }); } + private Negotiator Newsletter() + { + var settings = NewsLetterService.GetSettings(); + return View["NewsletterSettings", settings]; + } + + private Response SaveNewsletter() + { + var settings = this.Bind(); + + var valid = this.Validate(settings); + if (!valid.IsValid) + { + var error = valid.SendJsonError(); + Log.Info("Error validating Headphones settings, message: {0}", error.Message); + return Response.AsJson(error); + } + settings.SendRecentlyAddedEmail = settings.SendRecentlyAddedEmail; + var result = NewsLetterService.SaveSettings(settings); + + Log.Info("Saved headphones settings, result: {0}", result); + return Response.AsJson(result + ? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Newsletter!" } + : new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." }); + } + + private Response CreateApiKey() { this.RequiresClaims(UserClaims.Admin); diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 366464d37..6c377cad6 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -719,6 +719,7 @@ Always + web.config diff --git a/PlexRequests.UI/Views/Admin/NewsletterSettings.cshtml b/PlexRequests.UI/Views/Admin/NewsletterSettings.cshtml new file mode 100644 index 000000000..f45060aa8 --- /dev/null +++ b/PlexRequests.UI/Views/Admin/NewsletterSettings.cshtml @@ -0,0 +1,76 @@ +@using System.Linq +@using PlexRequests.Core.Models +@using PlexRequests.UI.Helpers +@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase +@Html.Partial("_Sidebar") + +
+
+
+ Newsletter Settings + + +
+
+ + Note: This will require you to setup your email notifications + @if (Model.SendRecentlyAddedEmail) + { + + } + else + { + + } + +
+ +
+ +
+
+
+
+ +
+
+ + +
+
+
+ + + \ No newline at end of file diff --git a/PlexRequests.UI/Views/Admin/Settings.cshtml b/PlexRequests.UI/Views/Admin/Settings.cshtml index 8ed022ee8..fdb847b13 100644 --- a/PlexRequests.UI/Views/Admin/Settings.cshtml +++ b/PlexRequests.UI/Views/Admin/Settings.cshtml @@ -74,27 +74,6 @@ -
-
-
-
- - Note: This will require you to setup your email notifications - @if (Model.SendRecentlyAddedEmail) - { - - } - else - { - - } - -
-
- -
-
-
diff --git a/PlexRequests.UI/Views/Admin/_Sidebar.cshtml b/PlexRequests.UI/Views/Admin/_Sidebar.cshtml index 3ba6078f9..d65cd9848 100644 --- a/PlexRequests.UI/Views/Admin/_Sidebar.cshtml +++ b/PlexRequests.UI/Views/Admin/_Sidebar.cshtml @@ -10,6 +10,7 @@ @Html.GetSidebarUrl(Context, "/admin/sonarr", "Sonarr") @Html.GetSidebarUrl(Context, "/admin/sickrage", "SickRage") @Html.GetSidebarUrl(Context, "/admin/headphones", "Headphones (Beta)") + @Html.GetSidebarUrl(Context, "/admin/newsletter", "Newsletter Settings") @Html.GetSidebarUrl(Context, "/admin/emailnotification", "Email Notifications") @Html.GetSidebarUrl(Context, "/admin/pushbulletnotification", "Pushbullet Notifications") @Html.GetSidebarUrl(Context, "/admin/pushovernotification", "Pushover Notifications") diff --git a/appveyor.yml b/appveyor.yml index 7282f9b16..a860b2de2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,9 +3,9 @@ configuration: Release assembly_info: patch: true file: '**\AssemblyInfo.*' - assembly_version: '1.9.3' + assembly_version: '1.9.4' assembly_file_version: '{version}' - assembly_informational_version: '1.9.3' + assembly_informational_version: '1.9.4' before_build: - cmd: appveyor-retry nuget restore build: