From d0998f2f213602a817ab5447690eb18c28b439db Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Wed, 25 Jan 2017 08:42:11 +0000 Subject: [PATCH 1/4] Small changed to the sidebar --- Ombi.UI/Helpers/BaseUrlHelper.cs | 28 ++++--- Ombi.UI/Views/Shared/Partial/_Sidebar.cshtml | 84 +++++++++++++------- 2 files changed, 71 insertions(+), 41 deletions(-) diff --git a/Ombi.UI/Helpers/BaseUrlHelper.cs b/Ombi.UI/Helpers/BaseUrlHelper.cs index 37482005c..99c37459e 100644 --- a/Ombi.UI/Helpers/BaseUrlHelper.cs +++ b/Ombi.UI/Helpers/BaseUrlHelper.cs @@ -199,7 +199,7 @@ namespace Ombi.UI.Helpers var assetLocation = GetBaseUrl(); var content = GetContentUrl(assetLocation); - + sb.AppendLine($""); return helper.Raw(sb.ToString()); @@ -226,9 +226,9 @@ namespace Ombi.UI.Helpers sb.Append($""); sb.Append($""); sb.Append($""); - sb.Append($""); - sb.Append($""); - sb.Append($""); + sb.Append($""); + sb.Append($""); + sb.Append($""); return helper.Raw(sb.ToString()); } @@ -290,17 +290,19 @@ namespace Ombi.UI.Helpers return helper.Raw(asset); } - public static IHtmlString GetSidebarUrl(this HtmlHelpers helper, NancyContext context, string url, string title, bool dropdown = false) + public static IHtmlString GetSidebarUrl(this HtmlHelpers helper, NancyContext context, string url, string title, string icon = null) { var content = GetLinkUrl(GetBaseUrl()); if (!string.IsNullOrEmpty(content)) { url = $"/{content}{url}"; } - var dropdownClass = dropdown ? "list-group-item-dropdown" : string.Empty; - var returnString = context.Request.Path == url - ? $"{title}" - : $"{title}"; + + + var iconHtml = string.IsNullOrEmpty(icon) ? "" : $""; + var returnString = context.Request.Path == url + ? $"{title} {iconHtml}" + : $"{title} {iconHtml}"; return helper.Raw(returnString); } @@ -312,8 +314,8 @@ namespace Ombi.UI.Helpers { url = $"/{content}{url}"; } - var returnString = context.Request.Path == url ? - $"
  • {title}
  • " + var returnString = context.Request.Path == url ? + $"
  • {title}
  • " : $"
  • {title}
  • "; return helper.Raw(returnString); @@ -327,8 +329,8 @@ namespace Ombi.UI.Helpers url = $"/{content}{url}"; } - var returnString = context.Request.Path == url - ? $"
  • {title} {extraHtml}
  • " + var returnString = context.Request.Path == url + ? $"
  • {title} {extraHtml}
  • " : $"
  • {title} {extraHtml}
  • "; return helper.Raw(returnString); diff --git a/Ombi.UI/Views/Shared/Partial/_Sidebar.cshtml b/Ombi.UI/Views/Shared/Partial/_Sidebar.cshtml index 0d4db7818..e62947012 100644 --- a/Ombi.UI/Views/Shared/Partial/_Sidebar.cshtml +++ b/Ombi.UI/Views/Shared/Partial/_Sidebar.cshtml @@ -2,34 +2,62 @@ @Html.LoadSettingsAssets()
    - @Html.GetSidebarUrl(Context, "/admin/about", "About") - @Html.GetSidebarUrl(Context, "/admin", "Ombi Configuration") - @Html.GetSidebarUrl(Context, "/admin/customization", "Customization") - @Html.GetSidebarUrl(Context, "/admin/landingpage", "Landing Page") - @Html.GetSidebarUrl(Context, "/admin/authentication", "Authentication") - @Html.GetSidebarUrl(Context, "/admin/usermanagementsettings", "User Management Settings") - @Html.GetSidebarUrl(Context, "/admin/plex", "Plex") - @Html.GetSidebarUrl(Context, "/admin/couchpotato", "CouchPotato") - @Html.GetSidebarUrl(Context, "/admin/watcher", "Watcher (beta)") - @Html.GetSidebarUrl(Context, "/admin/radarr", "Radarr (beta)") - @Html.GetSidebarUrl(Context, "/admin/sonarr", "Sonarr") - @Html.GetSidebarUrl(Context, "/admin/sickrage", "SickRage") - @Html.GetSidebarUrl(Context, "/admin/headphones", "Headphones (beta)") - @Html.GetSidebarUrl(Context, "/admin/newsletter", "Newsletter Settings") - -
    - @Html.GetSidebarUrl(Context, "/admin/logs", "Logs") - @Html.GetSidebarUrl(Context, "/admin/status", "Status") - @Html.GetSidebarUrl(Context, "/admin/scheduledjobs", "Scheduled Jobs") - @Html.GetSidebarUrl(Context, "/admin/faultqueue", "Request Fault Queue") + + + @Html.GetSidebarUrl(Context, "/admin/logs", "Logs", "fa fa-edit") + @Html.GetSidebarUrl(Context, "/admin/status", "Status", "fa fa-dashboard") + @Html.GetSidebarUrl(Context, "/admin/scheduledjobs", "Scheduled Jobs", "fa fa-hand-spock-o") + @Html.GetSidebarUrl(Context, "/admin/faultqueue", "Request Fault Queue", "fa fa-history")
    - \ No newline at end of file + + + + + \ No newline at end of file From b7e26a3deec411e627b779692c1ad2ae822de014 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Wed, 25 Jan 2017 11:50:07 +0000 Subject: [PATCH 2/4] Potential Fix for #985 --- Ombi.Services/Notification/NotificationEngine.cs | 8 ++++++-- Ombi.Store/RequestedModel.cs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Ombi.Services/Notification/NotificationEngine.cs b/Ombi.Services/Notification/NotificationEngine.cs index 7a119cca1..dbf6d4dc0 100644 --- a/Ombi.Services/Notification/NotificationEngine.cs +++ b/Ombi.Services/Notification/NotificationEngine.cs @@ -152,8 +152,12 @@ namespace Ombi.Services.Notification var users = UserHelper.GetUsersWithFeature(Features.RequestAddedNotification).ToList(); Log.Debug("Notifying Users Count {0}", users.Count); - var selectedUsers = users.Select(x => x.Username).Intersect(model.RequestedUsers, StringComparer.CurrentCultureIgnoreCase); - foreach (var user in selectedUsers) + var userNamesWithFeature = users.Select(x => x.Username).ToList(); + + + 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) { Log.Info("Notifying user {0}", user); if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase)) diff --git a/Ombi.Store/RequestedModel.cs b/Ombi.Store/RequestedModel.cs index 89c30e21e..6d0342a14 100644 --- a/Ombi.Store/RequestedModel.cs +++ b/Ombi.Store/RequestedModel.cs @@ -65,7 +65,7 @@ namespace Ombi.Store u.Add(RequestedBy); } - if (RequestedUsers.Any()) + if (RequestedUsers != null && RequestedUsers.Any()) { u.AddRange(RequestedUsers.Where(requestedUser => requestedUser != RequestedBy)); } From 9f7523d7c58a86faef39dd06d0de65861eb5789d Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Wed, 25 Jan 2017 11:52:11 +0000 Subject: [PATCH 3/4] Possible issue with the empty username --- Ombi.UI/Modules/BaseModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ombi.UI/Modules/BaseModule.cs b/Ombi.UI/Modules/BaseModule.cs index 989e3ee1a..f3608d4f4 100644 --- a/Ombi.UI/Modules/BaseModule.cs +++ b/Ombi.UI/Modules/BaseModule.cs @@ -121,7 +121,7 @@ namespace Ombi.UI.Modules } catch (Exception) { - return string.Empty; + return "Unknown User Error"; } } return _username; From 3d2209d163a14a52b5144b93d35cb38370d7f60f Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Wed, 25 Jan 2017 12:03:55 +0000 Subject: [PATCH 4/4] more small tweaks around the username/alias --- Ombi.Core/SecurityExtensions.cs | 8 ++++++-- Ombi.Core/Users/UserHelperModel.cs | 4 ++++ Ombi.Services/Notification/NotificationEngine.cs | 10 ++++++++-- Ombi.Store/Models/PlexUsers.cs | 1 + Ombi.UI/Modules/BaseModule.cs | 5 +++-- Ombi.UI/Modules/UserLoginModule.cs | 2 +- 6 files changed, 23 insertions(+), 7 deletions(-) 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);