pull/1029/head
Jamie.Rees 8 years ago
parent 643676e7ea
commit dd54064507

@ -30,6 +30,7 @@ using System.Linq;
using Ombi.Core.Models;
using Ombi.Helpers;
using Ombi.Helpers.Permissions;
using Ombi.Store.Models.Emby;
using Ombi.Store.Models.Plex;
using Ombi.Store.Repository;
@ -37,16 +38,18 @@ namespace Ombi.Core.Users
{
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;
PlexUserRepository = plexUsers;
Security = security;
EmbyUserRepository = emby;
}
private IUserRepository LocalUserRepository { get; }
private IExternalUserRepository<PlexUsers> PlexUserRepository { get; }
private ISecurityExtensions Security { get; }
private IExternalUserRepository<EmbyUsers> EmbyUserRepository { get; }
public IEnumerable<UserHelperModel> GetUsers()
@ -54,7 +57,8 @@ namespace Ombi.Core.Users
var model = new List<UserHelperModel>();
var localUsers = LocalUserRepository.GetAll();
var plexUsers = PlexUserRepository.GetAll();
var plexUsers = PlexUserRepository.GetAll().ToList();
var embyUsers = EmbyUserRepository.GetAll().ToList();
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,
Username = user.Username,
UserAlias = user.UserAlias,
EmailAddress = user.EmailAddress,
Permissions = (Permissions)user.Permissions
}));
model.AddRange(plexUsers.Select(user => new UserHelperModel
{
Type = UserType.PlexUser,
Username = user.Username,
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;
}
@ -87,9 +107,11 @@ namespace Ombi.Core.Users
var localUsers = LocalUserRepository.GetAll().ToList();
var plexUsers = PlexUserRepository.GetAll().ToList();
var embyUsers = EmbyUserRepository.GetAll().ToList();
var filteredLocal = localUsers.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)
@ -108,7 +130,17 @@ namespace Ombi.Core.Users
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,
UserAlias = user.UserAlias,
EmailAddress = user.EmailAddress,
@ -116,6 +148,7 @@ namespace Ombi.Core.Users
Features = (Features)user.Features
}));
return model;
}
@ -125,9 +158,11 @@ namespace Ombi.Core.Users
var localUsers = LocalUserRepository.GetAll().ToList();
var plexUsers = PlexUserRepository.GetAll().ToList();
var embyUsers = PlexUserRepository.GetAll().ToList();
var filteredLocal = localUsers.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)
@ -146,7 +181,17 @@ namespace Ombi.Core.Users
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,
UserAlias = user.UserAlias,
EmailAddress = user.EmailAddress,

@ -12,19 +12,21 @@ using Ombi.Helpers.Permissions;
using Ombi.Services.Interfaces;
using Ombi.Store;
using Ombi.Store.Models;
using Ombi.Store.Models.Emby;
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)
public EmbyNotificationEngine(IEmbyApi p, IRepository<UsersToNotify> repo, ISettingsService<EmbySettings> embySettings, INotificationService service, IUserHelper userHelper, IExternalUserRepository<EmbyUsers> embyUsers)
{
EmbyApi = p;
UserNotifyRepo = repo;
Notification = service;
UserHelper = userHelper;
EmbySettings = embySettings;
EmbyUserRepo = embyUsers;
}
private IEmbyApi EmbyApi { get; }
@ -33,6 +35,7 @@ namespace Ombi.Services.Notification
private INotificationService Notification { get; }
private IUserHelper UserHelper { get; }
private ISettingsService<EmbySettings> EmbySettings { get; }
private IExternalUserRepository<EmbyUsers> EmbyUserRepo { get; }
public async Task NotifyUsers(IEnumerable<RequestedModel> modelChanged, NotificationType type)
{
@ -68,22 +71,23 @@ namespace Ombi.Services.Notification
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);
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
await PublishUserNotification(userAccount?.Name, localUser?.EmailAddress, model.Title, model.PosterPath, type, model.Type);
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 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 Emby and Local users will most always be in the database.
if (localUser != null)
{
if (string.IsNullOrEmpty(localUser?.EmailAddress))
@ -98,16 +102,17 @@ namespace Ombi.Services.Notification
}
else
{
var embyUser = EmbyUserRepo.GetUserByUsername(user);
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!
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
Log.Info("Sending notification to: {0} at: {1}, for : {2}", embyUser?.Username, embyUser?.EmailAddress, model.Title);
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);
foreach (var user in usersToNotify)
{
var embyUser = EmbyUserRepo.GetUserByUsername(user);
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
await PublishUserNotification(userAccount.Name, embyUser.EmailAddress, model.Title, model.PosterPath, type, model.Type);
return;
}
@ -174,12 +180,12 @@ namespace Ombi.Services.Notification
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!
// We do not have a emby 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
Log.Info("Sending notification to: {0} at: {1}, for title: {2}", email.Name, embyUser.EmailAddress, model.Title);
await PublishUserNotification(email.Name, embyUser.EmailAddress, model.Title, model.PosterPath, type, model.Type);
}
}
catch (Exception e)

@ -153,6 +153,7 @@ namespace Ombi.UI.Modules
var firstServer = servers.Server.FirstOrDefault(x => x.AccessToken == form.PlexAuthToken);
Session[SessionKeys.UserWizardMachineId] = firstServer?.MachineIdentifier;
form.MachineIdentifier = firstServer?.MachineIdentifier;
}
catch (Exception e)
{

Loading…
Cancel
Save