mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 13:53:19 -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
|
@ -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
|
||||
{
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
using System;
|
||||
using Nancy;
|
||||
using Nancy.Security;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
|
||||
namespace PlexRequests.UI.Helpers
|
||||
{
|
||||
public interface ISecurityExtensions
|
||||
{
|
||||
Response AdminLoginRedirect(Permissions perm, NancyContext context);
|
||||
bool DoesNotHavePermissions(Permissions perm, IUserIdentity currentUser);
|
||||
bool DoesNotHavePermissions(int perm, IUserIdentity currentUser);
|
||||
Func<NancyContext, Response> ForbiddenIfNot(Func<NancyContext, bool> test);
|
||||
bool HasAnyPermissions(IUserIdentity user, params Permissions[] perm);
|
||||
bool HasPermissions(IUserIdentity user, Permissions perm);
|
||||
Response HasPermissionsRedirect(Permissions perm, NancyContext context, string routeName, HttpStatusCode code);
|
||||
Func<NancyContext, Response> HttpStatusCodeIfNot(HttpStatusCode statusCode, Func<NancyContext, bool> test);
|
||||
bool IsLoggedIn(NancyContext context);
|
||||
bool IsNormalUser(NancyContext context);
|
||||
bool IsPlexUser(NancyContext context);
|
||||
}
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: SecurityExtensions.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using Nancy;
|
||||
using Nancy.Linker;
|
||||
using Nancy.Responses;
|
||||
using Nancy.Security;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
namespace PlexRequests.UI.Helpers
|
||||
{
|
||||
public class SecurityExtensions : ISecurityExtensions
|
||||
{
|
||||
public SecurityExtensions(IUserRepository userRepository, IResourceLinker linker, IPlexUserRepository plexUsers)
|
||||
{
|
||||
UserRepository = userRepository;
|
||||
Linker = linker;
|
||||
PlexUsers = plexUsers;
|
||||
}
|
||||
|
||||
private IUserRepository UserRepository { get; }
|
||||
private IResourceLinker Linker { get; }
|
||||
private IPlexUserRepository PlexUsers { get; }
|
||||
|
||||
public bool IsLoggedIn(NancyContext context)
|
||||
{
|
||||
var userName = context.Request.Session[SessionKeys.UsernameKey];
|
||||
var realUser = false;
|
||||
var plexUser = userName != null;
|
||||
|
||||
if (context.CurrentUser?.IsAuthenticated() ?? false)
|
||||
{
|
||||
realUser = true;
|
||||
}
|
||||
|
||||
return realUser || plexUser;
|
||||
}
|
||||
|
||||
public bool IsPlexUser(NancyContext context)
|
||||
{
|
||||
var plexUser = PlexUsers.GetUserByUsername(context.CurrentUser.UserName);
|
||||
return plexUser != null;
|
||||
}
|
||||
|
||||
public bool IsNormalUser(NancyContext context)
|
||||
{
|
||||
var dbUser = UserRepository.GetUserByUsername(context.CurrentUser.UserName);
|
||||
|
||||
return dbUser != null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates a hook to be used in a pipeline before a route handler to ensure
|
||||
/// that the request was made by an authenticated user does not have the claims.
|
||||
/// </summary>
|
||||
/// <param name="perm">Claims the authenticated user needs to have</param>
|
||||
/// <returns>Hook that returns an Unauthorized response if the user is not
|
||||
/// authenticated or does have the claims, null otherwise</returns>
|
||||
private Func<NancyContext, Response> DoesNotHavePermissions(int perm)
|
||||
{
|
||||
return ForbiddenIfNot(ctx =>
|
||||
{
|
||||
var permissions = GetPermissions(ctx.CurrentUser);
|
||||
var result = permissions.HasFlag((Permissions)perm);
|
||||
return !result;
|
||||
});
|
||||
}
|
||||
|
||||
public bool DoesNotHavePermissions(int perm, IUserIdentity currentUser)
|
||||
{
|
||||
return DoesNotHavePermissions((Permissions) perm, currentUser);
|
||||
}
|
||||
|
||||
public bool DoesNotHavePermissions(Permissions perm, IUserIdentity currentUser)
|
||||
{
|
||||
var permissions = GetPermissions(currentUser);
|
||||
var result = permissions.HasFlag(perm);
|
||||
return !result;
|
||||
}
|
||||
|
||||
public bool HasPermissions(IUserIdentity user, Permissions perm)
|
||||
{
|
||||
var permissions = GetPermissions(user);
|
||||
return permissions.HasFlag(perm);
|
||||
}
|
||||
|
||||
public bool HasAnyPermissions(IUserIdentity user, params Permissions[] perm)
|
||||
{
|
||||
var permissions = GetPermissions(user);
|
||||
|
||||
foreach (var p in perm)
|
||||
{
|
||||
var result = permissions.HasFlag(p);
|
||||
if (result)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Response HasPermissionsRedirect(Permissions perm, NancyContext context, string routeName, HttpStatusCode code)
|
||||
{
|
||||
var url = Linker.BuildRelativeUri(context, routeName);
|
||||
|
||||
var response = ForbiddenIfNot(ctx =>
|
||||
{
|
||||
var permissions = GetPermissions(ctx.CurrentUser);
|
||||
var result = permissions.HasFlag(perm);
|
||||
return result;
|
||||
});
|
||||
|
||||
var r = response(context);
|
||||
return r.StatusCode == code
|
||||
? new RedirectResponse(url.ToString())
|
||||
: null;
|
||||
}
|
||||
|
||||
|
||||
public Response AdminLoginRedirect(Permissions perm, NancyContext context)
|
||||
{
|
||||
// This will redirect us to the Login Page if we don't have the correct permission passed in (e.g. Admin with Http 403 status code).
|
||||
return HasPermissionsRedirect(perm, context, "LocalLogin", HttpStatusCode.Forbidden);
|
||||
}
|
||||
|
||||
// BELOW IS A COPY FROM THE SecurityHooks CLASS!
|
||||
|
||||
/// <summary>
|
||||
/// Creates a hook to be used in a pipeline before a route handler to ensure that
|
||||
/// the request satisfies a specific test.
|
||||
/// </summary>
|
||||
/// <param name="test">Test that must return true for the request to continue</param>
|
||||
/// <returns>Hook that returns an Forbidden response if the test fails, null otherwise</returns>
|
||||
public Func<NancyContext, Response> ForbiddenIfNot(Func<NancyContext, bool> test)
|
||||
{
|
||||
return HttpStatusCodeIfNot(HttpStatusCode.Forbidden, test);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a hook to be used in a pipeline before a route handler to ensure that
|
||||
/// the request satisfies a specific test.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">HttpStatusCode to use for the response</param>
|
||||
/// <param name="test">Test that must return true for the request to continue</param>
|
||||
/// <returns>Hook that returns a response with a specific HttpStatusCode if the test fails, null otherwise</returns>
|
||||
public Func<NancyContext, Response> HttpStatusCodeIfNot(HttpStatusCode statusCode, Func<NancyContext, bool> test)
|
||||
{
|
||||
return ctx =>
|
||||
{
|
||||
Response response = new Response
|
||||
{
|
||||
StatusCode = HttpStatusCode.OK
|
||||
};
|
||||
if (!test(ctx))
|
||||
{
|
||||
response = new Response
|
||||
{
|
||||
StatusCode = statusCode
|
||||
};
|
||||
}
|
||||
return response;
|
||||
};
|
||||
}
|
||||
|
||||
private Permissions GetPermissions(IUserIdentity user)
|
||||
{
|
||||
if (user == null) return 0;
|
||||
|
||||
var dbUser = UserRepository.GetUserByUsername(user.UserName);
|
||||
|
||||
if (dbUser != null)
|
||||
{
|
||||
var permissions = (Permissions)dbUser.Permissions;
|
||||
return permissions;
|
||||
}
|
||||
|
||||
var plexUser = PlexUsers.GetUserByUsername(user.UserName);
|
||||
if (plexUser != null)
|
||||
{
|
||||
var permissions = (Permissions)plexUser.Permissions;
|
||||
return permissions;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: SessionKeys.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
|
||||
namespace PlexRequests.UI.Models
|
||||
{
|
||||
public class SessionKeys
|
||||
{
|
||||
public const string UsernameKey = "Username";
|
||||
public const string ClientDateTimeOffsetKey = "ClientDateTimeOffset";
|
||||
public const string UserWizardPlexAuth = nameof(UserWizardPlexAuth);
|
||||
public const string UserWizardMachineId = nameof(UserWizardMachineId);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
{
|
||||
|
@ -139,7 +140,7 @@ namespace PlexRequests.UI.Modules
|
|||
Get["/episodes", true] = async (x, ct) => await GetEpisodes();
|
||||
}
|
||||
|
||||
private IRepository<PlexContent> PlexContentRepository { get; }
|
||||
private IRepository<PlexContent> PlexContentRepository { get; }
|
||||
private TvMazeApi TvApi { get; }
|
||||
private IPlexApi PlexApi { get; }
|
||||
private TheMovieDbApi MovieApi { get; }
|
||||
|
@ -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,10 +985,10 @@ 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;
|
||||
|
||||
|
||||
if (IsAdmin)
|
||||
{
|
||||
sendNotification = false; // Don't bother sending a notification if the user is an admin
|
||||
|
@ -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