1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-19 17:32:38 +01:00

Fixed: Validation for Movie Info language

This commit is contained in:
Bogdan 2024-08-18 00:21:04 +03:00
parent 0ad4d7ea9a
commit c9f28fdc4f
5 changed files with 26 additions and 12 deletions

View File

@ -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') }
]}
/>
</FormGroup>

View File

@ -5,4 +5,6 @@ export interface UiSettings {
longDateFormat: string;
timeFormat: string;
movieRuntimeFormat: string;
movieInfoLanguage: number;
uiLanguage: number;
}

View File

@ -177,6 +177,8 @@ public static List<Language> All
}
}
private static readonly Dictionary<int, Language> Lookup = All.ToDictionary(v => v.Id);
public static Language FindById(int id)
{
if (id == 0)
@ -184,9 +186,7 @@ public static Language FindById(int id)
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));
}

View File

@ -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",

View File

@ -19,17 +19,21 @@ public UiConfigController(IConfigFileProvider configFileProvider, IConfigService
{
_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");
.GreaterThanOrEqualTo(1)
.WithMessage("The UI Language value cannot be less than 1");
SharedValidator.RuleFor(c => c.UILanguage)
.Must(value => Language.All.Any(o => o.Id == value))
.WithMessage("Invalid UI Language ID");
}
[RestPutById]