diff --git a/PlexRequests.UI.Tests/ApiModuleTests.cs b/PlexRequests.UI.Tests/ApiModuleTests.cs index 05b443162..854616d93 100644 --- a/PlexRequests.UI.Tests/ApiModuleTests.cs +++ b/PlexRequests.UI.Tests/ApiModuleTests.cs @@ -26,9 +26,7 @@ #endregion using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; -using System.Runtime.InteropServices; using FluentValidation; @@ -45,7 +43,6 @@ using NUnit.Framework; using PlexRequests.Core; using PlexRequests.Core.SettingModels; -using PlexRequests.Helpers; using PlexRequests.Store; using PlexRequests.Store.Repository; using PlexRequests.UI.Models; @@ -71,6 +68,11 @@ namespace PlexRequests.UI.Tests var userRepoMock = new Mock>(); var mapperMock = new Mock(); var authSettingsMock = new Mock>(); + var plexSettingsMock = new Mock>(); + var cpMock = new Mock>(); + var sonarrMock = new Mock>(); + var sickRageMock = new Mock>(); + var headphonesMock = new Mock>(); var userModels = fixture.CreateMany().ToList(); userModels.Add(new UsersModel @@ -78,7 +80,7 @@ namespace PlexRequests.UI.Tests UserName = "user1" }); - settingsMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings {ApiKey = "api"}); + settingsMock.Setup(x => x.GetSettings()).Returns(new PlexRequestSettings { ApiKey = "api" }); requestMock.Setup(x => x.GetAll()).Returns(requests); requestMock.Setup(x => x.Get(1)).Returns(requests.FirstOrDefault()); requestMock.Setup(x => x.Get(99)).Returns(new RequestedModel()); @@ -92,6 +94,21 @@ namespace PlexRequests.UI.Tests authSettingsMock.Setup(x => x.SaveSettings(It.Is(c => c.PlexAuthToken.Equals("abc")))).Returns(true); + plexSettingsMock.Setup(x => x.GetSettings()).Returns(fixture.Create()); + plexSettingsMock.Setup(x => x.SaveSettings(It.Is(c => c.Ip.Equals("192")))).Returns(true); + + cpMock.Setup(x => x.GetSettings()).Returns(fixture.Create()); + cpMock.Setup(x => x.SaveSettings(It.Is(c => c.Ip.Equals("192")))).Returns(true); + + sonarrMock.Setup(x => x.GetSettings()).Returns(fixture.Create()); + sonarrMock.Setup(x => x.SaveSettings(It.Is(c => c.Ip.Equals("192")))).Returns(true); + + sickRageMock.Setup(x => x.GetSettings()).Returns(fixture.Create()); + sickRageMock.Setup(x => x.SaveSettings(It.Is(c => c.Ip.Equals("192")))).Returns(true); + + headphonesMock.Setup(x => x.GetSettings()).Returns(fixture.Create()); + headphonesMock.Setup(x => x.SaveSettings(It.Is(c => c.Ip.Equals("192")))).Returns(true); + Bootstrapper = new ConfigurableBootstrapper(with => { with.Module(); @@ -102,7 +119,12 @@ namespace PlexRequests.UI.Tests with.Dependency(settingsMock.Object); with.Dependency(userRepoMock.Object); with.Dependency(mapperMock.Object); + with.Dependency(headphonesMock.Object); with.Dependency(authSettingsMock.Object); + with.Dependency(plexSettingsMock.Object); + with.Dependency(cpMock.Object); + with.Dependency(sonarrMock.Object); + with.Dependency(sickRageMock.Object); with.RootPathProvider(); @@ -112,7 +134,7 @@ namespace PlexRequests.UI.Tests { new FluentValidationValidatorFactory( new DefaultFluentAdapterFactory(new List()), - new List { new RequestedModelValidator(), new UserViewModelValidator() }) + new List { new RequestedModelValidator(), new UserViewModelValidator(), new PlexValidator() }) })); }); } @@ -136,7 +158,7 @@ namespace PlexRequests.UI.Tests { with.HttpRequest(); with.Header("Accept", "application/json"); - with.Query("apikey","a"); + with.Query("apikey", "a"); }); Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); @@ -227,7 +249,7 @@ namespace PlexRequests.UI.Tests var result = browser.Post("/api/requests/", GetBrowser()); Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); - + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); Assert.That(body.Data, Is.Not.Null.Or.Empty); Assert.That(body.Error, Is.True); @@ -343,8 +365,8 @@ namespace PlexRequests.UI.Tests with.HttpRequest(); with.Header("Accept", "application/json"); with.Query("apikey", "api"); - with.Query("username","user1"); - with.Query("password","password"); + with.Query("username", "user1"); + with.Query("password", "password"); }); Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode)); @@ -405,6 +427,338 @@ namespace PlexRequests.UI.Tests Assert.That(body.ErrorMessage, Is.Null.Or.Empty); } + [Test] + public void GetPlexSettings() + { + var browser = new Browser(Bootstrapper); + var result = browser.Get("/api/settings/plex", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.Not.Null); + Assert.That(body.Error, Is.False); + Assert.That(body.ErrorMessage, Is.Null); + } + + [Test] + public void SavePlexSettings() + { + var model = new PlexSettings() + { + Port = 231, + Ip = "192", + Ssl = true, + }; + var browser = new Browser(Bootstrapper); + var result = browser.Post("/api/settings/plex", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + with.JsonBody(model); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.EqualTo(true)); + Assert.That(body.Error, Is.False); + Assert.That(body.ErrorMessage, Is.Null); + } + [Test] + public void SaveBadPlexSettings() + { + var model = new PlexSettings + { + Ip = "q", + Ssl = true, + }; + var browser = new Browser(Bootstrapper); + var result = browser.Post("/api/settings/plex", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + with.JsonBody(model); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.EqualTo(false)); + Assert.That(body.Error, Is.True); + Assert.That(body.ErrorMessage, Is.EqualTo("Could not update the settings")); + } + + [Test] + public void GetCpSettings() + { + var browser = new Browser(Bootstrapper); + var result = browser.Get("/api/settings/couchpotato", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.Not.Null); + Assert.That(body.Error, Is.False); + Assert.That(body.ErrorMessage, Is.Null); + } + + [Test] + public void SaveCpSettings() + { + var model = new CouchPotatoSettings + { + Port = 231, + Ip = "192", + Ssl = true, + }; + var browser = new Browser(Bootstrapper); + var result = browser.Post("/api/settings/couchpotato", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + with.JsonBody(model); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.EqualTo(true)); + Assert.That(body.Error, Is.False); + Assert.That(body.ErrorMessage, Is.Null); + } + [Test] + public void SaveBadCpSettings() + { + var model = new CouchPotatoSettings + { + Ip = "q", + Ssl = true, + }; + var browser = new Browser(Bootstrapper); + var result = browser.Post("/api/settings/couchpotato", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + with.JsonBody(model); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.EqualTo(false)); + Assert.That(body.Error, Is.True); + Assert.That(body.ErrorMessage, Is.EqualTo("Could not update the settings")); + } + + [Test] + public void GetSonarrSettings() + { + var browser = new Browser(Bootstrapper); + var result = browser.Get("/api/settings/sonarr", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.Not.Null); + Assert.That(body.Error, Is.False); + Assert.That(body.ErrorMessage, Is.Null); + } + + [Test] + public void SaveSonarrSettings() + { + var model = new SonarrSettings + { + Port = 231, + Ip = "192", + Ssl = true, + }; + var browser = new Browser(Bootstrapper); + var result = browser.Post("/api/settings/sonarr", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + with.JsonBody(model); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.EqualTo(true)); + Assert.That(body.Error, Is.False); + Assert.That(body.ErrorMessage, Is.Null); + } + [Test] + public void SaveBadSonarrSettings() + { + var model = new SonarrSettings + { + Ip = "q", + Ssl = true, + }; + var browser = new Browser(Bootstrapper); + var result = browser.Post("/api/settings/sonarr", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + with.JsonBody(model); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.EqualTo(false)); + Assert.That(body.Error, Is.True); + Assert.That(body.ErrorMessage, Is.EqualTo("Could not update the settings")); + } + + [Test] + public void GetSickRageSettings() + { + var browser = new Browser(Bootstrapper); + var result = browser.Get("/api/settings/sickrage", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.Not.Null); + Assert.That(body.Error, Is.False); + Assert.That(body.ErrorMessage, Is.Null); + } + + [Test] + public void SaveSickRageSettings() + { + var model = new SickRageSettings + { + Port = 231, + Ip = "192", + Ssl = true, + }; + var browser = new Browser(Bootstrapper); + var result = browser.Post("/api/settings/sickrage", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + with.JsonBody(model); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.EqualTo(true)); + Assert.That(body.Error, Is.False); + Assert.That(body.ErrorMessage, Is.Null); + } + [Test] + public void SaveBadSickRageSettings() + { + var model = new SickRageSettings + { + Ip = "q", + Ssl = true, + }; + var browser = new Browser(Bootstrapper); + var result = browser.Post("/api/settings/sickrage", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + with.JsonBody(model); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.EqualTo(false)); + Assert.That(body.Error, Is.True); + Assert.That(body.ErrorMessage, Is.EqualTo("Could not update the settings")); + } + + [Test] + public void GetHeadphonesSettings() + { + var browser = new Browser(Bootstrapper); + var result = browser.Get("/api/settings/headphones", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.Not.Null); + Assert.That(body.Error, Is.False); + Assert.That(body.ErrorMessage, Is.Null); + } + + [Test] + public void SaveHeadphonesSettings() + { + var model = new HeadphonesSettings + { + Port = 231, + Ip = "192", + Ssl = true, + }; + var browser = new Browser(Bootstrapper); + var result = browser.Post("/api/settings/headphones", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + with.JsonBody(model); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.EqualTo(true)); + Assert.That(body.Error, Is.False); + Assert.That(body.ErrorMessage, Is.Null); + } + [Test] + public void SaveBadHeadphonesSettings() + { + var model = new HeadphonesSettings + { + Ip = "q", + Ssl = true, + }; + var browser = new Browser(Bootstrapper); + var result = browser.Post("/api/settings/headphones", with => + { + with.HttpRequest(); + with.Header("Accept", "application/json"); + with.Query("apikey", "api"); + with.JsonBody(model); + }); + + var body = JsonConvert.DeserializeObject>(result.Body.AsString()); + + Assert.That(body.Data, Is.EqualTo(false)); + Assert.That(body.Error, Is.True); + Assert.That(body.ErrorMessage, Is.EqualTo("Could not update the settings")); + } + + + [TestCaseSource(nameof(AuthSettingsData))] public object SaveNewAuthSettings(object model) { diff --git a/PlexRequests.UI/ModelDataProviders/AuthSettingsDataProvider.cs b/PlexRequests.UI/ModelDataProviders/AuthSettingsDataProvider.cs new file mode 100644 index 000000000..70cbb91c7 --- /dev/null +++ b/PlexRequests.UI/ModelDataProviders/AuthSettingsDataProvider.cs @@ -0,0 +1,61 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: AuthSettingsDataProvider.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 Nancy.Swagger; +using Nancy.Swagger.Services; + +using PlexRequests.Core.SettingModels; + +namespace PlexRequests.UI.ModelDataProviders +{ + public class AuthSettingsDataProvider : ISwaggerModelDataProvider + { + /// + /// Gets the model data for the api documentation. + /// + /// + public SwaggerModelData GetModelData() + { + return SwaggerModelData.ForType( + with => + { + with.Property(x => x.DeniedUserList) + .Description("The blacklisted users, this is for internal use by the application, do not modify this list.") + .Required(false); + with.Property(x => x.DeniedUsers).Description("The blacklisted users, comma separated.").Required(false); + with.Property(x => x.PlexAuthToken).Description("The Plex authentication token").Required(false); + with.Property(x => x.UsePassword) + .Description("Require users to use a password to login when authentication is enabled") + .Required(false) + .Default(false); + with.Property(x => x.UserAuthentication) + .Description("Require users to enter their username in, this will check against Plex") + .Required(false) + .Default(false); + }); + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/ModelDataProviders/CouchPotatoDataProvider.cs b/PlexRequests.UI/ModelDataProviders/CouchPotatoDataProvider.cs new file mode 100644 index 000000000..2e7a82b56 --- /dev/null +++ b/PlexRequests.UI/ModelDataProviders/CouchPotatoDataProvider.cs @@ -0,0 +1,55 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: CouchPotatoDataProvider.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 Nancy.Swagger; +using Nancy.Swagger.Services; + +using PlexRequests.Core.SettingModels; + +namespace PlexRequests.UI.ModelDataProviders +{ + public class CouchPotatoDataProvider : ISwaggerModelDataProvider + { + /// + /// Gets the model data for the api documentation. + /// + /// + public SwaggerModelData GetModelData() + { + return SwaggerModelData.ForType( + with => + { + with.Property(x => x.Ip).Description("The IP address of CouchPotato").Required(true); + with.Property(x => x.Port).Description("The Port address of CouchPotato").Required(true).Default(5050); + with.Property(x => x.Ssl).Description("Enable SSL").Required(false).Default(false); + with.Property(x => x.FullUri).Description("Internal Property, do not use").Required(false).Default(null); + with.Property(x => x.SubDir).Description("Subdir/BaseUrl of CouchPotato").Required(false); + with.Property(x => x.ApiKey).Description("CouchPotato's API key").Required(true); + with.Property(x => x.ProfileId).Description("CouchPotato's profileId").Required(false); + }); + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/ModelDataProviders/HeadphonesDataProvider.cs b/PlexRequests.UI/ModelDataProviders/HeadphonesDataProvider.cs new file mode 100644 index 000000000..36f2acdbf --- /dev/null +++ b/PlexRequests.UI/ModelDataProviders/HeadphonesDataProvider.cs @@ -0,0 +1,54 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: HeadphonesDataProvider.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 Nancy.Swagger; +using Nancy.Swagger.Services; + +using PlexRequests.Core.SettingModels; + +namespace PlexRequests.UI.ModelDataProviders +{ + public class HeadphonesDataProvider : ISwaggerModelDataProvider + { + /// + /// Gets the model data for the api documentation. + /// + /// + public SwaggerModelData GetModelData() + { + return SwaggerModelData.ForType( + with => + { + with.Property(x => x.Ip).Description("The IP address of Headphones").Required(true); + with.Property(x => x.Port).Description("The Port address of Headphones").Required(true).Default(5050); + with.Property(x => x.Ssl).Description("Enable SSL").Required(false).Default(false); + with.Property(x => x.FullUri).Description("Internal Property, do not use").Required(false).Default(null); + with.Property(x => x.SubDir).Description("Subdir/BaseUrl of Headphones").Required(false); + with.Property(x => x.ApiKey).Description("Headphones's API key").Required(true); + }); + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/ModelDataProviders/PlexSettingsDataProvider.cs b/PlexRequests.UI/ModelDataProviders/PlexSettingsDataProvider.cs new file mode 100644 index 000000000..742114bdb --- /dev/null +++ b/PlexRequests.UI/ModelDataProviders/PlexSettingsDataProvider.cs @@ -0,0 +1,54 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: PlexSettingsDataProvider.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 Nancy.Swagger; +using Nancy.Swagger.Services; + +using PlexRequests.Core.SettingModels; + +namespace PlexRequests.UI.ModelDataProviders +{ + public class PlexSettingsDataProvider : ISwaggerModelDataProvider + { + /// + /// Gets the model data for the api documentation. + /// + /// + public SwaggerModelData GetModelData() + { + return SwaggerModelData.ForType( + with => + { + with.Property(x => x.Ip).Description("The IP address of the Plex Server").Required(true); + with.Property(x => x.Port).Description("The Port address of the Plex Server").Required(true).Default(32400); + with.Property(x => x.Ssl).Description("Enable SSL").Required(false).Default(false); + with.Property(x => x.FullUri).Description("Internal Property").Required(false); + + with.Property(x => x.SubDir).Description("Subdir/BaseUrl of Plex").Required(false); + }); + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/ModelDataProviders/RequestedModelDataProvider.cs b/PlexRequests.UI/ModelDataProviders/RequestedModelDataProvider.cs index efaac31ed..532097590 100644 --- a/PlexRequests.UI/ModelDataProviders/RequestedModelDataProvider.cs +++ b/PlexRequests.UI/ModelDataProviders/RequestedModelDataProvider.cs @@ -24,7 +24,6 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion -using System; using Nancy.Swagger; using Nancy.Swagger.Services; @@ -40,31 +39,34 @@ namespace PlexRequests.UI.ModelDataProviders /// public SwaggerModelData GetModelData() { - return SwaggerModelData.ForType(with => - { - with.Property(x => x.Title) - .Description("The requests title e.g. Star Wars Episode III") - .Required(true); - with.Property(x => x.AdminNote).Description("A note left by the administrator"); - with.Property(x => x.Approved).Description("true or false if the request is approved").Required(true).Default(false); - with.Property(x => x.ArtistId).Description("The artist ID (if this request is for Headphones then it is required)"); - with.Property(x => x.ArtistName).Description("The artist name (if this request is for Headphones then it is required)"); - with.Property(x => x.Available).Description("If the request is available on Plex").Default(false); - with.Property(x => x.CanApprove).Description("Ignore"); - with.Property(x => x.ImdbId).Description("The IMDB id of the request").Required(true); - with.Property(x => x.Issues) - .Description( - "The issue type, None = 99, WrongAudio = 0, NoSubtitles = 1, WrongContent = 2, PlaybackIssues = 3, Other = 4. Use Other(4) when leaving an issue note"); - with.Property(x => x.MusicBrainzId).Description("The MusicBrainz ID of the album request (if this request is for Headphones then it is required)"); - with.Property(x => x.OtherMessage) - .Description("The issue message left by the user. The Issues property needs to be set to Other (4) for this to work correctly"); - with.Property(x => x.PosterPath).Description("The poster path for the request").Required(true); - with.Property(x => x.ProviderId).Description("The TVMaze/TheMovieDB Id for the request depending if it's a movie request or Tv request").Required(true); - with.Property(x => x.ReleaseDate).Description("The release date of the request").Required(true); - with.Property(x => x.RequestedDate).Description("The date if the request, if this is not set, the request date will be set at the time of the Api call"); - with.Property(x => x.RequestedUsers).Description("A collection of the requested users").Required(true); - with.Property(x => x.Type).Description("The type of request: Movie = 0, TvShow = 1, Album = 2").Required(true); - }); + return SwaggerModelData.ForType( + with => + { + with.Property(x => x.Title).Description("The requests title e.g. Star Wars Episode III").Required(true); + with.Property(x => x.AdminNote).Description("A note left by the administrator"); + with.Property(x => x.Approved).Description("true or false if the request is approved").Required(true).Default(false); + with.Property(x => x.ArtistId).Description("The artist ID (if this request is for Headphones then it is required)"); + with.Property(x => x.ArtistName).Description("The artist name (if this request is for Headphones then it is required)"); + with.Property(x => x.Available).Description("If the request is available on Plex").Default(false); + with.Property(x => x.CanApprove).Description("Ignore"); + with.Property(x => x.ImdbId).Description("The IMDB id of the request").Required(true); + with.Property(x => x.Issues) + .Description( + "The issue type, None = 99, WrongAudio = 0, NoSubtitles = 1, WrongContent = 2, PlaybackIssues = 3, Other = 4. Use Other(4) when leaving an issue note"); + with.Property(x => x.MusicBrainzId).Description("The MusicBrainz ID of the album request (if this request is for Headphones then it is required)"); + with.Property(x => x.OtherMessage) + .Description("The issue message left by the user. The Issues property needs to be set to Other (4) for this to work correctly"); + with.Property(x => x.PosterPath).Description("The poster path for the request").Required(true); + with.Property(x => x.ProviderId) + .Description("The TVMaze/TheMovieDB Id for the request depending if it's a movie request or Tv request") + .Required(true); + with.Property(x => x.ReleaseDate).Description("The release date of the request").Required(true); + with.Property(x => x.RequestedDate) + .Description("The date if the request, if this is not set, the request date will be set at the time of the Api call"); + with.Property(x => x.RequestedUsers).Description("A collection of the requested users").Required(true); + with.Property(x => x.Type).Description("The type of request: Movie = 0, TvShow = 1, Album = 2").Required(true); + with.Property(x => x.Id).Description("The request Id (Only use for deleting)"); + }); } } } \ No newline at end of file diff --git a/PlexRequests.UI/ModelDataProviders/SickRageDataProvider.cs b/PlexRequests.UI/ModelDataProviders/SickRageDataProvider.cs new file mode 100644 index 000000000..8906a991f --- /dev/null +++ b/PlexRequests.UI/ModelDataProviders/SickRageDataProvider.cs @@ -0,0 +1,56 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SickRageDataProvider.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 Nancy.Swagger; +using Nancy.Swagger.Services; + +using PlexRequests.Core.SettingModels; + +namespace PlexRequests.UI.ModelDataProviders +{ + public class SickRageDataProvider : ISwaggerModelDataProvider + { + /// + /// Gets the model data for the api documentation. + /// + /// + public SwaggerModelData GetModelData() + { + return SwaggerModelData.ForType( + with => + { + with.Property(x => x.Ip).Description("The IP address of SickRage").Required(true); + with.Property(x => x.Port).Description("The Port address of SickRage").Required(true).Default(5050); + with.Property(x => x.Ssl).Description("Enable SSL").Required(false).Default(false); + with.Property(x => x.FullUri).Description("Internal Property").Required(false); + + with.Property(x => x.SubDir).Description("Subdir/BaseUrl of SickRage").Required(false); + with.Property(x => x.ApiKey).Description("SickRage's API key").Required(true); + with.Property(x => x.QualityProfile).Description("SickRage's quality profile").Required(false); + }); + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/ModelDataProviders/SonarrSettingsDataProvider.cs b/PlexRequests.UI/ModelDataProviders/SonarrSettingsDataProvider.cs new file mode 100644 index 000000000..b1019eb58 --- /dev/null +++ b/PlexRequests.UI/ModelDataProviders/SonarrSettingsDataProvider.cs @@ -0,0 +1,60 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SonarrSettingsDataProvider.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 Nancy.Swagger; +using Nancy.Swagger.Services; + +using PlexRequests.Core.SettingModels; + +namespace PlexRequests.UI.ModelDataProviders +{ + public class SonarrSettingsDataProvider : ISwaggerModelDataProvider + { + /// + /// Gets the model data for the api documentation. + /// + /// + public SwaggerModelData GetModelData() + { + return SwaggerModelData.ForType( + with => + { + with.Property(x => x.Ip).Description("The IP address of Sonarr").Required(true); + with.Property(x => x.Port).Description("The Port address of Sonarr").Required(true).Default(5050); + with.Property(x => x.Ssl).Description("Enable SSL").Required(false).Default(false); + with.Property(x => x.FullUri).Description("Internal Property").Required(false); + + with.Property(x => x.SubDir).Description("Subdir/BaseUrl of Sonarr").Required(false); + with.Property(x => x.ApiKey).Description("Sonarr's API key").Required(true); + with.Property(x => x.QualityProfile).Description("Sonarr's quality profile").Required(true); + + with.Property(x => x.SeasonFolders).Description("Sonarr's season folders").Required(false); + + with.Property(x => x.RootPath).Description("Sonarr's root path").Required(false); + }); + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/ModelDataProviders/UserUpdateViewModel.cs b/PlexRequests.UI/ModelDataProviders/UserUpdateViewModelDataProvider.cs similarity index 74% rename from PlexRequests.UI/ModelDataProviders/UserUpdateViewModel.cs rename to PlexRequests.UI/ModelDataProviders/UserUpdateViewModelDataProvider.cs index 4c626a555..5f9823496 100644 --- a/PlexRequests.UI/ModelDataProviders/UserUpdateViewModel.cs +++ b/PlexRequests.UI/ModelDataProviders/UserUpdateViewModelDataProvider.cs @@ -1,7 +1,7 @@ #region Copyright // /************************************************************************ // Copyright (c) 2016 Jamie Rees -// File: RequestedModelDataProvider.cs +// File: UserUpdateViewModelDataProvider.cs // Created By: Jamie Rees // // Permission is hereby granted, free of charge, to any person obtaining @@ -24,15 +24,14 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion -using System; using Nancy.Swagger; using Nancy.Swagger.Services; -using PlexRequests.Store; +using PlexRequests.UI.Models; namespace PlexRequests.UI.ModelDataProviders { - public class UserUpdateViewModel : ISwaggerModelDataProvider + public class UserUpdateViewModelDataProvider : ISwaggerModelDataProvider { /// /// Gets the model data for the api documentation. @@ -40,16 +39,13 @@ namespace PlexRequests.UI.ModelDataProviders /// public SwaggerModelData GetModelData() { - return SwaggerModelData.ForType(with => - { - with.Property(x => x.CurrentPassword) - .Description("The users current password") - .Required(true); + return SwaggerModelData.ForType( + with => + { + with.Property(x => x.CurrentPassword).Description("The users current password").Required(true); - with.Property(x => x.NewPassword) - .Description("The users new password that we will change it to") - .Required(true); - }); + with.Property(x => x.NewPassword).Description("The users new password that we will change it to").Required(true); + }); } } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/ApiSettingsMetadataModule.cs b/PlexRequests.UI/Modules/ApiSettingsMetadataModule.cs index ee12514a8..7bb88faaa 100644 --- a/PlexRequests.UI/Modules/ApiSettingsMetadataModule.cs +++ b/PlexRequests.UI/Modules/ApiSettingsMetadataModule.cs @@ -55,6 +55,101 @@ namespace PlexRequests.UI.Modules with.Notes("Saves the authentication settings saved in the application"); }); + Describe["GetPlexSettings"] = description => description.AsSwagger(with => + { + with.ResourcePath("/settings/plex"); + with.Summary("Gets the Plex settings saved in the application"); + with.Model>(); + with.Notes("Gets the Plex settings saved in the application"); + with.QueryParam("apikey", "The Api Key found in the settings", true); + }); + + Describe["PostPlexSettings"] = description => description.AsSwagger(with => + { + with.ResourcePath("/settings/plex"); + with.Summary("Saves the Plex settings saved in the application"); + with.Model>(); + with.QueryParam("apikey", "The Api Key found in the settings", true); + with.BodyParam("Plex settings", true); + with.Notes("Saves the Plex settings saved in the application"); + }); + + + Describe["GetCouchPotatoSettings"] = description => description.AsSwagger(with => + { + with.ResourcePath("/settings/couchpotato"); + with.Summary("Gets the CouchPotato settings saved in the application"); + with.Model>(); + with.Notes("Gets the CouchPotato settings saved in the application"); + with.QueryParam("apikey", "The Api Key found in the settings", true); + }); + + Describe["PostCouchPotatoSettings"] = description => description.AsSwagger(with => + { + with.ResourcePath("/settings/couchpotato"); + with.Summary("Saves the CouchPotato settings saved in the application"); + with.Model>(); + with.QueryParam("apikey", "The Api Key found in the settings", true); + with.BodyParam("CouchPotato settings", true); + with.Notes("Saves the CouchPotato settings saved in the application"); + }); + + Describe["GetSonarrSettings"] = description => description.AsSwagger(with => + { + with.ResourcePath("/settings/sonarr"); + with.Summary("Gets the sonarr settings saved in the application"); + with.Model>(); + with.Notes("Gets the sonarr settings saved in the application"); + with.QueryParam("apikey", "The Api Key found in the settings", true); + }); + + Describe["PostSonarrSettings"] = description => description.AsSwagger(with => + { + with.ResourcePath("/settings/sonarr"); + with.Summary("Saves the sonarr settings saved in the application"); + with.Model>(); + with.QueryParam("apikey", "The Api Key found in the settings", true); + with.BodyParam("sonarr settings", true); + with.Notes("Saves the sonarr settings saved in the application"); + }); + + Describe["GetSickRageSettings"] = description => description.AsSwagger(with => + { + with.ResourcePath("/settings/sickrage"); + with.Summary("Gets the SickRage settings saved in the application"); + with.Model>(); + with.Notes("Gets the SickRage settings saved in the application"); + with.QueryParam("apikey", "The Api Key found in the settings", true); + }); + + Describe["PostSickRageSettings"] = description => description.AsSwagger(with => + { + with.ResourcePath("/settings/sickrage"); + with.Summary("Saves the SickRage settings saved in the application"); + with.Model>(); + with.QueryParam("apikey", "The Api Key found in the settings", true); + with.BodyParam("SickRage settings", true); + with.Notes("Saves the sickrage settings saved in the application"); + }); + + Describe["GetHeadphonesSettings"] = description => description.AsSwagger(with => + { + with.ResourcePath("/settings/headphones"); + with.Summary("Gets the headphones settings saved in the application"); + with.Model>(); + with.Notes("Gets the headphones settings saved in the application"); + with.QueryParam("apikey", "The Api Key found in the settings", true); + }); + + Describe["PostHeadphonesSettings"] = description => description.AsSwagger(with => + { + with.ResourcePath("/settings/sickrage"); + with.Summary("Saves the headphones settings saved in the application"); + with.Model>(); + with.QueryParam("apikey", "The Api Key found in the settings", true); + with.BodyParam("headphones settings", true); + with.Notes("Saves the headphones settings saved in the application"); + }); } } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/ApiSettingsModule.cs b/PlexRequests.UI/Modules/ApiSettingsModule.cs index f0f50eb07..984986399 100644 --- a/PlexRequests.UI/Modules/ApiSettingsModule.cs +++ b/PlexRequests.UI/Modules/ApiSettingsModule.cs @@ -24,6 +24,8 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion +using System.Web.UI.WebControls; + using Nancy; using Nancy.ModelBinding; @@ -34,19 +36,46 @@ namespace PlexRequests.UI.Modules { public class ApiSettingsModule : BaseApiModule { - public ApiSettingsModule(ISettingsService pr, ISettingsService auth) : base("api", pr) + public ApiSettingsModule(ISettingsService pr, ISettingsService auth, + ISettingsService plexSettings, ISettingsService cp, + ISettingsService sonarr, ISettingsService sr, ISettingsService hp) : base("api", pr) { Get["GetAuthSettings","/settings/authentication"] = x => GetAuthSettings(); Post["PostAuthSettings","/settings/authentication"] = x => PostAuthSettings(); + Get["GetPlexSettings", "/settings/plex"] = x => GetPlexSettings(); + Post["PostPlexSettings", "/settings/plex"] = x => PostPlexSettings(); + + Get["GetCouchPotatoSettings", "/settings/couchpotato"] = x => GetCpSettings(); + Post["PostCouchPotatoSettings", "/settings/couchpotato"] = x => PostCpSettings(); + + Get["GetSonarrSettings", "/settings/sonarr"] = x => GetSonarrSettings(); + Post["PostSonarrSettings", "/settings/sonarr"] = x => PostSonarrSettings(); + + Get["GetSickRageSettings", "/settings/sickrage"] = x => GetSickRageSettings(); + Post["PostSickRageSettings", "/settings/sickrage"] = x => PostSickRageSettings(); + + Get["GetHeadphonesSettings", "/settings/headphones"] = x => GetHeadphonesSettings(); + Post["PostHeadphonesSettings", "/settings/headphones"] = x => PostHeadphonesSettings(); + SettingsService = pr; AuthSettings = auth; + PlexSettings = plexSettings; + CpSettings = cp; + SonarrSettings = sonarr; + SickRageSettings = sr; + HeadphonesSettings = hp; } private ISettingsService SettingsService { get; } private ISettingsService AuthSettings { get; } + private ISettingsService PlexSettings { get; } + private ISettingsService CpSettings { get; } + private ISettingsService SonarrSettings { get; } + private ISettingsService SickRageSettings { get; } + private ISettingsService HeadphonesSettings { get; } - public Response GetAuthSettings() + private Response GetAuthSettings() { var model = new ApiModel(); var settings = AuthSettings.GetSettings(); @@ -54,7 +83,7 @@ namespace PlexRequests.UI.Modules return ReturnReponse(model); } - public Response PostAuthSettings() + private Response PostAuthSettings() { var newSettings = this.BindAndValidate(); if (!ModelValidationResult.IsValid) @@ -73,7 +102,150 @@ namespace PlexRequests.UI.Modules model.Error = true; model.ErrorMessage = "Could not update the settings"; return ReturnReponse(model); - } + } + + private Response GetPlexSettings() + { + var model = new ApiModel(); + var settings = PlexSettings.GetSettings(); + model.Data = settings; + return ReturnReponse(model); + } + + private Response PostPlexSettings() + { + var newSettings = this.BindAndValidate(); + if (!ModelValidationResult.IsValid) + { + return ReturnValidationReponse(ModelValidationResult); + } + + var model = new ApiModel(); + var settings = PlexSettings.SaveSettings(newSettings); + if (settings) + { + model.Data = true; + return ReturnReponse(model); + } + + model.Error = true; + model.ErrorMessage = "Could not update the settings"; + return ReturnReponse(model); + } + + private Response GetCpSettings() + { + var model = new ApiModel(); + var settings = CpSettings.GetSettings(); + model.Data = settings; + return ReturnReponse(model); + } + + private Response PostCpSettings() + { + var newSettings = this.BindAndValidate(); + if (!ModelValidationResult.IsValid) + { + return ReturnValidationReponse(ModelValidationResult); + } + + var model = new ApiModel(); + var settings = CpSettings.SaveSettings(newSettings); + if (settings) + { + model.Data = true; + return ReturnReponse(model); + } + + model.Error = true; + model.ErrorMessage = "Could not update the settings"; + return ReturnReponse(model); + } + + private Response GetSonarrSettings() + { + var model = new ApiModel(); + var settings = SonarrSettings.GetSettings(); + model.Data = settings; + return ReturnReponse(model); + } + + private Response PostSonarrSettings() + { + var newSettings = this.BindAndValidate(); + if (!ModelValidationResult.IsValid) + { + return ReturnValidationReponse(ModelValidationResult); + } + + var model = new ApiModel(); + var settings = SonarrSettings.SaveSettings(newSettings); + if (settings) + { + model.Data = true; + return ReturnReponse(model); + } + + model.Error = true; + model.ErrorMessage = "Could not update the settings"; + return ReturnReponse(model); + } + + private Response GetSickRageSettings() + { + var model = new ApiModel(); + var settings = SickRageSettings.GetSettings(); + model.Data = settings; + return ReturnReponse(model); + } + + private Response PostSickRageSettings() + { + var newSettings = this.BindAndValidate(); + if (!ModelValidationResult.IsValid) + { + return ReturnValidationReponse(ModelValidationResult); + } + + var model = new ApiModel(); + var settings = SickRageSettings.SaveSettings(newSettings); + if (settings) + { + model.Data = true; + return ReturnReponse(model); + } + + model.Error = true; + model.ErrorMessage = "Could not update the settings"; + return ReturnReponse(model); + } + private Response GetHeadphonesSettings() + { + var model = new ApiModel(); + var settings = HeadphonesSettings.GetSettings(); + model.Data = settings; + return ReturnReponse(model); + } + + private Response PostHeadphonesSettings() + { + var newSettings = this.BindAndValidate(); + if (!ModelValidationResult.IsValid) + { + return ReturnValidationReponse(ModelValidationResult); + } + var model = new ApiModel(); + var settings = HeadphonesSettings.SaveSettings(newSettings); + if (settings) + { + model.Data = true; + return ReturnReponse(model); + } + + model.Error = true; + model.ErrorMessage = "Could not update the settings"; + return ReturnReponse(model); + } } } \ No newline at end of file diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 0abadf609..de8c6f870 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -165,7 +165,13 @@ - + + + + + + + diff --git a/PlexRequests.UI/Validators/PlexRequestsValidator.cs b/PlexRequests.UI/Validators/PlexRequestsValidator.cs index 416a099bf..6f8ba4d3e 100644 --- a/PlexRequests.UI/Validators/PlexRequestsValidator.cs +++ b/PlexRequests.UI/Validators/PlexRequestsValidator.cs @@ -1,28 +1,50 @@ -using System; +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: PlexRequestsValidator.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 FluentValidation; + using PlexRequests.Core.SettingModels; -namespace PlexRequests.UI +namespace PlexRequests.UI.Validators { - public class PlexRequestsValidator : AbstractValidator - { - public PlexRequestsValidator () - { - RuleFor (x => x.BaseUrl).NotEqual ("requests").WithMessage ("You cannot use 'requests' as this is reserved by the application."); - RuleFor (x => x.BaseUrl).NotEqual ("admin").WithMessage ("You cannot use 'admin' as this is reserved by the application."); - RuleFor (x => x.BaseUrl).NotEqual ("search").WithMessage ("You cannot use 'search' as this is reserved by the application."); - RuleFor (x => x.BaseUrl).NotEqual ("issues").WithMessage ("You cannot use 'issues' as this is reserved by the application."); - RuleFor (x => x.BaseUrl).NotEqual ("userlogin").WithMessage ("You cannot use 'userlogin' as this is reserved by the application."); - RuleFor (x => x.BaseUrl).NotEqual ("login").WithMessage ("You cannot use 'login' as this is reserved by the application."); - RuleFor (x => x.BaseUrl).NotEqual ("test").WithMessage ("You cannot use 'test' as this is reserved by the application."); - RuleFor (x => x.BaseUrl).NotEqual ("approval").WithMessage ("You cannot use 'approval' as this is reserved by the application."); - RuleFor (x => x.BaseUrl).NotEqual ("updatechecker").WithMessage ("You cannot use 'updatechecker' as this is reserved by the application."); - RuleFor (x => x.BaseUrl).NotEqual ("usermanagement").WithMessage ("You cannot use 'usermanagement' as this is reserved by the application."); - RuleFor (x => x.BaseUrl).NotEqual ("api").WithMessage ("You cannot use 'api' as this is reserved by the application."); - - - - } - } -} - + public class PlexRequestsValidator : AbstractValidator + { + public PlexRequestsValidator() + { + RuleFor(x => x.BaseUrl).NotEqual("requests").WithMessage("You cannot use 'requests' as this is reserved by the application."); + RuleFor(x => x.BaseUrl).NotEqual("admin").WithMessage("You cannot use 'admin' as this is reserved by the application."); + RuleFor(x => x.BaseUrl).NotEqual("search").WithMessage("You cannot use 'search' as this is reserved by the application."); + RuleFor(x => x.BaseUrl).NotEqual("issues").WithMessage("You cannot use 'issues' as this is reserved by the application."); + RuleFor(x => x.BaseUrl).NotEqual("userlogin").WithMessage("You cannot use 'userlogin' as this is reserved by the application."); + RuleFor(x => x.BaseUrl).NotEqual("login").WithMessage("You cannot use 'login' as this is reserved by the application."); + RuleFor(x => x.BaseUrl).NotEqual("test").WithMessage("You cannot use 'test' as this is reserved by the application."); + RuleFor(x => x.BaseUrl).NotEqual("approval").WithMessage("You cannot use 'approval' as this is reserved by the application."); + RuleFor(x => x.BaseUrl).NotEqual("updatechecker").WithMessage("You cannot use 'updatechecker' as this is reserved by the application."); + RuleFor(x => x.BaseUrl).NotEqual("usermanagement").WithMessage("You cannot use 'usermanagement' as this is reserved by the application."); + RuleFor(x => x.BaseUrl).NotEqual("api").WithMessage("You cannot use 'api' as this is reserved by the application."); + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/Validators/PlexValidator.cs b/PlexRequests.UI/Validators/PlexValidator.cs index a686b1b62..53f541855 100644 --- a/PlexRequests.UI/Validators/PlexValidator.cs +++ b/PlexRequests.UI/Validators/PlexValidator.cs @@ -34,8 +34,8 @@ namespace PlexRequests.UI.Validators { public PlexValidator() { - RuleFor(request => request.Ip).NotEmpty().WithMessage("You must specify a IP/Host name."); - RuleFor(request => request.Port).NotEmpty().WithMessage("You must specify a Port."); + RuleFor(request => request.Ip).NotNull().WithMessage("You must specify a IP/Host name."); + RuleFor(request => request.Port).NotNull().WithMessage("You must specify a Port."); } } } \ No newline at end of file