pull/88/head
tidusjar 9 years ago
commit 68f8b9cd71

@ -0,0 +1,36 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: IPushoverApi.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 PlexRequests.Api.Models.Notifications;
namespace PlexRequests.Api.Interfaces
{
public interface IPushoverApi
{
PushoverResponse Push(string accessToken, string message, string userToken);
}
}

@ -49,6 +49,7 @@
<Compile Include="ICouchPotatoApi.cs" /> <Compile Include="ICouchPotatoApi.cs" />
<Compile Include="IPlexApi.cs" /> <Compile Include="IPlexApi.cs" />
<Compile Include="IPushbulletApi.cs" /> <Compile Include="IPushbulletApi.cs" />
<Compile Include="IPushoverApi.cs" />
<Compile Include="ISickRageApi.cs" /> <Compile Include="ISickRageApi.cs" />
<Compile Include="ISonarrApi.cs" /> <Compile Include="ISonarrApi.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

@ -0,0 +1,34 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PushoverResponse.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
namespace PlexRequests.Api.Models.Notifications
{
public class PushoverResponse
{
public int status { get; set; }
public string request { get; set; }
}
}

@ -50,6 +50,7 @@
<Compile Include="Movie\CouchPotatoStatus.cs" /> <Compile Include="Movie\CouchPotatoStatus.cs" />
<Compile Include="Notifications\PushbulletPush.cs" /> <Compile Include="Notifications\PushbulletPush.cs" />
<Compile Include="Notifications\PushbulletResponse.cs" /> <Compile Include="Notifications\PushbulletResponse.cs" />
<Compile Include="Notifications\PushoverResponse.cs" />
<Compile Include="Plex\PlexAccount.cs" /> <Compile Include="Plex\PlexAccount.cs" />
<Compile Include="Plex\PlexAuthentication.cs" /> <Compile Include="Plex\PlexAuthentication.cs" />
<Compile Include="Plex\PlexError.cs" /> <Compile Include="Plex\PlexError.cs" />

@ -72,6 +72,7 @@
<DependentUpon>MockApiData.resx</DependentUpon> <DependentUpon>MockApiData.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="Mocks\MockSonarrApi.cs" /> <Compile Include="Mocks\MockSonarrApi.cs" />
<Compile Include="PushoverApi.cs" />
<Compile Include="PushbulletApi.cs" /> <Compile Include="PushbulletApi.cs" />
<Compile Include="SickrageApi.cs" /> <Compile Include="SickrageApi.cs" />
<Compile Include="SonarrApi.cs" /> <Compile Include="SonarrApi.cs" />

@ -0,0 +1,56 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexApi.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using Nancy.Helpers;
using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Notifications;
using RestSharp;
namespace PlexRequests.Api
{
public class PushoverApi : IPushoverApi
{
public PushoverResponse Push(string accessToken, string message, string userToken)
{
var request = new RestRequest
{
Method = Method.POST,
Resource = "messages.json?token={token}&user={user}&message={message}"
};
request.AddUrlSegment("token", accessToken);
request.AddUrlSegment("message", message);
request.AddUrlSegment("user", userToken);
var api = new ApiRequest();
return api.ExecuteJson<PushoverResponse>(request, new Uri("https://api.pushover.net/1"));
}
}
}

@ -73,6 +73,7 @@
<Compile Include="JsonRequestService.cs" /> <Compile Include="JsonRequestService.cs" />
<Compile Include="Models\StatusModel.cs" /> <Compile Include="Models\StatusModel.cs" />
<Compile Include="SettingModels\AuthenticationSettings.cs" /> <Compile Include="SettingModels\AuthenticationSettings.cs" />
<Compile Include="SettingModels\PushoverNotificationSettings.cs" />
<Compile Include="SettingModels\PushBulletNotificationSettings.cs" /> <Compile Include="SettingModels\PushBulletNotificationSettings.cs" />
<Compile Include="SettingModels\EmailNotificationSettings.cs" /> <Compile Include="SettingModels\EmailNotificationSettings.cs" />
<Compile Include="SettingModels\PlexSettings.cs" /> <Compile Include="SettingModels\PlexSettings.cs" />

