Merge pull request #251 from tidusjar/dev

1.7.4
pull/269/head PlexRequests-v1.7.407
Jamie 8 years ago
commit ee35d3bb52

@ -26,8 +26,6 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Mono.Data.Sqlite;
@ -84,7 +82,11 @@ namespace PlexRequests.Core
connection.CreateSchema(version); // Set the default.
schema = connection.GetSchemaVersion();
}
if (version > schema.SchemaVersion)
{
Db.DbConnection().UpdateSchemaVersion(version);
schema = connection.GetSchemaVersion();
}
version = schema.SchemaVersion;
return version;

@ -73,6 +73,8 @@ namespace PlexRequests.UI.Tests
private Mock<INotificationService> NotificationService { get; set; }
private Mock<ICacheProvider> Cache { get; set; }
private Mock<ISettingsService<LogSettings>> Log { get; set; }
private Mock<ISettingsService<SlackNotificationSettings>> SlackSettings { get; set; }
private Mock<ISlackApi> SlackApi { get; set; }
private ConfigurableBootstrapper Bootstrapper { get; set; }
@ -105,6 +107,8 @@ namespace PlexRequests.UI.Tests
HeadphonesSettings = new Mock<ISettingsService<HeadphonesSettings>>();
Cache = new Mock<ICacheProvider>();
Log = new Mock<ISettingsService<LogSettings>>();
SlackApi = new Mock<ISlackApi>();
SlackSettings = new Mock<ISettingsService<SlackNotificationSettings>>();
Bootstrapper = new ConfigurableBootstrapper(with =>
{
@ -128,6 +132,8 @@ namespace PlexRequests.UI.Tests
with.Dependency(HeadphonesSettings.Object);
with.Dependency(Cache.Object);
with.Dependency(Log.Object);
with.Dependency(SlackApi.Object);
with.Dependency(SlackSettings.Object);
with.RootPathProvider<TestRootPathProvider>();
with.RequestStartup((container, pipelines, context) =>
{

@ -82,6 +82,8 @@ namespace PlexRequests.UI.Modules
private IRepository<LogEntity> LogsRepo { get; }
private INotificationService NotificationService { get; }
private ICacheProvider Cache { get; }
private ISettingsService<SlackNotificationSettings> SlackSettings { get; }
private ISlackApi SlackApi { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
public AdminModule(ISettingsService<PlexRequestSettings> prService,
@ -102,7 +104,8 @@ namespace PlexRequests.UI.Modules
INotificationService notify,
ISettingsService<HeadphonesSettings> headphones,
ISettingsService<LogSettings> logs,
ICacheProvider cache) : base("admin", prService)
ICacheProvider cache, ISettingsService<SlackNotificationSettings> slackSettings,
ISlackApi slackApi) : base("admin", prService)
{
PrService = prService;
CpService = cpService;
@ -123,6 +126,8 @@ namespace PlexRequests.UI.Modules
HeadphonesService = headphones;
LogService = logs;
Cache = cache;
SlackSettings = slackSettings;
SlackApi = slackApi;
this.RequiresClaims(UserClaims.Admin);
@ -176,6 +181,11 @@ namespace PlexRequests.UI.Modules
Post["/createapikey"] = x => CreateApiKey();
Post["/autoupdate"] = x => AutoUpdate();
Post["/testslacknotification"] = _ => TestSlackNotification();
Get["/slacknotification"] = _ => SlackNotifications();
Post["/slacknotification"] = _ => SaveSlackNotifications();
}
private Negotiator Authentication()
@ -735,5 +745,65 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(apiKey);
}
private Response TestSlackNotification()
{
var settings = this.BindAndValidate<SlackNotificationSettings>();
if (!ModelValidationResult.IsValid)
{
return Response.AsJson(ModelValidationResult.SendJsonError());
}
var notificationModel = new NotificationModel
{
NotificationType = NotificationType.Test,
DateTime = DateTime.Now
};
try
{
NotificationService.Subscribe(new SlackNotification(SlackApi, SlackSettings));
settings.Enabled = true;
NotificationService.Publish(notificationModel, settings);
Log.Info("Sent slack notification test");
}
catch (Exception e)
{
Log.Error(e, "Failed to subscribe and publish test Slack Notification");
}
finally
{
NotificationService.UnSubscribe(new SlackNotification(SlackApi, SlackSettings));
}
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully sent a test Slack Notification! If you do not receive it please check the logs." });
}
private Negotiator SlackNotifications()
{
var settings = SlackSettings.GetSettings();
return View["SlackNotifications", settings];
}
private Response SaveSlackNotifications()
{
var settings = this.BindAndValidate<SlackNotificationSettings>();
if (!ModelValidationResult.IsValid)
{
return Response.AsJson(ModelValidationResult.SendJsonError());
}
var result = SlackSettings.SaveSettings(settings);
if (settings.Enabled)
{
NotificationService.Subscribe(new SlackNotification(SlackApi, SlackSettings));
}
else
{
NotificationService.UnSubscribe(new SlackNotification(SlackApi, SlackSettings));
}
Log.Info("Saved slack settings, result: {0}", result);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Slack Notifications!" }
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}
}
}

@ -1,130 +0,0 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: AdminNotificationsModule.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;
using Nancy.ModelBinding;
using Nancy.Responses.Negotiation;
using Nancy.Security;
using Nancy.Validation;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Services.Interfaces;
using PlexRequests.Services.Notification;
using PlexRequests.UI.Helpers;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Modules
{
public class AdminNotificationsModule : BaseModule
{
public AdminNotificationsModule(ISettingsService<PlexRequestSettings> prService, ISettingsService<SlackNotificationSettings> slackSettings,
INotificationService notify, ISlackApi slackApi) : base("admin", prService)
{
this.RequiresClaims(UserClaims.Admin);
SlackSettings = slackSettings;
NotificationService = notify;
SlackApi = slackApi;
Post["/testslacknotification"] = _ => TestSlackNotification();
Get["/slacknotification"] = _ => SlackNotifications();
Post["/slacknotification"] = _ => SaveSlackNotifications();
}
private ISettingsService<SlackNotificationSettings> SlackSettings { get; }
private INotificationService NotificationService { get; }
private ISlackApi SlackApi { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
private Response TestSlackNotification()
{
var settings = this.BindAndValidate<SlackNotificationSettings>();
if (!ModelValidationResult.IsValid)
{
return Response.AsJson(ModelValidationResult.SendJsonError());
}
var notificationModel = new NotificationModel
{
NotificationType = NotificationType.Test,
DateTime = DateTime.Now
};
try
{
NotificationService.Subscribe(new SlackNotification(SlackApi,SlackSettings));
settings.Enabled = true;
NotificationService.Publish(notificationModel, settings);
Log.Info("Sent slack notification test");
}
catch (Exception e)
{
Log.Error(e,"Failed to subscribe and publish test Slack Notification");
}
finally
{
NotificationService.UnSubscribe(new SlackNotification(SlackApi, SlackSettings));
}
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully sent a test Slack Notification! If you do not receive it please check the logs." });
}
private Negotiator SlackNotifications()
{
var settings = SlackSettings.GetSettings();
return View["Admin/SlackNotifications", settings];
}
private Response SaveSlackNotifications()
{
var settings = this.BindAndValidate<SlackNotificationSettings>();
if (!ModelValidationResult.IsValid)
{
return Response.AsJson(ModelValidationResult.SendJsonError());
}
var result = SlackSettings.SaveSettings(settings);
if (settings.Enabled)
{
NotificationService.Subscribe(new SlackNotification(SlackApi, SlackSettings));
}
else
{
NotificationService.UnSubscribe(new SlackNotification(SlackApi, SlackSettings));
}
Log.Info("Saved slack settings, result: {0}", result);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Slack Notifications!" }
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}
}
}

@ -357,7 +357,7 @@ namespace PlexRequests.UI.Modules
private Response ClearIssue(int requestId)
{
this.RequiresClaims (UserClaims.PowerUser, UserClaims.Admin);
this.RequiresClaims ( UserClaims.Admin);
var originalRequest = Service.Get(requestId);
if (originalRequest == null)
@ -375,7 +375,7 @@ namespace PlexRequests.UI.Modules
private Response ChangeRequestAvailability(int requestId, bool available)
{
this.RequiresClaims (UserClaims.PowerUser, UserClaims.Admin);
this.RequiresClaims (UserClaims.Admin);
var originalRequest = Service.Get(requestId);
if (originalRequest == null)
{
@ -392,7 +392,7 @@ namespace PlexRequests.UI.Modules
private Response AddNote(int requestId, string noteArea)
{
this.RequiresClaims (UserClaims.PowerUser, UserClaims.Admin);
this.RequiresClaims (UserClaims.Admin);
var originalRequest = Service.Get(requestId);
if (originalRequest == null)
{

@ -182,7 +182,6 @@
<Compile Include="Models\SearchMusicViewModel.cs" />
<Compile Include="Models\SearchMovieViewModel.cs" />
<Compile Include="Models\UserUpdateViewModel.cs" />
<Compile Include="Modules\AdminNotificationsModule.cs" />
<Compile Include="Modules\ApiDocsModule.cs" />
<Compile Include="Modules\ApiSettingsMetadataModule.cs" />
<Compile Include="Modules\ApiUserMetadataModule.cs" />

@ -98,7 +98,7 @@
{
<input type="checkbox" id="SeasonFolders" name="SeasonFolders">
}
<label>Enable season folders</label>
<label for="SeasonFolders">Enable season folders</label>
</div>
<label>Enabled Season Folders to organize seasons into individual folders within a show.</label>

@ -51,7 +51,7 @@ If you feel like donating you can [here!](https://paypal.me/PlexRequestsNet)
## A massive thanks to everyone below for all their help!
[heartisall](https://github.com/heartisall), [Stuke00](https://github.com/Stuke00), [shiitake](https://github.com/shiitake), [Drewster727](https://github.com/Drewster727), Majawat, [EddiYo](https://github.com/EddiYo), [SaskiFX](https://github.com/SaskiFX)
[heartisall](https://github.com/heartisall), [Stuke00](https://github.com/Stuke00), [shiitake](https://github.com/shiitake), [Drewster727](https://github.com/Drewster727), Majawat, [EddiYo](https://github.com/EddiYo), [SaskiFX](https://github.com/SaskiFX), [zenjabba](https://github.com/zenjabba)
## Stats
[![Throughput Graph](https://graphs.waffle.io/tidusjar/PlexRequests.Net/throughput.svg)](https://waffle.io/tidusjar/PlexRequests.Net/metrics/throughput)

@ -3,9 +3,9 @@ configuration: Release
assembly_info:
patch: true
file: '**\AssemblyInfo.*'
assembly_version: '1.7.3'
assembly_version: '1.7.4'
assembly_file_version: '{version}'
assembly_informational_version: '1.7.3'
assembly_informational_version: '1.7.4'
before_build:
- cmd: appveyor-retry nuget restore
build:

Loading…
Cancel
Save