-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support backend validation for multiple data models #619
Conversation
Do you want me to review the whole thing or just the Would I think we have to have the implicit operator since we're doing |
I want any feedback I can get, apart from "Hi! I made a test app, how do I test this new behavior", because it isn't complete yet. |
9b19779
to
a02524d
Compare
src/Altinn.App.Core/Internal/Validation/ValidationService.cs
Dismissed
Show dismissed
Hide dismissed
src/Altinn.App.Core/Internal/Validation/ValidationService.cs
Dismissed
Show dismissed
Hide dismissed
src/Altinn.App.Core/Internal/Validation/ValidationService.cs
Dismissed
Show dismissed
Hide dismissed
src/Altinn.App.Core/Internal/Validation/ValidationService.cs
Dismissed
Show dismissed
Hide dismissed
src/Altinn.App.Core/Internal/Validation/ValidationService.cs
Dismissed
Show dismissed
Hide dismissed
[Route("{org}/{app}/api/validationconfig/{id}")] | ||
public ActionResult GetValidationConfiguration(string org, string app, string id) | ||
[Route("{org}/{app}/api/validationconfig/{dataTypeId}")] | ||
public ActionResult GetValidationConfiguration(string org, string app, string dataTypeId) |
Check failure
Code scanning / SonarCloud
ModelState.IsValid should be called in controller actions
Support the new interface for ValidationService Rewrite RequiredValidator to use the new interface to support muliple data models
3c74bf2
to
edb533c
Compare
93009a5
to
34863a2
Compare
0ba8554
to
7fd0b18
Compare
Da virker alle eksisterende tester og det er egentlig klart for review. Har ikke begynt å skrive tester for den nye funksjonaliteten ennå. Har inkludert |
f07f795
to
0161134
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made one pass, will make another once tests come in 😄
src/Altinn.App.Core/Internal/Expressions/ILayoutEvaluatorStateInitializer.cs
Show resolved
Hide resolved
src/Altinn.App.Core/Internal/Expressions/LayoutEvaluatorStateInitializer.cs
Show resolved
Hide resolved
} | ||
|
||
/// <inheritdoc /> | ||
public DataElement DefaultDataElement { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the usecase for this being public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing! (at least that I can think of)
I needed it to get the data element for ValidationIssue
, but it did not solve the full issue, so I added LayoutEvaluatorState.GetDataElement(ModelBinding field)
instead. I should probably just move that implementation into the data model and not rely on the _instanceContext
Also enforce that CachedFormDataAccessor verifies that it only runs in one request (to protect against any cross user leakage)
catch (Exception e) | ||
{ | ||
using var jsonDocument = JsonDocument.Parse(data); | ||
|
||
testCase.Name = jsonDocument.RootElement.GetProperty("name").GetString(); | ||
testCase.ExpectsFailure = jsonDocument.RootElement.TryGetProperty("expectsFailure", out var expectsFailure) | ||
? expectsFailure.GetString() | ||
: null; | ||
testCase.ParsingException = e; | ||
} |
Check notice
Code scanning / CodeQL
Generic catch clause Note test
var deserializedObject = JsonSerializer.Deserialize(jsonString, dynamicType); | ||
var numbersProperty = dynamicType.GetProperty("Numbers")!.GetValue(deserializedObject) as List<double?>; | ||
|
||
numbersProperty.Should().NotBeNull(); |
Check warning
Code scanning / CodeQL
Dereferenced variable may be null Warning test
numbersProperty
this
test/Altinn.App.Core.Tests/LayoutExpressions/TestUtilities/DynamicClassBuilderChatGPTTests.cs
Dismissed
Show dismissed
Hide dismissed
test/Altinn.App.Core.Tests/LayoutExpressions/TestUtilities/DynamicClassBuilderTests.cs
Dismissed
Show dismissed
Hide dismissed
And ressurect docs on DataModelClass from removed IDataModelAccessor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM 👍
In terms of public
vs internal
- I don't think we should add more public members unless we have an agreed-upon use-case with consumers already. Didn't seem like that was the case, so according to previous discussions I think those should be made internal. If not, I think we should revisit the decision in the team, so we have shared understanding
src/Altinn.App.Core/Internal/Expressions/LayoutEvaluatorStateInitializer.cs
Outdated
Show resolved
Hide resolved
…sues in initialization
Quality Gate passedIssues Measures |
var validationIssue = new ValidationIssue | ||
{ | ||
Field = resolvedField.Field, | ||
DataElementId = resolvedField.DataType, | ||
Severity = validation.Severity ?? ValidationIssueSeverity.Error, | ||
CustomTextKey = validation.Message, | ||
Code = validation.Message, | ||
Source = ValidationIssueSources.Expression, | ||
}; | ||
validationIssues.Add(validationIssue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DataElementId
should not be set to the data type id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that would not be very helpful. Good catch!
Quality Gate passedIssues Measures |
New type
record struct ModelBinding
to replace the current use ofstring
in a way that ensures a structured way of storing the optional reference to an extra data model.I'm pretty happy about the minimal changes required for everything but the actual lookup of data to work.
Remaining work
IDataModel
implementations aware of multiple data models so that lookups don't just ignore them.IDataClient
registered asscoped
in DI? Or do we have other options?Related Issue(s)
Verification
Documentation