mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 15:32:37 -07:00
Added some of the backend bits for #182
This commit is contained in:
parent
7956f9f7ff
commit
88a43563c4
20 changed files with 881 additions and 637 deletions
|
@ -1,59 +1,91 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: AuthenticationSettingsTests.cs
|
// File: AuthenticationSettingsTests.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using NUnit.Framework;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using PlexRequests.Core.SettingModels;
|
|
||||||
|
using NUnit.Framework;
|
||||||
namespace PlexRequests.Core.Tests
|
|
||||||
{
|
using PlexRequests.Core.Models;
|
||||||
[TestFixture]
|
using PlexRequests.Core.SettingModels;
|
||||||
public class AuthenticationSettingsTests
|
|
||||||
{
|
namespace PlexRequests.Core.Tests
|
||||||
[Test, TestCaseSource(nameof(UserData))]
|
{
|
||||||
public void DeniedUserListTest(string users, string[] expected)
|
[TestFixture]
|
||||||
{
|
public class NotificationMessageResolverTests
|
||||||
var model = new AuthenticationSettings { DeniedUsers = users };
|
{
|
||||||
|
[TestCaseSource(nameof(MessageResolver))]
|
||||||
var result = model.DeniedUserList;
|
public string Resolve(Dictionary<NotificationType, string> message, Dictionary<string,string> param)
|
||||||
|
{
|
||||||
Assert.That(result.Count, Is.EqualTo(expected.Length));
|
var n = new NotificationMessageResolver();
|
||||||
for (var i = 0; i < expected.Length; i++)
|
var s = new NotificationSettings
|
||||||
{
|
{
|
||||||
Assert.That(result[i], Is.EqualTo(expected[i]));
|
Message = message,
|
||||||
}
|
CustomParamaters = param
|
||||||
}
|
};
|
||||||
|
|
||||||
static readonly object[] UserData =
|
return n.ParseMessage(s, NotificationType.NewRequest);
|
||||||
{
|
}
|
||||||
new object[] { "john", new [] {"john"} },
|
|
||||||
new object[] { "john , abc ,", new [] {"john", "abc"} },
|
private static IEnumerable<TestCaseData> MessageResolver
|
||||||
new object[] { "john,, cde", new [] {"john", "cde"} },
|
{
|
||||||
new object[] { "john,,, aaa , baaa , ", new [] {"john","aaa","baaa"} },
|
get
|
||||||
new object[] { "john, aaa , baaa , maaa, caaa", new [] {"john","aaa","baaa", "maaa", "caaa"} },
|
{
|
||||||
};
|
yield return new TestCaseData(
|
||||||
}
|
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "There has been a new request from {Username}, Title: {Title} for {Type}" } },
|
||||||
|
new Dictionary<string, string>{{"Username", "Jamie" },{"Title", "Finding Dory" },{"Type", "Movie" }})
|
||||||
|
.Returns("There has been a new request from Jamie, Title: Finding Dory for Movie")
|
||||||
|
.SetName("FindingDory");
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, string.Empty } },
|
||||||
|
new Dictionary<string, string>())
|
||||||
|
.Returns(string.Empty)
|
||||||
|
.SetName("Empty Message");
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "{{Wowwzer}} Damn}{{son}}}}" } },
|
||||||
|
new Dictionary<string, string> { {"son","HEY!"} })
|
||||||
|
.Returns("{{Wowwzer}} Damn}{HEY!}}}")
|
||||||
|
.SetName("Multiple Curlys");
|
||||||
|
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "This is a message with no curlys" } },
|
||||||
|
new Dictionary<string, string> { { "son", "HEY!" } })
|
||||||
|
.Returns("This is a message with no curlys")
|
||||||
|
.SetName("No Curlys");
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, new string(')', 5000)} },
|
||||||
|
new Dictionary<string, string> { { "son", "HEY!" } })
|
||||||
|
.Returns(new string(')', 5000))
|
||||||
|
.SetName("Long String");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
59
PlexRequests.Core.Tests/NotificationMessageResolverTests.cs
Normal file
59
PlexRequests.Core.Tests/NotificationMessageResolverTests.cs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: AuthenticationSettingsTests.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 NUnit.Framework;
|
||||||
|
|
||||||
|
using PlexRequests.Core.SettingModels;
|
||||||
|
|
||||||
|
namespace PlexRequests.Core.Tests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class AuthenticationSettingsTests
|
||||||
|
{
|
||||||
|
[Test, TestCaseSource(nameof(UserData))]
|
||||||
|
public void DeniedUserListTest(string users, string[] expected)
|
||||||
|
{
|
||||||
|
var model = new AuthenticationSettings { DeniedUsers = users };
|
||||||
|
|
||||||
|
var result = model.DeniedUserList;
|
||||||
|
|
||||||
|
Assert.That(result.Count, Is.EqualTo(expected.Length));
|
||||||
|
for (var i = 0; i < expected.Length; i++)
|
||||||
|
{
|
||||||
|
Assert.That(result[i], Is.EqualTo(expected[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static readonly object[] UserData =
|
||||||
|
{
|
||||||
|
new object[] { "john", new [] {"john"} },
|
||||||
|
new object[] { "john , abc ,", new [] {"john", "abc"} },
|
||||||
|
new object[] { "john,, cde", new [] {"john", "cde"} },
|
||||||
|
new object[] { "john,,, aaa , baaa , ", new [] {"john","aaa","baaa"} },
|
||||||
|
new object[] { "john, aaa , baaa , maaa, caaa", new [] {"john","aaa","baaa", "maaa", "caaa"} },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,107 +1,108 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<ProjectGuid>{FCFECD5D-47F6-454D-8692-E27A921BE655}</ProjectGuid>
|
<ProjectGuid>{FCFECD5D-47F6-454D-8692-E27A921BE655}</ProjectGuid>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>PlexRequests.Core.Tests</RootNamespace>
|
<RootNamespace>PlexRequests.Core.Tests</RootNamespace>
|
||||||
<AssemblyName>PlexRequests.Core.Tests</AssemblyName>
|
<AssemblyName>PlexRequests.Core.Tests</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||||
<IsCodedUITest>False</IsCodedUITest>
|
<IsCodedUITest>False</IsCodedUITest>
|
||||||
<TestProjectType>UnitTest</TestProjectType>
|
<TestProjectType>UnitTest</TestProjectType>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
|
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="nunit.framework, Version=3.0.5813.39031, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
<Reference Include="nunit.framework, Version=3.0.5813.39031, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll</HintPath>
|
<HintPath>..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Ploeh.AutoFixture, Version=3.40.0.0, Culture=neutral, PublicKeyToken=b24654c590009d4f, processorArchitecture=MSIL">
|
<Reference Include="Ploeh.AutoFixture, Version=3.40.0.0, Culture=neutral, PublicKeyToken=b24654c590009d4f, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\AutoFixture.3.40.0\lib\net40\Ploeh.AutoFixture.dll</HintPath>
|
<HintPath>..\packages\AutoFixture.3.40.0\lib\net40\Ploeh.AutoFixture.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Choose>
|
<Choose>
|
||||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</When>
|
</When>
|
||||||
<Otherwise />
|
<Otherwise />
|
||||||
</Choose>
|
</Choose>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="StatusCheckerTests.cs" />
|
<Compile Include="NotificationMessageResolverTests.cs" />
|
||||||
<Compile Include="AuthenticationSettingsTests.cs" />
|
<Compile Include="StatusCheckerTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="AuthenticationSettingsTests.cs" />
|
||||||
</ItemGroup>
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<None Include="app.config" />
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="app.config" />
|
||||||
</ItemGroup>
|
<None Include="packages.config" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<ProjectReference Include="..\PlexRequests.Core\PlexRequests.Core.csproj">
|
<ItemGroup>
|
||||||
<Project>{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}</Project>
|
<ProjectReference Include="..\PlexRequests.Core\PlexRequests.Core.csproj">
|
||||||
<Name>PlexRequests.Core</Name>
|
<Project>{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}</Project>
|
||||||
</ProjectReference>
|
<Name>PlexRequests.Core</Name>
|
||||||
<ProjectReference Include="..\PlexRequests.Helpers\PlexRequests.Helpers.csproj">
|
</ProjectReference>
|
||||||
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
|
<ProjectReference Include="..\PlexRequests.Helpers\PlexRequests.Helpers.csproj">
|
||||||
<Name>PlexRequests.Helpers</Name>
|
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
|
||||||
</ProjectReference>
|
<Name>PlexRequests.Helpers</Name>
|
||||||
</ItemGroup>
|
</ProjectReference>
|
||||||
<Choose>
|
</ItemGroup>
|
||||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
<Choose>
|
||||||
<ItemGroup>
|
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
<ItemGroup>
|
||||||
<Private>False</Private>
|
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
</Reference>
|
<Private>False</Private>
|
||||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
</Reference>
|
||||||
<Private>False</Private>
|
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
</Reference>
|
<Private>False</Private>
|
||||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
</Reference>
|
||||||
<Private>False</Private>
|
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
</Reference>
|
<Private>False</Private>
|
||||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
</Reference>
|
||||||
<Private>False</Private>
|
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
</Reference>
|
<Private>False</Private>
|
||||||
</ItemGroup>
|
</Reference>
|
||||||
</When>
|
</ItemGroup>
|
||||||
</Choose>
|
</When>
|
||||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
</Choose>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
<Target Name="BeforeBuild">
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
</Target>
|
<Target Name="BeforeBuild">
|
||||||
<Target Name="AfterBuild">
|
</Target>
|
||||||
</Target>
|
<Target Name="AfterBuild">
|
||||||
-->
|
</Target>
|
||||||
|
-->
|
||||||
</Project>
|
</Project>
|
|
@ -1,39 +1,39 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: NotificationType.cs
|
// File: NotificationType.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
namespace PlexRequests.Services.Notification
|
namespace PlexRequests.Core.Models
|
||||||
{
|
{
|
||||||
public enum NotificationType
|
public enum NotificationType
|
||||||
{
|
{
|
||||||
NewRequest,
|
NewRequest,
|
||||||
Issue,
|
Issue,
|
||||||
RequestAvailable,
|
RequestAvailable,
|
||||||
RequestApproved,
|
RequestApproved,
|
||||||
AdminNote,
|
AdminNote,
|
||||||
Test,
|
Test,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
102
PlexRequests.Core/NotificationMessageResolver.cs
Normal file
102
PlexRequests.Core/NotificationMessageResolver.cs
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: CustomNotificationService.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.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
using PlexRequests.Core.Models;
|
||||||
|
using PlexRequests.Core.SettingModels;
|
||||||
|
|
||||||
|
namespace PlexRequests.Core
|
||||||
|
{
|
||||||
|
public class NotificationMessageResolver
|
||||||
|
{
|
||||||
|
public string ParseMessage<T>(T notification, NotificationType type) where T : NotificationSettings
|
||||||
|
{
|
||||||
|
var notificationToParse = notification.Message.FirstOrDefault(x => x.Key == type).Value;
|
||||||
|
if (string.IsNullOrEmpty(notificationToParse))
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
return Resolve(notificationToParse, notification.CustomParamaters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string Resolve(string message, Dictionary<string,string> paramaters)
|
||||||
|
{
|
||||||
|
var fields = FindCurlyFields(message);
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var f in fields)
|
||||||
|
{
|
||||||
|
string outString;
|
||||||
|
if (paramaters.TryGetValue(f, out outString))
|
||||||
|
{
|
||||||
|
message = message.Replace($"{{{f}}}", outString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<string> FindCurlyFields(string message)
|
||||||
|
{
|
||||||
|
var insideCurly = false;
|
||||||
|
var fields = new List<string>();
|
||||||
|
var currentWord = string.Empty;
|
||||||
|
var chars = message.ToCharArray();
|
||||||
|
|
||||||
|
foreach (var c in chars)
|
||||||
|
{
|
||||||
|
if (char.IsWhiteSpace(c))
|
||||||
|
{
|
||||||
|
currentWord = string.Empty;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == 123) // Start of curly '{'
|
||||||
|
{
|
||||||
|
insideCurly = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == 125) // End of curly '}'
|
||||||
|
{
|
||||||
|
fields.Add(currentWord); // We have finished the curly, add the word into the list
|
||||||
|
currentWord = string.Empty;
|
||||||
|
insideCurly = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (insideCurly)
|
||||||
|
{
|
||||||
|
currentWord += c.ToString(); // Add the character onto the word.
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -67,17 +67,20 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CacheKeys.cs" />
|
<Compile Include="CacheKeys.cs" />
|
||||||
|
<Compile Include="NotificationMessageResolver.cs" />
|
||||||
<Compile Include="IIssueService.cs" />
|
<Compile Include="IIssueService.cs" />
|
||||||
<Compile Include="IRequestService.cs" />
|
<Compile Include="IRequestService.cs" />
|
||||||
<Compile Include="ISettingsService.cs" />
|
<Compile Include="ISettingsService.cs" />
|
||||||
<Compile Include="JsonIssuesModelRequestService.cs" />
|
<Compile Include="JsonIssuesModelRequestService.cs" />
|
||||||
<Compile Include="JsonRequestModelRequestService.cs" />
|
<Compile Include="JsonRequestModelRequestService.cs" />
|
||||||
<Compile Include="Models\IssuesModel.cs" />
|
<Compile Include="Models\IssuesModel.cs" />
|
||||||
|
<Compile Include="Models\NotificationType.cs" />
|
||||||
<Compile Include="Models\StatusModel.cs" />
|
<Compile Include="Models\StatusModel.cs" />
|
||||||
<Compile Include="Models\UserProperties.cs" />
|
<Compile Include="Models\UserProperties.cs" />
|
||||||
<Compile Include="SettingModels\AuthenticationSettings.cs" />
|
<Compile Include="SettingModels\AuthenticationSettings.cs" />
|
||||||
<Compile Include="SettingModels\HeadphonesSettings.cs" />
|
<Compile Include="SettingModels\HeadphonesSettings.cs" />
|
||||||
<Compile Include="SettingModels\LandingPageSettings.cs" />
|
<Compile Include="SettingModels\LandingPageSettings.cs" />
|
||||||
|
<Compile Include="SettingModels\NotificationSettings.cs" />
|
||||||
<Compile Include="SettingModels\ScheduledJobsSettings.cs" />
|
<Compile Include="SettingModels\ScheduledJobsSettings.cs" />
|
||||||
<Compile Include="SettingModels\SlackNotificationSettings.cs" />
|
<Compile Include="SettingModels\SlackNotificationSettings.cs" />
|
||||||
<Compile Include="SettingModels\PushoverNotificationSettings.cs" />
|
<Compile Include="SettingModels\PushoverNotificationSettings.cs" />
|
||||||
|
|
|
@ -1,40 +1,40 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: EmailNotificationSettings.cs
|
// File: EmailNotificationSettings.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
namespace PlexRequests.Core.SettingModels
|
namespace PlexRequests.Core.SettingModels
|
||||||
{
|
{
|
||||||
public class EmailNotificationSettings : Settings
|
public class EmailNotificationSettings : NotificationSettings
|
||||||
{
|
{
|
||||||
public string EmailHost { get; set; }
|
public string EmailHost { get; set; }
|
||||||
public string EmailPassword { get; set; }
|
public string EmailPassword { get; set; }
|
||||||
public int EmailPort { get; set; }
|
public int EmailPort { get; set; }
|
||||||
public string EmailSender { get; set; }
|
public string EmailSender { get; set; }
|
||||||
public string EmailUsername { get; set; }
|
public string EmailUsername { get; set; }
|
||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
public bool EnableUserEmailNotifications { get; set; }
|
public bool EnableUserEmailNotifications { get; set; }
|
||||||
public string RecipientEmail { get; set; }
|
public string RecipientEmail { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
38
PlexRequests.Core/SettingModels/NotificationSettings.cs
Normal file
38
PlexRequests.Core/SettingModels/NotificationSettings.cs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: NotificationSettings.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.Collections.Generic;
|
||||||
|
|
||||||
|
using PlexRequests.Core.Models;
|
||||||
|
|
||||||
|
namespace PlexRequests.Core.SettingModels
|
||||||
|
{
|
||||||
|
public class NotificationSettings : Settings
|
||||||
|
{
|
||||||
|
public Dictionary<NotificationType, string> Message { get; set; }
|
||||||
|
public Dictionary<string,string> CustomParamaters { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
namespace PlexRequests.Core.SettingModels
|
namespace PlexRequests.Core.SettingModels
|
||||||
{
|
{
|
||||||
public class PushbulletNotificationSettings : Settings
|
public class PushbulletNotificationSettings : NotificationSettings
|
||||||
{
|
{
|
||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
public string AccessToken { get; set; }
|
public string AccessToken { get; set; }
|
||||||
public string DeviceIdentifier { get; set; }
|
public string DeviceIdentifier { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
namespace PlexRequests.Core.SettingModels
|
namespace PlexRequests.Core.SettingModels
|
||||||
{
|
{
|
||||||
public class PushoverNotificationSettings : Settings
|
public class PushoverNotificationSettings : NotificationSettings
|
||||||
{
|
{
|
||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
public string AccessToken { get; set; }
|
public string AccessToken { get; set; }
|
||||||
public string UserToken { get; set; }
|
public string UserToken { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,7 @@ using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace PlexRequests.Core.SettingModels
|
namespace PlexRequests.Core.SettingModels
|
||||||
{
|
{
|
||||||
public class SlackNotificationSettings : Settings
|
public class SlackNotificationSettings : NotificationSettings
|
||||||
{
|
{
|
||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
public string WebhookUrl { get; set; }
|
public string WebhookUrl { get; set; }
|
||||||
|
|
|
@ -33,6 +33,7 @@ using NLog;
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Api.Models.Plex;
|
using PlexRequests.Api.Models.Plex;
|
||||||
using PlexRequests.Core;
|
using PlexRequests.Core;
|
||||||
|
using PlexRequests.Core.Models;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Helpers;
|
using PlexRequests.Helpers;
|
||||||
using PlexRequests.Helpers.Analytics;
|
using PlexRequests.Helpers.Analytics;
|
||||||
|
|
|
@ -33,6 +33,7 @@ using MimeKit;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
using PlexRequests.Core;
|
using PlexRequests.Core;
|
||||||
|
using PlexRequests.Core.Models;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
using SmtpClient = MailKit.Net.Smtp.SmtpClient;
|
using SmtpClient = MailKit.Net.Smtp.SmtpClient;
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
using PlexRequests.Store;
|
using PlexRequests.Store;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
using PlexRequests.Core.Models;
|
||||||
|
|
||||||
namespace PlexRequests.Services.Notification
|
namespace PlexRequests.Services.Notification
|
||||||
{
|
{
|
||||||
public class NotificationModel
|
public class NotificationModel
|
||||||
|
|
|
@ -31,6 +31,7 @@ using NLog;
|
||||||
|
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Core;
|
using PlexRequests.Core;
|
||||||
|
using PlexRequests.Core.Models;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
using PlexRequests.Store;
|
using PlexRequests.Store;
|
||||||
|
|
|
@ -31,6 +31,7 @@ using NLog;
|
||||||
|
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Core;
|
using PlexRequests.Core;
|
||||||
|
using PlexRequests.Core.Models;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
using PlexRequests.Store;
|
using PlexRequests.Store;
|
||||||
|
|
|
@ -32,6 +32,7 @@ using NLog;
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Api.Models.Notifications;
|
using PlexRequests.Api.Models.Notifications;
|
||||||
using PlexRequests.Core;
|
using PlexRequests.Core;
|
||||||
|
using PlexRequests.Core.Models;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,6 @@
|
||||||
<Compile Include="Notification\EmailMessageNotification.cs" />
|
<Compile Include="Notification\EmailMessageNotification.cs" />
|
||||||
<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\PushoverNotification.cs" />
|
<Compile Include="Notification\PushoverNotification.cs" />
|
||||||
<Compile Include="Notification\PushbulletNotification.cs" />
|
<Compile Include="Notification\PushbulletNotification.cs" />
|
||||||
<Compile Include="Notification\SlackNotification.cs" />
|
<Compile Include="Notification\SlackNotification.cs" />
|
||||||
|
|
|
@ -51,6 +51,7 @@ using Nancy.Responses;
|
||||||
using PlexRequests.Api;
|
using PlexRequests.Api;
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Core;
|
using PlexRequests.Core;
|
||||||
|
using PlexRequests.Core.Models;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Helpers;
|
using PlexRequests.Helpers;
|
||||||
using PlexRequests.Helpers.Analytics;
|
using PlexRequests.Helpers.Analytics;
|
||||||
|
|
|
@ -1,377 +1,379 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: RequestsModule.cs
|
// File: RequestsModule.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
// a copy of this software and associated documentation files (the
|
// a copy of this software and associated documentation files (the
|
||||||
// "Software"), to deal in the Software without restriction, including
|
// "Software"), to deal in the Software without restriction, including
|
||||||
// without limitation the rights to use, copy, modify, merge, publish,
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
// permit persons to whom the Software is furnished to do so, subject to
|
// permit persons to whom the Software is furnished to do so, subject to
|
||||||
// the following conditions:
|
// the following conditions:
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be
|
// The above copyright notice and this permission notice shall be
|
||||||
// included in all copies or substantial portions of the Software.
|
// included in all copies or substantial portions of the Software.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Nancy;
|
using Nancy;
|
||||||
using Nancy.Responses.Negotiation;
|
using Nancy.Responses.Negotiation;
|
||||||
using Nancy.Security;
|
using Nancy.Security;
|
||||||
|
|
||||||
using PlexRequests.Core;
|
using PlexRequests.Core;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Services.Interfaces;
|
using PlexRequests.Services.Interfaces;
|
||||||
using PlexRequests.Services.Notification;
|
using PlexRequests.Services.Notification;
|
||||||
using PlexRequests.Store;
|
using PlexRequests.Store;
|
||||||
using PlexRequests.UI.Models;
|
using PlexRequests.UI.Models;
|
||||||
using PlexRequests.Helpers;
|
using PlexRequests.Helpers;
|
||||||
using PlexRequests.UI.Helpers;
|
using PlexRequests.UI.Helpers;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
namespace PlexRequests.UI.Modules
|
using PlexRequests.Core.Models;
|
||||||
{
|
|
||||||
public class RequestsModule : BaseAuthModule
|
namespace PlexRequests.UI.Modules
|
||||||
{
|
{
|
||||||
public RequestsModule(
|
public class RequestsModule : BaseAuthModule
|
||||||
IRequestService service,
|
{
|
||||||
ISettingsService<PlexRequestSettings> prSettings,
|
public RequestsModule(
|
||||||
ISettingsService<PlexSettings> plex,
|
IRequestService service,
|
||||||
INotificationService notify,
|
ISettingsService<PlexRequestSettings> prSettings,
|
||||||
ISettingsService<SonarrSettings> sonarrSettings,
|
ISettingsService<PlexSettings> plex,
|
||||||
ISettingsService<SickRageSettings> sickRageSettings,
|
INotificationService notify,
|
||||||
ISettingsService<CouchPotatoSettings> cpSettings,
|
ISettingsService<SonarrSettings> sonarrSettings,
|
||||||
ICouchPotatoApi cpApi,
|
ISettingsService<SickRageSettings> sickRageSettings,
|
||||||
ISonarrApi sonarrApi,
|
ISettingsService<CouchPotatoSettings> cpSettings,
|
||||||
ISickRageApi sickRageApi,
|
ICouchPotatoApi cpApi,
|
||||||
ICacheProvider cache) : base("requests", prSettings)
|
ISonarrApi sonarrApi,
|
||||||
{
|
ISickRageApi sickRageApi,
|
||||||
Service = service;
|
ICacheProvider cache) : base("requests", prSettings)
|
||||||
PrSettings = prSettings;
|
{
|
||||||
PlexSettings = plex;
|
Service = service;
|
||||||
NotificationService = notify;
|
PrSettings = prSettings;
|
||||||
SonarrSettings = sonarrSettings;
|
PlexSettings = plex;
|
||||||
SickRageSettings = sickRageSettings;
|
NotificationService = notify;
|
||||||
CpSettings = cpSettings;
|
SonarrSettings = sonarrSettings;
|
||||||
SonarrApi = sonarrApi;
|
SickRageSettings = sickRageSettings;
|
||||||
SickRageApi = sickRageApi;
|
CpSettings = cpSettings;
|
||||||
CpApi = cpApi;
|
SonarrApi = sonarrApi;
|
||||||
Cache = cache;
|
SickRageApi = sickRageApi;
|
||||||
|
CpApi = cpApi;
|
||||||
Get["/", true] = async (x, ct) => await LoadRequests();
|
Cache = cache;
|
||||||
Get["/movies", true] = async (x, ct) => await GetMovies();
|
|
||||||
Get["/tvshows", true] = async (c, ct) => await GetTvShows();
|
Get["/", true] = async (x, ct) => await LoadRequests();
|
||||||
Get["/albums", true] = async (x, ct) => await GetAlbumRequests();
|
Get["/movies", true] = async (x, ct) => await GetMovies();
|
||||||
Post["/delete", true] = async (x, ct) => await DeleteRequest((int)Request.Form.id);
|
Get["/tvshows", true] = async (c, ct) => await GetTvShows();
|
||||||
Post["/reportissue", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, (IssueState)(int)Request.Form.issue, null);
|
Get["/albums", true] = async (x, ct) => await GetAlbumRequests();
|
||||||
Post["/reportissuecomment", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, IssueState.Other, (string)Request.Form.commentArea);
|
Post["/delete", true] = async (x, ct) => await DeleteRequest((int)Request.Form.id);
|
||||||
|
Post["/reportissue", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, (IssueState)(int)Request.Form.issue, null);
|
||||||
Post["/clearissues", true] = async (x, ct) => await ClearIssue((int)Request.Form.Id);
|
Post["/reportissuecomment", true] = async (x, ct) => await ReportIssue((int)Request.Form.requestId, IssueState.Other, (string)Request.Form.commentArea);
|
||||||
|
|
||||||
Post["/changeavailability", true] = async (x, ct) => await ChangeRequestAvailability((int)Request.Form.Id, (bool)Request.Form.Available);
|
Post["/clearissues", true] = async (x, ct) => await ClearIssue((int)Request.Form.Id);
|
||||||
}
|
|
||||||
|
Post["/changeavailability", true] = async (x, ct) => await ChangeRequestAvailability((int)Request.Form.Id, (bool)Request.Form.Available);
|
||||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
}
|
||||||
private IRequestService Service { get; }
|
|
||||||
private INotificationService NotificationService { get; }
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
private ISettingsService<PlexRequestSettings> PrSettings { get; }
|
private IRequestService Service { get; }
|
||||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
private INotificationService NotificationService { get; }
|
||||||
private ISettingsService<SonarrSettings> SonarrSettings { get; }
|
private ISettingsService<PlexRequestSettings> PrSettings { get; }
|
||||||
private ISettingsService<SickRageSettings> SickRageSettings { get; }
|
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||||
private ISettingsService<CouchPotatoSettings> CpSettings { get; }
|
private ISettingsService<SonarrSettings> SonarrSettings { get; }
|
||||||
private ISonarrApi SonarrApi { get; }
|
private ISettingsService<SickRageSettings> SickRageSettings { get; }
|
||||||
private ISickRageApi SickRageApi { get; }
|
private ISettingsService<CouchPotatoSettings> CpSettings { get; }
|
||||||
private ICouchPotatoApi CpApi { get; }
|
private ISonarrApi SonarrApi { get; }
|
||||||
private ICacheProvider Cache { get; }
|
private ISickRageApi SickRageApi { get; }
|
||||||
|
private ICouchPotatoApi CpApi { get; }
|
||||||
private async Task<Negotiator> LoadRequests()
|
private ICacheProvider Cache { get; }
|
||||||
{
|
|
||||||
var settings = await PrSettings.GetSettingsAsync();
|
private async Task<Negotiator> LoadRequests()
|
||||||
return View["Index", settings];
|
{
|
||||||
}
|
var settings = await PrSettings.GetSettingsAsync();
|
||||||
|
return View["Index", settings];
|
||||||
private async Task<Response> GetMovies()
|
}
|
||||||
{
|
|
||||||
var settings = PrSettings.GetSettings();
|
private async Task<Response> GetMovies()
|
||||||
|
{
|
||||||
var allRequests = await Service.GetAllAsync();
|
var settings = PrSettings.GetSettings();
|
||||||
allRequests = allRequests.Where(x => x.Type == RequestType.Movie);
|
|
||||||
|
var allRequests = await Service.GetAllAsync();
|
||||||
var dbMovies = allRequests.ToList();
|
allRequests = allRequests.Where(x => x.Type == RequestType.Movie);
|
||||||
|
|
||||||
if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin)
|
var dbMovies = allRequests.ToList();
|
||||||
{
|
|
||||||
dbMovies = dbMovies.Where(x => x.UserHasRequested(Username)).ToList();
|
if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin)
|
||||||
}
|
{
|
||||||
|
dbMovies = dbMovies.Where(x => x.UserHasRequested(Username)).ToList();
|
||||||
List<QualityModel> qualities = new List<QualityModel>();
|
}
|
||||||
|
|
||||||
if (IsAdmin)
|
List<QualityModel> qualities = new List<QualityModel>();
|
||||||
{
|
|
||||||
var cpSettings = CpSettings.GetSettings();
|
if (IsAdmin)
|
||||||
if (cpSettings.Enabled)
|
{
|
||||||
{
|
var cpSettings = CpSettings.GetSettings();
|
||||||
try
|
if (cpSettings.Enabled)
|
||||||
{
|
{
|
||||||
var result = await Cache.GetOrSetAsync(CacheKeys.CouchPotatoQualityProfiles, async () =>
|
try
|
||||||
{
|
{
|
||||||
return await Task.Run(() => CpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey)).ConfigureAwait(false);
|
var result = await Cache.GetOrSetAsync(CacheKeys.CouchPotatoQualityProfiles, async () =>
|
||||||
});
|
{
|
||||||
|
return await Task.Run(() => CpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey)).ConfigureAwait(false);
|
||||||
qualities = result.list.Select(x => new QualityModel() { Id = x._id, Name = x.label }).ToList();
|
});
|
||||||
|
|
||||||
}
|
qualities = result.list.Select(x => new QualityModel() { Id = x._id, Name = x.label }).ToList();
|
||||||
catch (Exception e)
|
|
||||||
{
|
}
|
||||||
Log.Info(e);
|
catch (Exception e)
|
||||||
}
|
{
|
||||||
}
|
Log.Info(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
var viewModel = dbMovies.Select(movie => new RequestViewModel
|
}
|
||||||
{
|
|
||||||
ProviderId = movie.ProviderId,
|
var viewModel = dbMovies.Select(movie => new RequestViewModel
|
||||||
Type = movie.Type,
|
{
|
||||||
Status = movie.Status,
|
ProviderId = movie.ProviderId,
|
||||||
ImdbId = movie.ImdbId,
|
Type = movie.Type,
|
||||||
Id = movie.Id,
|
Status = movie.Status,
|
||||||
PosterPath = movie.PosterPath,
|
ImdbId = movie.ImdbId,
|
||||||
ReleaseDate = movie.ReleaseDate,
|
Id = movie.Id,
|
||||||
ReleaseDateTicks = movie.ReleaseDate.Ticks,
|
PosterPath = movie.PosterPath,
|
||||||
RequestedDate = movie.RequestedDate,
|
ReleaseDate = movie.ReleaseDate,
|
||||||
Released = DateTime.Now > movie.ReleaseDate,
|
ReleaseDateTicks = movie.ReleaseDate.Ticks,
|
||||||
RequestedDateTicks = DateTimeHelper.OffsetUTCDateTime(movie.RequestedDate, DateTimeOffset).Ticks,
|
RequestedDate = movie.RequestedDate,
|
||||||
Approved = movie.Available || movie.Approved,
|
Released = DateTime.Now > movie.ReleaseDate,
|
||||||
Title = movie.Title,
|
RequestedDateTicks = DateTimeHelper.OffsetUTCDateTime(movie.RequestedDate, DateTimeOffset).Ticks,
|
||||||
Overview = movie.Overview,
|
Approved = movie.Available || movie.Approved,
|
||||||
RequestedUsers = IsAdmin ? movie.AllUsers.ToArray() : new string[] { },
|
Title = movie.Title,
|
||||||
ReleaseYear = movie.ReleaseDate.Year.ToString(),
|
Overview = movie.Overview,
|
||||||
Available = movie.Available,
|
RequestedUsers = IsAdmin ? movie.AllUsers.ToArray() : new string[] { },
|
||||||
Admin = IsAdmin,
|
ReleaseYear = movie.ReleaseDate.Year.ToString(),
|
||||||
IssueId = movie.IssueId,
|
Available = movie.Available,
|
||||||
Qualities = qualities.ToArray()
|
Admin = IsAdmin,
|
||||||
}).ToList();
|
IssueId = movie.IssueId,
|
||||||
|
Qualities = qualities.ToArray()
|
||||||
return Response.AsJson(viewModel);
|
}).ToList();
|
||||||
}
|
|
||||||
|
return Response.AsJson(viewModel);
|
||||||
private async Task<Response> GetTvShows()
|
}
|
||||||
{
|
|
||||||
var settings = PrSettings.GetSettings();
|
private async Task<Response> GetTvShows()
|
||||||
|
{
|
||||||
var requests = await Service.GetAllAsync();
|
var settings = PrSettings.GetSettings();
|
||||||
requests = requests.Where(x => x.Type == RequestType.TvShow);
|
|
||||||
|
var requests = await Service.GetAllAsync();
|
||||||
var dbTv = requests;
|
requests = requests.Where(x => x.Type == RequestType.TvShow);
|
||||||
|
|
||||||
if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin)
|
var dbTv = requests;
|
||||||
{
|
|
||||||
dbTv = dbTv.Where(x => x.UserHasRequested(Username)).ToList();
|
if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin)
|
||||||
}
|
{
|
||||||
|
dbTv = dbTv.Where(x => x.UserHasRequested(Username)).ToList();
|
||||||
IEnumerable<QualityModel> qualities = new List<QualityModel>();
|
}
|
||||||
if (IsAdmin)
|
|
||||||
{
|
IEnumerable<QualityModel> qualities = new List<QualityModel>();
|
||||||
try
|
if (IsAdmin)
|
||||||
{
|
{
|
||||||
var sonarrSettings = SonarrSettings.GetSettings();
|
try
|
||||||
if (sonarrSettings.Enabled)
|
{
|
||||||
{
|
var sonarrSettings = SonarrSettings.GetSettings();
|
||||||
var result = Cache.GetOrSetAsync(CacheKeys.SonarrQualityProfiles, async () =>
|
if (sonarrSettings.Enabled)
|
||||||
{
|
{
|
||||||
return await Task.Run(() => SonarrApi.GetProfiles(sonarrSettings.ApiKey, sonarrSettings.FullUri));
|
var result = Cache.GetOrSetAsync(CacheKeys.SonarrQualityProfiles, async () =>
|
||||||
});
|
{
|
||||||
qualities = result.Result.Select(x => new QualityModel() { Id = x.id.ToString(), Name = x.name }).ToList();
|
return await Task.Run(() => SonarrApi.GetProfiles(sonarrSettings.ApiKey, sonarrSettings.FullUri));
|
||||||
}
|
});
|
||||||
else
|
qualities = result.Result.Select(x => new QualityModel() { Id = x.id.ToString(), Name = x.name }).ToList();
|
||||||
{
|
}
|
||||||
var sickRageSettings = SickRageSettings.GetSettings();
|
else
|
||||||
if (sickRageSettings.Enabled)
|
{
|
||||||
{
|
var sickRageSettings = SickRageSettings.GetSettings();
|
||||||
qualities = sickRageSettings.Qualities.Select(x => new QualityModel() { Id = x.Key, Name = x.Value }).ToList();
|
if (sickRageSettings.Enabled)
|
||||||
}
|
{
|
||||||
}
|
qualities = sickRageSettings.Qualities.Select(x => new QualityModel() { Id = x.Key, Name = x.Value }).ToList();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
}
|
||||||
{
|
}
|
||||||
Log.Info(e);
|
catch (Exception e)
|
||||||
}
|
{
|
||||||
|
Log.Info(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
var viewModel = dbTv.Select(tv =>
|
}
|
||||||
{
|
|
||||||
return new RequestViewModel
|
var viewModel = dbTv.Select(tv =>
|
||||||
{
|
{
|
||||||
ProviderId = tv.ProviderId,
|
return new RequestViewModel
|
||||||
Type = tv.Type,
|
{
|
||||||
Status = tv.Status,
|
ProviderId = tv.ProviderId,
|
||||||
ImdbId = tv.ImdbId,
|
Type = tv.Type,
|
||||||
Id = tv.Id,
|
Status = tv.Status,
|
||||||
PosterPath = tv.PosterPath,
|
ImdbId = tv.ImdbId,
|
||||||
ReleaseDate = tv.ReleaseDate,
|
Id = tv.Id,
|
||||||
ReleaseDateTicks = tv.ReleaseDate.Ticks,
|
PosterPath = tv.PosterPath,
|
||||||
RequestedDate = tv.RequestedDate,
|
ReleaseDate = tv.ReleaseDate,
|
||||||
RequestedDateTicks = DateTimeHelper.OffsetUTCDateTime(tv.RequestedDate, DateTimeOffset).Ticks,
|
ReleaseDateTicks = tv.ReleaseDate.Ticks,
|
||||||
Released = DateTime.Now > tv.ReleaseDate,
|
RequestedDate = tv.RequestedDate,
|
||||||
Approved = tv.Available || tv.Approved,
|
RequestedDateTicks = DateTimeHelper.OffsetUTCDateTime(tv.RequestedDate, DateTimeOffset).Ticks,
|
||||||
Title = tv.Title,
|
Released = DateTime.Now > tv.ReleaseDate,
|
||||||
Overview = tv.Overview,
|
Approved = tv.Available || tv.Approved,
|
||||||
RequestedUsers = IsAdmin ? tv.AllUsers.ToArray() : new string[] { },
|
Title = tv.Title,
|
||||||
ReleaseYear = tv.ReleaseDate.Year.ToString(),
|
Overview = tv.Overview,
|
||||||
Available = tv.Available,
|
RequestedUsers = IsAdmin ? tv.AllUsers.ToArray() : new string[] { },
|
||||||
Admin = IsAdmin,
|
ReleaseYear = tv.ReleaseDate.Year.ToString(),
|
||||||
IssueId = tv.IssueId,
|
Available = tv.Available,
|
||||||
TvSeriesRequestType = tv.SeasonsRequested,
|
Admin = IsAdmin,
|
||||||
Qualities = qualities.ToArray()
|
IssueId = tv.IssueId,
|
||||||
};
|
TvSeriesRequestType = tv.SeasonsRequested,
|
||||||
}).ToList();
|
Qualities = qualities.ToArray()
|
||||||
|
};
|
||||||
return Response.AsJson(viewModel);
|
}).ToList();
|
||||||
}
|
|
||||||
|
return Response.AsJson(viewModel);
|
||||||
private async Task<Response> GetAlbumRequests()
|
}
|
||||||
{
|
|
||||||
var settings = PrSettings.GetSettings();
|
private async Task<Response> GetAlbumRequests()
|
||||||
var dbAlbum = await Service.GetAllAsync();
|
{
|
||||||
dbAlbum = dbAlbum.Where(x => x.Type == RequestType.Album);
|
var settings = PrSettings.GetSettings();
|
||||||
if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin)
|
var dbAlbum = await Service.GetAllAsync();
|
||||||
{
|
dbAlbum = dbAlbum.Where(x => x.Type == RequestType.Album);
|
||||||
dbAlbum = dbAlbum.Where(x => x.UserHasRequested(Username));
|
if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin)
|
||||||
}
|
{
|
||||||
|
dbAlbum = dbAlbum.Where(x => x.UserHasRequested(Username));
|
||||||
var viewModel = dbAlbum.Select(album =>
|
}
|
||||||
{
|
|
||||||
return new RequestViewModel
|
var viewModel = dbAlbum.Select(album =>
|
||||||
{
|
{
|
||||||
ProviderId = album.ProviderId,
|
return new RequestViewModel
|
||||||
Type = album.Type,
|
{
|
||||||
Status = album.Status,
|
ProviderId = album.ProviderId,
|
||||||
ImdbId = album.ImdbId,
|
Type = album.Type,
|
||||||
Id = album.Id,
|
Status = album.Status,
|
||||||
PosterPath = album.PosterPath,
|
ImdbId = album.ImdbId,
|
||||||
ReleaseDate = album.ReleaseDate,
|
Id = album.Id,
|
||||||
ReleaseDateTicks = album.ReleaseDate.Ticks,
|
PosterPath = album.PosterPath,
|
||||||
RequestedDate = album.RequestedDate,
|
ReleaseDate = album.ReleaseDate,
|
||||||
RequestedDateTicks = DateTimeHelper.OffsetUTCDateTime(album.RequestedDate, DateTimeOffset).Ticks,
|
ReleaseDateTicks = album.ReleaseDate.Ticks,
|
||||||
Released = DateTime.Now > album.ReleaseDate,
|
RequestedDate = album.RequestedDate,
|
||||||
Approved = album.Available || album.Approved,
|
RequestedDateTicks = DateTimeHelper.OffsetUTCDateTime(album.RequestedDate, DateTimeOffset).Ticks,
|
||||||
Title = album.Title,
|
Released = DateTime.Now > album.ReleaseDate,
|
||||||
Overview = album.Overview,
|
Approved = album.Available || album.Approved,
|
||||||
RequestedUsers = IsAdmin ? album.AllUsers.ToArray() : new string[] { },
|
Title = album.Title,
|
||||||
ReleaseYear = album.ReleaseDate.Year.ToString(),
|
Overview = album.Overview,
|
||||||
Available = album.Available,
|
RequestedUsers = IsAdmin ? album.AllUsers.ToArray() : new string[] { },
|
||||||
Admin = IsAdmin,
|
ReleaseYear = album.ReleaseDate.Year.ToString(),
|
||||||
IssueId = album.IssueId,
|
Available = album.Available,
|
||||||
TvSeriesRequestType = album.SeasonsRequested,
|
Admin = IsAdmin,
|
||||||
MusicBrainzId = album.MusicBrainzId,
|
IssueId = album.IssueId,
|
||||||
ArtistName = album.ArtistName
|
TvSeriesRequestType = album.SeasonsRequested,
|
||||||
|
MusicBrainzId = album.MusicBrainzId,
|
||||||
};
|
ArtistName = album.ArtistName
|
||||||
}).ToList();
|
|
||||||
|
};
|
||||||
return Response.AsJson(viewModel);
|
}).ToList();
|
||||||
}
|
|
||||||
|
return Response.AsJson(viewModel);
|
||||||
private async Task<Response> DeleteRequest(int requestid)
|
}
|
||||||
{
|
|
||||||
this.RequiresClaims(UserClaims.Admin);
|
private async Task<Response> DeleteRequest(int requestid)
|
||||||
|
{
|
||||||
var currentEntity = await Service.GetAsync(requestid);
|
this.RequiresClaims(UserClaims.Admin);
|
||||||
await Service.DeleteRequestAsync(currentEntity);
|
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
var currentEntity = await Service.GetAsync(requestid);
|
||||||
}
|
await Service.DeleteRequestAsync(currentEntity);
|
||||||
|
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||||
/// <summary>
|
}
|
||||||
/// Reports the issue.
|
|
||||||
/// Comment can be null if the <c>IssueState != Other</c>
|
/// <summary>
|
||||||
/// </summary>
|
/// Reports the issue.
|
||||||
/// <param name="requestId">The request identifier.</param>
|
/// Comment can be null if the <c>IssueState != Other</c>
|
||||||
/// <param name="issue">The issue.</param>
|
/// </summary>
|
||||||
/// <param name="comment">The comment.</param>
|
/// <param name="requestId">The request identifier.</param>
|
||||||
/// <returns></returns>
|
/// <param name="issue">The issue.</param>
|
||||||
private async Task<Response> ReportIssue(int requestId, IssueState issue, string comment)
|
/// <param name="comment">The comment.</param>
|
||||||
{
|
/// <returns></returns>
|
||||||
var originalRequest = await Service.GetAsync(requestId);
|
private async Task<Response> ReportIssue(int requestId, IssueState issue, string comment)
|
||||||
if (originalRequest == null)
|
{
|
||||||
{
|
var originalRequest = await Service.GetAsync(requestId);
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" });
|
if (originalRequest == null)
|
||||||
}
|
{
|
||||||
originalRequest.Issues = issue;
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" });
|
||||||
originalRequest.OtherMessage = !string.IsNullOrEmpty(comment)
|
}
|
||||||
? $"{Username} - {comment}"
|
originalRequest.Issues = issue;
|
||||||
: string.Empty;
|
originalRequest.OtherMessage = !string.IsNullOrEmpty(comment)
|
||||||
|
? $"{Username} - {comment}"
|
||||||
|
: string.Empty;
|
||||||
var result = await Service.UpdateRequestAsync(originalRequest);
|
|
||||||
|
|
||||||
var model = new NotificationModel
|
var result = await Service.UpdateRequestAsync(originalRequest);
|
||||||
{
|
|
||||||
User = Username,
|
var model = new NotificationModel
|
||||||
NotificationType = NotificationType.Issue,
|
{
|
||||||
Title = originalRequest.Title,
|
User = Username,
|
||||||
DateTime = DateTime.Now,
|
NotificationType = NotificationType.Issue,
|
||||||
Body = issue == IssueState.Other ? comment : issue.ToString().ToCamelCaseWords()
|
Title = originalRequest.Title,
|
||||||
};
|
DateTime = DateTime.Now,
|
||||||
await NotificationService.Publish(model);
|
Body = issue == IssueState.Other ? comment : issue.ToString().ToCamelCaseWords()
|
||||||
|
};
|
||||||
return Response.AsJson(result
|
await NotificationService.Publish(model);
|
||||||
? new JsonResponseModel { Result = true }
|
|
||||||
: new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" });
|
return Response.AsJson(result
|
||||||
}
|
? new JsonResponseModel { Result = true }
|
||||||
|
: new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" });
|
||||||
private async Task<Response> ClearIssue(int requestId)
|
}
|
||||||
{
|
|
||||||
this.RequiresClaims(UserClaims.Admin);
|
private async Task<Response> ClearIssue(int requestId)
|
||||||
|
{
|
||||||
var originalRequest = await Service.GetAsync(requestId);
|
this.RequiresClaims(UserClaims.Admin);
|
||||||
if (originalRequest == null)
|
|
||||||
{
|
var originalRequest = await Service.GetAsync(requestId);
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Request does not exist to clear it!" });
|
if (originalRequest == null)
|
||||||
}
|
{
|
||||||
originalRequest.Issues = IssueState.None;
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Request does not exist to clear it!" });
|
||||||
originalRequest.OtherMessage = string.Empty;
|
}
|
||||||
|
originalRequest.Issues = IssueState.None;
|
||||||
var result = await Service.UpdateRequestAsync(originalRequest);
|
originalRequest.OtherMessage = string.Empty;
|
||||||
return Response.AsJson(result
|
|
||||||
? new JsonResponseModel { Result = true }
|
var result = await Service.UpdateRequestAsync(originalRequest);
|
||||||
: new JsonResponseModel { Result = false, Message = "Could not clear issue, please try again or check the logs" });
|
return Response.AsJson(result
|
||||||
}
|
? new JsonResponseModel { Result = true }
|
||||||
|
: new JsonResponseModel { Result = false, Message = "Could not clear issue, please try again or check the logs" });
|
||||||
private async Task<Response> ChangeRequestAvailability(int requestId, bool available)
|
}
|
||||||
{
|
|
||||||
this.RequiresClaims(UserClaims.Admin);
|
private async Task<Response> ChangeRequestAvailability(int requestId, bool available)
|
||||||
var originalRequest = await Service.GetAsync(requestId);
|
{
|
||||||
if (originalRequest == null)
|
this.RequiresClaims(UserClaims.Admin);
|
||||||
{
|
var originalRequest = await Service.GetAsync(requestId);
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Request does not exist to change the availability!" });
|
if (originalRequest == null)
|
||||||
}
|
{
|
||||||
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Request does not exist to change the availability!" });
|
||||||
originalRequest.Available = available;
|
}
|
||||||
|
|
||||||
var result = await Service.UpdateRequestAsync(originalRequest);
|
originalRequest.Available = available;
|
||||||
return Response.AsJson(result
|
|
||||||
? new { Result = true, Available = available, Message = string.Empty }
|
var result = await Service.UpdateRequestAsync(originalRequest);
|
||||||
: new { Result = false, Available = false, Message = "Could not update the availability, please try again or check the logs" });
|
return Response.AsJson(result
|
||||||
}
|
? new { Result = true, Available = available, Message = string.Empty }
|
||||||
|
: new { Result = false, Available = false, Message = "Could not update the availability, please try again or check the logs" });
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue