From c9f28fdc4f078bfec776d84d2917494ad45563aa Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 18 Aug 2024 00:21:04 +0300 Subject: [PATCH] Fixed: Validation for Movie Info language --- frontend/src/Settings/UI/UISettings.js | 7 ++++++ frontend/src/typings/UiSettings.ts | 2 ++ src/NzbDrone.Core/Languages/Language.cs | 6 ++--- src/NzbDrone.Core/Localization/Core/en.json | 1 + .../Config/UiConfigController.cs | 22 +++++++++++-------- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/frontend/src/Settings/UI/UISettings.js b/frontend/src/Settings/UI/UISettings.js index db6458c4f..ae2c27f12 100644 --- a/frontend/src/Settings/UI/UISettings.js +++ b/frontend/src/Settings/UI/UISettings.js @@ -241,6 +241,13 @@ class UISettings extends Component { helpTextWarning={translate('MovieInfoLanguageHelpTextWarning')} onChange={onInputChange} {...settings.movieInfoLanguage} + errors={ + languages.some((language) => language.key === settings.movieInfoLanguage.value) ? + settings.movieInfoLanguage.errors : + [ + ...settings.movieInfoLanguage.errors, + { message: translate('InvalidMovieInfoLanguageLanguage') } + ]} /> diff --git a/frontend/src/typings/UiSettings.ts b/frontend/src/typings/UiSettings.ts index 7c642cbd0..97f79f849 100644 --- a/frontend/src/typings/UiSettings.ts +++ b/frontend/src/typings/UiSettings.ts @@ -5,4 +5,6 @@ export interface UiSettings { longDateFormat: string; timeFormat: string; movieRuntimeFormat: string; + movieInfoLanguage: number; + uiLanguage: number; } diff --git a/src/NzbDrone.Core/Languages/Language.cs b/src/NzbDrone.Core/Languages/Language.cs index edd189c57..ce127d391 100644 --- a/src/NzbDrone.Core/Languages/Language.cs +++ b/src/NzbDrone.Core/Languages/Language.cs @@ -177,6 +177,8 @@ namespace NzbDrone.Core.Languages } } + private static readonly Dictionary Lookup = All.ToDictionary(v => v.Id); + public static Language FindById(int id) { if (id == 0) @@ -184,9 +186,7 @@ namespace NzbDrone.Core.Languages return Unknown; } - var language = All.FirstOrDefault(v => v.Id == id); - - if (language == null) + if (!Lookup.TryGetValue(id, out var language)) { throw new ArgumentException("ID does not match a known language", nameof(id)); } diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index 584de3460..10a273dc3 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -797,6 +797,7 @@ "InteractiveSearchResultsFailedErrorMessage": "Search failed because its {message}. Try refreshing the movie info and verify the necessary information is present before searching again.", "Interval": "Interval", "InvalidFormat": "Invalid Format", + "InvalidMovieInfoLanguageLanguage": "Your Movie Info Language is set to an invalid value, correct it and save your settings", "InvalidUILanguage": "Your UI is set to an invalid language, correct it and save your settings", "KeepAndUnmonitorMovie": "Keep and Unmonitor Movie", "KeyboardShortcuts": "Keyboard Shortcuts", diff --git a/src/Radarr.Api.V3/Config/UiConfigController.cs b/src/Radarr.Api.V3/Config/UiConfigController.cs index e45e96758..4c3c1f119 100644 --- a/src/Radarr.Api.V3/Config/UiConfigController.cs +++ b/src/Radarr.Api.V3/Config/UiConfigController.cs @@ -19,17 +19,21 @@ namespace Radarr.Api.V3.Config { _configFileProvider = configFileProvider; - SharedValidator.RuleFor(c => c.UILanguage).Custom((value, context) => - { - if (!Language.All.Any(o => o.Id == value)) - { - context.AddFailure("Invalid UI Language ID"); - } - }); + SharedValidator.RuleFor(c => c.MovieInfoLanguage) + .GreaterThanOrEqualTo(1) + .WithMessage("The Movie Info Language value cannot be less than 1"); + + SharedValidator.RuleFor(c => c.MovieInfoLanguage) + .Must(value => Language.All.Any(o => o.Id == value)) + .WithMessage("Invalid Movie Info Language ID"); + + SharedValidator.RuleFor(c => c.UILanguage) + .GreaterThanOrEqualTo(1) + .WithMessage("The UI Language value cannot be less than 1"); SharedValidator.RuleFor(c => c.UILanguage) - .GreaterThanOrEqualTo(1) - .WithMessage("The UI Language value cannot be less than 1"); + .Must(value => Language.All.Any(o => o.Id == value)) + .WithMessage("Invalid UI Language ID"); } [RestPutById]