From 9261232babcaa263638b85e8c0ed71aadf66f70f Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Thu, 19 Oct 2017 08:45:03 +0100 Subject: [PATCH] #1588 When we make changes to any requests that we can trigger a notification, always send it to all notification agents, even if the user wont recieve it. --- .../Engine/Interfaces/ITvRequestEngine.cs | 5 ++-- src/Ombi.Core/Engine/MovieRequestEngine.cs | 18 ++++++++++-- src/Ombi.Core/Engine/TvRequestEngine.cs | 17 +++++++++++ src/Ombi.Core/Helpers/NotificationHelper.cs | 28 +++++++++++++++++-- src/Ombi.Core/Senders/INotificationHelper.cs | 3 ++ .../app/login/resetpassword.component.ts | 10 +++++-- .../requests/tvrequest-children.component.ts | 21 ++------------ .../ClientApp/app/services/request.service.ts | 6 ++++ src/Ombi/Controllers/RequestController.cs | 22 +++++++++++++++ 9 files changed, 101 insertions(+), 29 deletions(-) diff --git a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs index 760a784de..3410313cb 100644 --- a/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs +++ b/src/Ombi.Core/Engine/Interfaces/ITvRequestEngine.cs @@ -9,12 +9,11 @@ namespace Ombi.Core.Engine.Interfaces { Task RemoveTvRequest(int requestId); - Task RequestTvShow(SearchTvShowViewModel tv); - + Task DenyChildRequest(ChildRequests request); + Task ChangeAvailability(ChildRequests request); Task> SearchTvRequest(string search); Task>>> SearchTvRequestTree(string search); - Task UpdateTvRequest(TvRequests request); Task>>> GetRequestsTreeNode(int count, int position); Task> GetAllChldren(int tvId); diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index 350f11155..353624ec3 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -86,12 +86,12 @@ namespace Ombi.Core.Engine if (requestModel.Approved) // The rules have auto approved this { - var result = await Sender.Send(requestModel); - if (result.Success && result.Sent) + var result = await ApproveMovie(requestModel); + if (result.RequestAdded) { return await AddMovieRequest(requestModel, fullMovieName); } - if (!result.Success) + if (!result.IsError) { Logger.LogWarning("Tried auto sending movie but failed. Message: {0}", result.Message); return new RequestEngineResult @@ -150,6 +150,7 @@ namespace Ombi.Core.Engine public async Task ApproveMovie(MovieRequests request) { await MovieRepository.Update(request); + NotificationHelper.Notify(request, NotificationType.RequestApproved); if (request.Approved) { var result = await Sender.Send(request); @@ -189,6 +190,17 @@ namespace Ombi.Core.Engine var allRequests = await MovieRepository.Get().ToListAsync(); var results = allRequests.FirstOrDefault(x => x.Id == request.Id); + if (!(results.Denied ?? false) && (request.Denied ?? false)) + { + // We are denying a request + NotificationHelper.Notify(request, NotificationType.RequestDeclined); + } + if (!results.Available && request.Available) + { + // We changed the availability manually + NotificationHelper.Notify(request, NotificationType.RequestAvailable); + } + results.Approved = request.Approved; results.Available = request.Available; results.Denied = request.Denied; diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index 524ea0240..852d5e2f0 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -183,6 +183,7 @@ namespace Ombi.Core.Engine await TvRepository.UpdateChild(request); if (request.Approved) { + NotificationHelper.Notify(request, NotificationType.RequestApproved); await Audit.Record(AuditType.Approved, AuditArea.TvRequest, $"Approved Request {request.Title}", Username); // Autosend await TvSender.Send(request); @@ -193,6 +194,21 @@ namespace Ombi.Core.Engine }; } + public async Task DenyChildRequest(ChildRequests request) + { + NotificationHelper.Notify(request, NotificationType.RequestDeclined); + return await UpdateChildRequest(request); + } + + public async Task ChangeAvailability(ChildRequests request) + { + if (request.Available) + { + NotificationHelper.Notify(request, NotificationType.RequestAvailable); + } + return await UpdateChildRequest(request); + } + public async Task UpdateChildRequest(ChildRequests request) { await Audit.Record(AuditType.Updated, AuditArea.TvRequest, $"Updated Request {request.Title}", Username); @@ -289,6 +305,7 @@ namespace Ombi.Core.Engine if (model.Approved) { // Autosend + NotificationHelper.Notify(model, NotificationType.RequestApproved); var result = await TvSender.Send(model); if (result.Success) { diff --git a/src/Ombi.Core/Helpers/NotificationHelper.cs b/src/Ombi.Core/Helpers/NotificationHelper.cs index 3994ccf2d..aa8e2f8f7 100644 --- a/src/Ombi.Core/Helpers/NotificationHelper.cs +++ b/src/Ombi.Core/Helpers/NotificationHelper.cs @@ -1,10 +1,8 @@ using System; using Hangfire; -using Ombi.Core.Models.Requests; using Ombi.Core.Notifications; using Ombi.Helpers; using Ombi.Notifications.Models; -using Ombi.Store.Entities; using Ombi.Store.Entities.Requests; namespace Ombi.Core @@ -29,6 +27,7 @@ namespace Ombi.Core BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel)); } + public void NewRequest(ChildRequests model) { var notificationModel = new NotificationOptions @@ -39,7 +38,32 @@ namespace Ombi.Core RequestType = model.RequestType }; BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel)); + } + + public void Notify(MovieRequests model, NotificationType type) + { + var notificationModel = new NotificationOptions + { + RequestId = model.Id, + DateTime = DateTime.Now, + NotificationType = type, + RequestType = model.RequestType, + Recipient = model.RequestedUser.Email + }; + BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel)); + } + public void Notify(ChildRequests model, NotificationType type) + { + var notificationModel = new NotificationOptions + { + RequestId = model.Id, + DateTime = DateTime.Now, + NotificationType = type, + RequestType = model.RequestType, + Recipient = model.RequestedUser.Email + }; + BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel)); } } } \ No newline at end of file diff --git a/src/Ombi.Core/Senders/INotificationHelper.cs b/src/Ombi.Core/Senders/INotificationHelper.cs index fead5e475..efc45020c 100644 --- a/src/Ombi.Core/Senders/INotificationHelper.cs +++ b/src/Ombi.Core/Senders/INotificationHelper.cs @@ -1,4 +1,5 @@ using Ombi.Core.Models.Requests; +using Ombi.Helpers; using Ombi.Store.Entities.Requests; namespace Ombi.Core @@ -7,5 +8,7 @@ namespace Ombi.Core { void NewRequest(FullBaseRequest model); void NewRequest(ChildRequests model); + void Notify(MovieRequests model, NotificationType type); + void Notify(ChildRequests model, NotificationType type); } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/login/resetpassword.component.ts b/src/Ombi/ClientApp/app/login/resetpassword.component.ts index b033ee4ca..5ce14463d 100644 --- a/src/Ombi/ClientApp/app/login/resetpassword.component.ts +++ b/src/Ombi/ClientApp/app/login/resetpassword.component.ts @@ -1,4 +1,5 @@ -import { Component, OnInit } from "@angular/core"; +import { PlatformLocation } from "@angular/common"; +import { Component, OnInit } from "@angular/core"; import { FormBuilder, FormGroup, Validators } from "@angular/forms"; import { ICustomizationSettings, IEmailNotificationSettings } from "../interfaces"; @@ -15,15 +16,20 @@ export class ResetPasswordComponent implements OnInit { public form: FormGroup; public customizationSettings: ICustomizationSettings; public emailSettings: IEmailNotificationSettings; + public baseUrl: string; constructor(private identityService: IdentityService, private notify: NotificationService, - private fb: FormBuilder, private settingsService: SettingsService) { + private fb: FormBuilder, private settingsService: SettingsService, private location: PlatformLocation) { this.form = this.fb.group({ email: ["", [Validators.required]], }); } public ngOnInit() { + const base = this.location.getBaseHrefFromDOM(); + if (base.length > 1) { + this.baseUrl = base; + } this.settingsService.getCustomization().subscribe(x => this.customizationSettings = x); this.settingsService.getEmailNotificationSettings().subscribe(x => this.emailSettings = x); } diff --git a/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts b/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts index 5bccbd17e..268e42410 100644 --- a/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts +++ b/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts @@ -1,5 +1,5 @@ import { Component, Input } from "@angular/core"; -import { IChildRequests, IEpisodesRequests } from "../interfaces"; +import { IChildRequests } from "../interfaces"; import { NotificationService, RequestService } from "../services"; @Component({ @@ -31,7 +31,7 @@ export class TvRequestChildrenComponent { ep.approved = false; }); }); - this.requestService.updateChild(request) + this.requestService.deleteChild(request) .subscribe(); } @@ -55,23 +55,6 @@ export class TvRequestChildrenComponent { }); } - public denySeasonRequest(request: IChildRequests) { - request.approved = false; - request.denied = true; - this.requestService.updateChild(request) - .subscribe(); - } - - public getColour(ep: IEpisodesRequests): string { - if (ep.available) { - return "lime"; - } - if (ep.approved) { - return "#00c0ff"; - } - return "white"; - } - private removeRequestFromUi(key: IChildRequests) { const index = this.childRequests.indexOf(key, 0); if (index > -1) { diff --git a/src/Ombi/ClientApp/app/services/request.service.ts b/src/Ombi/ClientApp/app/services/request.service.ts index c70e7cedb..62bf694e0 100644 --- a/src/Ombi/ClientApp/app/services/request.service.ts +++ b/src/Ombi/ClientApp/app/services/request.service.ts @@ -78,6 +78,12 @@ export class RequestService extends ServiceAuthHelpers { public updateChild(child: IChildRequests): Observable { return this.http.put(`${this.url}tv/child`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); } + public denyChild(child: IChildRequests): Observable { + return this.http.put(`${this.url}tv/deny`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); + } + public changeAvailabilityChild(child: IChildRequests): Observable { + return this.http.put(`${this.url}tv/changeavailability`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); + } public approveChild(child: IChildRequests): Observable { return this.http.post(`${this.url}tv/child/approve`, JSON.stringify(child), { headers: this.headers }).map(this.extractData); } diff --git a/src/Ombi/Controllers/RequestController.cs b/src/Ombi/Controllers/RequestController.cs index 914278c90..9715e8ee7 100644 --- a/src/Ombi/Controllers/RequestController.cs +++ b/src/Ombi/Controllers/RequestController.cs @@ -200,6 +200,28 @@ namespace Ombi.Controllers return await TvRequestEngine.UpdateChildRequest(child); } + /// + /// Denies the a specific child request + /// + /// The model. + /// + [HttpPut("tv/deny")] + public async Task DenyChild([FromBody] ChildRequests child) + { + return await TvRequestEngine.DenyChildRequest(child); + } + + /// + /// Changes the availability of the a specific child request + /// + /// The model. + /// + [HttpPut("tv/changeavailability")] + public async Task ChangeAvailability([FromBody] ChildRequests child) + { + return await TvRequestEngine.ChangeAvailability(child); + } + /// /// Updates the a specific child request ///