Skip to content

Commit

Permalink
fix: ensure stream is closed after being read from app-dev's GetDefin…
Browse files Browse the repository at this point in the history
…itions method (#14334)
  • Loading branch information
standeren authored Jan 3, 2025
1 parent 20b4540 commit a712b7d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
10 changes: 4 additions & 6 deletions backend/src/Designer/Controllers/ProcessModelingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,19 @@ public async Task<IActionResult> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,11 @@ public Stream GetProcessDefinitionFile()

public Definitions GetDefinitions()
{
Stream processDefinitionStream = GetProcessDefinitionFile();
using Stream processDefinitionStream = GetProcessDefinitionFile();
XmlSerializer serializer = new(typeof(Definitions));
return (Definitions)serializer.Deserialize(processDefinitionStream);
Definitions definitions = (Definitions)serializer.Deserialize(processDefinitionStream);

return definitions;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class EndpointNameSyncEvaluator : IRequestSyncEvaluator
nameof(ProcessModelingController.AddDataTypeToApplicationMetadata),
nameof(ProcessModelingController.DeleteDataTypeFromApplicationMetadata),
nameof(ProcessModelingController.UpsertProcessDefinitionAndNotify),
nameof(ProcessModelingController.ProcessDataTypesChangedNotify),
nameof(ProcessModelingController.SaveProcessDefinitionFromTemplate)
)
},
Expand Down
3 changes: 3 additions & 0 deletions frontend/packages/ux-editor/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,6 +53,7 @@ export function App() {
org,
app,
);
const { status: layoutSetsExtendedStatus } = useLayoutSetsExtendedQuery(org, app);
const { status: dataModelStatus, isError: dataModelFetchedError } = useDataModelMetadataQuery({
org,
app,
Expand All @@ -69,6 +71,7 @@ export function App() {
const componentIsPending =
widgetsStatus === 'pending' ||
layoutSetsStatus === 'pending' ||
layoutSetsExtendedStatus === 'pending' ||
dataModelStatus === 'pending' ||
textsStatus === 'pending';
const componentIsReady =
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<section className={classes.toolbar}>
Expand Down

0 comments on commit a712b7d

Please sign in to comment.