@ -0,0 +1,9 @@
namespace PlexRequests.Core.SettingModels
{
public class PushoverNotificationSettings : Settings
{
public bool Enabled { get; set; }
public string AccessToken { get; set; }
public string UserToken { get; set; }
}
}

@ -77,7 +77,15 @@ namespace PlexRequests.Services.Notification
private bool ValidateConfiguration() private bool ValidateConfiguration()
{ {
return !Settings.Enabled && !string.IsNullOrEmpty(Settings.AccessToken); if (!Settings.Enabled)
{
return false;
}
if (string.IsNullOrEmpty(Settings.AccessToken))
{
return false;
}
return true;
} }
private PushbulletNotificationSettings GetSettings() private PushbulletNotificationSettings GetSettings()
@ -106,8 +114,8 @@ namespace PlexRequests.Services.Notification
private bool PushIssue(NotificationModel model) private bool PushIssue(NotificationModel model)
{ {
var message = $"A new issue: {model.Title} has been reported by user: {model.User} for the title: {model.Body}"; var message = $"A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
var pushTitle = $"Plex Requests: A new issue has been reported for {model.Body}"; var pushTitle = $"Plex Requests: A new issue has been reported for {model.Title}";
try try
{ {
var result = PushbulletApi.Push(Settings.AccessToken, pushTitle, message, Settings.DeviceIdentifier); var result = PushbulletApi.Push(Settings.AccessToken, pushTitle, message, Settings.DeviceIdentifier);

@ -0,0 +1,132 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PushbulletNotification.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
namespace PlexRequests.Services.Notification
{
public class PushoverNotification : INotification
{
public PushoverNotification(IPushoverApi pushoverApi, ISettingsService<PushoverNotificationSettings> settings)
{
PushoverApi = pushoverApi;
SettingsService = settings;
}
private IPushoverApi PushoverApi { get; }
private ISettingsService<PushoverNotificationSettings> SettingsService { get; }
private PushoverNotificationSettings Settings => GetSettings();
private static Logger Log = LogManager.GetCurrentClassLogger();
public string NotificationName => "PushoverNotification";
public bool Notify(NotificationModel model)
{
if (!ValidateConfiguration())
{
return false;
}
switch (model.NotificationType)
{
case NotificationType.NewRequest:
return PushNewRequest(model);
case NotificationType.Issue:
return PushIssue(model);
case NotificationType.RequestAvailable:
break;
case NotificationType.RequestApproved:
break;
case NotificationType.AdminNote:
break;
default:
throw new ArgumentOutOfRangeException();
}
return false;
}
private bool ValidateConfiguration()
{
if (!Settings.Enabled)
{
return false;
}
if (string.IsNullOrEmpty(Settings.AccessToken) || string.IsNullOrEmpty(Settings.UserToken))
{
return false;
}
return true;
}
private PushoverNotificationSettings GetSettings()
{
return SettingsService.GetSettings();
}
private bool PushNewRequest(NotificationModel model)
{
var message = $"Plex Requests: {model.Title} has been requested by user: {model.User}";
try
{
var result = PushoverApi.Push(Settings.AccessToken, message, Settings.UserToken);
if (result?.status == 1)
{
return true;
}
}
catch (Exception e)
{
Log.Fatal(e);
}
return false;
}
private bool PushIssue(NotificationModel model)
{
var message = $"Plex Requests: A new issue: {model.Body} has been reported by user: {model.User} for the title: {model.Title}";
try
{
var result = PushoverApi.Push(Settings.AccessToken, message, Settings.UserToken);
if (result != null)
{
return true;
}
}
catch (Exception e)
{
Log.Fatal(e);
}
return false;
}
}
}

@ -82,6 +82,7 @@
<Compile Include="Notification\NotificationModel.cs" /> <Compile Include="Notification\NotificationModel.cs" />
<Compile Include="Notification\NotificationService.cs" /> <Compile Include="Notification\NotificationService.cs" />
<Compile Include="Notification\NotificationType.cs" /> <Compile Include="Notification\NotificationType.cs" />
<Compile Include="Notification\PushoverNotification.cs" />
<Compile Include="Notification\PushbulletNotification.cs" /> <Compile Include="Notification\PushbulletNotification.cs" />
<Compile Include="PlexAvailabilityChecker.cs" /> <Compile Include="PlexAvailabilityChecker.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

@ -57,9 +57,11 @@ namespace PlexRequests.UI.Tests
private Mock<ISettingsService<SickRageSettings>> SickRageSettingsMock { get; set; } private Mock<ISettingsService<SickRageSettings>> SickRageSettingsMock { get; set; }
private Mock<ISettingsService<EmailNotificationSettings>> EmailMock { get; set; } private Mock<ISettingsService<EmailNotificationSettings>> EmailMock { get; set; }
private Mock<ISettingsService<PushbulletNotificationSettings>> PushbulletSettings { get; set; } private Mock<ISettingsService<PushbulletNotificationSettings>> PushbulletSettings { get; set; }
private Mock<ISettingsService<PushoverNotificationSettings>> PushoverSettings { get; set; }
private Mock<IPlexApi> PlexMock { get; set; } private Mock<IPlexApi> PlexMock { get; set; }
private Mock<ISonarrApi> SonarrApiMock { get; set; } private Mock<ISonarrApi> SonarrApiMock { get; set; }
private Mock<IPushbulletApi> PushbulletApi { get; set; } private Mock<IPushbulletApi> PushbulletApi { get; set; }
private Mock<IPushoverApi> PushoverApi { get; set; }
private Mock<ICouchPotatoApi> CpApi { get; set; } private Mock<ICouchPotatoApi> CpApi { get; set; }
private Mock<IRepository<LogEntity>> LogRepo { get; set; } private Mock<IRepository<LogEntity>> LogRepo { get; set; }
@ -87,6 +89,8 @@ namespace PlexRequests.UI.Tests
CpApi = new Mock<ICouchPotatoApi>(); CpApi = new Mock<ICouchPotatoApi>();
SickRageSettingsMock = new Mock<ISettingsService<SickRageSettings>>(); SickRageSettingsMock = new Mock<ISettingsService<SickRageSettings>>();
LogRepo = new Mock<IRepository<LogEntity>>(); LogRepo = new Mock<IRepository<LogEntity>>();
PushoverSettings = new Mock<ISettingsService<PushoverNotificationSettings>>();
PushoverApi = new Mock<IPushoverApi>();
Bootstrapper = new ConfigurableBootstrapper(with => Bootstrapper = new ConfigurableBootstrapper(with =>
{ {
@ -104,6 +108,8 @@ namespace PlexRequests.UI.Tests
with.Dependency(CpApi.Object); with.Dependency(CpApi.Object);
with.Dependency(SickRageSettingsMock.Object); with.Dependency(SickRageSettingsMock.Object);
with.Dependency(LogRepo.Object); with.Dependency(LogRepo.Object);
with.Dependency(PushoverSettings.Object);
with.Dependency(PushoverApi.Object);
with.RootPathProvider<TestRootPathProvider>(); with.RootPathProvider<TestRootPathProvider>();
with.RequestStartup((container, pipelines, context) => with.RequestStartup((container, pipelines, context) =>
{ {

@ -75,6 +75,7 @@ namespace PlexRequests.UI
container.Register<ISettingsService<SickRageSettings>, SettingsServiceV2<SickRageSettings>>(); container.Register<ISettingsService<SickRageSettings>, SettingsServiceV2<SickRageSettings>>();
container.Register<ISettingsService<EmailNotificationSettings>, SettingsServiceV2<EmailNotificationSettings>>(); container.Register<ISettingsService<EmailNotificationSettings>, SettingsServiceV2<EmailNotificationSettings>>();
container.Register<ISettingsService<PushbulletNotificationSettings>, SettingsServiceV2<PushbulletNotificationSettings>>(); container.Register<ISettingsService<PushbulletNotificationSettings>, SettingsServiceV2<PushbulletNotificationSettings>>();
container.Register<ISettingsService<PushoverNotificationSettings>, SettingsServiceV2<PushoverNotificationSettings>>();
// Repo's // Repo's
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>(); container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();
@ -90,6 +91,7 @@ namespace PlexRequests.UI
// Api's // Api's
container.Register<ICouchPotatoApi, CouchPotatoApi>(); container.Register<ICouchPotatoApi, CouchPotatoApi>();
container.Register<IPushbulletApi, PushbulletApi>(); container.Register<IPushbulletApi, PushbulletApi>();
container.Register<IPushoverApi, PushoverApi>();
container.Register<ISickRageApi, SickrageApi>(); container.Register<ISickRageApi, SickrageApi>();
container.Register<ISonarrApi, SonarrApi>(); container.Register<ISonarrApi, SonarrApi>();
container.Register<IPlexApi, PlexApi>(); container.Register<IPlexApi, PlexApi>();
@ -139,7 +141,14 @@ namespace PlexRequests.UI
var pushbulletSettings = pushbulletService.GetSettings(); var pushbulletSettings = pushbulletService.GetSettings();
if (pushbulletSettings.Enabled) if (pushbulletSettings.Enabled)
{ {
NotificationService.Subscribe(new PushbulletNotification(container.Resolve<IPushbulletApi>(), container.Resolve<ISettingsService<PushbulletNotificationSettings>>())); NotificationService.Subscribe(new PushbulletNotification(container.Resolve<IPushbulletApi>(), pushbulletService));
}
var pushoverService = container.Resolve<ISettingsService<PushoverNotificationSettings>>();
var pushoverSettings = pushoverService.GetSettings();
if (pushoverSettings.Enabled)
{
NotificationService.Subscribe(new PushoverNotification(container.Resolve<IPushoverApi>(), pushoverService));
} }
} }
} }

@ -62,9 +62,11 @@ namespace PlexRequests.UI.Modules
private ISettingsService<SickRageSettings> SickRageService { get; } private ISettingsService<SickRageSettings> SickRageService { get; }
private ISettingsService<EmailNotificationSettings> EmailService { get; } private ISettingsService<EmailNotificationSettings> EmailService { get; }
private ISettingsService<PushbulletNotificationSettings> PushbulletService { get; } private ISettingsService<PushbulletNotificationSettings> PushbulletService { get; }
private ISettingsService<PushoverNotificationSettings> PushoverService { get; }
private IPlexApi PlexApi { get; } private IPlexApi PlexApi { get; }
private ISonarrApi SonarrApi { get; } private ISonarrApi SonarrApi { get; }
private PushbulletApi PushbulletApi { get; } private IPushbulletApi PushbulletApi { get; }
private IPushoverApi PushoverApi { get; }
private ICouchPotatoApi CpApi { get; } private ICouchPotatoApi CpApi { get; }
private IRepository<LogEntity> LogsRepo { get; } private IRepository<LogEntity> LogsRepo { get; }
@ -81,6 +83,8 @@ namespace PlexRequests.UI.Modules
ISettingsService<PushbulletNotificationSettings> pbSettings, ISettingsService<PushbulletNotificationSettings> pbSettings,
PushbulletApi pbApi, PushbulletApi pbApi,
ICouchPotatoApi cpApi, ICouchPotatoApi cpApi,
ISettingsService<PushoverNotificationSettings> pushoverSettings,
IPushoverApi pushoverApi,
IRepository<LogEntity> logsRepo) : base("admin") IRepository<LogEntity> logsRepo) : base("admin")
{ {
RpService = rpService; RpService = rpService;
@ -96,6 +100,8 @@ namespace PlexRequests.UI.Modules
CpApi = cpApi; CpApi = cpApi;
SickRageService = sickrage; SickRageService = sickrage;
LogsRepo = logsRepo; LogsRepo = logsRepo;
PushoverService = pushoverSettings;
PushoverApi = pushoverApi;
#if !DEBUG #if !DEBUG
this.RequiresAuthentication(); this.RequiresAuthentication();
@ -133,6 +139,9 @@ namespace PlexRequests.UI.Modules
Get["/pushbulletnotification"] = _ => PushbulletNotifications(); Get["/pushbulletnotification"] = _ => PushbulletNotifications();
Post["/pushbulletnotification"] = _ => SavePushbulletNotifications(); Post["/pushbulletnotification"] = _ => SavePushbulletNotifications();
Get["/pushovernotification"] = _ => PushoverNotifications();
Post["/pushovernotification"] = _ => SavePushoverNotifications();
Get["/logs"] = _ => Logs(); Get["/logs"] = _ => Logs();
Get["/loglevel"] = _ => GetLogLevels(); Get["/loglevel"] = _ => GetLogLevels();
Post["/loglevel"] = _ => UpdateLogLevels(Request.Form.level); Post["/loglevel"] = _ => UpdateLogLevels(Request.Form.level);
@ -425,6 +434,38 @@ namespace PlexRequests.UI.Modules
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." }); : new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
} }
private Negotiator PushoverNotifications()
{
var settings = PushoverService.GetSettings();
return View["PushoverNotifications", settings];
}
private Response SavePushoverNotifications()
{
var settings = this.Bind<PushoverNotificationSettings>();
var valid = this.Validate(settings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
Log.Trace(settings.DumpJson());
var result = PushoverService.SaveSettings(settings);
if (settings.Enabled)
{
NotificationService.Subscribe(new PushoverNotification(PushoverApi, PushoverService));
}
else
{
NotificationService.UnSubscribe(new PushoverNotification(PushoverApi, PushoverService));
}
Log.Info("Saved email settings, result: {0}", result);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Pushbullet Notifications!" }
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}
private Response GetCpProfiles() private Response GetCpProfiles()
{ {
var settings = this.Bind<CouchPotatoSettings>(); var settings = this.Bind<CouchPotatoSettings>();

@ -25,6 +25,7 @@
// ************************************************************************/ // ************************************************************************/
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -37,6 +38,7 @@ using Nancy.Security;
using PlexRequests.Api; using PlexRequests.Api;
using PlexRequests.Core; using PlexRequests.Core;
using PlexRequests.Core.SettingModels; using PlexRequests.Core.SettingModels;
using PlexRequests.Services.Notification;
using PlexRequests.Store; using PlexRequests.Store;
using PlexRequests.UI.Models; using PlexRequests.UI.Models;
@ -166,6 +168,17 @@ namespace PlexRequests.UI.Modules
var result = Service.UpdateRequest(originalRequest); var result = Service.UpdateRequest(originalRequest);
var model = new NotificationModel
{
User = Session[SessionKeys.UsernameKey].ToString(),
NotificationType = NotificationType.Issue,
Title = originalRequest.Title,
DateTime = DateTime.Now,
Body = issue == IssueState.Other ? comment : issue.Humanize()
};
NotificationService.Publish(model);
return Response.AsJson(result return Response.AsJson(result
? new JsonResponseModel { Result = true } ? new JsonResponseModel { Result = true }
: new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" }); : new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" });

@ -170,6 +170,7 @@
<Compile Include="Bootstrapper.cs" /> <Compile Include="Bootstrapper.cs" />
<Compile Include="Helpers\TvSender.cs" /> <Compile Include="Helpers\TvSender.cs" />
<Compile Include="Helpers\ValidationHelper.cs" /> <Compile Include="Helpers\ValidationHelper.cs" />
<Compile Include="Validators\PushoverSettingsValidator.cs" />
<Compile Include="Validators\PushbulletSettingsValidator.cs" /> <Compile Include="Validators\PushbulletSettingsValidator.cs" />
<Compile Include="Validators\EmailNotificationSettingsValidator.cs" /> <Compile Include="Validators\EmailNotificationSettingsValidator.cs" />
<Compile Include="Validators\CouchPotatoValidator.cs" /> <Compile Include="Validators\CouchPotatoValidator.cs" />
@ -342,6 +343,9 @@
<Content Include="Views\Admin\Logs.cshtml"> <Content Include="Views\Admin\Logs.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Views\Admin\PushoverNotifications.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Web.Debug.config"> <None Include="Web.Debug.config">
<DependentUpon>web.config</DependentUpon> <DependentUpon>web.config</DependentUpon>
</None> </None>

@ -0,0 +1,41 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SonarrValidator.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.Validators
{
public class PushoverSettingsValidator : AbstractValidator<PushoverNotificationSettings>
{
public PushoverSettingsValidator()
{
RuleFor(request => request.AccessToken).NotEmpty().WithMessage("You must specify a API Token.");
RuleFor(request => request.UserToken).NotEmpty().WithMessage("You must specify a User Token.");
}
}
}

@ -0,0 +1,74 @@
@Html.Partial("_Sidebar")
<div class="col-sm-8 col-sm-push-1">
<form class="form-horizontal" method="POST" id="mainForm">
<fieldset>
<legend>Pushover Notifications</legend>
<div class="form-group">
<div class="checkbox">
<label>
@if (Model.Enabled)
{
<input type="checkbox" id="Enabled" name="Enabled" checked="checked"><text>Enabled</text>
}
else
{
<input type="checkbox" id="Enabled" name="Enabled"><text>Enabled</text>
}
</label>
</div>
</div>
<div class="form-group">
<label for="AccessToken" class="control-label">API Key</label>
<small class="control-label">Enter your API Key from Pushover.</small>
<div class="">
<input type="text" class="form-control form-control-custom " id="AccessToken" name="AccessToken" value="@Model.AccessToken">
</div>
</div>
<div class="form-group">
<label for="UserToken" class="control-label">User Token</label>
<small class="control-label">Your user or group key from Pushover.</small>
<div class="">
<input type="text" class="form-control form-control-custom " id="UserToken" name="UserToken" value="@Model.UserToken">
</div>
</div>
<div class="form-group">
<div>
<button id="save" type="submit" class="btn btn-primary-outline">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>
<script>
$(function () {
$('#save').click(function (e) {
e.preventDefault();
var $form = $("#mainForm");
$.ajax({
type: $form.prop("method"),
data: $form.serialize(),
url: $form.prop("action"),
dataType: "json",
success: function (response) {
if (response.result === true) {
generateNotify(response.message, "success");
} else {
generateNotify(response.message, "warning");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});
});
</script>

@ -70,14 +70,16 @@
{ {
<a class="list-group-item" href="/admin/pushbulletnotification">Pushbullet Notifications</a> <a class="list-group-item" href="/admin/pushbulletnotification">Pushbullet Notifications</a>
} }
@if (Context.Request.Path == "/admin/logs")
@if (Context.Request.Path == "/admin/pushovernotification")
{ {
<a class="list-group-item active" href="/admin/logs">Logs</a> <a class="list-group-item active" href="/admin/pushovernotification">Pushover Notifications</a>
} }
else else
{ {
<a class="list-group-item" href="/admin/logs">Logs</a> <a class="list-group-item" href="/admin/pushovernotification">Pushover Notifications</a>
} }
@if (Context.Request.Path == "/admin/status") @if (Context.Request.Path == "/admin/status")
{ {
<a class="list-group-item active" href="/admin/status">Status</a> <a class="list-group-item active" href="/admin/status">Status</a>

@ -46,7 +46,7 @@ If you feel like donating you can [here!](https://paypal.me/PlexRequestsNet)
###### A massive thanks to everyone below! ###### A massive thanks to everyone below!
[heartisall](https://github.com/heartisall) [heartisall](https://github.com/heartisall), Stuke00, [shiitake](https://github.com/shiitake)
# Sponsors # Sponsors

Loading…
Cancel
Save