Skip to content

Commit

Permalink
Merge pull request #251 from tidusjar/dev
Browse files Browse the repository at this point in the history
1.7.4
  • Loading branch information
Jamie committed May 25, 2016
2 parents 826b1d5 + 3032c4f commit ee35d3b
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 143 deletions.
8 changes: 5 additions & 3 deletions PlexRequests.Core/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

using Mono.Data.Sqlite;
Expand Down Expand Up @@ -84,7 +82,11 @@ private int CheckSchema()
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;
Expand Down
6 changes: 6 additions & 0 deletions PlexRequests.UI.Tests/AdminModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public class AdminModuleTests
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; }

Expand Down Expand Up @@ -105,6 +107,8 @@ public void Setup()
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 =>
{
Expand All @@ -128,6 +132,8 @@ public void Setup()
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) =>
{
Expand Down
74 changes: 72 additions & 2 deletions PlexRequests.UI/Modules/AdminModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class AdminModule : BaseModule
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,
Expand All @@ -102,7 +104,8 @@ public AdminModule(ISettingsService<PlexRequestSettings> prService,
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;
Expand All @@ -123,8 +126,10 @@ public AdminModule(ISettingsService<PlexRequestSettings> prService,
HeadphonesService = headphones;
LogService = logs;
Cache = cache;
SlackSettings = slackSettings;
SlackApi = slackApi;

this.RequiresClaims(UserClaims.Admin);
this.RequiresClaims(UserClaims.Admin);

Get["/"] = _ => Admin();

Expand Down Expand Up @@ -176,6 +181,11 @@ public AdminModule(ISettingsService<PlexRequestSettings> prService,
Post["/createapikey"] = x => CreateApiKey();

Post["/autoupdate"] = x => AutoUpdate();

Post["/testslacknotification"] = _ => TestSlackNotification();

Get["/slacknotification"] = _ => SlackNotifications();
Post["/slacknotification"] = _ => SaveSlackNotifications();
}

private Negotiator Authentication()
Expand Down Expand Up @@ -735,5 +745,65 @@ private Response CreateApiKey()

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." });
}
}
}
130 changes: 0 additions & 130 deletions PlexRequests.UI/Modules/AdminNotificationsModule.cs

This file was deleted.

6 changes: 3 additions & 3 deletions PlexRequests.UI/Modules/RequestsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private Response ReportIssue(int requestId, IssueState issue, string comment)

private Response ClearIssue(int requestId)
{
this.RequiresClaims (UserClaims.PowerUser, UserClaims.Admin);
this.RequiresClaims ( UserClaims.Admin);

var originalRequest = Service.Get(requestId);
if (originalRequest == null)
Expand All @@ -375,7 +375,7 @@ private Response ClearIssue(int requestId)

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)
{
Expand All @@ -392,7 +392,7 @@ private Response ChangeRequestAvailability(int requestId, bool available)

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)
{
Expand Down
1 change: 0 additions & 1 deletion PlexRequests.UI/PlexRequests.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
2 changes: 1 addition & 1 deletion PlexRequests.UI/Views/Admin/Sonarr.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ee35d3b

Please sign in to comment.