From 9a1b0c49eca72d8e3db7ea959e3b6f4f5b69a235 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 4 Mar 2017 14:18:53 +0000 Subject: [PATCH] Fixed #1189 --- Ombi.Helpers/StringHasher.cs | 4 +++ Ombi.UI/Modules/LayoutModule.cs | 7 ++++ Ombi.UI/Modules/RequestsModule.cs | 54 ++++++++++++++++++----------- Ombi.UI/Views/Requests/Index.cshtml | 2 +- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/Ombi.Helpers/StringHasher.cs b/Ombi.Helpers/StringHasher.cs index 40228616c..64f089172 100644 --- a/Ombi.Helpers/StringHasher.cs +++ b/Ombi.Helpers/StringHasher.cs @@ -35,6 +35,10 @@ namespace Ombi.Helpers { public static string CalcuateMd5Hash(string input) { + if (string.IsNullOrEmpty(input)) + { + return string.Empty; + } using (var md5 = MD5.Create()) { var inputBytes = Encoding.UTF8.GetBytes(input); diff --git a/Ombi.UI/Modules/LayoutModule.cs b/Ombi.UI/Modules/LayoutModule.cs index 4f7d3c894..16b6f93e2 100644 --- a/Ombi.UI/Modules/LayoutModule.cs +++ b/Ombi.UI/Modules/LayoutModule.cs @@ -128,6 +128,13 @@ namespace Ombi.UI.Modules { var user = UserHelper.GetUser(Username); var hashed = StringHasher.CalcuateMd5Hash(user.EmailAddress); + if (string.IsNullOrEmpty(hashed)) + { + return Response.AsJson(new JsonResponseModel + { + Result = false + }); + } return Response.AsJson(new JsonResponseModel { diff --git a/Ombi.UI/Modules/RequestsModule.cs b/Ombi.UI/Modules/RequestsModule.cs index ae6c7778d..cf14ea26f 100644 --- a/Ombi.UI/Modules/RequestsModule.cs +++ b/Ombi.UI/Modules/RequestsModule.cs @@ -33,6 +33,7 @@ using Nancy; using Nancy.Responses.Negotiation; using NLog; using Ombi.Api.Interfaces; +using Ombi.Api.Models.Sonarr; using Ombi.Core; using Ombi.Core.Models; using Ombi.Core.SettingModels; @@ -104,7 +105,8 @@ namespace Ombi.UI.Modules Post["/changeavailability", true] = async (x, ct) => await ChangeRequestAvailability((int)Request.Form.Id, (bool)Request.Form.Available); - Post["/changeRootFolder", true] = async (x, ct) => await ChangeRootFolder((int) Request.Form.requestId, (int) Request.Form.rootFolderId); + Post["/changeRootFoldertv", true] = async (x, ct) => await ChangeRootFolder(RequestType.TvShow, (int)Request.Form.requestId, (int)Request.Form.rootFolderId); + Post["/changeRootFoldermovie", true] = async (x, ct) => await ChangeRootFolder(RequestType.Movie, (int)Request.Form.requestId, (int)Request.Form.rootFolderId); Get["/UpdateFilters", true] = async (x, ct) => await GetFilterAndSortSettings(); } @@ -171,7 +173,7 @@ namespace Ombi.UI.Modules if (result != null) { qualities = - result.list.Select(x => new QualityModel {Id = x._id, Name = x.label}).ToList(); + result.list.Select(x => new QualityModel { Id = x._id, Name = x.label }).ToList(); } } catch (Exception e) @@ -188,7 +190,7 @@ namespace Ombi.UI.Modules rootFolders = rootFoldersResult.Select( - x => new RootFolderModel {Id = x.id.ToString(), Path = x.path, FreeSpace = x.freespace}) + x => new RootFolderModel { Id = x.id.ToString(), Path = x.path, FreeSpace = x.freespace }) .ToList(); var result = await Cache.GetOrSetAsync(CacheKeys.RadarrQualityProfiles, async () => @@ -204,7 +206,7 @@ namespace Ombi.UI.Modules } } - + var canManageRequest = Security.HasAnyPermissions(User, Permissions.Administrator, Permissions.ManageRequests); var viewModel = dbMovies.Select(movie => new RequestViewModel { @@ -265,14 +267,14 @@ namespace Ombi.UI.Modules }); qualities = result.Select(x => new QualityModel { Id = x.id.ToString(), Name = x.name }).ToList(); - - var rootFoldersResult =await Cache.GetOrSetAsync(CacheKeys.SonarrRootFolders, async () => - { - return await Task.Run(() => SonarrApi.GetRootFolders(sonarrSettings.ApiKey, sonarrSettings.FullUri)); - }); - - rootFolders = rootFoldersResult.Select(x => new RootFolderModel { Id = x.id.ToString(), Path = x.path, FreeSpace = x.freespace}).ToList(); - } + + var rootFoldersResult = await Cache.GetOrSetAsync(CacheKeys.SonarrRootFolders, async () => + { + return await Task.Run(() => SonarrApi.GetRootFolders(sonarrSettings.ApiKey, sonarrSettings.FullUri)); + }); + + rootFolders = rootFoldersResult.Select(x => new RootFolderModel { Id = x.id.ToString(), Path = x.path, FreeSpace = x.freespace }).ToList(); + } else { var sickRageSettings = await SickRageSettings.GetSettingsAsync(); @@ -318,7 +320,7 @@ namespace Ombi.UI.Modules TvSeriesRequestType = tv.SeasonsRequested, Qualities = qualities.ToArray(), Episodes = tv.Episodes.ToArray(), - RootFolders = rootFolders.ToArray(), + RootFolders = rootFolders.ToArray(), HasRootFolders = rootFolders.Any(), CurrentRootPath = sonarrSettings.Enabled ? GetRootPath(tv.RootFolderSelected, sonarrSettings).Result : null }).ToList(); @@ -555,11 +557,21 @@ namespace Ombi.UI.Modules return Response.AsJson(vm); } - private async Task ChangeRootFolder(int id, int rootFolderId) + private async Task ChangeRootFolder(RequestType type, int id, int rootFolderId) { - // Get all root folders - var settings = await SonarrSettings.GetSettingsAsync(); - var rootFolders = SonarrApi.GetRootFolders(settings.ApiKey, settings.FullUri); + var rootFolders = new List(); + if (type == RequestType.TvShow) + { + // Get all root folders + var settings = await SonarrSettings.GetSettingsAsync(); + rootFolders = SonarrApi.GetRootFolders(settings.ApiKey, settings.FullUri); + } + else + { + + var settings = await Radarr.GetSettingsAsync(); + rootFolders = RadarrApi.GetRootFolders(settings.ApiKey, settings.FullUri); + } // Get Request var allRequests = await Service.GetAllAsync(); @@ -567,7 +579,7 @@ namespace Ombi.UI.Modules if (request == null) { - return Response.AsJson(new JsonResponseModel {Result = false}); + return Response.AsJson(new JsonResponseModel { Result = false }); } foreach (var folder in rootFolders) @@ -581,7 +593,7 @@ namespace Ombi.UI.Modules await Service.UpdateRequestAsync(request); - return Response.AsJson(new JsonResponseModel {Result = true}); - } - } + return Response.AsJson(new JsonResponseModel { Result = true }); + } + } } diff --git a/Ombi.UI/Views/Requests/Index.cshtml b/Ombi.UI/Views/Requests/Index.cshtml index 710339fe4..d6637530f 100644 --- a/Ombi.UI/Views/Requests/Index.cshtml +++ b/Ombi.UI/Views/Requests/Index.cshtml @@ -281,7 +281,7 @@ -
+ {{#if_eq hasRootFolders true}}