mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 10:36:54 -07:00
parent
e39512905a
commit
e46c43610f
11 changed files with 159 additions and 100 deletions
|
@ -56,6 +56,7 @@ using PlexRequests.Core.SettingModels;
|
|||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Analytics;
|
||||
using PlexRequests.Helpers.Exceptions;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Services.Interfaces;
|
||||
using PlexRequests.Services.Jobs;
|
||||
using PlexRequests.Services.Notification;
|
||||
|
@ -153,7 +154,7 @@ namespace PlexRequests.UI.Modules
|
|||
NotifySettings = notifyService;
|
||||
RecentlyAdded = recentlyAdded;
|
||||
|
||||
this.RequiresClaims(UserClaims.Admin);
|
||||
Security.HasPermissionsResponse(Permissions.Administrator);
|
||||
|
||||
Get["/"] = _ => Admin();
|
||||
|
||||
|
@ -849,7 +850,8 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private Response CreateApiKey()
|
||||
{
|
||||
this.RequiresClaims(UserClaims.Admin);
|
||||
Security.HasPermissionsResponse(Permissions.Administrator);
|
||||
|
||||
Analytics.TrackEventAsync(Category.Admin, Action.Create, "Created API Key", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||
var apiKey = Guid.NewGuid().ToString("N");
|
||||
var settings = PrService.GetSettings();
|
||||
|
|
|
@ -30,6 +30,7 @@ using System.Linq;
|
|||
using System.Threading;
|
||||
|
||||
using Nancy;
|
||||
using Nancy.Security;
|
||||
using Ninject;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
|
@ -121,10 +122,6 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
protected IDictionary<string, string> Cookies => Request?.Cookies;
|
||||
|
||||
// This is not ideal, but it's cleaner than having to pass it down through each module.
|
||||
[Inject]
|
||||
protected IUserRepository UserRepository { get; set; }
|
||||
|
||||
protected bool IsAdmin
|
||||
{
|
||||
get
|
||||
|
@ -134,7 +131,9 @@ namespace PlexRequests.UI.Modules
|
|||
return false;
|
||||
}
|
||||
|
||||
var user = UserRepository.GetUserByUsername(Context?.CurrentUser?.UserName);
|
||||
var userRepo = ServiceLocator.Instance.Resolve<IUserRepository>();
|
||||
|
||||
var user = userRepo.GetUserByUsername(Context?.CurrentUser?.UserName);
|
||||
|
||||
if (user == null) return false;
|
||||
|
||||
|
@ -144,6 +143,22 @@ namespace PlexRequests.UI.Modules
|
|||
}
|
||||
}
|
||||
|
||||
protected IUserIdentity User => Context?.CurrentUser;
|
||||
|
||||
protected SecurityExtensions Security
|
||||
{
|
||||
|
||||
get
|
||||
{
|
||||
var userRepo = ServiceLocator.Instance.Resolve<IUserRepository>();
|
||||
return _security ?? (_security = new SecurityExtensions(userRepo, this));
|
||||
}
|
||||
}
|
||||
|
||||
private SecurityExtensions _security;
|
||||
|
||||
|
||||
|
||||
protected bool LoggedIn => Context?.CurrentUser != null;
|
||||
|
||||
protected string Culture { get; set; }
|
||||
|
|
|
@ -55,6 +55,7 @@ using PlexRequests.Api.Models.Sonarr;
|
|||
using PlexRequests.Api.Models.Tv;
|
||||
using PlexRequests.Core.Models;
|
||||
using PlexRequests.Helpers.Analytics;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store.Models;
|
||||
using PlexRequests.Store.Repository;
|
||||
|
||||
|
@ -444,7 +445,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private async Task<Response> RequestMovie(int movieId)
|
||||
{
|
||||
if (this.DoesNotHaveClaimCheck(UserClaims.ReadOnlyUser))
|
||||
if (Security.DoesNotHavePermissions(Permissions.ReadOnlyUser, User))
|
||||
{
|
||||
return
|
||||
Response.AsJson(new JsonResponseModel()
|
||||
|
@ -553,7 +554,7 @@ namespace PlexRequests.UI.Modules
|
|||
/// <returns></returns>
|
||||
private async Task<Response> RequestTvShow(int showId, string seasons)
|
||||
{
|
||||
if (this.DoesNotHaveClaimCheck(UserClaims.ReadOnlyUser))
|
||||
if (Security.DoesNotHavePermissions(Permissions.ReadOnlyUser, User))
|
||||
{
|
||||
return
|
||||
Response.AsJson(new JsonResponseModel()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue