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

fix: ensure stream is closed after being read from app-dev's GetDefinitions method #14334

Merged
merged 7 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading