Skip to content

Commit 894644a

Browse files
authored
fix: Check Content for null, use DependentRules, disallow empty localization values (#413)
#375
1 parent 669c7a5 commit 894644a

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Localizations/LocalizationDtoValidator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public LocalizationDtoValidator(int maximumLength = 255)
2121
RuleFor(x => x).NotNull();
2222

2323
RuleFor(x => x.Value)
24+
.NotEmpty()
2425
.NotNull()
2526
.MaximumLength(maximumLength);
2627

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs

+13-7
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,19 @@ public CreateDialogCommandValidator(
6363
.IsInEnum();
6464

6565
RuleFor(x => x.Content)
66-
.UniqueBy(x => x.Type)
67-
.Must(content => DialogContentType.RequiredTypes
68-
.All(requiredContent => content
69-
.Select(x => x.Type)
70-
.Contains(requiredContent)))
71-
.WithMessage($"Dialog must contain the following content: [{string.Join(", ", DialogContentType.RequiredTypes)}].")
72-
.ForEach(x => x.SetValidator(contentValidator));
66+
.NotNull()
67+
.DependentRules(() =>
68+
{
69+
RuleFor(x => x.Content)
70+
.UniqueBy(x => x.Type)
71+
.Must(content => DialogContentType.RequiredTypes
72+
.All(requiredContent => content
73+
.Select(x => x.Type)
74+
.Contains(requiredContent)))
75+
.WithMessage("Dialog must contain the following content: " +
76+
$"[{string.Join(", ", DialogContentType.RequiredTypes)}].")
77+
.ForEach(x => x.SetValidator(contentValidator));
78+
});
7379

7480
RuleForEach(x => x.SearchTags)
7581
.SetValidator(searchTagValidator);

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs

+13-7
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,19 @@ public UpdateDialogDtoValidator(
5656
.IsInEnum();
5757

5858
RuleFor(x => x.Content)
59-
.UniqueBy(x => x.Type)
60-
.Must(content => DialogContentType.RequiredTypes
61-
.All(requiredContent => content
62-
.Select(x => x.Type)
63-
.Contains(requiredContent)))
64-
.WithMessage($"Dialog must contain the following content: [{string.Join(", ", DialogContentType.RequiredTypes)}].")
65-
.ForEach(x => x.SetValidator(contentValidator));
59+
.NotNull()
60+
.DependentRules(() =>
61+
{
62+
RuleFor(x => x.Content)
63+
.UniqueBy(x => x.Type)
64+
.Must(content => DialogContentType.RequiredTypes
65+
.All(requiredContent => content
66+
.Select(x => x.Type)
67+
.Contains(requiredContent)))
68+
.WithMessage("Dialog must contain the following content: " +
69+
$"[{string.Join(", ", DialogContentType.RequiredTypes)}].")
70+
.ForEach(x => x.SetValidator(contentValidator));
71+
});
6672

6773
RuleFor(x => x.SearchTags)
6874
.UniqueBy(x => x.Value, StringComparer.InvariantCultureIgnoreCase)

0 commit comments

Comments
 (0)