mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 11:38:32 -07:00
Implimented auto approve permissions #218
This commit is contained in:
parent
a34b228178
commit
4629301264
39 changed files with 140 additions and 121 deletions
|
@ -3,7 +3,7 @@ using Nancy;
|
|||
using Nancy.Security;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
|
||||
namespace PlexRequests.UI.Helpers
|
||||
namespace PlexRequests.Core
|
||||
{
|
||||
public interface ISecurityExtensions
|
||||
{
|
||||
|
@ -18,5 +18,6 @@ namespace PlexRequests.UI.Helpers
|
|||
bool IsLoggedIn(NancyContext context);
|
||||
bool IsNormalUser(NancyContext context);
|
||||
bool IsPlexUser(NancyContext context);
|
||||
bool HasPermissions(string userName, Permissions perm);
|
||||
}
|
||||
}
|
|
@ -46,6 +46,10 @@
|
|||
<Reference Include="Mono.Data.Sqlite">
|
||||
<HintPath>..\Assemblies\Mono.Data.Sqlite.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Nancy.Linker, Version=0.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Nancy.Linker.0.3.1\lib\net40-Client\Nancy.Linker.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
@ -92,6 +96,7 @@
|
|||
<Compile Include="CacheKeys.cs" />
|
||||
<Compile Include="HeadphonesSender.cs" />
|
||||
<Compile Include="IPlexReadOnlyDatabase.cs" />
|
||||
<Compile Include="ISecurityExtensions.cs" />
|
||||
<Compile Include="IStatusChecker.cs" />
|
||||
<Compile Include="Notification\NotificationMessage.cs" />
|
||||
<Compile Include="Notification\NotificationMessageContent.cs" />
|
||||
|
@ -112,7 +117,7 @@
|
|||
<Compile Include="PlexReadOnlyDatabase.cs" />
|
||||
<Compile Include="Queue\ITransientFaultQueue.cs" />
|
||||
<Compile Include="Queue\TransientFaultQueue.cs" />
|
||||
<Compile Include="RequestHelper.cs" />
|
||||
<Compile Include="SecurityExtensions.cs" />
|
||||
<Compile Include="SettingModels\AuthenticationSettings.cs" />
|
||||
<Compile Include="SettingModels\ExternalSettings.cs" />
|
||||
<Compile Include="SettingModels\HeadphonesSettings.cs" />
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,11 +30,12 @@ using Nancy;
|
|||
using Nancy.Linker;
|
||||
using Nancy.Responses;
|
||||
using Nancy.Security;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Helpers
|
||||
namespace PlexRequests.Core
|
||||
{
|
||||
public class SecurityExtensions : ISecurityExtensions
|
||||
{
|
||||
|
@ -111,6 +112,11 @@ namespace PlexRequests.UI.Helpers
|
|||
var permissions = GetPermissions(user);
|
||||
return permissions.HasFlag(perm);
|
||||
}
|
||||
public bool HasPermissions(string userName, Permissions perm)
|
||||
{
|
||||
var permissions = GetPermissions(userName);
|
||||
return permissions.HasFlag(perm);
|
||||
}
|
||||
|
||||
public bool HasAnyPermissions(IUserIdentity user, params Permissions[] perm)
|
||||
{
|
||||
|
@ -193,9 +199,14 @@ namespace PlexRequests.UI.Helpers
|
|||
|
||||
private Permissions GetPermissions(IUserIdentity user)
|
||||
{
|
||||
if (user == null) return 0;
|
||||
return GetPermissions(user.UserName);
|
||||
}
|
||||
|
||||
var dbUser = UserRepository.GetUserByUsername(user.UserName);
|
||||
private Permissions GetPermissions(string userName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(userName)) return 0;
|
||||
|
||||
var dbUser = UserRepository.GetUserByUsername(userName);
|
||||
|
||||
if (dbUser != null)
|
||||
{
|
||||
|
@ -203,7 +214,7 @@ namespace PlexRequests.UI.Helpers
|
|||
return permissions;
|
||||
}
|
||||
|
||||
var plexUser = PlexUsers.GetUserByUsername(user.UserName);
|
||||
var plexUser = PlexUsers.GetUserByUsername(userName);
|
||||
if (plexUser != null)
|
||||
{
|
||||
var permissions = (Permissions)plexUser.Permissions;
|
|
@ -5,6 +5,7 @@
|
|||
<package id="Dapper" version="1.50.0-beta8" targetFramework="net45" />
|
||||
<package id="Nancy" version="1.4.3" targetFramework="net45" />
|
||||
<package id="Nancy.Authentication.Forms" version="1.4.1" targetFramework="net45" />
|
||||
<package id="Nancy.Linker" version="0.3.1" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
|
||||
<package id="NLog" version="4.3.6" targetFramework="net45" />
|
||||
<package id="Octokit" version="0.19.0" targetFramework="net45" />
|
||||
|
|
|
@ -90,6 +90,7 @@
|
|||
<Compile Include="PlexHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SerializerSettings.cs" />
|
||||
<Compile Include="SessionKeys.cs" />
|
||||
<Compile Include="StringCipher.cs" />
|
||||
<Compile Include="StringHasher.cs" />
|
||||
<Compile Include="StringHelper.cs" />
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
namespace PlexRequests.UI.Models
|
||||
namespace PlexRequests.Helpers
|
||||
{
|
||||
public class SessionKeys
|
||||
{
|
|
@ -54,7 +54,8 @@ 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<PlexRequestSettings> prSettings)
|
||||
ISettingsService<HeadphonesSettings> hpSettings, IHeadphonesApi headphonesApi, ISettingsService<PlexRequestSettings> prSettings,
|
||||
ISecurityExtensions security)
|
||||
{
|
||||
Record = record;
|
||||
Repo = repo;
|
||||
|
@ -69,6 +70,7 @@ namespace PlexRequests.Services.Jobs
|
|||
SonarrSettings = sonarrSettings;
|
||||
CpSettings = cpsettings;
|
||||
HeadphoneSettings = hpSettings;
|
||||
Security = security;
|
||||
PrSettings = prSettings.GetSettings();
|
||||
}
|
||||
|
||||
|
@ -84,6 +86,7 @@ namespace PlexRequests.Services.Jobs
|
|||
private ISettingsService<SickRageSettings> SickrageSettings { get; }
|
||||
private ISettingsService<CouchPotatoSettings> CpSettings { get; }
|
||||
private ISettingsService<HeadphonesSettings> HeadphoneSettings { get; }
|
||||
private ISecurityExtensions Security { get; }
|
||||
|
||||
public void Execute(IJobExecutionContext context)
|
||||
{
|
||||
|
@ -235,7 +238,7 @@ namespace PlexRequests.Services.Jobs
|
|||
if (result)
|
||||
{
|
||||
|
||||
if (model.Type.ShouldAutoApprove(PrSettings, false, model.RequestedUsers))
|
||||
if (ShouldAutoApprove(model.Type, PrSettings, model.RequestedUsers))
|
||||
// Approve it now
|
||||
model.Approved = true;
|
||||
RequestService.UpdateRequest(model);
|
||||
|
@ -296,5 +299,37 @@ namespace PlexRequests.Services.Jobs
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShouldAutoApprove(RequestType requestType, PlexRequestSettings prSettings, List<string> username)
|
||||
{
|
||||
if (prSettings.ApprovalWhiteList.Intersect(username).Any())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var user in username)
|
||||
{
|
||||
var admin = Security.HasPermissions(user, Permissions.Administrator);
|
||||
// if the user is an admin or they are whitelisted, they go ahead and allow auto-approval
|
||||
if (admin) return true;
|
||||
|
||||
// check by request type if the category requires approval or not
|
||||
switch (requestType)
|
||||
{
|
||||
case RequestType.Movie:
|
||||
return Security.HasPermissions(user, Permissions.AutoApproveMovie) ||
|
||||
!prSettings.RequireMovieApproval;
|
||||
case RequestType.TvShow:
|
||||
return Security.HasPermissions(user, Permissions.AutoApproveTv) ||
|
||||
!prSettings.RequireTvShowApproval;
|
||||
case RequestType.Album:
|
||||
return Security.HasPermissions(user, Permissions.AutoApproveAlbum) ||
|
||||
!prSettings.RequireMusicApproval;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,6 +36,10 @@
|
|||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Build.Framework" />
|
||||
<Reference Include="Nancy, Version=1.4.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Nancy.1.4.3\lib\net40\Nancy.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<package id="Dapper" version="1.50.0-beta8" targetFramework="net45" />
|
||||
<package id="MailKit" version="1.2.21" targetFramework="net45" requireReinstallation="True" />
|
||||
<package id="MimeKit" version="1.2.22" targetFramework="net45" />
|
||||
<package id="Nancy" version="1.4.3" targetFramework="net45" />
|
||||
<package id="NLog" version="4.3.6" targetFramework="net45" />
|
||||
<package id="Quartz" version="2.3.3" targetFramework="net45" />
|
||||
</packages>
|
|
@ -42,6 +42,7 @@ using PlexRequests.Api.Interfaces;
|
|||
using PlexRequests.Api.Models.Plex;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Analytics;
|
||||
using PlexRequests.UI.Models;
|
||||
using PlexRequests.UI.Modules;
|
||||
|
|
|
@ -32,6 +32,7 @@ using Nancy.ViewEngines.Razor;
|
|||
using Ninject;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store.Repository;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Helpers
|
||||
{
|
||||
|
|
|
@ -67,6 +67,7 @@ using PlexRequests.UI.Models;
|
|||
using Quartz;
|
||||
using Action = PlexRequests.Helpers.Analytics.Action;
|
||||
using HttpStatusCode = Nancy.HttpStatusCode;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -37,6 +37,7 @@ using PlexRequests.Store.Models;
|
|||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules.Admin
|
||||
{
|
||||
|
|
|
@ -40,6 +40,7 @@ using PlexRequests.Helpers;
|
|||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules.Admin
|
||||
{
|
||||
|
|
|
@ -29,7 +29,9 @@ using Nancy.Responses.Negotiation;
|
|||
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -36,9 +36,11 @@ using Newtonsoft.Json;
|
|||
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -37,7 +37,9 @@ using Newtonsoft.Json;
|
|||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -32,9 +32,11 @@ using Nancy.ModelBinding;
|
|||
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -36,10 +36,12 @@ using NLog;
|
|||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@ using PlexRequests.Helpers.Permissions;
|
|||
using PlexRequests.Store;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -32,8 +32,10 @@ using Nancy.Validation;
|
|||
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -28,10 +28,10 @@
|
|||
|
||||
using Nancy;
|
||||
using Nancy.Extensions;
|
||||
using PlexRequests.UI.Models;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.Helpers;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -30,17 +30,13 @@ using System.Linq;
|
|||
using System.Threading;
|
||||
|
||||
using Nancy;
|
||||
using Nancy.Linker;
|
||||
using Nancy.Security;
|
||||
using Ninject;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -35,7 +35,9 @@ using PlexRequests.Core;
|
|||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Analytics;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -7,7 +7,9 @@ using NLog;
|
|||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -33,7 +33,9 @@ using Nancy.Responses;
|
|||
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@ using PlexRequests.Services.Notification;
|
|||
using PlexRequests.Store;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -33,8 +33,10 @@ using Nancy.Linker;
|
|||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -36,10 +36,12 @@ using PlexRequests.Core;
|
|||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Core.StatusChecker;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Services.Interfaces;
|
||||
using PlexRequests.Services.Jobs;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -43,9 +43,8 @@ using PlexRequests.Helpers.Permissions;
|
|||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Authentication;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ModuleExtensions = Nancy.Authentication.Forms.ModuleExtensions;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -50,6 +50,7 @@ using PlexRequests.Helpers.Analytics;
|
|||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using Action = PlexRequests.Helpers.Analytics.Action;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
|
|
@ -68,6 +68,7 @@ using TMDbLib.Objects.General;
|
|||
|
||||
using Action = PlexRequests.Helpers.Analytics.Action;
|
||||
using EpisodesModel = PlexRequests.Store.EpisodesModel;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
|
@ -563,7 +564,7 @@ namespace PlexRequests.UI.Modules
|
|||
};
|
||||
try
|
||||
{
|
||||
if (RequestType.Movie.ShouldAutoApprove(settings, IsAdmin, Username))
|
||||
if (ShouldAutoApprove(RequestType.Movie, settings, Username))
|
||||
{
|
||||
var cpSettings = await CpService.GetSettingsAsync();
|
||||
model.Approved = true;
|
||||
|
@ -888,7 +889,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
try
|
||||
{
|
||||
if (RequestType.TvShow.ShouldAutoApprove(settings, IsAdmin, Username))
|
||||
if (ShouldAutoApprove(RequestType.TvShow, settings, Username))
|
||||
{
|
||||
model.Approved = true;
|
||||
var s = await sonarrSettings;
|
||||
|
@ -984,7 +985,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private bool ShouldSendNotification(RequestType type, PlexRequestSettings prSettings)
|
||||
{
|
||||
var sendNotification = type.ShouldAutoApprove(prSettings, IsAdmin, Username)
|
||||
var sendNotification = ShouldAutoApprove(type, prSettings, Username)
|
||||
? !prSettings.IgnoreNotifyForAutoApprovedRequests
|
||||
: true;
|
||||
|
||||
|
@ -1092,7 +1093,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
try
|
||||
{
|
||||
if (RequestType.Album.ShouldAutoApprove(settings, IsAdmin, Username))
|
||||
if (ShouldAutoApprove(RequestType.Album, settings, Username))
|
||||
{
|
||||
model.Approved = true;
|
||||
var hpSettings = HeadphonesService.GetSettings();
|
||||
|
@ -1424,5 +1425,28 @@ namespace PlexRequests.UI.Modules
|
|||
var diff = model.Episodes.Except(available);
|
||||
return diff;
|
||||
}
|
||||
|
||||
public bool ShouldAutoApprove(RequestType requestType, PlexRequestSettings prSettings, string username)
|
||||
{
|
||||
var admin = Security.HasPermissions(Context.CurrentUser, Permissions.Administrator);
|
||||
// if the user is an admin or they are whitelisted, they go ahead and allow auto-approval
|
||||
if (admin || 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 Security.HasPermissions(User, Permissions.AutoApproveMovie) ||
|
||||
!prSettings.RequireMovieApproval;
|
||||
case RequestType.TvShow:
|
||||
return Security.HasPermissions(User, Permissions.AutoApproveTv) ||
|
||||
!prSettings.RequireTvShowApproval;
|
||||
case RequestType.Album:
|
||||
return Security.HasPermissions(User, Permissions.AutoApproveAlbum) ||
|
||||
!prSettings.RequireMusicApproval;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,6 @@ using System.Threading.Tasks;
|
|||
using Nancy;
|
||||
using Nancy.Extensions;
|
||||
using Nancy.Linker;
|
||||
using Nancy.Responses.Negotiation;
|
||||
|
||||
using NLog;
|
||||
|
||||
using PlexRequests.Api.Interfaces;
|
||||
|
@ -45,9 +43,7 @@ using PlexRequests.Helpers.Analytics;
|
|||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Authentication;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ModuleExtensions = Nancy.Authentication.Forms.ModuleExtensions;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
|
|
|
@ -17,9 +17,10 @@ using PlexRequests.Helpers.Permissions;
|
|||
using PlexRequests.Store;
|
||||
using PlexRequests.Store.Models;
|
||||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
public class UserManagementModule : BaseModule
|
||||
|
|
|
@ -29,10 +29,8 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
|
||||
using Nancy;
|
||||
using Nancy.Authentication.Forms;
|
||||
using Nancy.Extensions;
|
||||
using Nancy.ModelBinding;
|
||||
using Nancy.Responses.Negotiation;
|
||||
using Nancy.Validation;
|
||||
using NLog;
|
||||
using PlexRequests.Api.Interfaces;
|
||||
|
@ -44,6 +42,7 @@ using PlexRequests.Helpers.Permissions;
|
|||
using PlexRequests.UI.Authentication;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
|
||||
using Action = PlexRequests.Helpers.Analytics.Action;
|
||||
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
// ************************************************************************/
|
||||
#endregion
|
||||
using Mono.Data.Sqlite;
|
||||
|
||||
using Nancy;
|
||||
using Nancy.Authentication.Forms;
|
||||
|
||||
using Ninject.Modules;
|
||||
|
@ -38,7 +36,8 @@ using PlexRequests.Helpers;
|
|||
using PlexRequests.Services.Interfaces;
|
||||
using PlexRequests.Services.Notification;
|
||||
using PlexRequests.Store;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions;
|
||||
using SecurityExtensions = PlexRequests.Core.SecurityExtensions;
|
||||
|
||||
namespace PlexRequests.UI.NinjectModules
|
||||
{
|
||||
|
|
|
@ -215,8 +215,6 @@
|
|||
<Compile Include="Helpers\EmptyViewBase.cs" />
|
||||
<Compile Include="Helpers\AngularViewBase.cs" />
|
||||
<Compile Include="Helpers\HtmlSecurityHelper.cs" />
|
||||
<Compile Include="Helpers\ISecurityExtensions.cs" />
|
||||
<Compile Include="Helpers\SecurityExtensions.cs" />
|
||||
<Compile Include="Helpers\ServiceLocator.cs" />
|
||||
<Compile Include="Helpers\Themes.cs" />
|
||||
<Compile Include="Helpers\ValidationHelper.cs" />
|
||||
|
@ -326,7 +324,6 @@
|
|||
<Compile Include="Models\PlexAuth.cs" />
|
||||
<Compile Include="Models\RequestViewModel.cs" />
|
||||
<Compile Include="Models\SearchTvShowViewModel.cs" />
|
||||
<Compile Include="Models\SessionKeys.cs" />
|
||||
<Compile Include="Modules\Admin\AdminModule.cs" />
|
||||
<Compile Include="Modules\ApplicationTesterModule.cs" />
|
||||
<Compile Include="Modules\BaseAuthModule.cs" />
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
@using Nancy.Session
|
||||
@using Nancy;
|
||||
@using PlexRequests.Core.SettingModels
|
||||
@using PlexRequests.Helpers
|
||||
@using PlexRequests.UI.Helpers
|
||||
@using PlexRequests.UI.Models
|
||||
@using PlexRequests.UI.Resources
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue