Skip to content
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

Multipart form data #329

Merged
merged 24 commits into from
Dec 13, 2023
Merged

Multipart form data #329

merged 24 commits into from
Dec 13, 2023

Conversation

ivarne
Copy link
Member

@ivarne ivarne commented Oct 24, 2023

Work in process

Builds on #328, so temporary the target branch is different

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

@ivarne ivarne force-pushed the ivarne/multipart-form-data branch 2 times, most recently from 792ae43 to 319ce56 Compare October 25, 2023 20:45
@ivarne ivarne marked this pull request as ready for review October 26, 2023 07:09
@ivarne ivarne requested a review from RonnyB71 October 26, 2023 07:54
@ivarne ivarne self-assigned this Oct 26, 2023
@ivarne ivarne added this to the 8.0.0 milestone Oct 26, 2023
@ivarne ivarne linked an issue Oct 26, 2023 that may be closed by this pull request
@ivarne ivarne requested a review from tjololo October 26, 2023 07:57
@ivarne ivarne changed the base branch from ivarne/warning-fixes to v8 October 26, 2023 07:58
@ivarne ivarne changed the base branch from v8 to main October 26, 2023 07:59
@ivarne ivarne changed the base branch from main to v8 October 26, 2023 07:59
@@ -332,19 +330,19 @@

if (appLogic == null)
{
_logger.LogError($"Could not determine if {dataType} requires app logic for application {org}/{app}");
_logger.LogError("Could not determine if {dataType} requires app logic for application {org}/{app}", dataType, org, app);

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
@@ -332,19 +330,19 @@

if (appLogic == null)
{
_logger.LogError($"Could not determine if {dataType} requires app logic for application {org}/{app}");
_logger.LogError("Could not determine if {dataType} requires app logic for application {org}/{app}", dataType, org, app);

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
@@ -332,19 +330,19 @@

if (appLogic == null)
{
_logger.LogError($"Could not determine if {dataType} requires app logic for application {org}/{app}");
_logger.LogError("Could not determine if {dataType} requires app logic for application {org}/{app}", dataType, org, app);

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
Comment on lines +38 to +43
catch (Exception e)
{
logger.LogError(e, "Unable to determine changed fields");
return null;
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
Copy link
Member

@tjololo tjololo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! :godmode:

Copy link
Member Author

@ivarne ivarne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fikset noen av kommentarene

Copy link
Member

@tjololo tjololo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing I missed, but looks good. Lets get this from review to test 🙁

@tjololo
Copy link
Member

tjololo commented Nov 29, 2023

Can we add some test for the bad requests. Like that the first part not having name=dataModel and so on?

@tjololo tjololo added the feature Label Pull requests with new features. Used when generation releasenotes label Nov 29, 2023
@olemartinorg
Copy link
Contributor

I tried this against frontend v4/main now, and it's not quite there. Should be the same with v3, as I haven't tested with the form data rewrite in frontend yet.

  1. A feature flag, multiPartSave is expected to be returned in applicationmetadata for frontend to start sending multipart changes. I added this manually in FrontendFeatues.cs when testing.
  2. Frontend sends name="dataModel", not name=dataModel (note the quotes). I manually added some quotes in ModelDeserializer when testing.
  3. The whole data model seems to be returned, not the metadata combined with changedFields, as is expected in v3. Be sure not to conflate this task with Return the full data model to app-frontend after processing a write operation #316, as that's an entirely different beast. Also, returning the entire data model on the top level might not be what we want, as it would be nice to include validation messages etc as well in the future.

For some reason backend returns 303 See Other when datamodel updates are availible.
This is a redirect code and crashed the tests as no Location header was set.
@olemartinorg
Copy link
Contributor

Tested again now, and it's all working against v4/main as far as I can tell! 🙌

Copy link
Member

@tjololo tjololo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a look at the code smells/codeql warnings, and try to add the last few percentages of testscoverage and we should be good to go as far as I can see

src/Altinn.App.Api/Controllers/DataController.cs Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Dec 8, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

67.7% 67.7% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@ivarne ivarne merged commit db957c0 into v8 Dec 13, 2023
8 of 10 checks passed
@ivarne ivarne deleted the ivarne/multipart-form-data branch December 13, 2023 11:57
Instance virutalInstance = new Instance() { InstanceOwner = owner };
await _dataProcessor.ProcessDataRead(virutalInstance, null, appModel);
Instance virtualInstance = new Instance() { InstanceOwner = owner };
await ProcessAllDataWrite(virtualInstance, appModel);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjololo This was not good!!!

Happens to be OK, as ProcessAllDataWrite actually calls processDataRead 😊 ☺️ I'll fix in the next rewrite that uses json patch

ivarne added a commit that referenced this pull request Dec 20, 2023
@ivarne ivarne mentioned this pull request Dec 20, 2023
5 tasks
ivarne added a commit that referenced this pull request Jan 22, 2024
* Revert Multipart form data #329 on PUT endpoint

* Add JsonPatch and create a new PATCH endpoint for updating form data

* Fix a few SonarCloud warnings

* Start work on new validation

Improve GetJsonPath(Expression) and fix some sonarcloud issues

Improve test coverage

Full validation rewrite complete and existing tests work

Probably still some issues and test coverage was spoty so more tests needs to be written.

Make IInstanceValidator obsolete

Add DataType as input to validators

Fix a few issues to prepare for tests of expressions

Add more tests

* Fix sonar cloud issues

* Rename to get more consistent naming

* Clanup DataType/TaskId to allow *

Also comment out KeyedService fetching

* Fix more sonarcloud issues

* Registrer new validators in DI container

* Remove dead code

* Adjust interface and add a few tests

* Add object? previousData to IDataProcessor

* Cleanup and more tests

* OptionsSource doesn't really need a label to work. In recent fronted versions, this label can also be an expression, so parsing fails when this is expected to be a string.

* Removing the requirement for a 'pageRef' property on Summary components. Frontend doesn't use this anymore, and disallows rendering Summary components with it.

* Allowing attachments to be deleted (attachments don't have AppLogic)

* ValidationIssue.Severity is an int in json

Improve handeling of errors in PATCH endpoint
code style fixes

* Initialize lists for concistency in frontend after patch

also add tests

* Fix issues with list initialization and prettify tests

* Add test to verify that PATCH initializes arrays (as xml serialization does)

* Read json configuration file for api tests

* Set empty strings to null in patch endpoint

xml serializing does always preserve empty string when using attributes and [XmlText].

* Apply suggestions from code review

Co-authored-by: Vemund Gaukstad <[email protected]>

* Remove caching logic for CanTaskBeEnded

* Improve description on validationsource

* Rename ShouldRun to HasRelevantChanges

fix style issues

* Fix dataProcessorRewriter

* Add genericDataProcessor

* Fix a few codestyle issues

* Making some validator sources match those used on the frontend

* Fix tests after validator source name change

* Adding support for explicit repeating group components (new in frontend v4)

---------

Co-authored-by: Ole Martin Handeland <[email protected]>
Co-authored-by: Vemund Gaukstad <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Label Pull requests with new features. Used when generation releasenotes
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Support multipart saving
3 participants