From 263240c648a69caccd37279aaeefba96d9bd33e4 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Thu, 6 Jul 2017 16:24:51 +0100 Subject: [PATCH] Lot's of refactoring --- src/Ombi.Core.Tests/DbHelper.cs | 16 +- .../Engine/MovieRequestEngineTests.cs | 198 +++++++-------- .../Engine/TvRequestEngineTests.cs | 83 +++--- .../Rule/Request/AutoApproveRuleTests.cs | 175 +++++++------ .../Rule/Request/CanRequestRuleTests.cs | 141 +++++------ .../Rule/Search/ExistingRequestRuleTests.cs | 238 ++++++++++-------- src/Ombi.Core/Engine/BaseMediaEngine.cs | 2 +- src/Ombi.Core/Engine/Interfaces/BaseEngine.cs | 7 +- .../Engine/Interfaces/IMovieEngine.cs | 3 +- src/Ombi.Core/Engine/MovieRequestEngine.cs | 105 +++----- src/Ombi.Core/Engine/MovieSearchEngine.cs | 105 +++----- src/Ombi.Core/Engine/TvRequestEngine.cs | 42 +--- src/Ombi.Core/Engine/TvSearchEngine.cs | 2 +- src/Ombi.Core/Rule/BaseRequestRule.cs | 2 +- .../Rule/Interfaces/IRuleEvaluator.cs | 7 +- .../{IRequestRules.cs => IRules.cs} | 2 +- .../Rule/Interfaces/ISpecificRule.cs | 11 + .../Rule/Interfaces/SpecificRules.cs | 7 + src/Ombi.Core/Rule/RuleEvaluator.cs | 97 ++++--- .../Rule/Rules/Request/AutoApproveRule.cs | 2 +- .../Rule/Rules/Request/CanRequestRule.cs | 2 +- .../Rules/Request/ExistingMovieRequestRule.cs | 39 +++ .../Rule/Rules/Search/ExistingRequestRule.cs | 50 ---- .../Rule/Rules/Search/ExistingRule.cs | 48 ++++ .../Rule/Rules/Search/PlexAvailabilityRule.cs | 2 +- .../Rule/Rules/Search/RadarrCacheRule.cs | 2 +- .../Rule/Rules/Specific/CanRequestRule.cs | 32 +++ src/Ombi.Core/Rule/SpecificRule.cs | 19 ++ src/Ombi.DependencyInjection/IocExtensions.cs | 2 +- src/Ombi.Helpers/RuleNotFoundException.cs | 12 + .../Entities/Requests/BaseRequest.cs | 2 +- .../Entities/Requests/FullBaseRequest.cs | 1 - .../Migrations/20170703134019_Initial.cs | 3 +- .../ClientApp/app/services/search.service.ts | 3 - .../notificationtemplate.component.ts | 2 +- src/Ombi/Controllers/SearchController.cs | 12 - 36 files changed, 774 insertions(+), 702 deletions(-) rename src/Ombi.Core/Rule/Interfaces/{IRequestRules.cs => IRules.cs} (73%) create mode 100644 src/Ombi.Core/Rule/Interfaces/ISpecificRule.cs create mode 100644 src/Ombi.Core/Rule/Interfaces/SpecificRules.cs create mode 100644 src/Ombi.Core/Rule/Rules/Request/ExistingMovieRequestRule.cs delete mode 100644 src/Ombi.Core/Rule/Rules/Search/ExistingRequestRule.cs create mode 100644 src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs create mode 100644 src/Ombi.Core/Rule/Rules/Specific/CanRequestRule.cs create mode 100644 src/Ombi.Core/Rule/SpecificRule.cs create mode 100644 src/Ombi.Helpers/RuleNotFoundException.cs diff --git a/src/Ombi.Core.Tests/DbHelper.cs b/src/Ombi.Core.Tests/DbHelper.cs index 26e93eee6..11ec52011 100644 --- a/src/Ombi.Core.Tests/DbHelper.cs +++ b/src/Ombi.Core.Tests/DbHelper.cs @@ -1,4 +1,8 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Moq; @@ -18,5 +22,15 @@ namespace Ombi.Core.Tests return dbSet.Object; } + + public static IQueryable GetQueryable(params T[] sourceList) where T : class + { + var mock = new Mock>(); + + mock.As>().Setup(x => x.ToListAsync(It.IsAny())).ReturnsAsync(sourceList.ToList()); + + return mock.Object; + + } } } \ No newline at end of file diff --git a/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs b/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs index 5b2316412..d9d7c932f 100644 --- a/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs +++ b/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs @@ -4,8 +4,8 @@ //using Moq; //using Ombi.Core.Engine; //using Ombi.Core.Models.Requests; -//using Ombi.Core.Models.Requests.Movie; -//using Ombi.Core.Requests.Models; +//using Ombi.Store.Entities.Requests; +//using Ombi.Store.Repository; //using Xunit; //namespace Ombi.Core.Tests.Engine @@ -14,118 +14,120 @@ // { // public MovieRequestEngineTests() // { -// RequestService = new Mock>(); +// RequestService = new Mock(); // var requestService = new RequestService(null, RequestService.Object); -// Engine = new MovieRequestEngine(null, requestService, null, null, null, null, null); +// Engine = new MovieRequestEngine(null, requestService, null, null, null, null, null, null); // } // private MovieRequestEngine Engine { get; } -// private Mock> RequestService { get; } +// private Mock RequestService { get; } // [Fact] // public async Task GetNewRequests_Should_ReturnEmpty_WhenThereAreNoNewRequests() // { -// var requests = new List +// var requests = new List // { -// new MovieRequestModel { Available = true }, -// new MovieRequestModel { Approved = true }, +// new MovieRequests { Available = true }, +// new MovieRequests { Approved = true }, // }; -// RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); -// var result = await Engine.GetNewRequests(); - -// Assert.False(result.Any()); -// } - -// [Fact] -// public async Task GetNewRequests_Should_ReturnOnlyNewRequests_WhenThereAreMultipleRequests() -// { -// var requests = new List -// { -// new MovieRequestModel { Available = true }, -// new MovieRequestModel { Approved = true }, -// new MovieRequestModel(), -// }; -// RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); +// var r = DbHelper.GetQueryable(requests[0], requests[1]); +// RequestService.Setup(x => x.Get()).Returns(r); // var result = await Engine.GetNewRequests(); -// Assert.Equal(result.Count(), 1); -// Assert.All(result, x => -// { -// Assert.Equal(x.Available, false); -// Assert.Equal(x.Approved, false); -// }); -// } - -// [Fact] -// public async Task GetApprovedRequests_Should_ReturnEmpty_WhenThereAreNoApprovedRequests() -// { -// var requests = new List -// { -// new MovieRequestModel { Available = true }, -// }; -// RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); - -// var result = await Engine.GetApprovedRequests(); - -// Assert.False(result.Any()); -// } - -// [Fact] -// public async Task GetApprovedRequests_Should_ReturnOnlyApprovedRequests_WhenThereAreMultipleRequests() -// { -// var requests = new List -// { -// new MovieRequestModel { Available = true }, -// new MovieRequestModel { Approved = true }, -// new MovieRequestModel(), -// }; -// RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); - -// var result = await Engine.GetApprovedRequests(); - -// Assert.Equal(result.Count(), 1); -// Assert.All(result, x => -// { -// Assert.Equal(x.Available, false); -// Assert.Equal(x.Approved, true); -// }); -// } - -// [Fact] -// public async Task GetAvailableRequests_Should_ReturnEmpty_WhenThereAreNoAvailableRequests() -// { -// var requests = new List -// { -// new MovieRequestModel { Approved = true }, -// }; -// RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); - -// var result = await Engine.GetAvailableRequests(); - // Assert.False(result.Any()); // } -// [Fact] -// public async Task GetAvailableRequests_Should_ReturnOnlyAvailableRequests_WhenThereAreMultipleRequests() -// { -// var requests = new List -// { -// new MovieRequestModel { Available = true }, -// new MovieRequestModel { Approved = true }, -// new MovieRequestModel(), -// }; -// RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); - -// var result = await Engine.GetAvailableRequests(); - -// Assert.Equal(result.Count(), 1); -// Assert.All(result, x => -// { -// Assert.Equal(x.Available, true); -// Assert.Equal(x.Approved, false); -// }); -// } +// //[Fact] +// //public async Task GetNewRequests_Should_ReturnOnlyNewRequests_WhenThereAreMultipleRequests() +// //{ +// // var requests = new List +// // { +// // new MovieRequestModel { Available = true }, +// // new MovieRequestModel { Approved = true }, +// // new MovieRequestModel(), +// // }; +// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); + +// // var result = await Engine.GetNewRequests(); + +// // Assert.Equal(result.Count(), 1); +// // Assert.All(result, x => +// // { +// // Assert.Equal(x.Available, false); +// // Assert.Equal(x.Approved, false); +// // }); +// //} + +// //[Fact] +// //public async Task GetApprovedRequests_Should_ReturnEmpty_WhenThereAreNoApprovedRequests() +// //{ +// // var requests = new List +// // { +// // new MovieRequestModel { Available = true }, +// // }; +// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); + +// // var result = await Engine.GetApprovedRequests(); + +// // Assert.False(result.Any()); +// //} + +// //[Fact] +// //public async Task GetApprovedRequests_Should_ReturnOnlyApprovedRequests_WhenThereAreMultipleRequests() +// //{ +// // var requests = new List +// // { +// // new MovieRequestModel { Available = true }, +// // new MovieRequestModel { Approved = true }, +// // new MovieRequestModel(), +// // }; +// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); + +// // var result = await Engine.GetApprovedRequests(); + +// // Assert.Equal(result.Count(), 1); +// // Assert.All(result, x => +// // { +// // Assert.Equal(x.Available, false); +// // Assert.Equal(x.Approved, true); +// // }); +// //} + +// //[Fact] +// //public async Task GetAvailableRequests_Should_ReturnEmpty_WhenThereAreNoAvailableRequests() +// //{ +// // var requests = new List +// // { +// // new MovieRequestModel { Approved = true }, +// // }; +// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); + +// // var result = await Engine.GetAvailableRequests(); + +// // Assert.False(result.Any()); +// //} + +// //[Fact] +// //public async Task GetAvailableRequests_Should_ReturnOnlyAvailableRequests_WhenThereAreMultipleRequests() +// //{ +// // var requests = new List +// // { +// // new MovieRequestModel { Available = true }, +// // new MovieRequestModel { Approved = true }, +// // new MovieRequestModel(), +// // }; +// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); + +// // var result = await Engine.GetAvailableRequests(); + +// // Assert.Equal(result.Count(), 1); +// // Assert.All(result, x => +// // { +// // Assert.Equal(x.Available, true); +// // Assert.Equal(x.Approved, false); +// // }); +// //} // } //} \ No newline at end of file diff --git a/src/Ombi.Core.Tests/Engine/TvRequestEngineTests.cs b/src/Ombi.Core.Tests/Engine/TvRequestEngineTests.cs index 13776a6b2..48c7b995d 100644 --- a/src/Ombi.Core.Tests/Engine/TvRequestEngineTests.cs +++ b/src/Ombi.Core.Tests/Engine/TvRequestEngineTests.cs @@ -1,11 +1,10 @@ //using System.Collections.Generic; -//using System.Linq; //using System.Threading.Tasks; //using Moq; //using Ombi.Core.Engine; //using Ombi.Core.Models.Requests; -//using Ombi.Core.Models.Requests.Tv; -//using Ombi.Core.Requests.Models; +//using Ombi.Store.Entities.Requests; +//using Ombi.Store.Repository.Requests; //using Xunit; //namespace Ombi.Core.Tests.Engine @@ -14,49 +13,49 @@ // { // public TvRequestEngineTests() // { -// RequestService = new Mock>(); +// RequestService = new Mock(); // var requestService = new RequestService(RequestService.Object, null); -// Engine = new TvRequestEngine(null, requestService, null, null, null, null); +// Engine = new TvRequestEngine(null, requestService, null, null, null, null, null, null); // } // private TvRequestEngine Engine { get; } -// private Mock> RequestService { get; } - -// [Fact] -// public async Task GetNewRequests_Should_ReturnEmpty_WhenThereAreNoNewRequests() -// { -// var requests = new List -// { -// new TvRequestModel { Available = true }, -// new TvRequestModel { Approved = true }, -// }; -// RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); - -// var result = await Engine.GetNewRequests(); - -// Assert.False(result.Any()); -// } - -// [Fact] -// public async Task GetNewRequests_Should_ReturnOnlyNewRequests_WhenThereAreMultipleRequests() -// { -// var requests = new List -// { -// new TvRequestModel { Available = true }, -// new TvRequestModel { Approved = true }, -// new TvRequestModel(), -// }; -// RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); - -// var result = await Engine.GetNewRequests(); - -// Assert.Equal(result.Count(), 1); -// Assert.All(result, x => -// { -// Assert.Equal(x.Available, false); -// Assert.Equal(x.Approved, false); -// }); -// } +// private Mock RequestService { get; } + +// //[Fact] +// //public async Task GetNewRequests_Should_ReturnEmpty_WhenThereAreNoNewRequests() +// //{ +// // var requests = new List +// // { +// // new TvRequests { Available = true }, +// // new TvRequests { Approved = true }, +// // }; +// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); + +// // var result = await Engine.GetNewRequests(); + +// // Assert.False(result.Any()); +// //} + +// //[Fact] +// //public async Task GetNewRequests_Should_ReturnOnlyNewRequests_WhenThereAreMultipleRequests() +// //{ +// // var requests = new List +// // { +// // new TvRequestModel { Available = true }, +// // new TvRequestModel { Approved = true }, +// // new TvRequestModel(), +// // }; +// // RequestService.Setup(x => x.GetAllAsync()).ReturnsAsync(requests); + +// // var result = await Engine.GetNewRequests(); + +// // Assert.Equal(result.Count(), 1); +// // Assert.All(result, x => +// // { +// // Assert.Equal(x.Available, false); +// // Assert.Equal(x.Approved, false); +// // }); +// //} // [Fact] // public async Task GetApprovedRequests_Should_ReturnEmpty_WhenThereAreNoApprovedRequests() diff --git a/src/Ombi.Core.Tests/Rule/Request/AutoApproveRuleTests.cs b/src/Ombi.Core.Tests/Rule/Request/AutoApproveRuleTests.cs index c62e7373f..e3fdda556 100644 --- a/src/Ombi.Core.Tests/Rule/Request/AutoApproveRuleTests.cs +++ b/src/Ombi.Core.Tests/Rule/Request/AutoApproveRuleTests.cs @@ -1,89 +1,86 @@ -//using System.Security.Principal; -//using System.Threading.Tasks; -//using Moq; -//using Ombi.Core.Claims; -//using Ombi.Core.Models.Requests; -//using Ombi.Core.Rule.Rules; -//using Ombi.Core.Rule.Rules.Request; -//using Xunit; - -//namespace Ombi.Core.Tests.Rule -//{ -// public class AutoApproveRuleTests -// { -// public AutoApproveRuleTests() -// { -// PrincipalMock = new Mock(); -// Rule = new AutoApproveRule(PrincipalMock.Object); -// } - -// private AutoApproveRule Rule { get; } -// private Mock PrincipalMock { get; } - -// [Fact] -// public async Task Should_ReturnSuccess_WhenAdminAndRequestMovie() -// { -// PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true); -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie }; -// var result = await Rule.Execute(request); - -// Assert.Equal(result.Success, true); -// Assert.Equal(request.Approved, true); -// } - -// [Fact] -// public async Task Should_ReturnSuccess_WhenAdminAndRequestTV() -// { -// PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true); -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow }; -// var result = await Rule.Execute(request); - -// Assert.Equal(result.Success, true); -// Assert.Equal(request.Approved, true); -// } - -// [Fact] -// public async Task Should_ReturnSuccess_WhenAutoApproveMovieAndRequestMovie() -// { -// PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.AutoApproveMovie)).Returns(true); -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie }; -// var result = await Rule.Execute(request); - -// Assert.Equal(result.Success, true); -// Assert.Equal(request.Approved, true); -// } - -// [Fact] -// public async Task Should_ReturnSuccess_WhenAutoApproveTVAndRequestTV() -// { -// PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.AutoApproveTv)).Returns(true); -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow }; -// var result = await Rule.Execute(request); - -// Assert.Equal(result.Success, true); -// Assert.Equal(request.Approved, true); -// } - -// [Fact] -// public async Task Should_ReturnFail_WhenNoClaimsAndRequestMovie() -// { -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie }; -// var result = await Rule.Execute(request); - -// Assert.Equal(result.Success, true); -// Assert.Equal(request.Approved, false); -// } - -// [Fact] -// public async Task Should_ReturnFail_WhenNoClaimsAndRequestTV() -// { -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow }; -// var result = await Rule.Execute(request); - -// Assert.Equal(result.Success, true); -// Assert.Equal(request.Approved, false); -// } - - -// } -//} +using System.Security.Principal; +using System.Threading.Tasks; +using Moq; +using Ombi.Core.Claims; +using Ombi.Core.Rule.Rules.Request; +using Ombi.Store.Entities.Requests; +using Xunit; + +namespace Ombi.Core.Tests.Rule.Request +{ + public class AutoApproveRuleTests + { + public AutoApproveRuleTests() + { + PrincipalMock = new Mock(); + Rule = new AutoApproveRule(PrincipalMock.Object); + } + + private AutoApproveRule Rule { get; } + private Mock PrincipalMock { get; } + + [Fact] + public async Task Should_ReturnSuccess_WhenAdminAndRequestMovie() + { + PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true); + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie }; + var result = await Rule.Execute(request); + + Assert.Equal(result.Success, true); + Assert.Equal(request.Approved, true); + } + + [Fact] + public async Task Should_ReturnSuccess_WhenAdminAndRequestTV() + { + PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true); + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow }; + var result = await Rule.Execute(request); + + Assert.Equal(result.Success, true); + Assert.Equal(request.Approved, true); + } + + [Fact] + public async Task Should_ReturnSuccess_WhenAutoApproveMovieAndRequestMovie() + { + PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.AutoApproveMovie)).Returns(true); + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie }; + var result = await Rule.Execute(request); + + Assert.Equal(result.Success, true); + Assert.Equal(request.Approved, true); + } + + [Fact] + public async Task Should_ReturnSuccess_WhenAutoApproveTVAndRequestTV() + { + PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.AutoApproveTv)).Returns(true); + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow }; + var result = await Rule.Execute(request); + + Assert.Equal(result.Success, true); + Assert.Equal(request.Approved, true); + } + + [Fact] + public async Task Should_ReturnFail_WhenNoClaimsAndRequestMovie() + { + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie }; + var result = await Rule.Execute(request); + + Assert.Equal(result.Success, true); + Assert.Equal(request.Approved, false); + } + + [Fact] + public async Task Should_ReturnFail_WhenNoClaimsAndRequestTV() + { + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow }; + var result = await Rule.Execute(request); + + Assert.Equal(result.Success, true); + Assert.Equal(request.Approved, false); + } + } +} diff --git a/src/Ombi.Core.Tests/Rule/Request/CanRequestRuleTests.cs b/src/Ombi.Core.Tests/Rule/Request/CanRequestRuleTests.cs index 10a0d24e1..cc5ebebee 100644 --- a/src/Ombi.Core.Tests/Rule/Request/CanRequestRuleTests.cs +++ b/src/Ombi.Core.Tests/Rule/Request/CanRequestRuleTests.cs @@ -1,84 +1,85 @@ -//using System.Security.Principal; -//using System.Threading.Tasks; -//using Moq; -//using Ombi.Core.Claims; -//using Ombi.Core.Models.Requests; -//using Ombi.Core.Rule.Rules; -//using Xunit; +using System.Security.Principal; +using System.Threading.Tasks; +using Moq; +using Ombi.Core.Claims; +using Ombi.Core.Models.Requests; +using Ombi.Core.Rule.Rules; +using Ombi.Store.Entities.Requests; +using Xunit; -//namespace Ombi.Core.Tests.Rule -//{ -// public class CanRequestRuleTests -// { -// public CanRequestRuleTests() -// { -// PrincipalMock = new Mock(); -// Rule = new CanRequestRule(PrincipalMock.Object); -// } +namespace Ombi.Core.Tests.Rule +{ + public class CanRequestRuleTests + { + public CanRequestRuleTests() + { + PrincipalMock = new Mock(); + Rule = new CanRequestRule(PrincipalMock.Object); + } -// private CanRequestRule Rule { get; } -// private Mock PrincipalMock { get; } + private CanRequestRule Rule { get; } + private Mock PrincipalMock { get; } -// [Fact] -// public async Task Should_ReturnSuccess_WhenRequestingMovieWithMovieRole() -// { -// PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestMovie)).Returns(true); -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie }; -// var result = await Rule.Execute(request); + [Fact] + public async Task Should_ReturnSuccess_WhenRequestingMovieWithMovieRole() + { + PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestMovie)).Returns(true); + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie }; + var result = await Rule.Execute(request); -// Assert.Equal(result.Success, true); -// } + Assert.Equal(result.Success, true); + } -// [Fact] -// public async Task Should_ReturnFail_WhenRequestingMovieWithoutMovieRole() -// { -// PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestMovie)).Returns(false); -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie }; -// var result = await Rule.Execute(request); + [Fact] + public async Task Should_ReturnFail_WhenRequestingMovieWithoutMovieRole() + { + PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestMovie)).Returns(false); + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie }; + var result = await Rule.Execute(request); -// Assert.Equal(result.Success, false); -// Assert.Equal(string.IsNullOrEmpty(result.Message), false); -// } + Assert.Equal(result.Success, false); + Assert.Equal(string.IsNullOrEmpty(result.Message), false); + } -// [Fact] -// public async Task Should_ReturnSuccess_WhenRequestingMovieWithAdminRole() -// { -// PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true); -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie }; -// var result = await Rule.Execute(request); + [Fact] + public async Task Should_ReturnSuccess_WhenRequestingMovieWithAdminRole() + { + PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true); + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie }; + var result = await Rule.Execute(request); -// Assert.Equal(result.Success, true); -// } + Assert.Equal(result.Success, true); + } -// [Fact] -// public async Task Should_ReturnSuccess_WhenRequestingTVWithAdminRole() -// { -// PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true); -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow }; -// var result = await Rule.Execute(request); + [Fact] + public async Task Should_ReturnSuccess_WhenRequestingTVWithAdminRole() + { + PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true); + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow }; + var result = await Rule.Execute(request); -// Assert.Equal(result.Success, true); -// } + Assert.Equal(result.Success, true); + } -// [Fact] -// public async Task Should_ReturnSuccess_WhenRequestingTVWithTVRole() -// { -// PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestTv)).Returns(true); -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow }; -// var result = await Rule.Execute(request); + [Fact] + public async Task Should_ReturnSuccess_WhenRequestingTVWithTVRole() + { + PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestTv)).Returns(true); + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow }; + var result = await Rule.Execute(request); -// Assert.Equal(result.Success, true); -// } + Assert.Equal(result.Success, true); + } -// [Fact] -// public async Task Should_ReturnFail_WhenRequestingTVWithoutTVRole() -// { -// PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestTv)).Returns(false); -// var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow }; -// var result = await Rule.Execute(request); + [Fact] + public async Task Should_ReturnFail_WhenRequestingTVWithoutTVRole() + { + PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestTv)).Returns(false); + var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow }; + var result = await Rule.Execute(request); -// Assert.Equal(result.Success, false); -// Assert.Equal(string.IsNullOrEmpty(result.Message), false); -// } -// } -//} + Assert.Equal(result.Success, false); + Assert.Equal(string.IsNullOrEmpty(result.Message), false); + } + } +} diff --git a/src/Ombi.Core.Tests/Rule/Search/ExistingRequestRuleTests.cs b/src/Ombi.Core.Tests/Rule/Search/ExistingRequestRuleTests.cs index 9efeb751d..2516325a5 100644 --- a/src/Ombi.Core.Tests/Rule/Search/ExistingRequestRuleTests.cs +++ b/src/Ombi.Core.Tests/Rule/Search/ExistingRequestRuleTests.cs @@ -1,110 +1,128 @@ -//using System.Collections.Generic; -//using System.Threading.Tasks; -//using Moq; -//using Ombi.Core.Models.Requests; -//using Ombi.Core.Models.Requests.Movie; -//using Ombi.Core.Models.Requests.Tv; -//using Ombi.Core.Models.Search; -//using Ombi.Core.Requests.Models; -//using Ombi.Core.Rule.Rules.Search; -//using Xunit; - -//namespace Ombi.Core.Tests.Rule.Search -//{ -// public class ExistignRequestRuleTests -// { -// public ExistignRequestRuleTests() -// { -// MovieMock = new Mock>(); -// TvMock = new Mock>(); -// Rule = new ExistingRequestRule(MovieMock.Object, TvMock.Object); -// } - -// private ExistingRequestRule Rule { get; } -// private Mock> MovieMock { get; } -// private Mock> TvMock { get; } - - -// [Fact] -// public async Task ShouldBe_Requested_WhenExisitngMovie() -// { -// var list = new List{new MovieRequestModel -// { -// ProviderId = 123, -// Approved = true -// }}; -// MovieMock.Setup(x => x.GetAllAsync()).ReturnsAsync(list); -// var search = new SearchMovieViewModel -// { -// Id = 123, - -// }; -// var result = await Rule.Execute(search); - -// Assert.True(result.Success); -// Assert.Equal(search.Approved, true); -// } - -// [Fact] -// public async Task ShouldBe_NotRequested_WhenNewMovie() -// { -// var list = new List{new MovieRequestModel -// { -// ProviderId = 123, -// Approved = true -// }}; -// MovieMock.Setup(x => x.GetAllAsync()).ReturnsAsync(list); -// var search = new SearchMovieViewModel -// { -// Id = 999, - -// }; -// var result = await Rule.Execute(search); - -// Assert.True(result.Success); -// Assert.Equal(search.Approved, false); -// } - -// [Fact] -// public async Task ShouldBe_Requested_WhenExisitngTv() -// { -// var list = new List{new TvRequestModel -// { -// ProviderId = 123, -// Approved = true -// }}; -// TvMock.Setup(x => x.GetAllAsync()).ReturnsAsync(list); -// var search = new SearchTvShowViewModel -// { -// Id = 123, - -// }; -// var result = await Rule.Execute(search); - -// Assert.True(result.Success); -// Assert.Equal(search.Approved, true); -// } - -// [Fact] -// public async Task ShouldBe_NotRequested_WhenNewTv() -// { -// var list = new List{new TvRequestModel -// { -// ProviderId = 123, -// Approved = true -// }}; -// TvMock.Setup(x => x.GetAllAsync()).ReturnsAsync(list); -// var search = new SearchTvShowViewModel() -// { -// Id = 999, - -// }; -// var result = await Rule.Execute(search); - -// Assert.True(result.Success); -// Assert.Equal(search.Approved, false); -// } - - -// } -//} \ No newline at end of file +using System.Collections.Generic; +using System.Threading.Tasks; +using Moq; +using Ombi.Core.Models.Search; +using Ombi.Core.Rule.Rules.Search; +using Ombi.Store.Entities.Requests; +using Ombi.Store.Repository; +using Ombi.Store.Repository.Requests; +using Xunit; + +namespace Ombi.Core.Tests.Rule.Search +{ + public class ExistignRequestRuleTests + { + public ExistignRequestRuleTests() + { + MovieMock = new Mock(); + TvMock = new Mock(); + Rule = new ExistingRule(MovieMock.Object, TvMock.Object); + } + + private ExistingRule Rule { get; } + private Mock MovieMock { get; } + private Mock TvMock { get; } + + + [Fact] + public async Task ShouldBe_Requested_WhenExisitngMovie() + { + var list = new MovieRequests + { + TheMovieDbId = 123, + Approved = true + }; + + MovieMock.Setup(x => x.GetRequest(123)).ReturnsAsync(list); + var search = new SearchMovieViewModel + { + Id = 123, + + }; + var result = await Rule.Execute(search); + + Assert.True(result.Success); + Assert.Equal(search.Approved, true); + } + + [Fact] + public async Task ShouldBe_NotRequested_WhenNewMovie() + { + var list = new MovieRequests + { + TheMovieDbId = 123, + Approved = true + }; + + MovieMock.Setup(x => x.GetRequest(123)).ReturnsAsync(list); + var search = new SearchMovieViewModel + { + Id = 999, + + }; + var result = await Rule.Execute(search); + + Assert.True(result.Success); + Assert.Equal(search.Approved, false); + } + + [Fact] + public async Task ShouldBe_Requested_WhenExisitngTv() + { + var list = new TvRequests + { + TvDbId = 123, + ChildRequests = new List + { + new ChildRequests() + { + Approved = true + + } + } + }; + + TvMock.Setup(x => x.GetRequest(123)).ReturnsAsync(list); + var search = new SearchTvShowViewModel + { + Id = 123, + + }; + var result = await Rule.Execute(search); + + Assert.True(result.Success); + Assert.Equal(search.Approved, true); + } + + [Fact] + public async Task ShouldBe_NotRequested_WhenNewTv() + { + var list = new TvRequests + { + TvDbId = 123, + ChildRequests = new List + { + new ChildRequests() + { + Approved = true + + } + } + }; + + + TvMock.Setup(x => x.GetRequest(123)).ReturnsAsync(list); + var search = new SearchTvShowViewModel() + { + Id = 999, + + }; + var result = await Rule.Execute(search); + + Assert.True(result.Success); + Assert.Equal(search.Approved, false); + } + + + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Engine/BaseMediaEngine.cs b/src/Ombi.Core/Engine/BaseMediaEngine.cs index 169dee1cf..ea8642456 100644 --- a/src/Ombi.Core/Engine/BaseMediaEngine.cs +++ b/src/Ombi.Core/Engine/BaseMediaEngine.cs @@ -1,6 +1,5 @@ using Ombi.Core.Engine.Interfaces; using Ombi.Core.Models.Requests; -using Ombi.Core.Rules; using Ombi.Helpers; using System; using System.Collections.Generic; @@ -8,6 +7,7 @@ using System.Linq; using System.Security.Principal; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; +using Ombi.Core.Rule.Interfaces; using Ombi.Store.Entities.Requests; using Ombi.Store.Repository; using Ombi.Store.Repository.Requests; diff --git a/src/Ombi.Core/Engine/Interfaces/BaseEngine.cs b/src/Ombi.Core/Engine/Interfaces/BaseEngine.cs index 42f3be755..7b4274b3f 100644 --- a/src/Ombi.Core/Engine/Interfaces/BaseEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/BaseEngine.cs @@ -1,10 +1,10 @@ using Ombi.Core.Claims; using Ombi.Core.Rule; -using Ombi.Core.Rules; using System.Collections.Generic; using System.Security.Principal; using System.Threading.Tasks; using Ombi.Core.Models.Search; +using Ombi.Core.Rule.Interfaces; using Ombi.Store.Entities.Requests; namespace Ombi.Core.Engine.Interfaces @@ -48,5 +48,10 @@ namespace Ombi.Core.Engine.Interfaces var ruleResults = await Rules.StartSearchRules(model); return ruleResults; } + public async Task RunSpecificRule(object model, SpecificRules rule) + { + var ruleResults = await Rules.StartSpecificRules(model, rule); + return ruleResults; + } } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs b/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs index 67768bd2c..1f65b5a15 100644 --- a/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/IMovieEngine.cs @@ -15,8 +15,7 @@ namespace Ombi.Core Task> TopRatedMovies(); Task> UpcomingMovies(); - - Task> LookupImdbInformation(IEnumerable movies); + Task LookupImdbInformation(int theMovieDbId); } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index 95f10ce3d..6f21f79df 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -1,7 +1,6 @@ using Ombi.Api.TheMovieDb; using Ombi.Core.Models.Requests; using Ombi.Core.Models.Search; -using Ombi.Core.Rules; using Ombi.Helpers; using Ombi.Store.Entities; using System; @@ -14,7 +13,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core.Engine.Interfaces; using Ombi.Core.IdentityResolver; -using Ombi.Core.Rule; +using Ombi.Core.Rule.Interfaces; using Ombi.Store.Entities.Requests; namespace Ombi.Core.Engine @@ -37,6 +36,11 @@ namespace Ombi.Core.Engine private ILogger Logger { get; } private IUserIdentityManager UserManager { get; } + /// + /// Requests the movie. + /// + /// The model. + /// public async Task RequestMovie(SearchMovieViewModel model) { var movieInfo = await MovieApi.GetMovieInformation(model.Id); @@ -52,42 +56,6 @@ namespace Ombi.Core.Engine var fullMovieName = $"{movieInfo.Title}{(!string.IsNullOrEmpty(movieInfo.ReleaseDate) ? $" ({DateTime.Parse(movieInfo.ReleaseDate).Year})" : string.Empty)}"; - var existingRequest = await MovieRepository.GetRequest(model.Id); - if (existingRequest != null) - { - return new RequestEngineResult - { - RequestAdded = false, - Message = $"{fullMovieName} has already been requested" - }; - } - - // TODO - //try - //{ - // var content = PlexContentRepository.GetAll(); - // var movies = PlexChecker.GetPlexMovies(content); - // if (PlexChecker.IsMovieAvailable(movies.ToArray(), movieInfo.Title, movieInfo.ReleaseDate?.Year.ToString())) - // { - // return - // Response.AsJson(new JsonResponseModel - // { - // Result = false, - // Message = $"{fullMovieName} is already in Plex!" - // }); - // } - //} - //catch (Exception e) - //{ - // Log.Error(e); - // return - // Response.AsJson(new JsonResponseModel - // { - // Result = false, - // Message = string.Format(Resources.UI.Search_CouldNotCheckPlex, fullMovieName, GetMediaServerName()) - // }); - //} - var userDetails = await UserManager.GetUser(User.Identity.Name); var requestModel = new MovieRequests @@ -107,13 +75,12 @@ namespace Ombi.Core.Engine RequestedUserId = userDetails.Id, }; - var ruleResults = await RunRequestRules(requestModel); - var results = ruleResults as RuleResult[] ?? ruleResults.ToArray(); - if (results.Any(x => !x.Success)) + var ruleResults = (await RunRequestRules(requestModel)).ToList(); + if (ruleResults.Any(x => !x.Success)) { return new RequestEngineResult { - ErrorMessage = results.FirstOrDefault(x => !string.IsNullOrEmpty(x.Message)).Message + ErrorMessage = ruleResults.FirstOrDefault(x => !string.IsNullOrEmpty(x.Message)).Message }; } @@ -122,8 +89,7 @@ namespace Ombi.Core.Engine var result = await Sender.Send(requestModel); if (result.Success && result.MovieSent) { - return await AddMovieRequest(requestModel, /*settings,*/ - $"{fullMovieName} has been successfully added!"); + return await AddMovieRequest(requestModel, fullMovieName); } if (!result.Success) { @@ -138,24 +104,37 @@ namespace Ombi.Core.Engine // If there are no providers then it's successful but movie has not been sent } - return await AddMovieRequest(requestModel, /*settings,*/ - $"{fullMovieName} has been successfully added!"); + return await AddMovieRequest(requestModel, fullMovieName); } - + /// + /// Gets the requests. + /// + /// The count. + /// The position. + /// public async Task> GetRequests(int count, int position) { var allRequests = await MovieRepository.Get().Skip(position).Take(count).ToListAsync(); return allRequests; } + /// + /// Gets the requests. + /// + /// public async Task> GetRequests() { var allRequests = await MovieRepository.Get().ToListAsync(); return allRequests; } + /// + /// Searches the movie request. + /// + /// The search. + /// public async Task> SearchMovieRequest(string search) { var allRequests = await MovieRepository.Get().ToListAsync(); @@ -163,6 +142,11 @@ namespace Ombi.Core.Engine return results; } + /// + /// Updates the movie request. + /// + /// The request. + /// public async Task UpdateMovieRequest(MovieRequests request) { var allRequests = await MovieRepository.Get().ToListAsync(); @@ -183,13 +167,18 @@ namespace Ombi.Core.Engine return results; } + /// + /// Removes the movie request. + /// + /// The request identifier. + /// public async Task RemoveMovieRequest(int requestId) { var request = await MovieRepository.Get().FirstOrDefaultAsync(x => x.Id == requestId); await MovieRepository.Delete(request); } - private async Task AddMovieRequest(MovieRequests model, string message) + private async Task AddMovieRequest(MovieRequests model, string movieName) { await MovieRepository.Add(model); @@ -198,25 +187,7 @@ namespace Ombi.Core.Engine NotificationHelper.NewRequest(model); } - //var limit = await RequestLimitRepo.GetAllAsync(); - //var usersLimit = limit.FirstOrDefault(x => x.Username == Username && x.RequestType == model.Type); - //if (usersLimit == null) - //{ - // await RequestLimitRepo.InsertAsync(new RequestLimit - // { - // Username = Username, - // RequestType = model.Type, - // FirstRequestDate = DateTime.UtcNow, - // RequestCount = 1 - // }); - //} - //else - //{ - // usersLimit.RequestCount++; - // await RequestLimitRepo.UpdateAsync(usersLimit); - //} - - return new RequestEngineResult { RequestAdded = true, Message = message }; + return new RequestEngineResult { RequestAdded = true, Message = $"{movieName} has been successfully added!" }; } public async Task> GetApprovedRequests() diff --git a/src/Ombi.Core/Engine/MovieSearchEngine.cs b/src/Ombi.Core/Engine/MovieSearchEngine.cs index 1cb26fcfb..f001da061 100644 --- a/src/Ombi.Core/Engine/MovieSearchEngine.cs +++ b/src/Ombi.Core/Engine/MovieSearchEngine.cs @@ -4,7 +4,6 @@ using Ombi.Api.TheMovieDb; using Ombi.Api.TheMovieDb.Models; using Ombi.Core.Models.Requests; using Ombi.Core.Models.Search; -using Ombi.Core.Rules; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Store.Repository; @@ -12,6 +11,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Principal; using System.Threading.Tasks; +using Ombi.Core.Rule.Interfaces; using StackExchange.Profiling; namespace Ombi.Core.Engine @@ -19,60 +19,36 @@ namespace Ombi.Core.Engine public class MovieSearchEngine : BaseMediaEngine, IMovieEngine { public MovieSearchEngine(IPrincipal identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper, - ISettingsService plexSettings, - ISettingsService embySettings, IPlexContentRepository repo, ILogger logger, IRuleEvaluator r) : base(identity, service, r) { MovieApi = movApi; Mapper = mapper; - PlexSettings = plexSettings; - EmbySettings = embySettings; Logger = logger; - PlexContentRepo = repo; } private IMovieDbApi MovieApi { get; } private IMapper Mapper { get; } - private ISettingsService PlexSettings { get; } - private ISettingsService EmbySettings { get; } private ILogger Logger { get; } - private IPlexContentRepository PlexContentRepo { get; } - - public async Task> LookupImdbInformation( - IEnumerable movies) - { - var searchMovieViewModels - = movies as IList ?? movies.ToList(); - if (searchMovieViewModels == null || !searchMovieViewModels.Any()) - return new List(); - - var retVal = new List(); - - var plexSettings = await PlexSettings.GetSettingsAsync(); - var embySettings = await EmbySettings.GetSettingsAsync(); - - foreach (var m in searchMovieViewModels) - { - var movieInfo = await MovieApi.GetMovieInformationWithVideo(m.Id); - var viewMovie = Mapper.Map(movieInfo); - - retVal.Add(await ProcessSingleMovie(viewMovie, plexSettings, embySettings)); - } - return retVal; - } + /// + /// Lookups the imdb information. + /// + /// The movie database identifier. + /// public async Task LookupImdbInformation(int theMovieDbId) { - var plexSettings = await PlexSettings.GetSettingsAsync(); - var embySettings = await EmbySettings.GetSettingsAsync(); - var movieInfo = await MovieApi.GetMovieInformationWithVideo(theMovieDbId); var viewMovie = Mapper.Map(movieInfo); - return await ProcessSingleMovie(viewMovie, plexSettings, embySettings, true); + return await ProcessSingleMovie(viewMovie, true); } + /// + /// Searches the specified movie. + /// + /// The search. + /// public async Task> Search(string search) { using (MiniProfiler.Current.Step("Starting Movie Search Engine")) @@ -89,12 +65,14 @@ namespace Ombi.Core.Engine } } - return null; } } - + /// + /// Gets popular movies. + /// + /// public async Task> PopularMovies() { var result = await MovieApi.PopularMovies(); @@ -106,6 +84,10 @@ namespace Ombi.Core.Engine return null; } + /// + /// Gets top rated movies. + /// + /// public async Task> TopRatedMovies() { var result = await MovieApi.TopRated(); @@ -117,6 +99,10 @@ namespace Ombi.Core.Engine return null; } + /// + /// Gets upcoming movies. + /// + /// public async Task> UpcomingMovies() { var result = await MovieApi.Upcoming(); @@ -128,6 +114,10 @@ namespace Ombi.Core.Engine return null; } + /// + /// Gets now playing movies. + /// + /// public async Task> NowPlayingMovies() { var result = await MovieApi.NowPlaying(); @@ -142,45 +132,20 @@ namespace Ombi.Core.Engine private async Task> TransformMovieResultsToResponse( IEnumerable movies) { - var viewMovies = new List(); - Settings.Models.External.PlexSettings plexSettings; - Settings.Models.External.EmbySettings embySettings; - using (MiniProfiler.Current.Step("Gettings Movies and Settings")) - { - plexSettings = await PlexSettings.GetSettingsAsync(); - embySettings = await EmbySettings.GetSettingsAsync(); - } foreach (var movie in movies) { - viewMovies.Add(await ProcessSingleMovie(movie, plexSettings, embySettings)); + viewMovies.Add(await ProcessSingleMovie(movie)); } return viewMovies; } - private async Task ProcessSingleMovie(SearchMovieViewModel viewMovie, - PlexSettings plexSettings, EmbySettings embySettings, bool lookupExtraInfo = false) + private async Task ProcessSingleMovie(SearchMovieViewModel viewMovie, bool lookupExtraInfo = false) { - - if (plexSettings.Enable) - { - if (lookupExtraInfo) - { - var showInfo = await MovieApi.GetMovieInformation(viewMovie.Id); - viewMovie.Id = showInfo.Id; // TheMovieDbId - } - } - if (embySettings.Enable) + if (lookupExtraInfo) { - // var embyContent = EmbyContentRepository.GetAll(); - // var embyMovies = EmbyChecker.GetEmbyMovies(embyContent); - - // var embyMovie = EmbyChecker.GetMovie(embyMovies.ToArray(), movie.Title, - // movie.ReleaseDate?.Year.ToString(), viewMovie.ImdbId); - // if (embyMovie != null) - // { - // viewMovie.Available = true; - // } + var showInfo = await MovieApi.GetMovieInformation(viewMovie.Id); + viewMovie.Id = showInfo.Id; // TheMovieDbId } await RunSearchRules(viewMovie); @@ -189,10 +154,10 @@ namespace Ombi.Core.Engine } - private async Task ProcessSingleMovie(MovieSearchResult movie, PlexSettings plexSettings, EmbySettings embySettings) + private async Task ProcessSingleMovie(MovieSearchResult movie) { var viewMovie = Mapper.Map(movie); - return await ProcessSingleMovie(viewMovie, plexSettings, embySettings); + return await ProcessSingleMovie(viewMovie); } } } \ No newline at end of file diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index 2df8a2e3d..b7261cb63 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -2,7 +2,6 @@ using Ombi.Api.TvMaze; using Ombi.Core.Models.Requests; using Ombi.Core.Models.Search; -using Ombi.Core.Rules; using Ombi.Helpers; using Ombi.Store.Entities; using System; @@ -15,6 +14,7 @@ using Microsoft.EntityFrameworkCore; using Ombi.Core.Engine.Interfaces; using Ombi.Core.IdentityResolver; using Ombi.Core.Rule; +using Ombi.Core.Rule.Interfaces; using Ombi.Store.Entities.Requests; using Ombi.Store.Repository.Requests; @@ -71,11 +71,6 @@ namespace Ombi.Core.Engine { Id = tv.Id, RequestType = RequestType.TvShow, - //Overview = showInfo.summary.RemoveHtml(), - //PosterPath = posterPath, - //Title = showInfo.name, - //ReleaseDate = firstAir, - //Status = showInfo.status, RequestedDate = DateTime.UtcNow, Approved = false, RequestedUserId = user.Id, @@ -85,10 +80,8 @@ namespace Ombi.Core.Engine if (tv.RequestAll) { var episodes = await TvApi.EpisodeLookup(showInfo.id); - var seasonRequests = new List(); foreach (var ep in episodes) { - var episodesRequests = new List(); var season = childRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == ep.season); if (season == null) { @@ -184,7 +177,6 @@ namespace Ombi.Core.Engine if (existingRequest != null) { // Remove requests we already have, we just want new ones - var existingSeasons = existingRequest.ChildRequests.Select(x => x.SeasonRequests); foreach (var existingSeason in existingRequest.ChildRequests) foreach (var existing in existingSeason.SeasonRequests) { @@ -259,7 +251,6 @@ namespace Ombi.Core.Engine results = Mapper.Map(request); // TODO need to check if we need to approve any child requests since they may have updated - await TvRepository.Update(results); return results; } @@ -277,10 +268,6 @@ namespace Ombi.Core.Engine await TvRepository.Update(existingRequest); - if (newRequest.Approved) // The auto approve rule - { - // TODO Auto Approval Code - } return await AfterRequest(newRequest); } @@ -291,9 +278,10 @@ namespace Ombi.Core.Engine return await AfterRequest(model.ChildRequests.FirstOrDefault()); } - private Task AfterRequest(ChildRequests model) + private async Task AfterRequest(ChildRequests model) { - if (ShouldSendNotification(model)) + var sendRuleResult = await RunSpecificRule(model, SpecificRules.CanSendNotification); + if (sendRuleResult.Success) { NotificationHelper.NewRequest(model); } @@ -301,28 +289,10 @@ namespace Ombi.Core.Engine if(model.Approved) { // Autosend - TvSender.SendToSonarr(model); + await TvSender.SendToSonarr(model); } - //var limit = await RequestLimitRepo.GetAllAsync(); - //var usersLimit = limit.FirstOrDefault(x => x.Username == Username && x.RequestType == model.Type); - //if (usersLimit == null) - //{ - // await RequestLimitRepo.InsertAsync(new RequestLimit - // { - // Username = Username, - // RequestType = model.Type, - // FirstRequestDate = DateTime.UtcNow, - // RequestCount = 1 - // }); - //} - //else - //{ - // usersLimit.RequestCount++; - // await RequestLimitRepo.UpdateAsync(usersLimit); - //} - - return Task.FromResult(new RequestEngineResult { RequestAdded = true }); + return new RequestEngineResult { RequestAdded = true }; } //public async Task> GetApprovedRequests() diff --git a/src/Ombi.Core/Engine/TvSearchEngine.cs b/src/Ombi.Core/Engine/TvSearchEngine.cs index 8312936ae..3e46d87bf 100644 --- a/src/Ombi.Core/Engine/TvSearchEngine.cs +++ b/src/Ombi.Core/Engine/TvSearchEngine.cs @@ -5,7 +5,6 @@ using Ombi.Api.TvMaze; using Ombi.Core.Engine.Interfaces; using Ombi.Core.Models.Requests; using Ombi.Core.Models.Search; -using Ombi.Core.Rules; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Store.Repository; @@ -15,6 +14,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Principal; using System.Threading.Tasks; +using Ombi.Core.Rule.Interfaces; using Ombi.Store.Entities.Requests; using Ombi.Store.Repository.Requests; diff --git a/src/Ombi.Core/Rule/BaseRequestRule.cs b/src/Ombi.Core/Rule/BaseRequestRule.cs index 27a12223e..fe4daa7ff 100644 --- a/src/Ombi.Core/Rule/BaseRequestRule.cs +++ b/src/Ombi.Core/Rule/BaseRequestRule.cs @@ -9,7 +9,7 @@ public RuleResult Fail(string message) { - return new RuleResult {Message = message}; + return new RuleResult { Message = message }; } } } \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Interfaces/IRuleEvaluator.cs b/src/Ombi.Core/Rule/Interfaces/IRuleEvaluator.cs index 69ce0f36f..c32342146 100644 --- a/src/Ombi.Core/Rule/Interfaces/IRuleEvaluator.cs +++ b/src/Ombi.Core/Rule/Interfaces/IRuleEvaluator.cs @@ -1,15 +1,14 @@ -using Ombi.Core.Models.Requests; -using Ombi.Core.Rule; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; using Ombi.Core.Models.Search; using Ombi.Store.Entities.Requests; -namespace Ombi.Core.Rules +namespace Ombi.Core.Rule.Interfaces { public interface IRuleEvaluator { Task> StartRequestRules(BaseRequest obj); Task> StartSearchRules(SearchViewModel obj); + Task StartSpecificRules(object obj, SpecificRules selectedRule); } } \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Interfaces/IRequestRules.cs b/src/Ombi.Core/Rule/Interfaces/IRules.cs similarity index 73% rename from src/Ombi.Core/Rule/Interfaces/IRequestRules.cs rename to src/Ombi.Core/Rule/Interfaces/IRules.cs index 6ea0e1510..a46749cd1 100644 --- a/src/Ombi.Core/Rule/Interfaces/IRequestRules.cs +++ b/src/Ombi.Core/Rule/Interfaces/IRules.cs @@ -3,7 +3,7 @@ using Ombi.Core.Models.Requests; namespace Ombi.Core.Rule.Interfaces { - public interface IRequestRules where T : new() + public interface IRules where T : new() { Task Execute(T obj); } diff --git a/src/Ombi.Core/Rule/Interfaces/ISpecificRule.cs b/src/Ombi.Core/Rule/Interfaces/ISpecificRule.cs new file mode 100644 index 000000000..065b2f990 --- /dev/null +++ b/src/Ombi.Core/Rule/Interfaces/ISpecificRule.cs @@ -0,0 +1,11 @@ +using System.Threading.Tasks; +using Ombi.Core.Models.Requests; + +namespace Ombi.Core.Rule.Interfaces +{ + public interface ISpecificRule where T : new() + { + Task Execute(T obj); + SpecificRules Rule { get; } + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Interfaces/SpecificRules.cs b/src/Ombi.Core/Rule/Interfaces/SpecificRules.cs new file mode 100644 index 000000000..522ba8a95 --- /dev/null +++ b/src/Ombi.Core/Rule/Interfaces/SpecificRules.cs @@ -0,0 +1,7 @@ +namespace Ombi.Core.Rule.Interfaces +{ + public enum SpecificRules + { + CanSendNotification, + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Rule/RuleEvaluator.cs b/src/Ombi.Core/Rule/RuleEvaluator.cs index 961b4aa4b..2f3b96b2a 100644 --- a/src/Ombi.Core/Rule/RuleEvaluator.cs +++ b/src/Ombi.Core/Rule/RuleEvaluator.cs @@ -1,5 +1,4 @@ using Ombi.Core.Models.Requests; -using Ombi.Core.Rules; using System; using System.Collections.Generic; using System.Linq; @@ -7,6 +6,7 @@ using System.Reflection; using System.Threading.Tasks; using Ombi.Core.Models.Search; using Ombi.Core.Rule.Interfaces; +using Ombi.Helpers; using Ombi.Store.Entities.Requests; namespace Ombi.Core.Rule @@ -15,13 +15,66 @@ namespace Ombi.Core.Rule { public RuleEvaluator(IServiceProvider provider) { - RequestRules = new List>(); - SearchRules = new List>(); + RequestRules = new List>(); + SearchRules = new List>(); + SpecificRules = new List>(); + var baseSearchType = typeof(BaseRequestRule).FullName; var baseRequestType = typeof(BaseSearchRule).FullName; + var baseSpecificRuleType = typeof(SpecificRule).FullName; var ass = typeof(RuleEvaluator).GetTypeInfo().Assembly; + GetTypes(provider, ass, baseSearchType, RequestRules); + GetTypes(provider, ass, baseRequestType, SearchRules); + GetTypes(provider, ass, baseSpecificRuleType, SpecificRules); + } + + private List> RequestRules { get; } + private List> SearchRules { get; } + private List> SpecificRules { get; } + + public async Task> StartRequestRules(BaseRequest obj) + { + var results = new List(); + foreach (var rule in RequestRules) + { + var result = await rule.Execute(obj); + results.Add(result); + } + + return results; + } + + public async Task> StartSearchRules(SearchViewModel obj) + { + var results = new List(); + foreach (var rule in SearchRules) + { + var result = await rule.Execute(obj); + results.Add(result); + } + + return results; + } + + public async Task StartSpecificRules(object obj, SpecificRules selectedRule) + { + foreach (var rule in SpecificRules) + { + if (selectedRule == rule.Rule) + { + var result = await rule.Execute(obj); + return result; + } + } + + throw new RuleNotFoundException(nameof(selectedRule)); + } + + + private void GetTypes(IServiceProvider provider, Assembly ass, string baseSearchType, List> ruleList) where T : new() + { foreach (var ti in ass.DefinedTypes) { if (ti?.BaseType?.FullName == baseSearchType) @@ -37,13 +90,16 @@ namespace Ombi.Core.Rule } var item = Activator.CreateInstance(type, services.ToArray()); - RequestRules.Add((IRequestRules) item); + ruleList.Add((IRules)item); } } - + } + + private void GetTypes(IServiceProvider provider, Assembly ass, string baseSearchType, ICollection> ruleList) where T : new() + { foreach (var ti in ass.DefinedTypes) { - if (ti?.BaseType?.FullName == baseRequestType) + if (ti?.BaseType?.FullName == baseSearchType) { var type = ti?.AsType(); var ctors = type.GetConstructors(); @@ -56,36 +112,9 @@ namespace Ombi.Core.Rule } var item = Activator.CreateInstance(type, services.ToArray()); - SearchRules.Add((IRequestRules) item); + ruleList.Add((ISpecificRule)item); } } } - - private List> RequestRules { get; } - private List> SearchRules { get; } - - public async Task> StartRequestRules(BaseRequest obj) - { - var results = new List(); - foreach (var rule in RequestRules) - { - var result = await rule.Execute(obj); - results.Add(result); - } - - return results; - } - - public async Task> StartSearchRules(SearchViewModel obj) - { - var results = new List(); - foreach (var rule in SearchRules) - { - var result = await rule.Execute(obj); - results.Add(result); - } - - return results; - } } } \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Rules/Request/AutoApproveRule.cs b/src/Ombi.Core/Rule/Rules/Request/AutoApproveRule.cs index b661b5130..7079530b4 100644 --- a/src/Ombi.Core/Rule/Rules/Request/AutoApproveRule.cs +++ b/src/Ombi.Core/Rule/Rules/Request/AutoApproveRule.cs @@ -8,7 +8,7 @@ using Ombi.Store.Entities.Requests; namespace Ombi.Core.Rule.Rules.Request { - public class AutoApproveRule : BaseRequestRule, IRequestRules + public class AutoApproveRule : BaseRequestRule, IRules { public AutoApproveRule(IPrincipal principal) { diff --git a/src/Ombi.Core/Rule/Rules/Request/CanRequestRule.cs b/src/Ombi.Core/Rule/Rules/Request/CanRequestRule.cs index f12d23830..a8630f368 100644 --- a/src/Ombi.Core/Rule/Rules/Request/CanRequestRule.cs +++ b/src/Ombi.Core/Rule/Rules/Request/CanRequestRule.cs @@ -7,7 +7,7 @@ using Ombi.Store.Entities.Requests; namespace Ombi.Core.Rule.Rules { - public class CanRequestRule : BaseRequestRule, IRequestRules + public class CanRequestRule : BaseRequestRule, IRules { public CanRequestRule(IPrincipal principal) { diff --git a/src/Ombi.Core/Rule/Rules/Request/ExistingMovieRequestRule.cs b/src/Ombi.Core/Rule/Rules/Request/ExistingMovieRequestRule.cs new file mode 100644 index 000000000..de678af78 --- /dev/null +++ b/src/Ombi.Core/Rule/Rules/Request/ExistingMovieRequestRule.cs @@ -0,0 +1,39 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Ombi.Core.Rule.Interfaces; +using Ombi.Store.Entities; +using Ombi.Store.Entities.Requests; +using Ombi.Store.Repository; + +namespace Ombi.Core.Rule.Rules.Request +{ + public class ExistingMovieRequestRule : BaseRequestRule, IRules + { + public ExistingMovieRequestRule(IMovieRequestRepository movie) + { + Movie = movie; + } + + private IMovieRequestRepository Movie { get; } + + /// + /// We check if the request exists, if it does then we don't want to re-request it. + /// + /// The object. + /// + public async Task Execute(BaseRequest obj) + { + if (obj.RequestType == RequestType.Movie) + { + var movieRequests = Movie.Get(); + var existing = await movieRequests.FirstOrDefaultAsync(x => x.TheMovieDbId == obj.Id); + if (existing != null) // Do we already have a request for this? + { + + return Fail($"{obj.Title} has already been requested"); + } + } + return Success(); + } + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Rules/Search/ExistingRequestRule.cs b/src/Ombi.Core/Rule/Rules/Search/ExistingRequestRule.cs deleted file mode 100644 index e71c48969..000000000 --- a/src/Ombi.Core/Rule/Rules/Search/ExistingRequestRule.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Ombi.Core.Models.Search; -using Ombi.Core.Rule.Interfaces; -using Ombi.Store.Repository; -using Ombi.Store.Repository.Requests; - -namespace Ombi.Core.Rule.Rules.Search -{ - public class ExistingRequestRule : BaseSearchRule, IRequestRules - { - public ExistingRequestRule(IMovieRequestRepository movie, ITvRequestRepository tv) - { - Movie = movie; - Tv = tv; - } - - private IMovieRequestRepository Movie { get; } - private ITvRequestRepository Tv { get; } - - public async Task Execute(SearchViewModel obj) - { - var movieRequests = Movie.Get(); - var existing = await movieRequests.FirstOrDefaultAsync(x => x.TheMovieDbId == obj.Id); - if (existing != null) // Do we already have a request for this? - { - - obj.Requested = true; - obj.Approved = existing.Approved; - obj.Available = existing.Available; - - return Success(); - } - - var tvRequests = Tv.Get(); - var tv = await tvRequests.FirstOrDefaultAsync(x => x.TvDbId == obj.Id); - if (tv != null) // Do we already have a request for this? - { - - obj.Requested = true; - obj.Approved = tv.ChildRequests.Any(x => x.Approved); - obj.Available = tv.ChildRequests.Any(x => x.Available); - - return Success(); - } - return Success(); - } - } -} \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs b/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs new file mode 100644 index 000000000..abbafd8f9 --- /dev/null +++ b/src/Ombi.Core/Rule/Rules/Search/ExistingRule.cs @@ -0,0 +1,48 @@ +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Ombi.Core.Models.Search; +using Ombi.Core.Rule.Interfaces; +using Ombi.Store.Repository; +using Ombi.Store.Repository.Requests; + +namespace Ombi.Core.Rule.Rules.Search +{ + public class ExistingRule : BaseSearchRule, IRules + { + public ExistingRule(IMovieRequestRepository movie, ITvRequestRepository tv) + { + Movie = movie; + Tv = tv; + } + + private IMovieRequestRepository Movie { get; } + private ITvRequestRepository Tv { get; } + + public async Task Execute(SearchViewModel obj) + { + var movieRequests = await Movie.GetRequest(obj.Id); + if (movieRequests != null) // Do we already have a request for this? + { + + obj.Requested = true; + obj.Approved = movieRequests.Approved; + obj.Available = movieRequests.Available; + + return Success(); + } + + var tvRequests = await Tv.GetRequest(obj.Id); + if (tvRequests != null) // Do we already have a request for this? + { + + obj.Requested = true; + obj.Approved = tvRequests.ChildRequests.Any(x => x.Approved); + obj.Available = tvRequests.ChildRequests.Any(x => x.Available); + + return Success(); + } + return Success(); + } + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Rule/Rules/Search/PlexAvailabilityRule.cs b/src/Ombi.Core/Rule/Rules/Search/PlexAvailabilityRule.cs index 82f5f7c8f..9c2a0bbb1 100644 --- a/src/Ombi.Core/Rule/Rules/Search/PlexAvailabilityRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/PlexAvailabilityRule.cs @@ -5,7 +5,7 @@ using Ombi.Store.Repository; namespace Ombi.Core.Rule.Rules.Search { - public class PlexAvailabilityRule : BaseSearchRule, IRequestRules + public class PlexAvailabilityRule : BaseSearchRule, IRules { public PlexAvailabilityRule(IPlexContentRepository repo) { diff --git a/src/Ombi.Core/Rule/Rules/Search/RadarrCacheRule.cs b/src/Ombi.Core/Rule/Rules/Search/RadarrCacheRule.cs index ef20def62..033d279a9 100644 --- a/src/Ombi.Core/Rule/Rules/Search/RadarrCacheRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/RadarrCacheRule.cs @@ -6,7 +6,7 @@ using Ombi.Store.Context; namespace Ombi.Core.Rule.Rules.Search { - public class RadarrCacheRule : BaseSearchRule, IRequestRules + public class RadarrCacheRule : BaseSearchRule, IRules { public RadarrCacheRule(IOmbiContext ctx) { diff --git a/src/Ombi.Core/Rule/Rules/Specific/CanRequestRule.cs b/src/Ombi.Core/Rule/Rules/Specific/CanRequestRule.cs new file mode 100644 index 000000000..536212992 --- /dev/null +++ b/src/Ombi.Core/Rule/Rules/Specific/CanRequestRule.cs @@ -0,0 +1,32 @@ +using System.Security.Principal; +using System.Threading.Tasks; +using Ombi.Core.Claims; +using Ombi.Core.Rule.Interfaces; +using Ombi.Store.Entities.Requests; + +namespace Ombi.Core.Rule.Rules.Specific +{ + public class SendNotificationRule : SpecificRule, ISpecificRule + { + public SendNotificationRule(IPrincipal principal) + { + User = principal; + } + + public override SpecificRules Rule => SpecificRules.CanSendNotification; + private IPrincipal User { get; } + + public Task Execute(object obj) + { + var req = (BaseRequest)obj; + var sendNotification = !req.Approved; /*|| !prSettings.IgnoreNotifyForAutoApprovedRequests;*/ + + if (User.IsInRole(OmbiClaims.Admin)) + sendNotification = false; // Don't bother sending a notification if the user is an admin + return Task.FromResult(new RuleResult + { + Success = sendNotification + }); + } + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Rule/SpecificRule.cs b/src/Ombi.Core/Rule/SpecificRule.cs new file mode 100644 index 000000000..071bce292 --- /dev/null +++ b/src/Ombi.Core/Rule/SpecificRule.cs @@ -0,0 +1,19 @@ +using Ombi.Core.Rule.Interfaces; + +namespace Ombi.Core.Rule +{ + public abstract class SpecificRule + { + public RuleResult Success() + { + return new RuleResult { Success = true }; + } + + public RuleResult Fail(string message) + { + return new RuleResult { Message = message }; + } + + public abstract SpecificRules Rule { get; } + } +} \ No newline at end of file diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index cec44a8a7..7860710c9 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -25,10 +25,10 @@ using Ombi.Schedule.Jobs; using Ombi.Settings.Settings; using Ombi.Store.Context; using Ombi.Store.Repository; -using Ombi.Core.Rules; using Ombi.Notifications.Agents; using Ombi.Schedule.Jobs.Radarr; using Ombi.Api; +using Ombi.Core.Rule.Interfaces; using Ombi.Store.Repository.Requests; namespace Ombi.DependencyInjection diff --git a/src/Ombi.Helpers/RuleNotFoundException.cs b/src/Ombi.Helpers/RuleNotFoundException.cs new file mode 100644 index 000000000..99659a158 --- /dev/null +++ b/src/Ombi.Helpers/RuleNotFoundException.cs @@ -0,0 +1,12 @@ +using System; + +namespace Ombi.Helpers +{ + public class RuleNotFoundException : Exception + { + public RuleNotFoundException(string rule) : base($"rule: {rule} was not found") + { + + } + } +} \ No newline at end of file diff --git a/src/Ombi.Store/Entities/Requests/BaseRequest.cs b/src/Ombi.Store/Entities/Requests/BaseRequest.cs index 7402ca8e0..6f46820f1 100644 --- a/src/Ombi.Store/Entities/Requests/BaseRequest.cs +++ b/src/Ombi.Store/Entities/Requests/BaseRequest.cs @@ -6,7 +6,7 @@ namespace Ombi.Store.Entities.Requests { public class BaseRequest : Entity { - + public string Title { get; set; } public bool Approved { get; set; } public DateTime RequestedDate { get; set; } public bool Available { get; set; } diff --git a/src/Ombi.Store/Entities/Requests/FullBaseRequest.cs b/src/Ombi.Store/Entities/Requests/FullBaseRequest.cs index d43824d4a..cba280289 100644 --- a/src/Ombi.Store/Entities/Requests/FullBaseRequest.cs +++ b/src/Ombi.Store/Entities/Requests/FullBaseRequest.cs @@ -8,7 +8,6 @@ namespace Ombi.Store.Entities.Requests { public string ImdbId { get; set; } public string Overview { get; set; } - public string Title { get; set; } public string PosterPath { get; set; } public DateTime ReleaseDate { get; set; } public string Status { get; set; } diff --git a/src/Ombi.Store/Migrations/20170703134019_Initial.cs b/src/Ombi.Store/Migrations/20170703134019_Initial.cs index 7931e4083..edca99333 100644 --- a/src/Ombi.Store/Migrations/20170703134019_Initial.cs +++ b/src/Ombi.Store/Migrations/20170703134019_Initial.cs @@ -146,7 +146,8 @@ namespace Ombi.Store.Migrations ParentRequestId = table.Column(nullable: false), RequestType = table.Column(nullable: false), RequestedDate = table.Column(nullable: false), - RequestedUserId = table.Column(nullable: false) + RequestedUserId = table.Column(nullable: false), + Title = table.Column(nullable: true) }, constraints: table => { diff --git a/src/Ombi/ClientApp/app/services/search.service.ts b/src/Ombi/ClientApp/app/services/search.service.ts index 384b524d9..afef58f0c 100644 --- a/src/Ombi/ClientApp/app/services/search.service.ts +++ b/src/Ombi/ClientApp/app/services/search.service.ts @@ -29,9 +29,6 @@ export class SearchService extends ServiceAuthHelpers { topRatedMovies(): Observable { return this.http.get(`${this.url}/Movie/toprated`).map(this.extractData); } - extraInfo(movies: ISearchMovieResult[]): Observable { - return this.http.post(`${this.url}/Movie/extrainfo`, JSON.stringify(movies), { headers: this.headers }).map(this.extractData); - } getMovieInformation(theMovieDbId: number): Observable { return this.http.get(`${this.url}/Movie/info/${theMovieDbId}`).map(this.extractData); } diff --git a/src/Ombi/ClientApp/app/settings/notifications/notificationtemplate.component.ts b/src/Ombi/ClientApp/app/settings/notifications/notificationtemplate.component.ts index fdb952ee3..8dabb5a49 100644 --- a/src/Ombi/ClientApp/app/settings/notifications/notificationtemplate.component.ts +++ b/src/Ombi/ClientApp/app/settings/notifications/notificationtemplate.component.ts @@ -25,5 +25,5 @@ export class NotificationTemplate { {LongTime} : 16:02:34
{ShortTime} : 16:02
-` +`; } \ No newline at end of file diff --git a/src/Ombi/Controllers/SearchController.cs b/src/Ombi/Controllers/SearchController.cs index afa3a30fc..570206696 100644 --- a/src/Ombi/Controllers/SearchController.cs +++ b/src/Ombi/Controllers/SearchController.cs @@ -44,18 +44,6 @@ namespace Ombi.Controllers } } - /// - /// Gets extra information on the movie e.g. IMDBId - /// - /// We use TheMovieDb as the Movie Provider - /// The model. - /// - [HttpPost("movie/extrainfo")] - public async Task> GetImdbInfo([FromBody]IEnumerable model) - { - return await MovieEngine.LookupImdbInformation(model); - } - /// /// Gets extra information on the movie e.g. IMDBId ///