mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-08 14:10:50 -07:00
Fix for #1026
This commit is contained in:
parent
643676e7ea
commit
dd54064507
3 changed files with 79 additions and 27 deletions
|
@ -30,6 +30,7 @@ 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.Emby;
|
||||||
using Ombi.Store.Models.Plex;
|
using Ombi.Store.Models.Plex;
|
||||||
using Ombi.Store.Repository;
|
using Ombi.Store.Repository;
|
||||||
|
|
||||||
|
@ -37,16 +38,18 @@ namespace Ombi.Core.Users
|
||||||
{
|
{
|
||||||
public class UserHelper : IUserHelper
|
public class UserHelper : IUserHelper
|
||||||
{
|
{
|
||||||
public UserHelper(IUserRepository userRepository, IExternalUserRepository<PlexUsers> plexUsers, ISecurityExtensions security)
|
public UserHelper(IUserRepository userRepository, IExternalUserRepository<PlexUsers> plexUsers, IExternalUserRepository<EmbyUsers> emby, ISecurityExtensions security)
|
||||||
{
|
{
|
||||||
LocalUserRepository = userRepository;
|
LocalUserRepository = userRepository;
|
||||||
PlexUserRepository = plexUsers;
|
PlexUserRepository = plexUsers;
|
||||||
Security = security;
|
Security = security;
|
||||||
|
EmbyUserRepository = emby;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IUserRepository LocalUserRepository { get; }
|
private IUserRepository LocalUserRepository { get; }
|
||||||
private IExternalUserRepository<PlexUsers> PlexUserRepository { get; }
|
private IExternalUserRepository<PlexUsers> PlexUserRepository { get; }
|
||||||
private ISecurityExtensions Security { get; }
|
private ISecurityExtensions Security { get; }
|
||||||
|
private IExternalUserRepository<EmbyUsers> EmbyUserRepository { get; }
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<UserHelperModel> GetUsers()
|
public IEnumerable<UserHelperModel> GetUsers()
|
||||||
|
@ -54,7 +57,8 @@ namespace Ombi.Core.Users
|
||||||
var model = new List<UserHelperModel>();
|
var model = new List<UserHelperModel>();
|
||||||
|
|
||||||
var localUsers = LocalUserRepository.GetAll();
|
var localUsers = LocalUserRepository.GetAll();
|
||||||
var plexUsers = PlexUserRepository.GetAll();
|
var plexUsers = PlexUserRepository.GetAll().ToList();
|
||||||
|
var embyUsers = EmbyUserRepository.GetAll().ToList();
|
||||||
|
|
||||||
foreach (var user in localUsers)
|
foreach (var user in localUsers)
|
||||||
{
|
{
|
||||||
|
@ -69,14 +73,30 @@ namespace Ombi.Core.Users
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
model.AddRange(plexUsers.Select(user => new UserHelperModel
|
if (plexUsers.Any())
|
||||||
{
|
{
|
||||||
Type = UserType.LocalUser,
|
model.AddRange(plexUsers.Select(user => new UserHelperModel
|
||||||
Username = user.Username,
|
{
|
||||||
UserAlias = user.UserAlias,
|
Type = UserType.PlexUser,
|
||||||
EmailAddress = user.EmailAddress,
|
Username = user.Username,
|
||||||
Permissions = (Permissions)user.Permissions
|
UserAlias = user.UserAlias,
|
||||||
}));
|
EmailAddress = user.EmailAddress,
|
||||||
|
Permissions = (Permissions) user.Permissions
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (embyUsers.Any())
|
||||||
|
{
|
||||||
|
model.AddRange(embyUsers.Select(user => new UserHelperModel
|
||||||
|
{
|
||||||
|
Type = UserType.EmbyUser,
|
||||||
|
Username = user.Username,
|
||||||
|
UserAlias = user.UserAlias,
|
||||||
|
EmailAddress = user.EmailAddress,
|
||||||
|
Permissions = (Permissions)user.Permissions
|
||||||
|
}));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -87,9 +107,11 @@ namespace Ombi.Core.Users
|
||||||
|
|
||||||
var localUsers = LocalUserRepository.GetAll().ToList();
|
var localUsers = LocalUserRepository.GetAll().ToList();
|
||||||
var plexUsers = PlexUserRepository.GetAll().ToList();
|
var plexUsers = PlexUserRepository.GetAll().ToList();
|
||||||
|
var embyUsers = EmbyUserRepository.GetAll().ToList();
|
||||||
|
|
||||||
var filteredLocal = localUsers.Where(x => ((Permissions)x.Permissions).HasFlag(permission));
|
var filteredLocal = localUsers.Where(x => ((Permissions)x.Permissions).HasFlag(permission));
|
||||||
var filteredPlex = plexUsers.Where(x => ((Permissions)x.Permissions).HasFlag(permission));
|
var filteredPlex = plexUsers.Where(x => ((Permissions)x.Permissions).HasFlag(permission));
|
||||||
|
var filteredEmby = embyUsers.Where(x => ((Permissions)x.Permissions).HasFlag(permission));
|
||||||
|
|
||||||
|
|
||||||
foreach (var user in filteredLocal)
|
foreach (var user in filteredLocal)
|
||||||
|
@ -108,7 +130,7 @@ namespace Ombi.Core.Users
|
||||||
|
|
||||||
model.AddRange(filteredPlex.Select(user => new UserHelperModel
|
model.AddRange(filteredPlex.Select(user => new UserHelperModel
|
||||||
{
|
{
|
||||||
Type = UserType.LocalUser,
|
Type = UserType.PlexUser,
|
||||||
Username = user.Username,
|
Username = user.Username,
|
||||||
UserAlias = user.UserAlias,
|
UserAlias = user.UserAlias,
|
||||||
EmailAddress = user.EmailAddress,
|
EmailAddress = user.EmailAddress,
|
||||||
|
@ -116,6 +138,17 @@ namespace Ombi.Core.Users
|
||||||
Features = (Features)user.Features
|
Features = (Features)user.Features
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
model.AddRange(filteredEmby.Select(user => new UserHelperModel
|
||||||
|
{
|
||||||
|
Type = UserType.EmbyUser,
|
||||||
|
Username = user.Username,
|
||||||
|
UserAlias = user.UserAlias,
|
||||||
|
EmailAddress = user.EmailAddress,
|
||||||
|
Permissions = (Permissions)user.Permissions,
|
||||||
|
Features = (Features)user.Features
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,9 +158,11 @@ namespace Ombi.Core.Users
|
||||||
|
|
||||||
var localUsers = LocalUserRepository.GetAll().ToList();
|
var localUsers = LocalUserRepository.GetAll().ToList();
|
||||||
var plexUsers = PlexUserRepository.GetAll().ToList();
|
var plexUsers = PlexUserRepository.GetAll().ToList();
|
||||||
|
var embyUsers = PlexUserRepository.GetAll().ToList();
|
||||||
|
|
||||||
var filteredLocal = localUsers.Where(x => ((Features)x.Features).HasFlag(features));
|
var filteredLocal = localUsers.Where(x => ((Features)x.Features).HasFlag(features));
|
||||||
var filteredPlex = plexUsers.Where(x => ((Features)x.Features).HasFlag(features));
|
var filteredPlex = plexUsers.Where(x => ((Features)x.Features).HasFlag(features));
|
||||||
|
var filteredEmby = embyUsers.Where(x => ((Features)x.Features).HasFlag(features));
|
||||||
|
|
||||||
|
|
||||||
foreach (var user in filteredLocal)
|
foreach (var user in filteredLocal)
|
||||||
|
@ -146,7 +181,17 @@ namespace Ombi.Core.Users
|
||||||
|
|
||||||
model.AddRange(filteredPlex.Select(user => new UserHelperModel
|
model.AddRange(filteredPlex.Select(user => new UserHelperModel
|
||||||
{
|
{
|
||||||
Type = UserType.LocalUser,
|
Type = UserType.PlexUser,
|
||||||
|
Username = user.Username,
|
||||||
|
UserAlias = user.UserAlias,
|
||||||
|
EmailAddress = user.EmailAddress,
|
||||||
|
Permissions = (Permissions)user.Permissions,
|
||||||
|
Features = (Features)user.Features
|
||||||
|
}));
|
||||||
|
|
||||||
|
model.AddRange(filteredEmby.Select(user => new UserHelperModel
|
||||||
|
{
|
||||||
|
Type = UserType.EmbyUser,
|
||||||
Username = user.Username,
|
Username = user.Username,
|
||||||
UserAlias = user.UserAlias,
|
UserAlias = user.UserAlias,
|
||||||
EmailAddress = user.EmailAddress,
|
EmailAddress = user.EmailAddress,
|
||||||
|
|
|
@ -12,19 +12,21 @@ using Ombi.Helpers.Permissions;
|
||||||
using Ombi.Services.Interfaces;
|
using Ombi.Services.Interfaces;
|
||||||
using Ombi.Store;
|
using Ombi.Store;
|
||||||
using Ombi.Store.Models;
|
using Ombi.Store.Models;
|
||||||
|
using Ombi.Store.Models.Emby;
|
||||||
using Ombi.Store.Repository;
|
using Ombi.Store.Repository;
|
||||||
|
|
||||||
namespace Ombi.Services.Notification
|
namespace Ombi.Services.Notification
|
||||||
{
|
{
|
||||||
public class EmbyNotificationEngine : IEmbyNotificationEngine
|
public class EmbyNotificationEngine : IEmbyNotificationEngine
|
||||||
{
|
{
|
||||||
public EmbyNotificationEngine(IEmbyApi p, IRepository<UsersToNotify> repo, ISettingsService<EmbySettings> embySettings, INotificationService service, IUserHelper userHelper)
|
public EmbyNotificationEngine(IEmbyApi p, IRepository<UsersToNotify> repo, ISettingsService<EmbySettings> embySettings, INotificationService service, IUserHelper userHelper, IExternalUserRepository<EmbyUsers> embyUsers)
|
||||||
{
|
{
|
||||||
EmbyApi = p;
|
EmbyApi = p;
|
||||||
UserNotifyRepo = repo;
|
UserNotifyRepo = repo;
|
||||||
Notification = service;
|
Notification = service;
|
||||||
UserHelper = userHelper;
|
UserHelper = userHelper;
|
||||||
EmbySettings = embySettings;
|
EmbySettings = embySettings;
|
||||||
|
EmbyUserRepo = embyUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEmbyApi EmbyApi { get; }
|
private IEmbyApi EmbyApi { get; }
|
||||||
|
@ -33,6 +35,7 @@ namespace Ombi.Services.Notification
|
||||||
private INotificationService Notification { get; }
|
private INotificationService Notification { get; }
|
||||||
private IUserHelper UserHelper { get; }
|
private IUserHelper UserHelper { get; }
|
||||||
private ISettingsService<EmbySettings> EmbySettings { get; }
|
private ISettingsService<EmbySettings> EmbySettings { get; }
|
||||||
|
private IExternalUserRepository<EmbyUsers> EmbyUserRepo { get; }
|
||||||
|
|
||||||
public async Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, NotificationType type)
|
public async Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, NotificationType type)
|
||||||
{
|
{
|
||||||
|
@ -68,22 +71,23 @@ namespace Ombi.Services.Notification
|
||||||
|
|
||||||
foreach (var user in selectedUsers)
|
foreach (var user in selectedUsers)
|
||||||
{
|
{
|
||||||
|
var localUser =
|
||||||
|
users.FirstOrDefault(x =>
|
||||||
|
x.Username.Equals(user, StringComparison.CurrentCultureIgnoreCase) ||
|
||||||
|
x.UserAlias.Equals(user, StringComparison.CurrentCultureIgnoreCase));
|
||||||
Log.Info("Notifying user {0}", user);
|
Log.Info("Notifying user {0}", user);
|
||||||
if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase))
|
if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
Log.Info("This user is the Plex server owner");
|
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
|
await PublishUserNotification(userAccount?.Name, localUser?.EmailAddress, model.Title, model.PosterPath, type, model.Type);
|
||||||
return;
|
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).
|
// 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.
|
// If we do not have a local user, then we should be using the Emby user if that user exists.
|
||||||
// This will execute most of the time since Plex and Local users will most always be in the database.
|
// This will execute most of the time since Emby and Local users will most always be in the database.
|
||||||
if (localUser != null)
|
if (localUser != null)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(localUser?.EmailAddress))
|
if (string.IsNullOrEmpty(localUser?.EmailAddress))
|
||||||
|
@ -98,16 +102,17 @@ namespace Ombi.Services.Notification
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
var embyUser = EmbyUserRepo.GetUserByUsername(user);
|
||||||
var email = embyUsers.FirstOrDefault(x => x.Name.Equals(user, StringComparison.CurrentCultureIgnoreCase));
|
var email = embyUsers.FirstOrDefault(x => x.Name.Equals(user, StringComparison.CurrentCultureIgnoreCase));
|
||||||
if (string.IsNullOrEmpty(email?.Name)) // TODO this needs to be the email
|
if (string.IsNullOrEmpty(embyUser?.EmailAddress)) // 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
|
Log.Info("There is no email address for this Emby user ({0}), cannot send notification", email?.Name);
|
||||||
// We do not have a plex user that requested this!
|
// We do not have a plex user that requested this!
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Info("Sending notification to: {0} at: {1}, for : {2}", email.Name, email.Name, model.Title);
|
Log.Info("Sending notification to: {0} at: {1}, for : {2}", embyUser?.Username, embyUser?.EmailAddress, model.Title);
|
||||||
await PublishUserNotification(email.Name, email.Name, model.Title, model.PosterPath, type, model.Type); //TODO
|
await PublishUserNotification(email?.Name, embyUser?.EmailAddress, model.Title, model.PosterPath, type, model.Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,11 +167,12 @@ namespace Ombi.Services.Notification
|
||||||
Log.Debug("Users being notified for this request count {0}", users.Count);
|
Log.Debug("Users being notified for this request count {0}", users.Count);
|
||||||
foreach (var user in usersToNotify)
|
foreach (var user in usersToNotify)
|
||||||
{
|
{
|
||||||
|
var embyUser = EmbyUserRepo.GetUserByUsername(user);
|
||||||
Log.Info("Notifying user {0}", user);
|
Log.Info("Notifying user {0}", user);
|
||||||
if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase))
|
if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
Log.Info("This user is the Emby server owner");
|
Log.Info("This user is the Emby server owner");
|
||||||
await PublishUserNotification(userAccount.Name, userAccount.Name, model.Title, model.PosterPath, type, model.Type); // TODO
|
await PublishUserNotification(userAccount.Name, embyUser.EmailAddress, model.Title, model.PosterPath, type, model.Type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,12 +180,12 @@ namespace Ombi.Services.Notification
|
||||||
if (email == null)
|
if (email == null)
|
||||||
{
|
{
|
||||||
Log.Info("There is no email address for this Emby user, cannot send notification");
|
Log.Info("There is no email address for this Emby user, cannot send notification");
|
||||||
// We do not have a plex user that requested this!
|
// We do not have a emby user that requested this!
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Info("Sending notification to: {0} at: {1}, for title: {2}", email.Name, email.Name, model.Title); // TODO
|
Log.Info("Sending notification to: {0} at: {1}, for title: {2}", email.Name, embyUser.EmailAddress, model.Title);
|
||||||
await PublishUserNotification(email.Name, email.Name, model.Title, model.PosterPath, type, model.Type); // TODO
|
await PublishUserNotification(email.Name, embyUser.EmailAddress, model.Title, model.PosterPath, type, model.Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -153,6 +153,7 @@ namespace Ombi.UI.Modules
|
||||||
var firstServer = servers.Server.FirstOrDefault(x => x.AccessToken == form.PlexAuthToken);
|
var firstServer = servers.Server.FirstOrDefault(x => x.AccessToken == form.PlexAuthToken);
|
||||||
|
|
||||||
Session[SessionKeys.UserWizardMachineId] = firstServer?.MachineIdentifier;
|
Session[SessionKeys.UserWizardMachineId] = firstServer?.MachineIdentifier;
|
||||||
|
form.MachineIdentifier = firstServer?.MachineIdentifier;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue