mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Added the watchlist import for movies
This commit is contained in:
parent
df59b46a78
commit
f41eea89a0
55 changed files with 1824 additions and 136 deletions
|
@ -116,16 +116,25 @@ namespace Ombi.Core.Authentication
|
|||
public async Task<OmbiUser> GetOmbiUserFromPlexToken(string plexToken)
|
||||
{
|
||||
var plexAccount = await _plexApi.GetAccount(plexToken);
|
||||
|
||||
|
||||
// Check for a ombi user
|
||||
if (plexAccount?.user != null)
|
||||
if (plexAccount?.user == null)
|
||||
{
|
||||
var potentialOmbiUser = await Users.FirstOrDefaultAsync(x =>
|
||||
x.ProviderUserId == plexAccount.user.id);
|
||||
return potentialOmbiUser;
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
var potentialOmbiUser = await Users.FirstOrDefaultAsync(x =>
|
||||
x.ProviderUserId == plexAccount.user.id);
|
||||
// Update ombi user with the token
|
||||
|
||||
if (potentialOmbiUser != null)
|
||||
{
|
||||
potentialOmbiUser.MediaServerToken = plexAccount.user.authentication_token;
|
||||
await UpdateAsync(potentialOmbiUser);
|
||||
}
|
||||
|
||||
return potentialOmbiUser;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -142,6 +151,10 @@ namespace Ombi.Core.Authentication
|
|||
var result = await _plexApi.SignIn(new UserRequest { password = password, login = login });
|
||||
if (result.user?.authentication_token != null)
|
||||
{
|
||||
// Update ombi user with the token
|
||||
user.MediaServerToken = result.user?.authentication_token;
|
||||
await UpdateAsync(user);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Ombi.Core.Engine
|
|||
private Dictionary<int, MovieRequests> _dbMovies;
|
||||
private Dictionary<int, TvRequests> _dbTv;
|
||||
|
||||
protected BaseMediaEngine(IPrincipal identity, IRequestServiceMain requestService,
|
||||
protected BaseMediaEngine(ICurrentUser identity, IRequestServiceMain requestService,
|
||||
IRuleEvaluator rules, OmbiUserManager um, ICacheService cache, ISettingsService<OmbiSettings> ombiSettings, IRepository<RequestSubscription> sub) : base(identity, um, rules)
|
||||
{
|
||||
RequestService = requestService;
|
||||
|
|
|
@ -11,6 +11,7 @@ using Ombi.Api.TheMovieDb;
|
|||
using Ombi.Api.TheMovieDb.Models;
|
||||
using Ombi.Config;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Helpers;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
|
@ -24,7 +25,7 @@ namespace Ombi.Core.Engine.Demo
|
|||
{
|
||||
public class DemoMovieSearchEngine : MovieSearchEngine, IDemoMovieSearchEngine
|
||||
{
|
||||
public DemoMovieSearchEngine(IPrincipal identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
|
||||
public DemoMovieSearchEngine(ICurrentUser identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
|
||||
ILogger<MovieSearchEngine> logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService<OmbiSettings> s,
|
||||
IRepository<RequestSubscription> sub, IOptions<DemoLists> lists)
|
||||
: base(identity, service, movApi, mapper, logger, r, um, mem, s, sub)
|
||||
|
|
|
@ -4,6 +4,7 @@ using Ombi.Api.Trakt;
|
|||
using Ombi.Api.TvMaze;
|
||||
using Ombi.Config;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Helpers;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
|
@ -24,7 +25,7 @@ namespace Ombi.Core.Engine.Demo
|
|||
public class DemoTvSearchEngine : TvSearchEngine, IDemoTvSearchEngine
|
||||
{
|
||||
|
||||
public DemoTvSearchEngine(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
|
||||
public DemoTvSearchEngine(ICurrentUser identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
|
||||
ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um, ICacheService memCache,
|
||||
ISettingsService<OmbiSettings> s, IRepository<RequestSubscription> sub, IOptions<DemoLists> lists, IImageService imageService,
|
||||
ISettingsService<CustomizationSettings> custom)
|
||||
|
|
|
@ -1,42 +1,35 @@
|
|||
using System;
|
||||
using Ombi.Core.Rule;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
using Ombi.Store.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Core.Helpers;
|
||||
|
||||
namespace Ombi.Core.Engine.Interfaces
|
||||
{
|
||||
public abstract class BaseEngine
|
||||
{
|
||||
protected BaseEngine(IPrincipal user, OmbiUserManager um, IRuleEvaluator rules)
|
||||
protected BaseEngine(ICurrentUser user, OmbiUserManager um, IRuleEvaluator rules)
|
||||
{
|
||||
UserPrinciple = user;
|
||||
CurrentUser = user;
|
||||
Rules = rules;
|
||||
UserManager = um;
|
||||
}
|
||||
|
||||
protected IPrincipal UserPrinciple { get; }
|
||||
protected ICurrentUser CurrentUser { get; }
|
||||
protected IRuleEvaluator Rules { get; }
|
||||
protected OmbiUserManager UserManager { get; }
|
||||
protected string Username => UserPrinciple.Identity.Name;
|
||||
protected OmbiUserManager UserManager { get; }
|
||||
protected string Username => CurrentUser.Username;
|
||||
protected Task<OmbiUser> GetUser() => CurrentUser.GetUser();
|
||||
|
||||
private OmbiUser _user;
|
||||
protected async Task<OmbiUser> GetUser()
|
||||
{
|
||||
if(!Username.HasValue())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var username = Username.ToUpper();
|
||||
return _user ??= await UserManager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username);
|
||||
}
|
||||
/// <summary>
|
||||
/// Only used for background tasks
|
||||
/// </summary>
|
||||
public void SetUser(OmbiUser user) => CurrentUser.SetUser(user);
|
||||
|
||||
protected async Task<string> UserAlias()
|
||||
{
|
||||
|
@ -52,7 +45,7 @@ namespace Ombi.Core.Engine.Interfaces
|
|||
var user = await GetUser();
|
||||
return await UserManager.IsInRoleAsync(user, roleName);
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<RuleResult>> RunRequestRules(BaseRequest model)
|
||||
{
|
||||
var ruleResults = await Rules.StartRequestRules(model);
|
||||
|
|
|
@ -25,5 +25,6 @@ namespace Ombi.Core.Engine.Interfaces
|
|||
Task UnSubscribeRequest(int requestId, RequestType type);
|
||||
Task SubscribeToRequest(int requestId, RequestType type);
|
||||
Task<RequestEngineResult> ReProcessRequest(int requestId, bool is4K, CancellationToken cancellationToken);
|
||||
void SetUser(OmbiUser user);
|
||||
}
|
||||
}
|
|
@ -23,12 +23,13 @@ using Ombi.Store.Repository;
|
|||
using Ombi.Core.Models;
|
||||
using System.Threading;
|
||||
using Ombi.Core.Services;
|
||||
using Ombi.Core.Helpers;
|
||||
|
||||
namespace Ombi.Core.Engine
|
||||
{
|
||||
public class MovieRequestEngine : BaseMediaEngine, IMovieRequestEngine
|
||||
{
|
||||
public MovieRequestEngine(IMovieDbApi movieApi, IRequestServiceMain requestService, IPrincipal user,
|
||||
public MovieRequestEngine(IMovieDbApi movieApi, IRequestServiceMain requestService, ICurrentUser user,
|
||||
INotificationHelper helper, IRuleEvaluator r, IMovieSender sender, ILogger<MovieRequestEngine> log,
|
||||
OmbiUserManager manager, IRepository<RequestLog> rl, ICacheService cache,
|
||||
ISettingsService<OmbiSettings> ombiSettings, IRepository<RequestSubscription> sub, IMediaCacheService mediaCacheService,
|
||||
|
|
|
@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging;
|
|||
using Ombi.Api.TheMovieDb;
|
||||
using Ombi.Api.TheMovieDb.Models;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Helpers;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
|
@ -22,7 +23,7 @@ namespace Ombi.Core.Engine
|
|||
{
|
||||
public class MovieSearchEngine : BaseMediaEngine, IMovieEngine
|
||||
{
|
||||
public MovieSearchEngine(IPrincipal identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
|
||||
public MovieSearchEngine(ICurrentUser identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
|
||||
ILogger<MovieSearchEngine> logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService<OmbiSettings> s, IRepository<RequestSubscription> sub)
|
||||
: base(identity, service, r, um, mem, s, sub)
|
||||
{
|
||||
|
|
|
@ -24,12 +24,13 @@ using Ombi.Settings.Settings.Models.External;
|
|||
using Ombi.Store.Entities.Requests;
|
||||
using Ombi.Store.Repository;
|
||||
using System.ComponentModel;
|
||||
using Ombi.Core.Helpers;
|
||||
|
||||
namespace Ombi.Core.Engine
|
||||
{
|
||||
public class MusicRequestEngine : BaseMediaEngine, IMusicRequestEngine
|
||||
{
|
||||
public MusicRequestEngine(IRequestServiceMain requestService, IPrincipal user,
|
||||
public MusicRequestEngine(IRequestServiceMain requestService, ICurrentUser user,
|
||||
INotificationHelper helper, IRuleEvaluator r, ILogger<MusicRequestEngine> log,
|
||||
OmbiUserManager manager, IRepository<RequestLog> rl, ICacheService cache,
|
||||
ISettingsService<OmbiSettings> ombiSettings, IRepository<RequestSubscription> sub, ILidarrApi lidarr,
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace Ombi.Core.Engine
|
|||
{
|
||||
public class MusicSearchEngine : BaseMediaEngine, IMusicSearchEngine
|
||||
{
|
||||
public MusicSearchEngine(IPrincipal identity, IRequestServiceMain service, ILidarrApi lidarrApi, IMapper mapper,
|
||||
public MusicSearchEngine(ICurrentUser identity, IRequestServiceMain service, ILidarrApi lidarrApi, IMapper mapper,
|
||||
ILogger<MusicSearchEngine> logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService<OmbiSettings> s, IRepository<RequestSubscription> sub,
|
||||
ISettingsService<LidarrSettings> lidarrSettings)
|
||||
: base(identity, service, r, um, mem, s, sub)
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Ombi.Core.Engine
|
|||
{
|
||||
public class TvRequestEngine : BaseMediaEngine, ITvRequestEngine
|
||||
{
|
||||
public TvRequestEngine(ITvMazeApi tvApi, IMovieDbApi movApi, IRequestServiceMain requestService, IPrincipal user,
|
||||
public TvRequestEngine(ITvMazeApi tvApi, IMovieDbApi movApi, IRequestServiceMain requestService, ICurrentUser user,
|
||||
INotificationHelper helper, IRuleEvaluator rule, OmbiUserManager manager, ILogger<TvRequestEngine> logger,
|
||||
ITvSender sender, IRepository<RequestLog> rl, ISettingsService<OmbiSettings> settings, ICacheService cache,
|
||||
IRepository<RequestSubscription> sub, IMediaCacheService mediaCacheService) : base(user, requestService, rule, manager, cache, settings, sub)
|
||||
|
|
|
@ -23,6 +23,7 @@ using Ombi.Api.TheMovieDb;
|
|||
using Ombi.Api.TheMovieDb.Models;
|
||||
using System.Threading;
|
||||
using TraktSharp.Entities;
|
||||
using Ombi.Core.Helpers;
|
||||
|
||||
namespace Ombi.Core.Engine
|
||||
{
|
||||
|
@ -32,7 +33,7 @@ namespace Ombi.Core.Engine
|
|||
private readonly IImageService _imageService;
|
||||
private readonly IMovieDbApi _theMovieDbApi;
|
||||
|
||||
public TvSearchEngine(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
|
||||
public TvSearchEngine(ICurrentUser identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
|
||||
ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um, ISettingsService<CustomizationSettings> customizationSettings,
|
||||
ICacheService memCache, ISettingsService<OmbiSettings> s, IRepository<RequestSubscription> sub, IImageService imageService,
|
||||
IMovieDbApi theMovieDbApi)
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Security.Principal;
|
|||
using System.Threading.Tasks;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Engine.Interfaces;
|
||||
using Ombi.Core.Helpers;
|
||||
using Ombi.Core.Models.Search.V2;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Store.Entities;
|
||||
|
@ -17,7 +18,7 @@ namespace Ombi.Core.Engine.V2
|
|||
{
|
||||
public DateTime DaysAgo => DateTime.Now.AddDays(-90);
|
||||
public DateTime DaysAhead => DateTime.Now.AddDays(90);
|
||||
public CalendarEngine(IPrincipal user, OmbiUserManager um, IRuleEvaluator rules, IMovieRequestRepository movieRepo,
|
||||
public CalendarEngine(ICurrentUser user, OmbiUserManager um, IRuleEvaluator rules, IMovieRequestRepository movieRepo,
|
||||
ITvRequestRepository tvRequestRepo) : base(user, um, rules)
|
||||
{
|
||||
_movieRepo = movieRepo;
|
||||
|
|
|
@ -5,6 +5,7 @@ using Ombi.Api.TheMovieDb;
|
|||
using Ombi.Api.TheMovieDb.Models;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Engine.Interfaces;
|
||||
using Ombi.Core.Helpers;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Models.Search.V2;
|
||||
|
@ -28,7 +29,7 @@ namespace Ombi.Core.Engine.V2
|
|||
{
|
||||
public class MovieSearchEngineV2 : BaseMediaEngine, IMovieEngineV2
|
||||
{
|
||||
public MovieSearchEngineV2(IPrincipal identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
|
||||
public MovieSearchEngineV2(ICurrentUser identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
|
||||
ILogger<MovieSearchEngineV2> logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService<OmbiSettings> s, IRepository<RequestSubscription> sub,
|
||||
ISettingsService<CustomizationSettings> customizationSettings, IMovieRequestEngine movieRequestEngine, IHttpClientFactory httpClientFactory)
|
||||
: base(identity, service, r, um, mem, s, sub)
|
||||
|
|
|
@ -7,6 +7,7 @@ using Ombi.Api.MusicBrainz;
|
|||
using Ombi.Api.TheMovieDb;
|
||||
using Ombi.Api.TheMovieDb.Models;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Helpers;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Models.Search.V2;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
|
@ -25,7 +26,7 @@ namespace Ombi.Core.Engine.V2
|
|||
{
|
||||
public class MultiSearchEngine : BaseMediaEngine, IMultiSearchEngine
|
||||
{
|
||||
public MultiSearchEngine(IPrincipal identity, IRequestServiceMain requestService, IRuleEvaluator rules,
|
||||
public MultiSearchEngine(ICurrentUser identity, IRequestServiceMain requestService, IRuleEvaluator rules,
|
||||
OmbiUserManager um, ICacheService cache, ISettingsService<OmbiSettings> ombiSettings, IRepository<RequestSubscription> sub,
|
||||
IMovieDbApi movieDbApi, ISettingsService<LidarrSettings> lidarrSettings, IMusicBrainzApi musicApi)
|
||||
: base(identity, requestService, rules, um, cache, ombiSettings, sub)
|
||||
|
|
|
@ -11,6 +11,7 @@ using Ombi.Api.Lidarr.Models;
|
|||
using Ombi.Api.MusicBrainz;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Engine.Interfaces;
|
||||
using Ombi.Core.Helpers;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Models.Search.V2.Music;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
|
@ -31,7 +32,7 @@ namespace Ombi.Core.Engine.V2
|
|||
private readonly ISettingsService<LidarrSettings> _lidarrSettings;
|
||||
private readonly ILidarrApi _lidarrApi;
|
||||
|
||||
public MusicSearchEngineV2(IPrincipal identity, IRequestServiceMain requestService, IRuleEvaluator rules,
|
||||
public MusicSearchEngineV2(ICurrentUser identity, IRequestServiceMain requestService, IRuleEvaluator rules,
|
||||
OmbiUserManager um, ICacheService cache, ISettingsService<OmbiSettings> ombiSettings,
|
||||
IRepository<RequestSubscription> sub, IMusicBrainzApi musicBrainzApi, ISettingsService<LidarrSettings> lidarrSettings,
|
||||
ILidarrApi lidarrApi)
|
||||
|
|
|
@ -25,6 +25,7 @@ using Ombi.Api.TheMovieDb.Models;
|
|||
using System.Diagnostics;
|
||||
using Ombi.Core.Engine.Interfaces;
|
||||
using Ombi.Core.Models.UI;
|
||||
using Ombi.Core.Helpers;
|
||||
|
||||
namespace Ombi.Core.Engine.V2
|
||||
{
|
||||
|
@ -37,7 +38,7 @@ namespace Ombi.Core.Engine.V2
|
|||
private readonly ISettingsService<CustomizationSettings> _customization;
|
||||
private readonly ITvRequestEngine _requestEngine;
|
||||
|
||||
public TvSearchEngineV2(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
|
||||
public TvSearchEngineV2(ICurrentUser identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
|
||||
ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um, ICacheService memCache, ISettingsService<OmbiSettings> s,
|
||||
IRepository<RequestSubscription> sub, IMovieDbApi movieApi, ISettingsService<CustomizationSettings> customization, ITvRequestEngine requestEngine)
|
||||
: base(identity, service, r, um, memCache, s, sub)
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Engine.Interfaces;
|
||||
using Ombi.Core.Helpers;
|
||||
using Ombi.Core.Models;
|
||||
using Ombi.Core.Models.UI;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
|
@ -20,7 +21,7 @@ namespace Ombi.Core.Engine
|
|||
{
|
||||
public class VoteEngine : BaseEngine, IVoteEngine
|
||||
{
|
||||
public VoteEngine(IRepository<Votes> votes, IPrincipal user, OmbiUserManager um, IRuleEvaluator r, ISettingsService<VoteSettings> voteSettings,
|
||||
public VoteEngine(IRepository<Votes> votes, ICurrentUser user, OmbiUserManager um, IRuleEvaluator r, ISettingsService<VoteSettings> voteSettings,
|
||||
IMusicRequestEngine musicRequestEngine, ITvRequestEngine tvRequestEngine, IMovieRequestEngine movieRequestEngine) : base(user, um, r)
|
||||
{
|
||||
_voteRepository = votes;
|
||||
|
|
47
src/Ombi.Core/Helpers/CurrentUser.cs
Normal file
47
src/Ombi.Core/Helpers/CurrentUser.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Entities;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ombi.Core.Helpers
|
||||
{
|
||||
public class CurrentUser : ICurrentUser
|
||||
{
|
||||
private readonly IPrincipal _principle;
|
||||
private readonly OmbiUserManager _userManager;
|
||||
private OmbiUser _user;
|
||||
public IIdentity Identity { get; set; }
|
||||
|
||||
public CurrentUser(IPrincipal principle, OmbiUserManager userManager)
|
||||
{
|
||||
_principle = principle;
|
||||
_userManager = userManager;
|
||||
Identity = _principle?.Identity;
|
||||
}
|
||||
|
||||
public void SetUser(OmbiUser user)
|
||||
{
|
||||
_user = user;
|
||||
}
|
||||
|
||||
public string Username => Identity.Name;
|
||||
public async Task<OmbiUser> GetUser()
|
||||
{
|
||||
if (!Username.HasValue() && _user == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_user != null)
|
||||
{
|
||||
return _user;
|
||||
}
|
||||
|
||||
var username = Username.ToUpper();
|
||||
return _user ??= await _userManager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
15
src/Ombi.Core/Helpers/ICurrentUser.cs
Normal file
15
src/Ombi.Core/Helpers/ICurrentUser.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using Ombi.Store.Entities;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ombi.Core.Helpers
|
||||
{
|
||||
public interface ICurrentUser
|
||||
{
|
||||
string Username { get; }
|
||||
|
||||
Task<OmbiUser> GetUser();
|
||||
void SetUser(OmbiUser user);
|
||||
IIdentity Identity { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,31 +1,5 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2018 Jamie Rees
|
||||
// File: MovieRequestViewModel.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 Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
|
||||
namespace Ombi.Core.Models.Requests
|
||||
{
|
||||
|
@ -41,5 +15,11 @@ namespace Ombi.Core.Models.Requests
|
|||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string RequestedByAlias { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only set via list imports
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public RequestSource Source { get; set; } = RequestSource.Ombi;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using System.Security.Principal;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Helpers;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Core.Services;
|
||||
|
@ -15,20 +16,21 @@ namespace Ombi.Core.Rule.Rules.Request
|
|||
{
|
||||
public class AutoApproveRule : BaseRequestRule, IRules<BaseRequest>
|
||||
{
|
||||
public AutoApproveRule(IPrincipal principal, OmbiUserManager um, IFeatureService featureService)
|
||||
public AutoApproveRule(ICurrentUser principal, OmbiUserManager um, IFeatureService featureService)
|
||||
{
|
||||
User = principal;
|
||||
_manager = um;
|
||||
_featureService = featureService;
|
||||
}
|
||||
|
||||
private IPrincipal User { get; }
|
||||
private ICurrentUser User { get; }
|
||||
private readonly OmbiUserManager _manager;
|
||||
private readonly IFeatureService _featureService;
|
||||
|
||||
public async Task<RuleResult> Execute(BaseRequest obj)
|
||||
{
|
||||
var username = User.Identity.Name.ToUpper();
|
||||
var currentUser = await User.GetUser();
|
||||
var username = currentUser.UserName.ToUpper();
|
||||
var user = await _manager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username);
|
||||
if (await _manager.IsInRoleAsync(user, OmbiRoles.Admin) || user.IsSystemUser)
|
||||
{
|
||||
|
|
|
@ -10,23 +10,25 @@ using Ombi.Core.Engine;
|
|||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
using Ombi.Core.Helpers;
|
||||
|
||||
namespace Ombi.Core.Rule.Rules.Request
|
||||
{
|
||||
public class CanRequestRule : BaseRequestRule, IRules<BaseRequest>
|
||||
{
|
||||
public CanRequestRule(IPrincipal principal, OmbiUserManager manager)
|
||||
public CanRequestRule(ICurrentUser principal, OmbiUserManager manager)
|
||||
{
|
||||
User = principal;
|
||||
_manager = manager;
|
||||
}
|
||||
|
||||
private IPrincipal User { get; }
|
||||
private ICurrentUser User { get; }
|
||||
private readonly OmbiUserManager _manager;
|
||||
|
||||
public async Task<RuleResult> Execute(BaseRequest obj)
|
||||
{
|
||||
var username = User.Identity.Name.ToUpper();
|
||||
var currentUser = await User.GetUser();
|
||||
var username = currentUser.UserName.ToUpper();
|
||||
var user = await _manager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username);
|
||||
if (await _manager.IsInRoleAsync(user, OmbiRoles.Admin) || user.IsSystemUser)
|
||||
return Success();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Helpers;
|
||||
using Ombi.Core.Models;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Entities;
|
||||
|
@ -20,11 +21,11 @@ namespace Ombi.Core.Services
|
|||
}
|
||||
public class RequestLimitService : IRequestLimitService
|
||||
{
|
||||
private readonly IPrincipal _user;
|
||||
private readonly ICurrentUser _user;
|
||||
private readonly OmbiUserManager _userManager;
|
||||
private readonly IRepository<RequestLog> _requestLog;
|
||||
|
||||
public RequestLimitService(IPrincipal user, OmbiUserManager userManager, IRepository<RequestLog> rl)
|
||||
public RequestLimitService(ICurrentUser user, OmbiUserManager userManager, IRepository<RequestLog> rl)
|
||||
{
|
||||
_user = user;
|
||||
_userManager = userManager;
|
||||
|
@ -141,7 +142,8 @@ namespace Ombi.Core.Services
|
|||
|
||||
private async Task<OmbiUser> GetUser()
|
||||
{
|
||||
var username = _user.Identity.Name.ToUpper();
|
||||
var currentUser = await _user.GetUser();
|
||||
var username = currentUser.UserName.ToUpper();
|
||||
return await _userManager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue