diff --git a/Ombi.Core/SecurityExtensions.cs b/Ombi.Core/SecurityExtensions.cs index a68884009..7a244554a 100644 --- a/Ombi.Core/SecurityExtensions.cs +++ b/Ombi.Core/SecurityExtensions.cs @@ -114,9 +114,13 @@ namespace Ombi.Core } // could be a local user - var localName = session[SessionKeys.UsernameKey]; + var hasSessionKey = session[SessionKeys.UsernameKey] != null; + if (hasSessionKey) + { + return (string)session[SessionKeys.UsernameKey]; + } - return localName as string; + return string.Empty; } diff --git a/Ombi.Core/Users/UserHelperModel.cs b/Ombi.Core/Users/UserHelperModel.cs index 1b08d9fb1..ace42d4f9 100644 --- a/Ombi.Core/Users/UserHelperModel.cs +++ b/Ombi.Core/Users/UserHelperModel.cs @@ -25,6 +25,7 @@ // ************************************************************************/ #endregion +using Newtonsoft.Json; using Ombi.Helpers; using Ombi.Helpers.Permissions; @@ -38,5 +39,8 @@ namespace Ombi.Core.Users public Features Features { get; set; } public string EmailAddress { get; set; } public UserType Type { get; set; } + + [JsonIgnore] + public string UsernameOrAlias => string.IsNullOrEmpty(UserAlias) ? Username : UserAlias; } } \ No newline at end of file diff --git a/Ombi.Services/Notification/NotificationEngine.cs b/Ombi.Services/Notification/NotificationEngine.cs index dbf6d4dc0..01b50898b 100644 --- a/Ombi.Services/Notification/NotificationEngine.cs +++ b/Ombi.Services/Notification/NotificationEngine.cs @@ -152,10 +152,16 @@ namespace Ombi.Services.Notification var users = UserHelper.GetUsersWithFeature(Features.RequestAddedNotification).ToList(); Log.Debug("Notifying Users Count {0}", users.Count); - var userNamesWithFeature = users.Select(x => x.Username).ToList(); + // Get the usernames or alias depending if they have an alias + var userNamesWithFeature = users.Select(x => x.UsernameOrAlias).ToList(); + var usersToNotify = userNamesWithFeature.Intersect(model.AllUsers, StringComparer.CurrentCultureIgnoreCase).ToList(); + + if (!usersToNotify.Any()) + { + Log.Debug("Could not find any users after the .Intersect()"); + } - var usersToNotify = userNamesWithFeature.Intersect(model.AllUsers, StringComparer.CurrentCultureIgnoreCase); Log.Debug("Users being notified for this request count {0}", users.Count); foreach (var user in usersToNotify) { diff --git a/Ombi.Store/Models/PlexUsers.cs b/Ombi.Store/Models/PlexUsers.cs index b61b2a99e..0a3b735d1 100644 --- a/Ombi.Store/Models/PlexUsers.cs +++ b/Ombi.Store/Models/PlexUsers.cs @@ -26,6 +26,7 @@ #endregion using Dapper.Contrib.Extensions; +using Newtonsoft.Json; namespace Ombi.Store.Models { diff --git a/Ombi.UI/Modules/BaseModule.cs b/Ombi.UI/Modules/BaseModule.cs index f3608d4f4..5e6ca5d4a 100644 --- a/Ombi.UI/Modules/BaseModule.cs +++ b/Ombi.UI/Modules/BaseModule.cs @@ -149,9 +149,10 @@ namespace Ombi.UI.Modules protected bool LoggedIn => Context?.CurrentUser != null; - protected string Culture { get; set; } + private string Culture { get; set; } protected const string CultureCookieName = "_culture"; - protected Response SetCookie() + + private Response SetCookie() { try { diff --git a/Ombi.UI/Modules/UserLoginModule.cs b/Ombi.UI/Modules/UserLoginModule.cs index 59c30a1aa..40fea430f 100644 --- a/Ombi.UI/Modules/UserLoginModule.cs +++ b/Ombi.UI/Modules/UserLoginModule.cs @@ -564,7 +564,7 @@ namespace Ombi.UI.Modules UserLogins.Insert(new UserLogins { UserId = userId, Type = UserType.PlexUser, LastLoggedIn = DateTime.UtcNow }); Log.Debug("We are authenticated! Setting session."); // Add to the session (Used in the BaseModules) - Session[SessionKeys.UsernameKey] = (string)username; + Session[SessionKeys.UsernameKey] = username; Session[SessionKeys.ClientDateTimeOffsetKey] = dateTimeOffset; var plexLocal = plexLocalUsers.FirstOrDefault(x => x.Username == username);