mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 07:46:05 -07:00
Final Tweaks #483
This commit is contained in:
parent
8a61371048
commit
cb50fc61fb
5 changed files with 103 additions and 32 deletions
|
@ -112,6 +112,7 @@
|
|||
<Compile Include="PlexReadOnlyDatabase.cs" />
|
||||
<Compile Include="Queue\ITransientFaultQueue.cs" />
|
||||
<Compile Include="Queue\TransientFaultQueue.cs" />
|
||||
<Compile Include="RequestHelper.cs" />
|
||||
<Compile Include="SettingModels\AuthenticationSettings.cs" />
|
||||
<Compile Include="SettingModels\ExternalSettings.cs" />
|
||||
<Compile Include="SettingModels\HeadphonesSettings.cs" />
|
||||
|
|
82
PlexRequests.Core/RequestHelper.cs
Normal file
82
PlexRequests.Core/RequestHelper.cs
Normal file
|
@ -0,0 +1,82 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: RequestHelper.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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Store;
|
||||
|
||||
namespace PlexRequests.Core
|
||||
{
|
||||
public static class RequestHelper
|
||||
{
|
||||
public static bool ShouldAutoApprove(this RequestType requestType, PlexRequestSettings prSettings, bool isAdmin, string username)
|
||||
{
|
||||
// if the user is an admin or they are whitelisted, they go ahead and allow auto-approval
|
||||
if (isAdmin || prSettings.ApprovalWhiteList.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase))) return true;
|
||||
|
||||
// check by request type if the category requires approval or not
|
||||
switch (requestType)
|
||||
{
|
||||
case RequestType.Movie:
|
||||
return !prSettings.RequireMovieApproval;
|
||||
case RequestType.TvShow:
|
||||
return !prSettings.RequireTvShowApproval;
|
||||
case RequestType.Album:
|
||||
return !prSettings.RequireMusicApproval;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ShouldAutoApprove(this RequestType requestType, PlexRequestSettings prSettings, bool isAdmin, List<string> username)
|
||||
{
|
||||
// if the user is an admin or they are whitelisted, they go ahead and allow auto-approval
|
||||
if (isAdmin) return true;
|
||||
|
||||
|
||||
if(prSettings.ApprovalWhiteList.Intersect(username).Any())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// check by request type if the category requires approval or not
|
||||
switch (requestType)
|
||||
{
|
||||
case RequestType.Movie:
|
||||
return !prSettings.RequireMovieApproval;
|
||||
case RequestType.TvShow:
|
||||
return !prSettings.RequireTvShowApproval;
|
||||
case RequestType.Album:
|
||||
return !prSettings.RequireMusicApproval;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ using PlexRequests.Api.Interfaces;
|
|||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Services.Interfaces;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Models;
|
||||
|
@ -53,7 +54,7 @@ namespace PlexRequests.Services.Jobs
|
|||
public FaultQueueHandler(IJobRecord record, IRepository<RequestQueue> repo, ISonarrApi sonarrApi,
|
||||
ISickRageApi srApi, ISettingsService<SonarrSettings> sonarrSettings, ISettingsService<SickRageSettings> srSettings,
|
||||
ICouchPotatoApi cpApi, ISettingsService<CouchPotatoSettings> cpsettings, IRequestService requestService,
|
||||
ISettingsService<HeadphonesSettings> hpSettings, IHeadphonesApi headphonesApi)
|
||||
ISettingsService<HeadphonesSettings> hpSettings, IHeadphonesApi headphonesApi, ISettingsService<PlexRequestSettings> prSettings)
|
||||
{
|
||||
Record = record;
|
||||
Repo = repo;
|
||||
|
@ -68,6 +69,7 @@ namespace PlexRequests.Services.Jobs
|
|||
SonarrSettings = sonarrSettings;
|
||||
CpSettings = cpsettings;
|
||||
HeadphoneSettings = hpSettings;
|
||||
PrSettings = prSettings.GetSettings();
|
||||
}
|
||||
|
||||
private IRepository<RequestQueue> Repo { get; }
|
||||
|
@ -77,6 +79,7 @@ namespace PlexRequests.Services.Jobs
|
|||
private ICouchPotatoApi CpApi { get; }
|
||||
private IHeadphonesApi HpApi { get; }
|
||||
private IRequestService RequestService { get; }
|
||||
private PlexRequestSettings PrSettings { get; }
|
||||
private ISettingsService<SonarrSettings> SonarrSettings { get; }
|
||||
private ISettingsService<SickRageSettings> SickrageSettings { get; }
|
||||
private ISettingsService<CouchPotatoSettings> CpSettings { get; }
|
||||
|
@ -108,13 +111,14 @@ namespace PlexRequests.Services.Jobs
|
|||
|
||||
private void ProcessMissingInformation(List<RequestQueue> requests)
|
||||
{
|
||||
var sonarrSettings = SonarrSettings.GetSettings();
|
||||
var sickrageSettings = SickrageSettings.GetSettings();
|
||||
|
||||
if (!requests.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var sonarrSettings = SonarrSettings.GetSettings();
|
||||
var sickrageSettings = SickrageSettings.GetSettings();
|
||||
|
||||
var tv = requests.Where(x => x.Type == RequestType.TvShow);
|
||||
|
||||
// TV
|
||||
|
@ -122,7 +126,7 @@ namespace PlexRequests.Services.Jobs
|
|||
foreach (var t in tv)
|
||||
{
|
||||
var providerId = int.Parse(t.PrimaryIdentifier);
|
||||
var showInfo = tvApi.ShowLookupByTheTvDbId(providerId);
|
||||
var showInfo = tvApi.ShowLookup(providerId);
|
||||
|
||||
if (showInfo.externals?.thetvdb != null)
|
||||
{
|
||||
|
@ -227,6 +231,8 @@ namespace PlexRequests.Services.Jobs
|
|||
|
||||
if (result)
|
||||
{
|
||||
|
||||
if (model.Type.ShouldAutoApprove(PrSettings, false, model.RequestedUsers))
|
||||
// Approve it now
|
||||
model.Approved = true;
|
||||
RequestService.UpdateRequest(model);
|
||||
|
@ -258,7 +264,7 @@ namespace PlexRequests.Services.Jobs
|
|||
foreach (var request in requests)
|
||||
{
|
||||
var model = ByteConverterHelper.ReturnObject<RequestedModel>(request.Content);
|
||||
var result = false;
|
||||
bool result;
|
||||
switch (request.Type)
|
||||
{
|
||||
case RequestType.Movie:
|
||||
|
|
|
@ -226,7 +226,8 @@ namespace PlexRequests.UI.Jobs
|
|||
var fault =
|
||||
TriggerBuilder.Create()
|
||||
.WithIdentity("FaultQueueHandler", "Fault")
|
||||
.StartAt(DateBuilder.FutureDate(10, IntervalUnit.Minute))
|
||||
//.StartAt(DateBuilder.FutureDate(10, IntervalUnit.Minute))
|
||||
.StartNow()
|
||||
.WithSimpleSchedule(x => x.WithIntervalInHours(s.FaultQueueHandler).RepeatForever())
|
||||
.Build();
|
||||
|
||||
|
|
|
@ -878,7 +878,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
try
|
||||
{
|
||||
if (ShouldAutoApprove(RequestType.TvShow, settings))
|
||||
if (RequestType.TvShow.ShouldAutoApprove(settings, IsAdmin, Username))
|
||||
{
|
||||
model.Approved = true;
|
||||
var s = await sonarrSettings;
|
||||
|
@ -974,7 +974,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private bool ShouldSendNotification(RequestType type, PlexRequestSettings prSettings)
|
||||
{
|
||||
var sendNotification = ShouldAutoApprove(type, prSettings)
|
||||
var sendNotification = type.ShouldAutoApprove(prSettings, IsAdmin, Username)
|
||||
? !prSettings.IgnoreNotifyForAutoApprovedRequests
|
||||
: true;
|
||||
var claims = Context.CurrentUser?.Claims;
|
||||
|
@ -1073,7 +1073,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
try
|
||||
{
|
||||
if (ShouldAutoApprove(RequestType.Album, settings))
|
||||
if (RequestType.Album.ShouldAutoApprove(settings, IsAdmin, Username))
|
||||
{
|
||||
model.Approved = true;
|
||||
var hpSettings = HeadphonesService.GetSettings();
|
||||
|
@ -1127,25 +1127,6 @@ namespace PlexRequests.UI.Modules
|
|||
return img;
|
||||
}
|
||||
|
||||
private bool ShouldAutoApprove(RequestType requestType, PlexRequestSettings prSettings)
|
||||
{
|
||||
// if the user is an admin or they are whitelisted, they go ahead and allow auto-approval
|
||||
if (IsAdmin || prSettings.ApprovalWhiteList.Any(x => x.Equals(Username, StringComparison.OrdinalIgnoreCase))) return true;
|
||||
|
||||
// check by request type if the category requires approval or not
|
||||
switch (requestType)
|
||||
{
|
||||
case RequestType.Movie:
|
||||
return !prSettings.RequireMovieApproval;
|
||||
case RequestType.TvShow:
|
||||
return !prSettings.RequireTvShowApproval;
|
||||
case RequestType.Album:
|
||||
return !prSettings.RequireMusicApproval;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Response> NotifyUser(bool notify)
|
||||
{
|
||||
Analytics.TrackEventAsync(Category.Search, Action.Save, "NotifyUser", Username, CookieHelper.GetAnalyticClientId(Cookies), notify ? 1 : 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue