This commit is contained in:
Jamie.Rees 2017-01-30 16:30:01 +00:00
parent 1f4ece8b5b
commit 4feb3cd462
33 changed files with 526 additions and 119 deletions

View file

@ -37,6 +37,7 @@ using Ombi.Helpers;
using Ombi.Helpers.Permissions; using Ombi.Helpers.Permissions;
using Ombi.Store; using Ombi.Store;
using Ombi.Store.Models; using Ombi.Store.Models;
using Ombi.Store.Models.Plex;
using Ombi.Store.Repository; using Ombi.Store.Repository;
namespace Ombi.Core.Migration.Migrations namespace Ombi.Core.Migration.Migrations
@ -46,7 +47,7 @@ namespace Ombi.Core.Migration.Migrations
{ {
public Version1100(IUserRepository userRepo, IRequestService requestService, ISettingsService<LogSettings> log, public Version1100(IUserRepository userRepo, IRequestService requestService, ISettingsService<LogSettings> log,
IPlexApi plexApi, ISettingsService<PlexSettings> plexService, IPlexApi plexApi, ISettingsService<PlexSettings> plexService,
IPlexUserRepository plexusers, ISettingsService<PlexRequestSettings> prSettings, IExternalUserRepository<PlexUsers> plexusers, ISettingsService<PlexRequestSettings> prSettings,
ISettingsService<UserManagementSettings> umSettings, ISettingsService<UserManagementSettings> umSettings,
ISettingsService<ScheduledJobsSettings> sjs, IRepository<UsersToNotify> usersToNotify) ISettingsService<ScheduledJobsSettings> sjs, IRepository<UsersToNotify> usersToNotify)
{ {
@ -69,7 +70,7 @@ namespace Ombi.Core.Migration.Migrations
private ISettingsService<LogSettings> Log { get; } private ISettingsService<LogSettings> Log { get; }
private IPlexApi PlexApi { get; } private IPlexApi PlexApi { get; }
private ISettingsService<PlexSettings> PlexSettings { get; } private ISettingsService<PlexSettings> PlexSettings { get; }
private IPlexUserRepository PlexUsers { get; } private IExternalUserRepository<PlexUsers> PlexUsers { get; }
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; } private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
private ISettingsService<UserManagementSettings> UserManagementSettings { get; } private ISettingsService<UserManagementSettings> UserManagementSettings { get; }
private ISettingsService<ScheduledJobsSettings> ScheduledJobSettings { get; } private ISettingsService<ScheduledJobsSettings> ScheduledJobSettings { get; }

View file

@ -36,13 +36,14 @@ using Ombi.Core.SettingModels;
using Ombi.Core.Users; using Ombi.Core.Users;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Helpers.Permissions; using Ombi.Helpers.Permissions;
using Ombi.Store.Models.Plex;
using Ombi.Store.Repository; using Ombi.Store.Repository;
namespace Ombi.Core namespace Ombi.Core
{ {
public class SecurityExtensions : ISecurityExtensions public class SecurityExtensions : ISecurityExtensions
{ {
public SecurityExtensions(IUserRepository userRepository, IResourceLinker linker, IPlexUserRepository plexUsers, ISettingsService<UserManagementSettings> umSettings) public SecurityExtensions(IUserRepository userRepository, IResourceLinker linker, IExternalUserRepository<PlexUsers> plexUsers, ISettingsService<UserManagementSettings> umSettings)
{ {
UserRepository = userRepository; UserRepository = userRepository;
Linker = linker; Linker = linker;
@ -52,7 +53,7 @@ namespace Ombi.Core
private IUserRepository UserRepository { get; } private IUserRepository UserRepository { get; }
private IResourceLinker Linker { get; } private IResourceLinker Linker { get; }
private IPlexUserRepository PlexUsers { get; } private IExternalUserRepository<PlexUsers> PlexUsers { get; }
private ISettingsService<UserManagementSettings> UserManagementSettings { get; } private ISettingsService<UserManagementSettings> UserManagementSettings { get; }
public bool IsLoggedIn(NancyContext context) public bool IsLoggedIn(NancyContext context)

View file

@ -30,13 +30,14 @@ using System.Linq;
using Ombi.Core.Models; using Ombi.Core.Models;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Helpers.Permissions; using Ombi.Helpers.Permissions;
using Ombi.Store.Models.Plex;
using Ombi.Store.Repository; using Ombi.Store.Repository;
namespace Ombi.Core.Users namespace Ombi.Core.Users
{ {
public class UserHelper : IUserHelper public class UserHelper : IUserHelper
{ {
public UserHelper(IUserRepository userRepository, IPlexUserRepository plexUsers, ISecurityExtensions security) public UserHelper(IUserRepository userRepository, IExternalUserRepository<PlexUsers> plexUsers, ISecurityExtensions security)
{ {
LocalUserRepository = userRepository; LocalUserRepository = userRepository;
PlexUserRepository = plexUsers; PlexUserRepository = plexUsers;
@ -44,7 +45,7 @@ namespace Ombi.Core.Users
} }
private IUserRepository LocalUserRepository { get; } private IUserRepository LocalUserRepository { get; }
private IPlexUserRepository PlexUserRepository { get; } private IExternalUserRepository<PlexUsers> PlexUserRepository { get; }
private ISecurityExtensions Security { get; } private ISecurityExtensions Security { get; }

View file

@ -30,6 +30,7 @@ namespace Ombi.Helpers
public enum UserType public enum UserType
{ {
PlexUser, PlexUser,
LocalUser LocalUser,
EmbyUser
} }
} }

View file

@ -0,0 +1,6 @@
namespace Ombi.Services.Interfaces
{
public interface IEmbyNotificationEngine : INotificationEngine
{
}
}

View file

@ -34,7 +34,7 @@ namespace Ombi.Services.Interfaces
{ {
public interface INotificationEngine public interface INotificationEngine
{ {
Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, string apiKey, NotificationType type); Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, NotificationType type);
Task NotifyUsers(RequestedModel modelChanged, string apiKey, NotificationType type); Task NotifyUsers(RequestedModel modelChanged, NotificationType type);
} }
} }

View file

@ -0,0 +1,6 @@
namespace Ombi.Services.Interfaces
{
public interface IPlexNotificationEngine : INotificationEngine
{
}
}

View file

@ -52,7 +52,7 @@ namespace Ombi.Services.Jobs
public class EmbyAvailabilityChecker : IJob, IEmbyAvailabilityChecker public class EmbyAvailabilityChecker : IJob, IEmbyAvailabilityChecker
{ {
public EmbyAvailabilityChecker(ISettingsService<EmbySettings> embySettings, IRequestService request, IEmbyApi emby, ICacheProvider cache, public EmbyAvailabilityChecker(ISettingsService<EmbySettings> embySettings, IRequestService request, IEmbyApi emby, ICacheProvider cache,
INotificationService notify, IJobRecord rec, IRepository<UsersToNotify> users, IRepository<EmbyEpisodes> repo, INotificationEngine e, IRepository<EmbyContent> content) INotificationService notify, IJobRecord rec, IRepository<UsersToNotify> users, IRepository<EmbyEpisodes> repo, IEmbyNotificationEngine e, IRepository<EmbyContent> content)
{ {
Emby = embySettings; Emby = embySettings;
RequestService = request; RequestService = request;
@ -148,7 +148,7 @@ namespace Ombi.Services.Jobs
if (modifiedModel.Any()) if (modifiedModel.Any())
{ {
//NotificationEngine.NotifyUsers(modifiedModel, embySettings.ApiKey, NotificationType.RequestAvailable); // TODO Emby NotificationEngine.NotifyUsers(modifiedModel, NotificationType.RequestAvailable);
RequestService.BatchUpdate(modifiedModel); RequestService.BatchUpdate(modifiedModel);
} }
} }

View file

@ -51,7 +51,7 @@ namespace Ombi.Services.Jobs
public class PlexAvailabilityChecker : IJob, IAvailabilityChecker public class PlexAvailabilityChecker : IJob, IAvailabilityChecker
{ {
public PlexAvailabilityChecker(ISettingsService<PlexSettings> plexSettings, IRequestService request, IPlexApi plex, ICacheProvider cache, public PlexAvailabilityChecker(ISettingsService<PlexSettings> plexSettings, IRequestService request, IPlexApi plex, ICacheProvider cache,
INotificationService notify, IJobRecord rec, IRepository<UsersToNotify> users, IRepository<PlexEpisodes> repo, INotificationEngine e, IRepository<PlexContent> content) INotificationService notify, IJobRecord rec, IRepository<UsersToNotify> users, IRepository<PlexEpisodes> repo, IPlexNotificationEngine e, IRepository<PlexContent> content)
{ {
Plex = plexSettings; Plex = plexSettings;
RequestService = request; RequestService = request;
@ -152,7 +152,7 @@ namespace Ombi.Services.Jobs
if (modifiedModel.Any()) if (modifiedModel.Any())
{ {
NotificationEngine.NotifyUsers(modifiedModel, plexSettings.PlexAuthToken, NotificationType.RequestAvailable); NotificationEngine.NotifyUsers(modifiedModel, NotificationType.RequestAvailable);
RequestService.BatchUpdate(modifiedModel); RequestService.BatchUpdate(modifiedModel);
} }
} }

View file

@ -48,7 +48,7 @@ namespace Ombi.Services.Jobs
public class PlexContentCacher : IJob, IPlexContentCacher public class PlexContentCacher : IJob, IPlexContentCacher
{ {
public PlexContentCacher(ISettingsService<PlexSettings> plexSettings, IRequestService request, IPlexApi plex, ICacheProvider cache, public PlexContentCacher(ISettingsService<PlexSettings> plexSettings, IRequestService request, IPlexApi plex, ICacheProvider cache,
INotificationService notify, IJobRecord rec, IRepository<UsersToNotify> users, IRepository<PlexEpisodes> repo, INotificationEngine e, IRepository<PlexContent> content) INotificationService notify, IJobRecord rec, IRepository<UsersToNotify> users, IRepository<PlexEpisodes> repo, IPlexNotificationEngine e, IRepository<PlexContent> content)
{ {
Plex = plexSettings; Plex = plexSettings;
RequestService = request; RequestService = request;

View file

@ -38,8 +38,10 @@ using Ombi.Core.SettingModels;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Services.Interfaces; using Ombi.Services.Interfaces;
using Ombi.Store.Models; using Ombi.Store.Models;
using Ombi.Store.Models.Plex;
using Ombi.Store.Repository; using Ombi.Store.Repository;
using Quartz; using Quartz;
using PlexMediaType = Ombi.Api.Models.Plex.PlexMediaType;
namespace Ombi.Services.Jobs namespace Ombi.Services.Jobs
{ {

View file

@ -37,6 +37,7 @@ using Ombi.Core.Users;
using Ombi.Helpers.Permissions; using Ombi.Helpers.Permissions;
using Ombi.Services.Interfaces; using Ombi.Services.Interfaces;
using Ombi.Store.Models; using Ombi.Store.Models;
using Ombi.Store.Models.Plex;
using Ombi.Store.Repository; using Ombi.Store.Repository;
using Quartz; using Quartz;
@ -46,7 +47,7 @@ namespace Ombi.Services.Jobs
{ {
private static readonly Logger Log = LogManager.GetCurrentClassLogger(); private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public PlexUserChecker(IPlexUserRepository plexUsers, IPlexApi plexAPi, IJobRecord rec, ISettingsService<PlexSettings> plexSettings, ISettingsService<PlexRequestSettings> prSettings, ISettingsService<UserManagementSettings> umSettings, public PlexUserChecker(IExternalUserRepository<PlexUsers> plexUsers, IPlexApi plexAPi, IJobRecord rec, ISettingsService<PlexSettings> plexSettings, ISettingsService<PlexRequestSettings> prSettings, ISettingsService<UserManagementSettings> umSettings,
IRequestService requestService, IUserRepository localUser) IRequestService requestService, IUserRepository localUser)
{ {
Repo = plexUsers; Repo = plexUsers;
@ -61,7 +62,7 @@ namespace Ombi.Services.Jobs
private IJobRecord JobRecord { get; } private IJobRecord JobRecord { get; }
private IPlexApi PlexApi { get; } private IPlexApi PlexApi { get; }
private IPlexUserRepository Repo { get; } private IExternalUserRepository<PlexUsers> Repo { get; }
private ISettingsService<PlexSettings> PlexSettings { get; } private ISettingsService<PlexSettings> PlexSettings { get; }
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; } private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
private ISettingsService<UserManagementSettings> UserManagementSettings { get; } private ISettingsService<UserManagementSettings> UserManagementSettings { get; }

View file

@ -0,0 +1,206 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NLog;
using Ombi.Api.Interfaces;
using Ombi.Core;
using Ombi.Core.Models;
using Ombi.Core.SettingModels;
using Ombi.Core.Users;
using Ombi.Helpers.Permissions;
using Ombi.Services.Interfaces;
using Ombi.Store;
using Ombi.Store.Models;
using Ombi.Store.Repository;
namespace Ombi.Services.Notification
{
public class EmbyNotificationEngine : IEmbyNotificationEngine
{
public EmbyNotificationEngine(IEmbyApi p, IRepository<UsersToNotify> repo, ISettingsService<EmbySettings> embySettings, INotificationService service, IUserHelper userHelper)
{
EmbyApi = p;
UserNotifyRepo = repo;
Notification = service;
UserHelper = userHelper;
EmbySettings = embySettings;
}
private IEmbyApi EmbyApi { get; }
private IRepository<UsersToNotify> UserNotifyRepo { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
private INotificationService Notification { get; }
private IUserHelper UserHelper { get; }
private ISettingsService<EmbySettings> EmbySettings { get; }
public async Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, NotificationType type)
{
try
{
var embySettings = await EmbySettings.GetSettingsAsync();
var embyUsers = EmbyApi.GetUsers(embySettings.FullUri, embySettings.ApiKey);
var userAccount = embyUsers.FirstOrDefault(x => x.Policy.IsAdministrator);
var adminUsername = userAccount?.Name ?? string.Empty;
var users = UserHelper.GetUsersWithFeature(Features.RequestAddedNotification).ToList();
Log.Debug("Notifying Users Count {0}", users.Count);
foreach (var model in modelChanged)
{
var selectedUsers = new List<string>();
foreach (var u in users)
{
var requestUser = model.RequestedUsers.FirstOrDefault(
x => x.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase) || x.Equals(u.UserAlias, StringComparison.CurrentCultureIgnoreCase));
if (string.IsNullOrEmpty(requestUser))
{
continue;
}
// Make sure we do not already have the user
if (!selectedUsers.Contains(requestUser))
{
selectedUsers.Add(requestUser);
}
}
foreach (var user in selectedUsers)
{
Log.Info("Notifying user {0}", user);
if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase))
{
Log.Info("This user is the Plex server owner");
await PublishUserNotification(userAccount?.Name, userAccount?.Name, model.Title, model.PosterPath, type, model.Type); // TODO Emby needs email address
return;
}
var localUser =
users.FirstOrDefault( x =>
x.Username.Equals(user, StringComparison.CurrentCultureIgnoreCase) ||
x.UserAlias.Equals(user, StringComparison.CurrentCultureIgnoreCase));
// So if the request was from an alias, then we need to use the local user (since that contains the alias).
// If we do not have a local user, then we should be using the Plex user if that user exists.
// This will execute most of the time since Plex and Local users will most always be in the database.
if (localUser != null)
{
if (string.IsNullOrEmpty(localUser?.EmailAddress))
{
Log.Info("There is no email address for this Local user ({0}), cannot send notification", localUser.Username);
continue;
}
Log.Info("Sending notification to: {0} at: {1}, for : {2}", localUser, localUser.EmailAddress, model.Title);
await PublishUserNotification(localUser.Username, localUser.EmailAddress, model.Title, model.PosterPath, type, model.Type);
}
else
{
var email = embyUsers.FirstOrDefault(x => x.Name.Equals(user, StringComparison.CurrentCultureIgnoreCase));
if (string.IsNullOrEmpty(email?.Name)) // TODO this needs to be the email
{
Log.Info("There is no email address for this Emby user ({0}), cannot send notification", email?.Name); //TODO
// We do not have a plex user that requested this!
continue;
}
Log.Info("Sending notification to: {0} at: {1}, for : {2}", email.Name, email.Name, model.Title);
await PublishUserNotification(email.Name, email.Name, model.Title, model.PosterPath, type, model.Type); //TODO
}
}
}
}
catch (Exception e)
{
Log.Error(e);
}
}
public async Task NotifyUsers(RequestedModel model, NotificationType type)
{
try
{
var embySettings = await EmbySettings.GetSettingsAsync();
var embyUsers = EmbyApi.GetUsers(embySettings.FullUri, embySettings.ApiKey);
var userAccount = embyUsers.FirstOrDefault(x => x.Policy.IsAdministrator);
var adminUsername = userAccount.Name ?? string.Empty;
var users = UserHelper.GetUsersWithFeature(Features.RequestAddedNotification).ToList();
Log.Debug("Notifying Users Count {0}", users.Count);
// Get the usernames or alias depending if they have an alias
var userNamesWithFeature = users.Select(x => x.UsernameOrAlias).ToList();
Log.Debug("Users with the feature count {0}", userNamesWithFeature.Count);
Log.Debug("Usernames: ");
foreach (var u in userNamesWithFeature)
{
Log.Debug(u);
}
Log.Debug("Users in the requested model count: {0}", model.AllUsers.Count);
Log.Debug("usernames from model: ");
foreach (var modelAllUser in model.AllUsers)
{
Log.Debug(modelAllUser);
}
if (model.AllUsers == null || !model.AllUsers.Any())
{
Log.Debug("There are no users in the model.AllUsers, no users to notify");
return;
}
var usersToNotify = userNamesWithFeature.Intersect(model.AllUsers, StringComparer.CurrentCultureIgnoreCase).ToList();
if (!usersToNotify.Any())
{
Log.Debug("Could not find any users after the .Intersect()");
}
Log.Debug("Users being notified for this request count {0}", users.Count);
foreach (var user in usersToNotify)
{
Log.Info("Notifying user {0}", user);
if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase))
{
Log.Info("This user is the Emby server owner");
await PublishUserNotification(userAccount.Name, userAccount.Name, model.Title, model.PosterPath, type, model.Type); // TODO
return;
}
var email = embyUsers.FirstOrDefault(x => x.Name.Equals(user, StringComparison.CurrentCultureIgnoreCase));
if (email == null)
{
Log.Info("There is no email address for this Emby user, cannot send notification");
// We do not have a plex user that requested this!
continue;
}
Log.Info("Sending notification to: {0} at: {1}, for title: {2}", email.Name, email.Name, model.Title); // TODO
await PublishUserNotification(email.Name, email.Name, model.Title, model.PosterPath, type, model.Type); // TODO
}
}
catch (Exception e)
{
Log.Error(e);
}
}
private async Task PublishUserNotification(string username, string email, string title, string img, NotificationType type, RequestType requestType)
{
var notificationModel = new NotificationModel
{
User = username,
UserEmail = email,
NotificationType = type,
Title = title,
ImgSrc = requestType == RequestType.Movie ? $"https://image.tmdb.org/t/p/w300/{img}" : img
};
// Send the notification to the user.
await Notification.Publish(notificationModel);
}
}
}

View file

@ -1,7 +1,7 @@
#region Copyright #region Copyright
// /************************************************************************ // /************************************************************************
// Copyright (c) 2016 Jamie Rees // Copyright (c) 2016 Jamie Rees
// File: NotificationEngine.cs // File: PlexNotificationEngine.cs
// Created By: Jamie Rees // Created By: Jamie Rees
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
@ -31,7 +31,9 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using NLog; using NLog;
using Ombi.Api.Interfaces; using Ombi.Api.Interfaces;
using Ombi.Core;
using Ombi.Core.Models; using Ombi.Core.Models;
using Ombi.Core.SettingModels;
using Ombi.Core.Users; using Ombi.Core.Users;
using Ombi.Helpers.Permissions; using Ombi.Helpers.Permissions;
using Ombi.Services.Interfaces; using Ombi.Services.Interfaces;
@ -41,14 +43,15 @@ using Ombi.Store.Repository;
namespace Ombi.Services.Notification namespace Ombi.Services.Notification
{ {
public class NotificationEngine : INotificationEngine public class PlexNotificationEngine : IPlexNotificationEngine
{ {
public NotificationEngine(IPlexApi p, IRepository<UsersToNotify> repo, INotificationService service, IUserHelper userHelper) public PlexNotificationEngine(IPlexApi p, IRepository<UsersToNotify> repo, INotificationService service, IUserHelper userHelper, ISettingsService<PlexSettings> ps)
{ {
PlexApi = p; PlexApi = p;
UserNotifyRepo = repo; UserNotifyRepo = repo;
Notification = service; Notification = service;
UserHelper = userHelper; UserHelper = userHelper;
PlexSettings = ps;
} }
private IPlexApi PlexApi { get; } private IPlexApi PlexApi { get; }
@ -56,13 +59,15 @@ namespace Ombi.Services.Notification
private static Logger Log = LogManager.GetCurrentClassLogger(); private static Logger Log = LogManager.GetCurrentClassLogger();
private INotificationService Notification { get; } private INotificationService Notification { get; }
private IUserHelper UserHelper { get; } private IUserHelper UserHelper { get; }
private ISettingsService<PlexSettings> PlexSettings { get; }
public async Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, string apiKey, NotificationType type) public async Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, NotificationType type)
{ {
try try
{ {
var plexUser = PlexApi.GetUsers(apiKey); var settings = await PlexSettings.GetSettingsAsync();
var userAccount = PlexApi.GetAccount(apiKey); var plexUser = PlexApi.GetUsers(settings.PlexAuthToken);
var userAccount = PlexApi.GetAccount(settings.PlexAuthToken);
var adminUsername = userAccount.Username ?? string.Empty; var adminUsername = userAccount.Username ?? string.Empty;
@ -140,12 +145,13 @@ namespace Ombi.Services.Notification
} }
} }
public async Task NotifyUsers(RequestedModel model, string apiKey, NotificationType type) public async Task NotifyUsers(RequestedModel model, NotificationType type)
{ {
try try
{ {
var plexUser = PlexApi.GetUsers(apiKey); var settings = await PlexSettings.GetSettingsAsync();
var userAccount = PlexApi.GetAccount(apiKey); var plexUser = PlexApi.GetUsers(settings.PlexAuthToken);
var userAccount = PlexApi.GetAccount(settings.PlexAuthToken);
var adminUsername = userAccount.Username ?? string.Empty; var adminUsername = userAccount.Username ?? string.Empty;

View file

@ -86,6 +86,8 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Interfaces\IEmbyNotificationEngine.cs" />
<Compile Include="Interfaces\IPlexNotificationEngine.cs" />
<Compile Include="Interfaces\IRadarrCacher.cs" /> <Compile Include="Interfaces\IRadarrCacher.cs" />
<Compile Include="Interfaces\IWatcherCacher.cs" /> <Compile Include="Interfaces\IWatcherCacher.cs" />
<Compile Include="Interfaces\IJobRecord.cs" /> <Compile Include="Interfaces\IJobRecord.cs" />
@ -135,7 +137,8 @@
<Compile Include="Interfaces\INotificationService.cs" /> <Compile Include="Interfaces\INotificationService.cs" />
<Compile Include="Models\SonarrCachedResult.cs" /> <Compile Include="Models\SonarrCachedResult.cs" />
<Compile Include="Notification\EmailMessageNotification.cs" /> <Compile Include="Notification\EmailMessageNotification.cs" />
<Compile Include="Notification\NotificationEngine.cs" /> <Compile Include="Notification\EmbyNotificationEngine.cs" />
<Compile Include="Notification\PlexNotificationEngine.cs" />
<Compile Include="Notification\NotificationModel.cs" /> <Compile Include="Notification\NotificationModel.cs" />
<Compile Include="Notification\NotificationService.cs" /> <Compile Include="Notification\NotificationService.cs" />
<Compile Include="Notification\PushoverNotification.cs" /> <Compile Include="Notification\PushoverNotification.cs" />

View file

@ -0,0 +1,43 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexUsers.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 Dapper.Contrib.Extensions;
namespace Ombi.Store.Models.Emby
{
[Table(nameof(EmbyUsers))]
public class EmbyUsers : Entity
{
public string PlexUserId { get; set; }
public string UserAlias { get; set; }
public int Permissions { get; set; }
public int Features { get; set; }
public string Username { get; set; }
public string EmailAddress { get; set; }
public string LoginId { get; set; }
}
}

View file

@ -27,7 +27,7 @@
using Dapper.Contrib.Extensions; using Dapper.Contrib.Extensions;
namespace Ombi.Store.Models namespace Ombi.Store.Models.Plex
{ {
[Table("PlexEpisodes")] [Table("PlexEpisodes")]
public class PlexEpisodes : Entity public class PlexEpisodes : Entity

View file

@ -26,9 +26,8 @@
#endregion #endregion
using Dapper.Contrib.Extensions; using Dapper.Contrib.Extensions;
using Newtonsoft.Json;
namespace Ombi.Store.Models namespace Ombi.Store.Models.Plex
{ {
[Table(nameof(PlexUsers))] [Table(nameof(PlexUsers))]
public class PlexUsers : Entity public class PlexUsers : Entity

View file

@ -68,8 +68,9 @@
<Compile Include="Models\Emby\EmbyContent.cs" /> <Compile Include="Models\Emby\EmbyContent.cs" />
<Compile Include="Models\Emby\EmbyEpisodes.cs" /> <Compile Include="Models\Emby\EmbyEpisodes.cs" />
<Compile Include="Models\IssueBlobs.cs" /> <Compile Include="Models\IssueBlobs.cs" />
<Compile Include="Models\PlexEpisodes.cs" /> <Compile Include="Models\Plex\PlexEpisodes.cs" />
<Compile Include="Models\PlexUsers.cs" /> <Compile Include="Models\Emby\EmbyUsers.cs" />
<Compile Include="Models\Plex\PlexUsers.cs" />
<Compile Include="Models\Plex\MetadataItems.cs" /> <Compile Include="Models\Plex\MetadataItems.cs" />
<Compile Include="Models\Plex\PlexContent.cs" /> <Compile Include="Models\Plex\PlexContent.cs" />
<Compile Include="Models\Emby\EmbyMediaType.cs" /> <Compile Include="Models\Emby\EmbyMediaType.cs" />
@ -80,6 +81,8 @@
<Compile Include="Models\UsersToNotify.cs" /> <Compile Include="Models\UsersToNotify.cs" />
<Compile Include="PlexDatabase.cs" /> <Compile Include="PlexDatabase.cs" />
<Compile Include="Repository\BaseGenericRepository.cs" /> <Compile Include="Repository\BaseGenericRepository.cs" />
<Compile Include="Repository\BaseExternalUserRepository.cs" />
<Compile Include="Repository\IExternalUserRepository.cs" />
<Compile Include="Repository\IRequestRepository.cs" /> <Compile Include="Repository\IRequestRepository.cs" />
<Compile Include="Repository\ISettingsRepository.cs" /> <Compile Include="Repository\ISettingsRepository.cs" />
<Compile Include="ISqliteConfiguration.cs" /> <Compile Include="ISqliteConfiguration.cs" />
@ -91,7 +94,6 @@
<Compile Include="Repository\SettingsJsonRepository.cs" /> <Compile Include="Repository\SettingsJsonRepository.cs" />
<Compile Include="Repository\RequestJsonRepository.cs" /> <Compile Include="Repository\RequestJsonRepository.cs" />
<Compile Include="Repository\GenericRepository.cs" /> <Compile Include="Repository\GenericRepository.cs" />
<Compile Include="Repository\PlexUserRepository.cs" />
<Compile Include="Repository\UserRepository.cs" /> <Compile Include="Repository\UserRepository.cs" />
<Compile Include="RequestedModel.cs" /> <Compile Include="RequestedModel.cs" />
<Compile Include="UserEntity.cs" /> <Compile Include="UserEntity.cs" />

View file

@ -26,18 +26,16 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Data; using System.Data;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dapper; using Dapper;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Store.Models;
namespace Ombi.Store.Repository namespace Ombi.Store.Repository
{ {
public class PlexUserRepository : BaseGenericRepository<PlexUsers>, IPlexUserRepository public class BaseExternalUserRepository<T> : BaseGenericRepository<T>, IExternalUserRepository<T> where T : class
{ {
public PlexUserRepository(ISqliteConfiguration config, ICacheProvider cache) : base(config,cache) public BaseExternalUserRepository(ISqliteConfiguration config, ICacheProvider cache) : base(config,cache)
{ {
DbConfig = config; DbConfig = config;
} }
@ -45,53 +43,53 @@ namespace Ombi.Store.Repository
private ISqliteConfiguration DbConfig { get; } private ISqliteConfiguration DbConfig { get; }
private IDbConnection Db => DbConfig.DbConnection(); private IDbConnection Db => DbConfig.DbConnection();
public PlexUsers GetUser(string userGuid) public T GetUser(string userGuid)
{ {
var sql = @"SELECT * FROM PlexUsers var sql = @"SELECT * FROM PlexUsers
WHERE PlexUserId = @UserGuid WHERE PlexUserId = @UserGuid
COLLATE NOCASE"; COLLATE NOCASE";
return Db.QueryFirstOrDefault<PlexUsers>(sql, new {UserGuid = userGuid}); return Db.QueryFirstOrDefault<T>(sql, new {UserGuid = userGuid});
} }
public PlexUsers GetUserByUsername(string username) public T GetUserByUsername(string username)
{ {
var sql = @"SELECT * FROM PlexUsers var sql = @"SELECT * FROM PlexUsers
WHERE Username = @UserName WHERE Username = @UserName
COLLATE NOCASE"; COLLATE NOCASE";
return Db.QueryFirstOrDefault<PlexUsers>(sql, new {UserName = username}); return Db.QueryFirstOrDefault<T>(sql, new {UserName = username});
} }
public async Task<PlexUsers> GetUserAsync(string userguid) public async Task<T> GetUserAsync(string userguid)
{ {
var sql = @"SELECT * FROM PlexUsers var sql = @"SELECT * FROM PlexUsers
WHERE PlexUserId = @UserGuid WHERE PlexUserId = @UserGuid
COLLATE NOCASE"; COLLATE NOCASE";
return await Db.QueryFirstOrDefaultAsync<PlexUsers>(sql, new {UserGuid = userguid}); return await Db.QueryFirstOrDefaultAsync<T>(sql, new {UserGuid = userguid});
} }
#region abstract implementation #region abstract implementation
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member #pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
[Obsolete] [Obsolete]
public override PlexUsers Get(string id) public override T Get(string id)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
[Obsolete] [Obsolete]
public override Task<PlexUsers> GetAsync(int id) public override Task<T> GetAsync(int id)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
[Obsolete] [Obsolete]
public override PlexUsers Get(int id) public override T Get(int id)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
[Obsolete] [Obsolete]
public override Task<PlexUsers> GetAsync(string id) public override Task<T> GetAsync(string id)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
@ -99,22 +97,5 @@ namespace Ombi.Store.Repository
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member #pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
#endregion #endregion
} }
public interface IPlexUserRepository
{
PlexUsers GetUser(string userGuid);
PlexUsers GetUserByUsername(string username);
Task<PlexUsers> GetUserAsync(string userguid);
IEnumerable<PlexUsers> Custom(Func<IDbConnection, IEnumerable<PlexUsers>> func);
long Insert(PlexUsers entity);
void Delete(PlexUsers entity);
IEnumerable<PlexUsers> GetAll();
bool UpdateAll(IEnumerable<PlexUsers> entity);
bool Update(PlexUsers entity);
Task<IEnumerable<PlexUsers>> GetAllAsync();
Task<bool> UpdateAsync(PlexUsers users);
Task<int> InsertAsync(PlexUsers users);
}
} }

View file

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
namespace Ombi.Store.Repository
{
public interface IExternalUserRepository<T> where T : class
{
T Get(string id);
T Get(int id);
Task<T> GetAsync(string id);
Task<T> GetAsync(int id);
T GetUser(string userGuid);
Task<T> GetUserAsync(string userguid);
T GetUserByUsername(string username);
IEnumerable<T> Custom(Func<IDbConnection, IEnumerable<T>> func);
long Insert(T entity);
void Delete(T entity);
IEnumerable<T> GetAll();
bool UpdateAll(IEnumerable<T> entity);
bool Update(T entity);
Task<IEnumerable<T>> GetAllAsync();
Task<bool> UpdateAsync(T users);
Task<int> InsertAsync(T users);
}
}

View file

@ -124,6 +124,20 @@ CREATE TABLE IF NOT EXISTS PlexUsers
); );
CREATE UNIQUE INDEX IF NOT EXISTS PlexUsers_Id ON PlexUsers (Id); CREATE UNIQUE INDEX IF NOT EXISTS PlexUsers_Id ON PlexUsers (Id);
CREATE TABLE IF NOT EXISTS EmbyUsers
(
Id INTEGER PRIMARY KEY AUTOINCREMENT,
PlexUserId varchar(100) NOT NULL,
UserAlias varchar(100) NOT NULL,
Permissions INTEGER,
Features INTEGER,
Username VARCHAR(100),
EmailAddress VARCHAR(100),
LoginId VARCHAR(100)
);
CREATE UNIQUE INDEX IF NOT EXISTS EmbyUsers_Id ON EmbyUsers (Id);
BEGIN; BEGIN;
CREATE TABLE IF NOT EXISTS PlexEpisodes CREATE TABLE IF NOT EXISTS PlexEpisodes
( (

View file

@ -26,6 +26,7 @@
#endregion #endregion
using Nancy.Cryptography; using Nancy.Cryptography;
using Ombi.Store.Models.Plex;
using Ombi.Store.Repository; using Ombi.Store.Repository;
namespace Ombi.UI.Authentication namespace Ombi.UI.Authentication
@ -47,7 +48,7 @@ namespace Ombi.UI.Authentication
/// <summary>Gets or sets the username/identifier mapper</summary> /// <summary>Gets or sets the username/identifier mapper</summary>
public IUserRepository LocalUserRepository { get; set; } public IUserRepository LocalUserRepository { get; set; }
public IPlexUserRepository PlexUserRepository { get; set; } public IExternalUserRepository<PlexUsers> PlexUserRepository { get; set; }
/// <summary>Gets or sets RequiresSSL property</summary> /// <summary>Gets or sets RequiresSSL property</summary>
/// <value>The flag that indicates whether SSL is required</value> /// <value>The flag that indicates whether SSL is required</value>

View file

@ -42,6 +42,7 @@ using Ombi.Core;
using Ombi.Core.SettingModels; using Ombi.Core.SettingModels;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Store; using Ombi.Store;
using Ombi.Store.Models.Plex;
using Ombi.Store.Repository; using Ombi.Store.Repository;
using Ombi.UI.Authentication; using Ombi.UI.Authentication;
using Ombi.UI.Helpers; using Ombi.UI.Helpers;
@ -88,7 +89,7 @@ namespace Ombi.UI
var config = new CustomAuthenticationConfiguration var config = new CustomAuthenticationConfiguration
{ {
RedirectUrl = redirect, RedirectUrl = redirect,
PlexUserRepository = container.Get<IPlexUserRepository>(), PlexUserRepository = container.Get<IExternalUserRepository<PlexUsers>>(), // TODO emby
LocalUserRepository = container.Get<IUserRepository>() LocalUserRepository = container.Get<IUserRepository>()
}; };

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Before After
Before After

View file

@ -65,7 +65,7 @@ namespace Ombi.UI.Modules
ISickRageApi sickRageApi, ISickRageApi sickRageApi,
ICacheProvider cache, ICacheProvider cache,
IAnalytics an, IAnalytics an,
INotificationEngine engine, IPlexNotificationEngine engine,
ISecurityExtensions security, ISecurityExtensions security,
ISettingsService<CustomizationSettings> customSettings) : base("requests", prSettings, security) ISettingsService<CustomizationSettings> customSettings) : base("requests", prSettings, security)
{ {
@ -438,8 +438,7 @@ namespace Ombi.UI.Modules
originalRequest.Available = available; originalRequest.Available = available;
var result = await Service.UpdateRequestAsync(originalRequest); var result = await Service.UpdateRequestAsync(originalRequest);
var plexService = await PlexSettings.GetSettingsAsync(); await NotificationEngine.NotifyUsers(originalRequest, available ? NotificationType.RequestAvailable : NotificationType.RequestDeclined);
await NotificationEngine.NotifyUsers(originalRequest, plexService.PlexAuthToken, available ? NotificationType.RequestAvailable : NotificationType.RequestDeclined);
return Response.AsJson(result return Response.AsJson(result
? new { Result = true, Available = available, Message = string.Empty } ? new { Result = true, Available = available, Message = string.Empty }
: new { Result = false, Available = false, Message = "Could not update the availability, please try again or check the logs" }); : new { Result = false, Available = false, Message = "Could not update the availability, please try again or check the logs" });

View file

@ -45,6 +45,7 @@ using Ombi.Helpers.Analytics;
using Ombi.Helpers.Permissions; using Ombi.Helpers.Permissions;
using Ombi.Store; using Ombi.Store;
using Ombi.Store.Models; using Ombi.Store.Models;
using Ombi.Store.Models.Plex;
using Ombi.Store.Repository; using Ombi.Store.Repository;
using Ombi.UI.Authentication; using Ombi.UI.Authentication;
using ISecurityExtensions = Ombi.Core.ISecurityExtensions; using ISecurityExtensions = Ombi.Core.ISecurityExtensions;
@ -55,7 +56,7 @@ namespace Ombi.UI.Modules
public class UserLoginModule : BaseModule public class UserLoginModule : BaseModule
{ {
public UserLoginModule(ISettingsService<AuthenticationSettings> auth, IPlexApi api, ISettingsService<PlexSettings> plexSettings, ISettingsService<PlexRequestSettings> pr, public UserLoginModule(ISettingsService<AuthenticationSettings> auth, IPlexApi api, ISettingsService<PlexSettings> plexSettings, ISettingsService<PlexRequestSettings> pr,
ISettingsService<LandingPageSettings> lp, IAnalytics a, IResourceLinker linker, IRepository<UserLogins> userLogins, IPlexUserRepository plexUsers, ICustomUserMapper custom, ISettingsService<LandingPageSettings> lp, IAnalytics a, IResourceLinker linker, IRepository<UserLogins> userLogins, IExternalUserRepository<PlexUsers> plexUsers, ICustomUserMapper custom,
ISecurityExtensions security, ISettingsService<UserManagementSettings> userManagementSettings) ISecurityExtensions security, ISettingsService<UserManagementSettings> userManagementSettings)
: base("userlogin", pr, security) : base("userlogin", pr, security)
{ {
@ -162,7 +163,7 @@ namespace Ombi.UI.Modules
private IResourceLinker Linker { get; } private IResourceLinker Linker { get; }
private IAnalytics Analytics { get; } private IAnalytics Analytics { get; }
private IRepository<UserLogins> UserLogins { get; } private IRepository<UserLogins> UserLogins { get; }
private IPlexUserRepository PlexUserRepository { get; } private IExternalUserRepository<PlexUsers> PlexUserRepository { get; }
private ICustomUserMapper CustomUserMapper { get; } private ICustomUserMapper CustomUserMapper { get; }
private ISettingsService<UserManagementSettings> UserManagementSettings { get; } private ISettingsService<UserManagementSettings> UserManagementSettings { get; }

View file

@ -7,6 +7,7 @@ using Nancy.Extensions;
using Nancy.Responses.Negotiation; using Nancy.Responses.Negotiation;
using Newtonsoft.Json; using Newtonsoft.Json;
using Ombi.Api.Interfaces; using Ombi.Api.Interfaces;
using Ombi.Api.Models.Emby;
using Ombi.Api.Models.Plex; using Ombi.Api.Models.Plex;
using Ombi.Core; using Ombi.Core;
using Ombi.Core.Models; using Ombi.Core.Models;
@ -16,6 +17,8 @@ using Ombi.Helpers.Analytics;
using Ombi.Helpers.Permissions; using Ombi.Helpers.Permissions;
using Ombi.Store; using Ombi.Store;
using Ombi.Store.Models; using Ombi.Store.Models;
using Ombi.Store.Models.Emby;
using Ombi.Store.Models.Plex;
using Ombi.Store.Repository; using Ombi.Store.Repository;
using Ombi.UI.Models; using Ombi.UI.Models;
using Ombi.UI.Models.UserManagement; using Ombi.UI.Models.UserManagement;
@ -26,8 +29,8 @@ namespace Ombi.UI.Modules
{ {
public class UserManagementModule : BaseModule public class UserManagementModule : BaseModule
{ {
public UserManagementModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m, IPlexApi plexApi, ISettingsService<PlexSettings> plex, IRepository<UserLogins> userLogins, IPlexUserRepository plexRepo public UserManagementModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m, IPlexApi plexApi, ISettingsService<PlexSettings> plex, IRepository<UserLogins> userLogins, IExternalUserRepository<PlexUsers> plexRepo
, ISecurityExtensions security, IRequestService req, IAnalytics ana) : base("usermanagement", pr, security) , ISecurityExtensions security, IRequestService req, IAnalytics ana, ISettingsService<EmbySettings> embyService, IEmbyApi embyApi, IExternalUserRepository<EmbyUsers> embyRepo) : base("usermanagement", pr, security)
{ {
#if !DEBUG #if !DEBUG
Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx); Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);
@ -40,6 +43,9 @@ namespace Ombi.UI.Modules
PlexRequestSettings = pr; PlexRequestSettings = pr;
RequestService = req; RequestService = req;
Analytics = ana; Analytics = ana;
EmbySettings = embyService;
EmbyApi = embyApi;
EmbyRepository = embyRepo;
Get["/"] = x => Load(); Get["/"] = x => Load();
@ -57,10 +63,13 @@ namespace Ombi.UI.Modules
private IPlexApi PlexApi { get; } private IPlexApi PlexApi { get; }
private ISettingsService<PlexSettings> PlexSettings { get; } private ISettingsService<PlexSettings> PlexSettings { get; }
private IRepository<UserLogins> UserLoginsRepo { get; } private IRepository<UserLogins> UserLoginsRepo { get; }
private IPlexUserRepository PlexUsersRepository { get; } private IExternalUserRepository<PlexUsers> PlexUsersRepository { get; }
private IExternalUserRepository<EmbyUsers> EmbyRepository { get; }
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; } private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
private ISettingsService<EmbySettings> EmbySettings { get; }
private IRequestService RequestService { get; } private IRequestService RequestService { get; }
private IAnalytics Analytics { get; } private IAnalytics Analytics { get; }
private IEmbyApi EmbyApi { get; }
private Negotiator Load() private Negotiator Load()
{ {
@ -69,48 +78,19 @@ namespace Ombi.UI.Modules
private async Task<Response> LoadUsers() private async Task<Response> LoadUsers()
{ {
var localUsers = await UserMapper.GetUsersAsync();
var plexDbUsers = await PlexUsersRepository.GetAllAsync();
var model = new List<UserManagementUsersViewModel>();
var userLogins = UserLoginsRepo.GetAll().ToList();
foreach (var user in localUsers)
{
var userDb = userLogins.FirstOrDefault(x => x.UserId == user.UserGuid);
model.Add(MapLocalUser(user, userDb?.LastLoggedIn ?? DateTime.MinValue));
}
var plexSettings = await PlexSettings.GetSettingsAsync(); var plexSettings = await PlexSettings.GetSettingsAsync();
if (!string.IsNullOrEmpty(plexSettings.PlexAuthToken)) var embySettings = await EmbySettings.GetSettingsAsync();
if (plexSettings.Enable)
{ {
//Get Plex Users return await LoadPlexUsers();
var plexUsers = PlexApi.GetUsers(plexSettings.PlexAuthToken);
if (plexUsers != null && plexUsers.User != null) {
foreach (var u in plexUsers.User) {
var dbUser = plexDbUsers.FirstOrDefault (x => x.PlexUserId == u.Id);
var userDb = userLogins.FirstOrDefault (x => x.UserId == u.Id);
// We don't have the user in the database yet
if (dbUser == null) {
model.Add (MapPlexUser (u, null, userDb?.LastLoggedIn ?? DateTime.MinValue));
} else {
// The Plex User is in the database
model.Add (MapPlexUser (u, dbUser, userDb?.LastLoggedIn ?? DateTime.MinValue));
}
} }
if (embySettings.Enable)
{
return await LoadEmbyUsers();
} }
// Also get the server admin return null;
var account = PlexApi.GetAccount(plexSettings.PlexAuthToken);
if (account != null)
{
var dbUser = plexDbUsers.FirstOrDefault(x => x.PlexUserId == account.Id);
var userDb = userLogins.FirstOrDefault(x => x.UserId == account.Id);
model.Add(MapPlexAdmin(account, dbUser, userDb?.LastLoggedIn ?? DateTime.MinValue));
}
}
return Response.AsJson(model);
} }
private async Task<Response> CreateUser() private async Task<Response> CreateUser()
@ -416,7 +396,7 @@ namespace Ombi.UI.Modules
var m = new UserManagementUsersViewModel var m = new UserManagementUsersViewModel
{ {
Id = plexInfo.Id, Id = plexInfo.Id,
PermissionsFormattedString = newUser ? "Processing..." :( permissions == 0 ? "None" : permissions.ToString()), PermissionsFormattedString = newUser ? "Processing..." : (permissions == 0 ? "None" : permissions.ToString()),
FeaturesFormattedString = newUser ? "Processing..." : features.ToString(), FeaturesFormattedString = newUser ? "Processing..." : features.ToString(),
Username = plexInfo.Title, Username = plexInfo.Title,
Type = UserType.PlexUser, Type = UserType.PlexUser,
@ -436,6 +416,36 @@ namespace Ombi.UI.Modules
return m; return m;
} }
private UserManagementUsersViewModel MapEmbyUser(EmbyUser embyInfo, EmbyUsers dbUser, DateTime lastLoggedIn)
{
var newUser = false;
if (dbUser == null)
{
newUser = true;
dbUser = new EmbyUsers();
}
var features = (Features)dbUser?.Features;
var permissions = (Permissions)dbUser?.Permissions;
var m = new UserManagementUsersViewModel
{
Id = embyInfo.Id,
PermissionsFormattedString = newUser ? "Processing..." : (permissions == 0 ? "None" : permissions.ToString()),
FeaturesFormattedString = newUser ? "Processing..." : features.ToString(),
Username = embyInfo.Name,
Type = UserType.EmbyUser,
EmailAddress =dbUser.EmailAddress,
Alias = dbUser?.UserAlias ?? string.Empty,
LastLoggedIn = lastLoggedIn,
ManagedUser = false
};
m.Permissions.AddRange(GetPermissions(permissions));
m.Features.AddRange(GetFeatures(features));
return m;
}
private UserManagementUsersViewModel MapPlexAdmin(PlexAccount plexInfo, PlexUsers dbUser, DateTime lastLoggedIn) private UserManagementUsersViewModel MapPlexAdmin(PlexAccount plexInfo, PlexUsers dbUser, DateTime lastLoggedIn)
{ {
var newUser = false; var newUser = false;
@ -505,6 +515,102 @@ namespace Ombi.UI.Modules
} }
return retVal; return retVal;
} }
private async Task<Response> LoadPlexUsers()
{
var localUsers = await UserMapper.GetUsersAsync();
var plexDbUsers = await PlexUsersRepository.GetAllAsync();
var model = new List<UserManagementUsersViewModel>();
var userLogins = UserLoginsRepo.GetAll().ToList();
foreach (var user in localUsers)
{
var userDb = userLogins.FirstOrDefault(x => x.UserId == user.UserGuid);
model.Add(MapLocalUser(user, userDb?.LastLoggedIn ?? DateTime.MinValue));
}
var plexSettings = await PlexSettings.GetSettingsAsync();
if (!string.IsNullOrEmpty(plexSettings.PlexAuthToken))
{
//Get Plex Users
var plexUsers = PlexApi.GetUsers(plexSettings.PlexAuthToken);
if (plexUsers != null && plexUsers.User != null)
{
foreach (var u in plexUsers.User)
{
var dbUser = plexDbUsers.FirstOrDefault(x => x.PlexUserId == u.Id);
var userDb = userLogins.FirstOrDefault(x => x.UserId == u.Id);
// We don't have the user in the database yet
if (dbUser == null)
{
model.Add(MapPlexUser(u, null, userDb?.LastLoggedIn ?? DateTime.MinValue));
}
else
{
// The Plex User is in the database
model.Add(MapPlexUser(u, dbUser, userDb?.LastLoggedIn ?? DateTime.MinValue));
}
}
}
// Also get the server admin
var account = PlexApi.GetAccount(plexSettings.PlexAuthToken);
if (account != null)
{
var dbUser = plexDbUsers.FirstOrDefault(x => x.PlexUserId == account.Id);
var userDb = userLogins.FirstOrDefault(x => x.UserId == account.Id);
model.Add(MapPlexAdmin(account, dbUser, userDb?.LastLoggedIn ?? DateTime.MinValue));
}
}
return Response.AsJson(model);
}
private async Task<Response> LoadEmbyUsers()
{
var localUsers = await UserMapper.GetUsersAsync();
var embyDbUsers = await EmbyRepository.GetAllAsync();
var model = new List<UserManagementUsersViewModel>();
var userLogins = UserLoginsRepo.GetAll().ToList();
foreach (var user in localUsers)
{
var userDb = userLogins.FirstOrDefault(x => x.UserId == user.UserGuid);
model.Add(MapLocalUser(user, userDb?.LastLoggedIn ?? DateTime.MinValue));
}
var embySettings = await EmbySettings.GetSettingsAsync();
if (!string.IsNullOrEmpty(embySettings.ApiKey))
{
//Get Plex Users
var plexUsers = EmbyApi.GetUsers(embySettings.FullUri, embySettings.ApiKey);
if (plexUsers != null)
{
foreach (var u in plexUsers)
{
var dbUser = embyDbUsers.FirstOrDefault(x => x.PlexUserId == u.Id);
var userDb = userLogins.FirstOrDefault(x => x.UserId == u.Id);
// We don't have the user in the database yet
model.Add(dbUser == null
? MapEmbyUser(u, null, userDb?.LastLoggedIn ?? DateTime.MinValue)
: MapEmbyUser(u, dbUser, userDb?.LastLoggedIn ?? DateTime.MinValue));
}
}
// Also get the server admin
var account = PlexApi.GetAccount(embySettings.PlexAuthToken);
if (account != null)
{
var dbUser = embyDbUsers.FirstOrDefault(x => x.PlexUserId == account.Id);
var userDb = userLogins.FirstOrDefault(x => x.UserId == account.Id);
model.Add(MapPlexAdmin(account, dbUser, userDb?.LastLoggedIn ?? DateTime.MinValue));
}
}
return Response.AsJson(model);
}
} }
} }

View file

@ -56,7 +56,8 @@ namespace Ombi.UI.NinjectModules
Bind<ICustomUserMapper>().To<UserMapper>(); Bind<ICustomUserMapper>().To<UserMapper>();
Bind<INotificationService>().To<NotificationService>().InSingletonScope(); Bind<INotificationService>().To<NotificationService>().InSingletonScope();
Bind<INotificationEngine>().To<NotificationEngine>(); Bind<IPlexNotificationEngine>().To<PlexNotificationEngine>();
Bind<IEmbyNotificationEngine>().To<EmbyNotificationEngine>();
Bind<IStatusChecker>().To<StatusChecker>(); Bind<IStatusChecker>().To<StatusChecker>();

View file

@ -40,6 +40,7 @@ namespace Ombi.UI.NinjectModules
{ {
Bind<IRepository<UsersModel>>().To<UserRepository<UsersModel>>(); Bind<IRepository<UsersModel>>().To<UserRepository<UsersModel>>();
Bind(typeof(IRepository<>)).To(typeof(GenericRepository<>)); Bind(typeof(IRepository<>)).To(typeof(GenericRepository<>));
Bind(typeof(IExternalUserRepository<>)).To(typeof(BaseExternalUserRepository<>));
Bind<IRequestService>().To<JsonRequestModelRequestService>(); Bind<IRequestService>().To<JsonRequestModelRequestService>();
Bind<IRequestRepository>().To<RequestJsonRepository>(); Bind<IRequestRepository>().To<RequestJsonRepository>();
@ -48,7 +49,6 @@ namespace Ombi.UI.NinjectModules
Bind<IJobRecord>().To<JobRecord>(); Bind<IJobRecord>().To<JobRecord>();
Bind<IUserRepository>().To<UserRepository>(); Bind<IUserRepository>().To<UserRepository>();
Bind<IPlexUserRepository>().To<PlexUserRepository>();
} }
} }

View file

@ -402,7 +402,7 @@
<Content Include="Content\images\logo original.png"> <Content Include="Content\images\logo original.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\images\logo-cropped.png"> <Content Include="Content\images\logo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\images\plex-logo-reversed.png"> <Content Include="Content\images\plex-logo-reversed.png">
@ -502,9 +502,6 @@
<Content Include="Content\bootstrap-datetimepicker.min.js"> <Content Include="Content\bootstrap-datetimepicker.min.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\images\logo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\tooltip\plugins\tooltipster\sideTip\themes\tooltipster-sideTip-borderless.min.css"> <Content Include="Content\tooltip\plugins\tooltipster\sideTip\themes\tooltipster-sideTip-borderless.min.css">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>

View file

@ -10,7 +10,7 @@
} }
@Html.LoadWizardAssets() @Html.LoadWizardAssets()
<img class="landing-header" src="@formAction/Content/images/logo-cropped.png" width="300" /> <img class="landing-header" src="@formAction/Content/images/logo.png" width="300" />
<div id="area" class="landing-block shadow"> <div id="area" class="landing-block shadow">
<div class="media"> <div class="media">