From cc503e6e988d860144163a6861f42bc6fa540fac Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Fri, 27 Dec 2024 10:35:42 +0100 Subject: [PATCH 1/4] fix: ensure stream is closed after being read from app-dev's GetDefinitions method --- .../Controllers/ProcessModelingController.cs | 12 +++++------- .../GitRepository/AltinnAppGitRepository.cs | 12 +++++++++++- .../EndpointNameSyncEvaluator.cs | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/backend/src/Designer/Controllers/ProcessModelingController.cs b/backend/src/Designer/Controllers/ProcessModelingController.cs index 0048b227bc0..7e8953ddee4 100644 --- a/backend/src/Designer/Controllers/ProcessModelingController.cs +++ b/backend/src/Designer/Controllers/ProcessModelingController.cs @@ -57,21 +57,19 @@ public async Task UpsertProcessDefinitionAndNotify(string org, st new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) : null; - Stream stream = content.OpenReadStream(); - + string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext); + var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, repo, developer); + + await using Stream stream = content.OpenReadStream(); try { - await Guard.AssertValidXmlStreamAndRewindAsync(stream); + await _processModelingService.SaveProcessDefinitionAsync(editingContext, stream, cancellationToken); } catch (ArgumentException) { return BadRequest("BPMN file is not valid XML"); } - string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext); - var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, repo, developer); - await _processModelingService.SaveProcessDefinitionAsync(editingContext, stream, cancellationToken); - if (metadataObject?.TaskIdChange is not null) { await _mediator.Publish(new ProcessTaskIdChangedEvent diff --git a/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs b/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs index b0c3c5ed527..0a190997f58 100644 --- a/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs +++ b/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs @@ -816,8 +816,18 @@ public Stream GetProcessDefinitionFile() public Definitions GetDefinitions() { Stream processDefinitionStream = GetProcessDefinitionFile(); + + MemoryStream memoryStream = new MemoryStream(); + processDefinitionStream.CopyTo(memoryStream); + + memoryStream.Position = 0; + XmlSerializer serializer = new(typeof(Definitions)); - return (Definitions)serializer.Deserialize(processDefinitionStream); + Definitions definitions = (Definitions)serializer.Deserialize(memoryStream); + + processDefinitionStream.Close(); + + return definitions; } /// diff --git a/backend/src/Designer/Middleware/UserRequestSynchronization/Services/RequestSyncEvaluators/EndpointNameSyncEvaluator.cs b/backend/src/Designer/Middleware/UserRequestSynchronization/Services/RequestSyncEvaluators/EndpointNameSyncEvaluator.cs index 87c5e76d1d2..36cc15d842b 100644 --- a/backend/src/Designer/Middleware/UserRequestSynchronization/Services/RequestSyncEvaluators/EndpointNameSyncEvaluator.cs +++ b/backend/src/Designer/Middleware/UserRequestSynchronization/Services/RequestSyncEvaluators/EndpointNameSyncEvaluator.cs @@ -54,6 +54,7 @@ public class EndpointNameSyncEvaluator : IRequestSyncEvaluator nameof(ProcessModelingController.AddDataTypeToApplicationMetadata), nameof(ProcessModelingController.DeleteDataTypeFromApplicationMetadata), nameof(ProcessModelingController.UpsertProcessDefinitionAndNotify), + nameof(ProcessModelingController.ProcessDataTypesChangedNotify), nameof(ProcessModelingController.SaveProcessDefinitionFromTemplate) ) }, From 24ef2fcd374e5180e0f45ab476bf64429be476e9 Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Fri, 27 Dec 2024 12:56:03 +0100 Subject: [PATCH 2/4] ensure formdesigner is rerendered if layoutSetsExtended is invalidated --- frontend/packages/ux-editor/src/App.tsx | 3 +++ .../ux-editor/src/containers/FormDesignerToolbar.tsx | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/packages/ux-editor/src/App.tsx b/frontend/packages/ux-editor/src/App.tsx index b9bc445c878..b7a53f0c972 100644 --- a/frontend/packages/ux-editor/src/App.tsx +++ b/frontend/packages/ux-editor/src/App.tsx @@ -11,6 +11,7 @@ import { cleanupStaleLocalStorageKeys } from './utils/localStorageUtils'; import { usePreviewContext } from 'app-development/contexts/PreviewContext'; import { FormDesignerToolbar } from '@altinn/ux-editor/containers/FormDesignerToolbar'; import { useLayoutSetsQuery } from 'app-shared/hooks/queries/useLayoutSetsQuery'; +import { useLayoutSetsExtendedQuery } from 'app-shared/hooks/queries/useLayoutSetsExtendedQuery'; /** * This is the main React component responsible for controlling @@ -52,6 +53,7 @@ export function App() { org, app, ); + const { status: layoutSetsExtendedStatus } = useLayoutSetsExtendedQuery(org, app); const { status: dataModelStatus, isError: dataModelFetchedError } = useDataModelMetadataQuery({ org, app, @@ -69,6 +71,7 @@ export function App() { const componentIsPending = widgetsStatus === 'pending' || layoutSetsStatus === 'pending' || + layoutSetsExtendedStatus === 'pending' || dataModelStatus === 'pending' || textsStatus === 'pending'; const componentIsReady = diff --git a/frontend/packages/ux-editor/src/containers/FormDesignerToolbar.tsx b/frontend/packages/ux-editor/src/containers/FormDesignerToolbar.tsx index 370773d5776..0b0ce9ea495 100644 --- a/frontend/packages/ux-editor/src/containers/FormDesignerToolbar.tsx +++ b/frontend/packages/ux-editor/src/containers/FormDesignerToolbar.tsx @@ -1,14 +1,14 @@ import React from 'react'; import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams'; import classes from './FormDesignerToolbar.module.css'; -import { useLayoutSetsQuery } from 'app-shared/hooks/queries/useLayoutSetsQuery'; import { LayoutSetsContainer } from '../components/Elements/LayoutSetsContainer'; import { ToggleAddComponentPoc } from './DesignView/AddItem/ToggleAddComponentPoc'; +import { useLayoutSetsExtendedQuery } from 'app-shared/hooks/queries/useLayoutSetsExtendedQuery'; export const FormDesignerToolbar = () => { const { org, app } = useStudioEnvironmentParams(); - const layoutSetsQuery = useLayoutSetsQuery(org, app); - const layoutSetNames = layoutSetsQuery?.data?.sets; + const { data: layoutSetsExtended } = useLayoutSetsExtendedQuery(org, app); + const layoutSetNames = layoutSetsExtended?.sets; return (
From d6690b754d09dfca31420a92d99d8168a86eede3 Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Fri, 27 Dec 2024 12:59:29 +0100 Subject: [PATCH 3/4] dispose streams --- .../Designer/Controllers/ProcessModelingController.cs | 2 +- .../GitRepository/AltinnAppGitRepository.cs | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/backend/src/Designer/Controllers/ProcessModelingController.cs b/backend/src/Designer/Controllers/ProcessModelingController.cs index 7e8953ddee4..df5e88e4e8f 100644 --- a/backend/src/Designer/Controllers/ProcessModelingController.cs +++ b/backend/src/Designer/Controllers/ProcessModelingController.cs @@ -59,7 +59,7 @@ public async Task UpsertProcessDefinitionAndNotify(string org, st string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext); var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, repo, developer); - + await using Stream stream = content.OpenReadStream(); try { diff --git a/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs b/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs index 0a190997f58..e0ed0beb769 100644 --- a/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs +++ b/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs @@ -815,17 +815,13 @@ public Stream GetProcessDefinitionFile() public Definitions GetDefinitions() { - Stream processDefinitionStream = GetProcessDefinitionFile(); - - MemoryStream memoryStream = new MemoryStream(); + using Stream processDefinitionStream = GetProcessDefinitionFile(); + using MemoryStream memoryStream = new MemoryStream(); processDefinitionStream.CopyTo(memoryStream); - memoryStream.Position = 0; - + XmlSerializer serializer = new(typeof(Definitions)); Definitions definitions = (Definitions)serializer.Deserialize(memoryStream); - - processDefinitionStream.Close(); return definitions; } From e523c6ce733c489c1e288f979502765fedd3c1d3 Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Thu, 2 Jan 2025 12:51:14 +0100 Subject: [PATCH 4/4] remove memoryStream usage --- .../Infrastructure/GitRepository/AltinnAppGitRepository.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs b/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs index 5e25e8cf4b1..c173b2aaaf8 100644 --- a/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs +++ b/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs @@ -905,12 +905,8 @@ public Stream GetProcessDefinitionFile() public Definitions GetDefinitions() { using Stream processDefinitionStream = GetProcessDefinitionFile(); - using MemoryStream memoryStream = new MemoryStream(); - processDefinitionStream.CopyTo(memoryStream); - memoryStream.Position = 0; - XmlSerializer serializer = new(typeof(Definitions)); - Definitions definitions = (Definitions)serializer.Deserialize(memoryStream); + Definitions definitions = (Definitions)serializer.Deserialize(processDefinitionStream); return definitions; }