From d44612217a589298e6269830d73db19619d8e5ba Mon Sep 17 00:00:00 2001 From: TidusJar Date: Sun, 15 May 2016 22:30:47 -0400 Subject: [PATCH] - Notifications will no longer be send to the admins if they request something. - Looks like we missed out adding the notifications to Music requests, so I added that in --- PlexRequests.UI/Modules/SearchModule.cs | 88 +++++++++++++++++++------ 1 file changed, 67 insertions(+), 21 deletions(-) diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 92bcb1f38..39b58dd59 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -499,15 +499,16 @@ namespace PlexRequests.UI.Modules Log.Info("Adding movie to database (No approval required)"); RequestService.AddRequest(model); - var notificationModel = new NotificationModel - { - Title = model.Title, - User = Username, - DateTime = DateTime.Now, - NotificationType = NotificationType.NewRequest - }; - NotificationService.Publish(notificationModel); + if (ShouldSendNotification) { + var notificationModel = new NotificationModel { + Title = model.Title, + User = Username, + DateTime = DateTime.Now, + NotificationType = NotificationType.NewRequest + }; + NotificationService.Publish (notificationModel); + } return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullMovieName} was successfully added!" }); } return @@ -524,14 +525,15 @@ namespace PlexRequests.UI.Modules Log.Info("Adding movie to database (No approval required)"); RequestService.AddRequest(model); - var notificationModel = new NotificationModel - { - Title = model.Title, - User = Username, - DateTime = DateTime.Now, - NotificationType = NotificationType.NewRequest - }; - NotificationService.Publish(notificationModel); + if (ShouldSendNotification) { + var notificationModel = new NotificationModel { + Title = model.Title, + User = Username, + DateTime = DateTime.Now, + NotificationType = NotificationType.NewRequest + }; + NotificationService.Publish (notificationModel); + } return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullMovieName} was successfully added!" }); } @@ -657,9 +659,16 @@ namespace PlexRequests.UI.Modules model.Approved = true; Log.Debug("Adding tv to database requests (No approval required & Sonarr)"); RequestService.AddRequest(model); - var notify1 = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest }; - NotificationService.Publish(notify1); + if (ShouldSendNotification) { + var notify1 = new NotificationModel { + Title = model.Title, + User = Username, + DateTime = DateTime.Now, + NotificationType = NotificationType.NewRequest + }; + NotificationService.Publish (notify1); + } return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" }); } @@ -677,9 +686,15 @@ namespace PlexRequests.UI.Modules model.Approved = true; Log.Debug("Adding tv to database requests (No approval required & SickRage)"); RequestService.AddRequest(model); - - var notify2 = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest }; - NotificationService.Publish(notify2); + if (ShouldSendNotification) { + var notify2 = new NotificationModel { + Title = model.Title, + User = Username, + DateTime = DateTime.Now, + NotificationType = NotificationType.NewRequest + }; + NotificationService.Publish (notify2); + } return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" }); } @@ -698,6 +713,18 @@ namespace PlexRequests.UI.Modules return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" }); } + private bool ShouldSendNotification(){ + var sendNotification = true; + var claims = Context.CurrentUser?.Claims; + if (claims != null) { + if (claims.Contains (UserClaims.Admin) || claims.Contains (UserClaims.PowerUser)) { + sendNotification = false; // Don't bother sending a notification if the user is an admin + } + } + return sendNotification; + } + + private Response RequestAlbum(string releaseId, bool notify) { var settings = PrService.GetSettings(); @@ -798,6 +825,16 @@ namespace PlexRequests.UI.Modules model.Approved = true; RequestService.AddRequest(model); + if (ShouldSendNotification ()) { + var notify2 = new NotificationModel { + Title = model.Title, + User = Username, + DateTime = DateTime.Now, + NotificationType = NotificationType.NewRequest + }; + NotificationService.Publish (notify2); + } + return Response.AsJson(new JsonResponseModel { @@ -806,6 +843,15 @@ namespace PlexRequests.UI.Modules }); } + if (ShouldSendNotification ()) { + var notify2 = new NotificationModel { + Title = model.Title, + User = Username, + DateTime = DateTime.Now, + NotificationType = NotificationType.NewRequest + }; + NotificationService.Publish (notify2); + } var result = RequestService.AddRequest(model); return Response.AsJson(new JsonResponseModel {