From 2113dd84a711dffbea6230d159aa7b0bb871a5cf Mon Sep 17 00:00:00 2001 From: Jonas Dyrlie Date: Wed, 27 Nov 2024 12:20:29 +0100 Subject: [PATCH 1/2] fix: add endpoint sync to upsert process definition endpoint (#14149) --- .../Controllers/ProcessModelingController.cs | 21 ------- .../EndpointNameSyncEvaluator.cs | 4 +- .../ApplicationMetadataFileSyncTaskIdTests.cs | 2 +- .../LayoutFileSyncTaskIdTests.cs | 2 +- .../LayoutSetsFileSyncTaskIdTests.cs | 2 +- .../PolicyFileSyncTaskIdTests.cs | 2 +- .../SaveProcessDefinitionTests.cs | 59 ------------------- .../UpsertProcessDefinitionAndNotifyTests.cs | 2 +- frontend/packages/shared/src/api/mutations.ts | 4 +- frontend/packages/shared/src/api/paths.js | 1 - 10 files changed, 10 insertions(+), 89 deletions(-) delete mode 100644 backend/tests/Designer.Tests/Controllers/ProcessModelingController/SaveProcessDefinitionTests.cs diff --git a/backend/src/Designer/Controllers/ProcessModelingController.cs b/backend/src/Designer/Controllers/ProcessModelingController.cs index 2a759502301..0048b227bc0 100644 --- a/backend/src/Designer/Controllers/ProcessModelingController.cs +++ b/backend/src/Designer/Controllers/ProcessModelingController.cs @@ -48,27 +48,6 @@ public FileStreamResult GetProcessDefinition(string org, string repo) } [HttpPut("process-definition")] - [Obsolete("This endpoint should be replaced by process-definition-latest, and url fixed after integration with frontend")] - public async Task SaveProcessDefinition(string org, string repo, - CancellationToken cancellationToken) - { - Request.EnableBuffering(); - try - { - await Guard.AssertValidXmlStreamAndRewindAsync(Request.Body); - } - catch (ArgumentException) - { - return BadRequest("BPMN file is not valid XML"); - } - - string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext); - await _processModelingService.SaveProcessDefinitionAsync( - AltinnRepoEditingContext.FromOrgRepoDeveloper(org, repo, developer), Request.Body, cancellationToken); - return Ok(); - } - - [HttpPut("process-definition-latest")] public async Task UpsertProcessDefinitionAndNotify(string org, string repo, [FromForm] IFormFile content, [FromForm] string metadata, CancellationToken cancellationToken) { Request.EnableBuffering(); diff --git a/backend/src/Designer/Middleware/UserRequestSynchronization/Services/RequestSyncEvaluators/EndpointNameSyncEvaluator.cs b/backend/src/Designer/Middleware/UserRequestSynchronization/Services/RequestSyncEvaluators/EndpointNameSyncEvaluator.cs index 24f1b91a67f..9b0c909fb7d 100644 --- a/backend/src/Designer/Middleware/UserRequestSynchronization/Services/RequestSyncEvaluators/EndpointNameSyncEvaluator.cs +++ b/backend/src/Designer/Middleware/UserRequestSynchronization/Services/RequestSyncEvaluators/EndpointNameSyncEvaluator.cs @@ -51,7 +51,9 @@ public class EndpointNameSyncEvaluator : IRequestSyncEvaluator nameof(ProcessModelingController).Replace(RemoveControllerSuffix, string.Empty), GenerateFrozenSet( nameof(ProcessModelingController.AddDataTypeToApplicationMetadata), - nameof(ProcessModelingController.DeleteDataTypeFromApplicationMetadata) + nameof(ProcessModelingController.DeleteDataTypeFromApplicationMetadata), + nameof(ProcessModelingController.UpsertProcessDefinitionAndNotify), + nameof(ProcessModelingController.SaveProcessDefinitionFromTemplate) ) }, { diff --git a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/ApplicationMetadataFileSyncTaskIdTests.cs b/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/ApplicationMetadataFileSyncTaskIdTests.cs index e4af2c030d9..52b5dcb9816 100644 --- a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/ApplicationMetadataFileSyncTaskIdTests.cs +++ b/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/ApplicationMetadataFileSyncTaskIdTests.cs @@ -21,7 +21,7 @@ namespace Designer.Tests.Controllers.ProcessModelingController.FileSync.TaskIdCh public class ApplicationMetadataFileSyncTaskIdTests : DesignerEndpointsTestsBase, IClassFixture> { - private static string VersionPrefix(string org, string repository) => $"/designer/api/{org}/{repository}/process-modelling/process-definition-latest"; + private static string VersionPrefix(string org, string repository) => $"/designer/api/{org}/{repository}/process-modelling/process-definition"; public ApplicationMetadataFileSyncTaskIdTests(WebApplicationFactory factory) : base(factory) { diff --git a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/LayoutFileSyncTaskIdTests.cs b/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/LayoutFileSyncTaskIdTests.cs index ca85006c349..21734ea9202 100644 --- a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/LayoutFileSyncTaskIdTests.cs +++ b/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/LayoutFileSyncTaskIdTests.cs @@ -25,7 +25,7 @@ public LayoutFileSyncTaskIdTests(WebApplicationFactory factory) : base( private static string GetVersionPrefix(string org, string repository) { - return $"/designer/api/{org}/{repository}/process-modelling/process-definition-latest"; + return $"/designer/api/{org}/{repository}/process-modelling/process-definition"; } [Theory] diff --git a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/LayoutSetsFileSyncTaskIdTests.cs b/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/LayoutSetsFileSyncTaskIdTests.cs index 64c9761dde5..d379af8c1b2 100644 --- a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/LayoutSetsFileSyncTaskIdTests.cs +++ b/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/LayoutSetsFileSyncTaskIdTests.cs @@ -22,7 +22,7 @@ public class LayoutSetsFileSyncTaskIdTests : DesignerEndpointsTestsBase> { private static string VersionPrefix(string org, string repository) => - $"/designer/api/{org}/{repository}/process-modelling/process-definition-latest"; + $"/designer/api/{org}/{repository}/process-modelling/process-definition"; public LayoutSetsFileSyncTaskIdTests(WebApplicationFactory factory) : base(factory) { diff --git a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/PolicyFileSyncTaskIdTests.cs b/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/PolicyFileSyncTaskIdTests.cs index 651f436d0d4..723a9b9daf7 100644 --- a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/PolicyFileSyncTaskIdTests.cs +++ b/backend/tests/Designer.Tests/Controllers/ProcessModelingController/FileSync/TaskIdChangeTests/PolicyFileSyncTaskIdTests.cs @@ -21,7 +21,7 @@ public class PolicyFileSyncTaskIdTests : DesignerEndpointsTestsBase> { private static string VersionPrefix(string org, string repository) => - $"/designer/api/{org}/{repository}/process-modelling/process-definition-latest"; + $"/designer/api/{org}/{repository}/process-modelling/process-definition"; public PolicyFileSyncTaskIdTests(WebApplicationFactory factory) : base(factory) { diff --git a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/SaveProcessDefinitionTests.cs b/backend/tests/Designer.Tests/Controllers/ProcessModelingController/SaveProcessDefinitionTests.cs deleted file mode 100644 index 97e30c7427d..00000000000 --- a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/SaveProcessDefinitionTests.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Net; -using System.Net.Http; -using System.Net.Mime; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; -using Designer.Tests.Controllers.ApiTests; -using Designer.Tests.Utils; -using FluentAssertions; -using Microsoft.AspNetCore.Mvc.Testing; -using SharedResources.Tests; -using Xunit; - -namespace Designer.Tests.Controllers.ProcessModelingController -{ - public class SaveProcessDefinitionTests : DesignerEndpointsTestsBase, IClassFixture> - { - private static string VersionPrefix(string org, string repository) => $"/designer/api/{org}/{repository}/process-modelling/process-definition"; - - public SaveProcessDefinitionTests(WebApplicationFactory factory) : base(factory) - { - } - - [Theory] - [InlineData("ttd", "empty-app", "testUser", "App/config/process/process.bpmn")] - public async Task SaveProcessDefinition_ShouldReturnOk(string org, string app, string developer, string bpmnFilePath) - { - string targetRepository = TestDataHelper.GenerateTestRepoName(); - await CopyRepositoryForTest(org, app, developer, targetRepository); - string fileContent = SharedResourcesHelper.LoadTestDataAsString(bpmnFilePath); - - string url = VersionPrefix(org, targetRepository); - using var content = new StringContent(fileContent, Encoding.UTF8, MediaTypeNames.Application.Xml); - - using var response = await HttpClient.PutAsync(url, content); - response.StatusCode.Should().Be(HttpStatusCode.OK); - - string savedFile = TestDataHelper.GetFileFromRepo(org, targetRepository, developer, "App/config/process/process.bpmn"); - - XDocument expectedXml = XDocument.Parse(fileContent); - XDocument savedXml = XDocument.Parse(savedFile); - XNode.DeepEquals(savedXml, expectedXml).Should().BeTrue(); - } - - [Theory] - [InlineData("ttd", "empty-app", "testUser", @"{""test"": ""test""}")] - public async Task InvalidXml_ShouldReturnBadRequest(string org, string app, string developer, string nonXmlContent) - { - string targetRepository = TestDataHelper.GenerateTestRepoName(); - await CopyRepositoryForTest(org, app, developer, targetRepository); - - string url = VersionPrefix(org, targetRepository); - using var content = new StringContent(nonXmlContent, Encoding.UTF8, MediaTypeNames.Application.Xml); - - using var response = await HttpClient.PutAsync(url, content); - response.StatusCode.Should().Be(HttpStatusCode.BadRequest); - } - } -} diff --git a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/UpsertProcessDefinitionAndNotifyTests.cs b/backend/tests/Designer.Tests/Controllers/ProcessModelingController/UpsertProcessDefinitionAndNotifyTests.cs index 41d0156dfbc..0cdfb92b6ee 100644 --- a/backend/tests/Designer.Tests/Controllers/ProcessModelingController/UpsertProcessDefinitionAndNotifyTests.cs +++ b/backend/tests/Designer.Tests/Controllers/ProcessModelingController/UpsertProcessDefinitionAndNotifyTests.cs @@ -20,7 +20,7 @@ namespace Designer.Tests.Controllers.ProcessModelingController; public class UpsertProcessDefinitionAndNotifyTests : DesignerEndpointsTestsBase, IClassFixture> { - private static string VersionPrefix(string org, string repository) => $"/designer/api/{org}/{repository}/process-modelling/process-definition-latest"; + private static string VersionPrefix(string org, string repository) => $"/designer/api/{org}/{repository}/process-modelling/process-definition"; public UpsertProcessDefinitionAndNotifyTests(WebApplicationFactory factory) : base(factory) { diff --git a/frontend/packages/shared/src/api/mutations.ts b/frontend/packages/shared/src/api/mutations.ts index 1eeb2980ab6..d09c54f5dbb 100644 --- a/frontend/packages/shared/src/api/mutations.ts +++ b/frontend/packages/shared/src/api/mutations.ts @@ -33,7 +33,6 @@ import { createAccessListsPath, accessListMemberPath, resourceAccessListPath, - processEditorPathPut, layoutSetPath, processEditorDataTypePath, processEditorDataTypesChangePath, @@ -43,6 +42,7 @@ import { addImagePath, optionListUploadPath, optionListUpdatePath, + processEditorPath, selectedMaskinportenScopesPath, } from 'app-shared/api/paths'; import type { AddLanguagePayload } from 'app-shared/types/api/AddLanguagePayload'; @@ -144,7 +144,7 @@ export const addDataTypeToAppMetadata = (org: string, app: string, dataTypeId: s export const deleteDataTypeFromAppMetadata = (org: string, app: string, dataTypeId: string) => del(processEditorDataTypePath(org, app, dataTypeId)); export const updateBpmnXml = (org: string, app: string, form: any) => - put(processEditorPathPut(org, app), form, { + put(processEditorPath(org, app), form, { headers: { 'Content-Type': 'multipart/form-data', }, diff --git a/frontend/packages/shared/src/api/paths.js b/frontend/packages/shared/src/api/paths.js index 11b18a1ab40..8e3d0b832f3 100644 --- a/frontend/packages/shared/src/api/paths.js +++ b/frontend/packages/shared/src/api/paths.js @@ -167,7 +167,6 @@ export const altinn2DelegationsMigrationPath = (org, env) => `${basePath}/${org} // Process Editor export const processEditorPath = (org, app) => `${basePath}/${org}/${app}/process-modelling/process-definition`; -export const processEditorPathPut = (org, app) => `${basePath}/${org}/${app}/process-modelling/process-definition-latest`; export const processEditorDataTypesChangePath = (org, app) => `${basePath}/${org}/${app}/process-modelling/data-types`; export const processTaskTypePath = (org, app, taskId) => `${basePath}/${org}/${app}/process-modelling/task-type/${taskId}`; // Get export const processEditorDataTypePath = (org, app, dataTypeId, taskId) => `${basePath}/${org}/${app}/process-modelling/data-type/${dataTypeId}?${s({ taskId })}`; From 4a7d1e233c7c2b5477a70ceba5add2e5b56c0b8c Mon Sep 17 00:00:00 2001 From: andreastanderen <71079896+standeren@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:33:42 +0100 Subject: [PATCH 2/2] fix: adapt fileNameValidation function to find file name error and return 'null' if no error exist (#14174) Co-authored-by: William Thorenfeldt <48119543+wrt95@users.noreply.github.com> --- .../src/FileNameUtils/FileNameUtils.test.ts | 44 ++++++++----------- .../src/FileNameUtils/FileNameUtils.ts | 17 ++++--- .../src/FileNameUtils/index.ts | 2 +- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.test.ts b/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.test.ts index 7bfd40d3983..67c9f848eac 100644 --- a/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.test.ts +++ b/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.test.ts @@ -1,4 +1,4 @@ -import { FileNameUtils, FileNameValidationResult } from './FileNameUtils'; +import { FileNameErrorResult, FileNameUtils } from './FileNameUtils'; describe('FileNameUtils', () => { describe('removeExtension', () => { @@ -91,78 +91,72 @@ describe('FileNameUtils', () => { }); }); - describe('validateFileName', () => { + describe('findFileNameError', () => { it('Returns "FileNameIsEmpty" when file name is empty', () => { const fileName: string = ''; - const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName( - fileName, - [], - ); - expect(fileNameValidation).toBe(FileNameValidationResult.FileNameIsEmpty); + const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError(fileName, []); + expect(fileNameError).toBe(FileNameErrorResult.FileNameIsEmpty); }); it('Returns "NoRegExMatch" when file name does not match given regex', () => { const fileName: string = 'ABC'; const fileNameRegEx: RegExp = /^[a-z]+$/; - const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName( + const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError( fileName, [], fileNameRegEx, ); - expect(fileNameValidation).toBe(FileNameValidationResult.NoRegExMatch); + expect(fileNameError).toBe(FileNameErrorResult.NoRegExMatch); }); it('Returns "FileExists" when file name matches regEx and exists in list', () => { const fileName: string = 'fileName1'; const invalidFileNames: string[] = ['fileName1', 'fileName2', 'fileName3']; const fileNameRegEx: RegExp = /^[a-zA-Z0-9]+$/; - const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName( + const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError( fileName, invalidFileNames, fileNameRegEx, ); - expect(fileNameValidation).toBe(FileNameValidationResult.FileExists); + expect(fileNameError).toBe(FileNameErrorResult.FileExists); }); it('Returns "FileExists" when no regEx is provided and exists in list', () => { const fileName: string = 'fileName1'; const invalidFileNames: string[] = ['fileName1', 'fileName2', 'fileName3']; - const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName( + const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError( fileName, invalidFileNames, ); - expect(fileNameValidation).toBe(FileNameValidationResult.FileExists); + expect(fileNameError).toBe(FileNameErrorResult.FileExists); }); - it('Returns "Valid" when file name matches regEx and does not exist in list of invalid names', () => { + it('Returns null when file name matches regEx and does not exist in list of invalid names', () => { const fileName: string = 'fileName'; const invalidFileNames: string[] = ['fileName2', 'fileName3']; const fileNameRegEx: RegExp = /^[a-zA-Z]+$/; - const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName( + const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError( fileName, invalidFileNames, fileNameRegEx, ); - expect(fileNameValidation).toBe(FileNameValidationResult.Valid); + expect(fileNameError).toBeNull(); }); - it('Returns "Valid" when no regEx is provided and file name does not exist in list of invalid names', () => { + it('Returns null when no regEx is provided and file name does not exist in list of invalid names', () => { const fileName: string = 'fileName'; const invalidFileNames: string[] = ['fileName2', 'fileName3']; - const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName( + const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError( fileName, invalidFileNames, ); - expect(fileNameValidation).toBe(FileNameValidationResult.Valid); + expect(fileNameError).toBeNull(); }); - it('Returns "Valid" when no regEx is provided and list of invalid names is empty', () => { + it('Returns null when no regEx is provided and list of invalid names is empty', () => { const fileName: string = 'fileName'; - const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName( - fileName, - [], - ); - expect(fileNameValidation).toBe(FileNameValidationResult.Valid); + const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError(fileName, []); + expect(fileNameError).toBeNull(); }); }); }); diff --git a/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.ts b/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.ts index dd02eefde4f..2c988075e42 100644 --- a/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.ts +++ b/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.ts @@ -1,10 +1,9 @@ import { StringUtils } from '@studio/pure-functions'; -export enum FileNameValidationResult { +export enum FileNameErrorResult { FileNameIsEmpty = 'fileNameIsEmpty', NoRegExMatch = 'noRegExMatch', FileExists = 'fileExists', - Valid = 'valid', } export class FileNameUtils { @@ -52,15 +51,15 @@ export class FileNameUtils { * @param fileName * @param invalidFileNames * @param regEx - * @returns FileNameValidationResult + * @returns {FileNameErrorResult | null} */ - static validateFileName = ( + static findFileNameError = ( fileName: string, invalidFileNames: string[], regEx?: RegExp, - ): FileNameValidationResult => { + ): FileNameErrorResult => { if (fileName === '') { - return FileNameValidationResult.FileNameIsEmpty; + return FileNameErrorResult.FileNameIsEmpty; } const isFileNameNotMatchingRegEx: boolean = regEx ? Boolean(!fileName.match(regEx)) : false; @@ -69,11 +68,11 @@ export class FileNameUtils { ); if (isFileNameNotMatchingRegEx) { - return FileNameValidationResult.NoRegExMatch; + return FileNameErrorResult.NoRegExMatch; } if (isFileNameInInvalidList) { - return FileNameValidationResult.FileExists; + return FileNameErrorResult.FileExists; } - return FileNameValidationResult.Valid; + return null; }; } diff --git a/frontend/libs/studio-pure-functions/src/FileNameUtils/index.ts b/frontend/libs/studio-pure-functions/src/FileNameUtils/index.ts index 61024b8bb54..7344d1c6c74 100644 --- a/frontend/libs/studio-pure-functions/src/FileNameUtils/index.ts +++ b/frontend/libs/studio-pure-functions/src/FileNameUtils/index.ts @@ -1,2 +1,2 @@ export { FileNameUtils } from './FileNameUtils'; -export { FileNameValidationResult } from './FileNameUtils'; +export { FileNameErrorResult } from './FileNameUtils';