From 7f3105003f02f70b3ecb6ea1601305c3a509e963 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 25 May 2016 13:14:42 +0100 Subject: [PATCH 1/7] We wan't updating the DB schema. --- PlexRequests.Core/Setup.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/PlexRequests.Core/Setup.cs b/PlexRequests.Core/Setup.cs index f00f2a144..8bdf2faa6 100644 --- a/PlexRequests.Core/Setup.cs +++ b/PlexRequests.Core/Setup.cs @@ -26,8 +26,6 @@ #endregion using System; -using System.Collections.Generic; -using System.Linq; using System.Text.RegularExpressions; using Mono.Data.Sqlite; @@ -84,7 +82,11 @@ namespace PlexRequests.Core connection.CreateSchema(version); // Set the default. schema = connection.GetSchemaVersion(); } - + if (version > schema.SchemaVersion) + { + Db.DbConnection().UpdateSchemaVersion(version); + schema = connection.GetSchemaVersion(); + } version = schema.SchemaVersion; return version; From a26026166d9fd93882e48ff96916bd8f3a1c9b15 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 25 May 2016 13:26:32 +0100 Subject: [PATCH 2/7] fully fixed #239 --- PlexRequests.UI/Modules/AdminModule.cs | 74 +++++++++- .../Modules/AdminNotificationsModule.cs | 130 ------------------ PlexRequests.UI/PlexRequests.UI.csproj | 1 - 3 files changed, 72 insertions(+), 133 deletions(-) delete mode 100644 PlexRequests.UI/Modules/AdminNotificationsModule.cs diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index ee7bcb0b8..c62b7ff46 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -82,6 +82,8 @@ namespace PlexRequests.UI.Modules private IRepository LogsRepo { get; } private INotificationService NotificationService { get; } private ICacheProvider Cache { get; } + private ISettingsService SlackSettings { get; } + private ISlackApi SlackApi { get; } private static Logger Log = LogManager.GetCurrentClassLogger(); public AdminModule(ISettingsService prService, @@ -102,7 +104,8 @@ namespace PlexRequests.UI.Modules INotificationService notify, ISettingsService headphones, ISettingsService logs, - ICacheProvider cache) : base("admin", prService) + ICacheProvider cache, ISettingsService slackSettings, + ISlackApi slackApi) : base("admin", prService) { PrService = prService; CpService = cpService; @@ -123,8 +126,10 @@ namespace PlexRequests.UI.Modules HeadphonesService = headphones; LogService = logs; Cache = cache; + SlackSettings = slackSettings; + SlackApi = slackApi; - this.RequiresClaims(UserClaims.Admin); + this.RequiresClaims(UserClaims.Admin); Get["/"] = _ => Admin(); @@ -176,6 +181,11 @@ namespace PlexRequests.UI.Modules Post["/createapikey"] = x => CreateApiKey(); Post["/autoupdate"] = x => AutoUpdate(); + + Post["/testslacknotification"] = _ => TestSlackNotification(); + + Get["/slacknotification"] = _ => SlackNotifications(); + Post["/slacknotification"] = _ => SaveSlackNotifications(); } private Negotiator Authentication() @@ -735,5 +745,65 @@ namespace PlexRequests.UI.Modules return Response.AsJson(apiKey); } + + private Response TestSlackNotification() + { + var settings = this.BindAndValidate(); + if (!ModelValidationResult.IsValid) + { + return Response.AsJson(ModelValidationResult.SendJsonError()); + } + var notificationModel = new NotificationModel + { + NotificationType = NotificationType.Test, + DateTime = DateTime.Now + }; + try + { + NotificationService.Subscribe(new SlackNotification(SlackApi, SlackSettings)); + settings.Enabled = true; + NotificationService.Publish(notificationModel, settings); + Log.Info("Sent slack notification test"); + } + catch (Exception e) + { + Log.Error(e, "Failed to subscribe and publish test Slack Notification"); + } + finally + { + NotificationService.UnSubscribe(new SlackNotification(SlackApi, SlackSettings)); + } + return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully sent a test Slack Notification! If you do not receive it please check the logs." }); + } + + private Negotiator SlackNotifications() + { + var settings = SlackSettings.GetSettings(); + return View["SlackNotifications", settings]; + } + + private Response SaveSlackNotifications() + { + var settings = this.BindAndValidate(); + if (!ModelValidationResult.IsValid) + { + return Response.AsJson(ModelValidationResult.SendJsonError()); + } + + var result = SlackSettings.SaveSettings(settings); + if (settings.Enabled) + { + NotificationService.Subscribe(new SlackNotification(SlackApi, SlackSettings)); + } + else + { + NotificationService.UnSubscribe(new SlackNotification(SlackApi, SlackSettings)); + } + + Log.Info("Saved slack settings, result: {0}", result); + return Response.AsJson(result + ? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Slack Notifications!" } + : new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." }); + } } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/AdminNotificationsModule.cs b/PlexRequests.UI/Modules/AdminNotificationsModule.cs deleted file mode 100644 index 709759d2e..000000000 --- a/PlexRequests.UI/Modules/AdminNotificationsModule.cs +++ /dev/null @@ -1,130 +0,0 @@ -#region Copyright -// /************************************************************************ -// Copyright (c) 2016 Jamie Rees -// File: AdminNotificationsModule.cs -// Created By: Jamie Rees -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// ************************************************************************/ -#endregion -using System; - -using Nancy; -using Nancy.ModelBinding; -using Nancy.Responses.Negotiation; -using Nancy.Security; -using Nancy.Validation; - -using NLog; - -using PlexRequests.Api.Interfaces; -using PlexRequests.Core; -using PlexRequests.Core.SettingModels; -using PlexRequests.Helpers; -using PlexRequests.Services.Interfaces; -using PlexRequests.Services.Notification; -using PlexRequests.UI.Helpers; -using PlexRequests.UI.Models; - -namespace PlexRequests.UI.Modules -{ - public class AdminNotificationsModule : BaseModule - { - public AdminNotificationsModule(ISettingsService prService, ISettingsService slackSettings, - INotificationService notify, ISlackApi slackApi) : base("admin", prService) - { - this.RequiresClaims(UserClaims.Admin); - - SlackSettings = slackSettings; - NotificationService = notify; - SlackApi = slackApi; - - Post["/testslacknotification"] = _ => TestSlackNotification(); - - Get["/slacknotification"] = _ => SlackNotifications(); - Post["/slacknotification"] = _ => SaveSlackNotifications(); - } - private ISettingsService SlackSettings { get; } - private INotificationService NotificationService { get; } - private ISlackApi SlackApi { get; } - - private static Logger Log = LogManager.GetCurrentClassLogger(); - - private Response TestSlackNotification() - { - var settings = this.BindAndValidate(); - if (!ModelValidationResult.IsValid) - { - return Response.AsJson(ModelValidationResult.SendJsonError()); - } - var notificationModel = new NotificationModel - { - NotificationType = NotificationType.Test, - DateTime = DateTime.Now - }; - try - { - NotificationService.Subscribe(new SlackNotification(SlackApi,SlackSettings)); - settings.Enabled = true; - NotificationService.Publish(notificationModel, settings); - Log.Info("Sent slack notification test"); - } - catch (Exception e) - { - Log.Error(e,"Failed to subscribe and publish test Slack Notification"); - } - finally - { - NotificationService.UnSubscribe(new SlackNotification(SlackApi, SlackSettings)); - } - return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully sent a test Slack Notification! If you do not receive it please check the logs." }); - } - - private Negotiator SlackNotifications() - { - var settings = SlackSettings.GetSettings(); - return View["Admin/SlackNotifications", settings]; - } - - private Response SaveSlackNotifications() - { - var settings = this.BindAndValidate(); - if (!ModelValidationResult.IsValid) - { - return Response.AsJson(ModelValidationResult.SendJsonError()); - } - - var result = SlackSettings.SaveSettings(settings); - if (settings.Enabled) - { - NotificationService.Subscribe(new SlackNotification(SlackApi, SlackSettings)); - } - else - { - NotificationService.UnSubscribe(new SlackNotification(SlackApi, SlackSettings)); - } - - Log.Info("Saved slack settings, result: {0}", result); - return Response.AsJson(result - ? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Slack Notifications!" } - : new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." }); - } - } -} \ No newline at end of file diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 563edeb50..0029e9ed6 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -182,7 +182,6 @@ - From 47057b297d233f2e8fff92ebfce6200f6b851f44 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 25 May 2016 13:29:54 +0100 Subject: [PATCH 3/7] Fixed tests --- PlexRequests.UI.Tests/AdminModuleTests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/PlexRequests.UI.Tests/AdminModuleTests.cs b/PlexRequests.UI.Tests/AdminModuleTests.cs index 7850bbdb7..f563d13e7 100644 --- a/PlexRequests.UI.Tests/AdminModuleTests.cs +++ b/PlexRequests.UI.Tests/AdminModuleTests.cs @@ -73,6 +73,8 @@ namespace PlexRequests.UI.Tests private Mock NotificationService { get; set; } private Mock Cache { get; set; } private Mock> Log { get; set; } + private Mock> SlackSettings { get; set; } + private Mock SlackApi { get; set; } private ConfigurableBootstrapper Bootstrapper { get; set; } @@ -105,6 +107,8 @@ namespace PlexRequests.UI.Tests HeadphonesSettings = new Mock>(); Cache = new Mock(); Log = new Mock>(); + SlackApi = new Mock(); + SlackSettings = new Mock>(); Bootstrapper = new ConfigurableBootstrapper(with => { @@ -128,6 +132,8 @@ namespace PlexRequests.UI.Tests with.Dependency(HeadphonesSettings.Object); with.Dependency(Cache.Object); with.Dependency(Log.Object); + with.Dependency(SlackApi.Object); + with.Dependency(SlackSettings.Object); with.RootPathProvider(); with.RequestStartup((container, pipelines, context) => { From 78c5fe01f1d55a424a416bb2749dcde990a1927b Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 25 May 2016 14:01:23 +0100 Subject: [PATCH 4/7] Version bump --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 509cc2c82..08772ff6e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,9 +3,9 @@ configuration: Release assembly_info: patch: true file: '**\AssemblyInfo.*' - assembly_version: '1.7.3' + assembly_version: '1.7.4' assembly_file_version: '{version}' - assembly_informational_version: '1.7.3' + assembly_informational_version: '1.7.4' before_build: - cmd: appveyor-retry nuget restore build: From 3611eb5a85b12a2b2cf1be3e91a79175fb27a7bb Mon Sep 17 00:00:00 2001 From: Jamie Date: Wed, 25 May 2016 14:03:40 +0100 Subject: [PATCH 5/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f4e8cf5cf..0247d963a 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ If you feel like donating you can [here!](https://paypal.me/PlexRequestsNet) ## A massive thanks to everyone below for all their help! -[heartisall](https://github.com/heartisall), [Stuke00](https://github.com/Stuke00), [shiitake](https://github.com/shiitake), [Drewster727](https://github.com/Drewster727), Majawat, [EddiYo](https://github.com/EddiYo), [SaskiFX](https://github.com/SaskiFX) +[heartisall](https://github.com/heartisall), [Stuke00](https://github.com/Stuke00), [shiitake](https://github.com/shiitake), [Drewster727](https://github.com/Drewster727), Majawat, [EddiYo](https://github.com/EddiYo), [SaskiFX](https://github.com/SaskiFX), [zenjabba](https://github.com/zenjabba) ## Stats [![Throughput Graph](https://graphs.waffle.io/tidusjar/PlexRequests.Net/throughput.svg)](https://waffle.io/tidusjar/PlexRequests.Net/metrics/throughput) From 4c85522c2baec1dab30b76b59735f5aa4556f614 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 25 May 2016 14:09:07 +0100 Subject: [PATCH 6/7] fixed #428 --- PlexRequests.UI/Views/Admin/Sonarr.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PlexRequests.UI/Views/Admin/Sonarr.cshtml b/PlexRequests.UI/Views/Admin/Sonarr.cshtml index 56f14cb7e..7b7401795 100644 --- a/PlexRequests.UI/Views/Admin/Sonarr.cshtml +++ b/PlexRequests.UI/Views/Admin/Sonarr.cshtml @@ -98,7 +98,7 @@ { } - + From 3032c4fed3ea1be77e90c08a589fcae0d990467d Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 25 May 2016 14:16:21 +0100 Subject: [PATCH 7/7] fixed #252 --- PlexRequests.UI/Modules/RequestsModule.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PlexRequests.UI/Modules/RequestsModule.cs b/PlexRequests.UI/Modules/RequestsModule.cs index 020aab78d..f813c038d 100644 --- a/PlexRequests.UI/Modules/RequestsModule.cs +++ b/PlexRequests.UI/Modules/RequestsModule.cs @@ -357,7 +357,7 @@ namespace PlexRequests.UI.Modules private Response ClearIssue(int requestId) { - this.RequiresClaims (UserClaims.PowerUser, UserClaims.Admin); + this.RequiresClaims ( UserClaims.Admin); var originalRequest = Service.Get(requestId); if (originalRequest == null) @@ -375,7 +375,7 @@ namespace PlexRequests.UI.Modules private Response ChangeRequestAvailability(int requestId, bool available) { - this.RequiresClaims (UserClaims.PowerUser, UserClaims.Admin); + this.RequiresClaims (UserClaims.Admin); var originalRequest = Service.Get(requestId); if (originalRequest == null) { @@ -392,7 +392,7 @@ namespace PlexRequests.UI.Modules private Response AddNote(int requestId, string noteArea) { - this.RequiresClaims (UserClaims.PowerUser, UserClaims.Admin); + this.RequiresClaims (UserClaims.Admin); var originalRequest = Service.Get(requestId); if (originalRequest == null) {