From 870ebf071dede7b167b2fb9a085198b883c98195 Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Mon, 23 Dec 2024 08:21:53 +0100 Subject: [PATCH 1/3] fix: use same regex for layoutsets in FE and BE --- .../AppDevelopmentErrorCodes.cs | 2 +- .../AppDevelopmentExceptionFilterAttribute.cs | 2 +- .../Implementation/AppDevelopmentService.cs | 2 +- .../UpdateLayoutSetNameTests.cs | 20 +++++++++++++++++++ frontend/language/src/nb.json | 2 +- .../src/FileNameUtils/FileNameUtils.test.ts | 6 ++++++ .../src/FileNameUtils/FileNameUtils.ts | 2 +- .../shared/src/utils/layoutSetsUtils.ts | 4 ++-- 8 files changed, 33 insertions(+), 7 deletions(-) diff --git a/backend/src/Designer/Filters/AppDevelopment/AppDevelopmentErrorCodes.cs b/backend/src/Designer/Filters/AppDevelopment/AppDevelopmentErrorCodes.cs index e819f8ca8da..99a29708cd9 100644 --- a/backend/src/Designer/Filters/AppDevelopment/AppDevelopmentErrorCodes.cs +++ b/backend/src/Designer/Filters/AppDevelopment/AppDevelopmentErrorCodes.cs @@ -4,7 +4,7 @@ public class AppDevelopmentErrorCodes { public const string NonUniqueLayoutSetIdError = "AD_01"; public const string NonUniqueTaskForLayoutSetError = "AD_02"; - public const string EmptyLayoutSetIdError = "AD_03"; + public const string InvalidLayoutSetIdError = "AD_03"; public const string ConflictingFileNameError = "AD_04"; public const string UploadedImageNotValid = nameof(UploadedImageNotValid); } diff --git a/backend/src/Designer/Filters/AppDevelopment/AppDevelopmentExceptionFilterAttribute.cs b/backend/src/Designer/Filters/AppDevelopment/AppDevelopmentExceptionFilterAttribute.cs index 4444c80a1e2..0aa273fece3 100644 --- a/backend/src/Designer/Filters/AppDevelopment/AppDevelopmentExceptionFilterAttribute.cs +++ b/backend/src/Designer/Filters/AppDevelopment/AppDevelopmentExceptionFilterAttribute.cs @@ -27,7 +27,7 @@ public override void OnException(ExceptionContext context) } if (context.Exception is InvalidLayoutSetIdException) { - context.Result = new ObjectResult(ProblemDetailsUtils.GenerateProblemDetails(context.Exception, AppDevelopmentErrorCodes.EmptyLayoutSetIdError, HttpStatusCode.BadRequest)) { StatusCode = (int)HttpStatusCode.BadRequest }; + context.Result = new ObjectResult(ProblemDetailsUtils.GenerateProblemDetails(context.Exception, AppDevelopmentErrorCodes.InvalidLayoutSetIdError, HttpStatusCode.BadRequest)) { StatusCode = (int)HttpStatusCode.BadRequest }; } if (context.Exception is ConflictingFileNameException) { diff --git a/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs b/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs index cc04b5523ec..33940606ae8 100644 --- a/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs +++ b/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs @@ -28,7 +28,7 @@ public class AppDevelopmentService : IAppDevelopmentService { private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory; private readonly ISchemaModelService _schemaModelService; - private readonly string _layoutSetNameRegEx = "[a-zA-Z0-9-]{2,28}"; + private readonly string _layoutSetNameRegEx = @"^[a-zA-Z0-9_\-]{2,28}$"; /// /// Constructor diff --git a/backend/tests/Designer.Tests/Controllers/AppDevelopmentController/UpdateLayoutSetNameTests.cs b/backend/tests/Designer.Tests/Controllers/AppDevelopmentController/UpdateLayoutSetNameTests.cs index 6d4d00a70f3..f1e72f245b4 100644 --- a/backend/tests/Designer.Tests/Controllers/AppDevelopmentController/UpdateLayoutSetNameTests.cs +++ b/backend/tests/Designer.Tests/Controllers/AppDevelopmentController/UpdateLayoutSetNameTests.cs @@ -94,6 +94,26 @@ public async Task UpdateLayoutSet_NewLayoutSetNameIsEmpty_ReturnsBadRequest(stri response.StatusCode.Should().Be(HttpStatusCode.BadRequest); } + [Theory] + [InlineData("ttd", "app-with-layoutsets", "testUser", "layoutSet1")] + public async Task UpdateLayoutSet_NewLayoutSetNameDoesNotMatchRegex_ReturnsBadRequest(string org, string app, string developer, + string oldLayoutSetName) + { + string targetRepository = TestDataHelper.GenerateTestRepoName(); + await CopyRepositoryForTest(org, app, developer, targetRepository); + string newLayoutSetName = ".abc"; + + string url = $"{VersionPrefix(org, targetRepository)}/layout-set/{oldLayoutSetName}"; + + using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, url) + { + Content = new StringContent($"\"{newLayoutSetName}\"", Encoding.UTF8, MediaTypeNames.Application.Json) + }; + + using var response = await HttpClient.SendAsync(httpRequestMessage); + response.StatusCode.Should().Be(HttpStatusCode.BadRequest); + } + [Theory] [InlineData("ttd", "app-without-layoutsets", "testUser", null)] public async Task UpdateLayoutSetName_AppWithoutLayoutSets_ReturnsNotFound(string org, string app, string developer, diff --git a/frontend/language/src/nb.json b/frontend/language/src/nb.json index 736cd69da66..0d5517a3531 100644 --- a/frontend/language/src/nb.json +++ b/frontend/language/src/nb.json @@ -1,7 +1,7 @@ { "api_errors.AD_01": "En annen sidegruppe har allerede dette navnet.", "api_errors.AD_02": "Det finnes allerede en sidegruppe med denne oppgaven.", - "api_errors.AD_03": "Navnet på sidegruppen kan ikke være tomt.", + "api_errors.AD_03": "Navnet på sidegruppen er ugyldig. Du kan bruke tall, understrek, bindestrek, og store/små bokstaver fra det engelske alfabetet.", "api_errors.DM_01": "Kunne ikke bygge datamodellen.", "api_errors.DM_05": "Kunne ikke lese ugyldig XML.", "api_errors.DM_CsharpCompiler_NameCollision": "Navnet {{nodeName}} er det samme som på et overordnet element. Gi ett av elementene et annet navn.", 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 2b6557335d8..3bf09bab655 100644 --- a/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.test.ts +++ b/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.test.ts @@ -104,6 +104,12 @@ describe('FileNameUtils', () => { expect(fileNameError).toBe(FileNameErrorResult.NoRegExMatch); }); + it('Returns "NoRegExMatch" when file name does not match file name regex in terms of length', () => { + const fileName: string = '12345678901234567890123456789'; + const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError(fileName, []); + expect(fileNameError).toBe(FileNameErrorResult.NoRegExMatch); + }); + it('Returns "FileExists" when file name matches regEx and name exists in list', () => { const fileName: string = 'fileName1'; const invalidFileNames: string[] = [fileName, 'fileName2', 'fileName3']; diff --git a/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.ts b/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.ts index b30e4c20159..efcf6acc245 100644 --- a/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.ts +++ b/frontend/libs/studio-pure-functions/src/FileNameUtils/FileNameUtils.ts @@ -1,6 +1,6 @@ import { StringUtils } from '@studio/pure-functions'; -export const FILE_NAME_REGEX = /^[a-zA-Z0-9_\-]{1,50}$/; +export const FILE_NAME_REGEX = /^[a-zA-Z0-9_\-]{2,28}$/; export enum FileNameErrorResult { FileNameIsEmpty = 'fileNameIsEmpty', diff --git a/frontend/packages/shared/src/utils/layoutSetsUtils.ts b/frontend/packages/shared/src/utils/layoutSetsUtils.ts index 3fc53a84a60..a774fc7a3b8 100644 --- a/frontend/packages/shared/src/utils/layoutSetsUtils.ts +++ b/frontend/packages/shared/src/utils/layoutSetsUtils.ts @@ -16,10 +16,10 @@ export const getLayoutSetIdValidationErrorKey = ( ): string => { if (oldLayoutSetId === newLayoutSetId) return null; if (!newLayoutSetId || newLayoutSetId.trim() === '') return 'validation_errors.required'; - if (!validateLayoutNameAndLayoutSetName(newLayoutSetId)) - return 'validation_errors.file_name_invalid'; if (newLayoutSetId.length === 1) return 'process_editor.configuration_panel_custom_receipt_layout_set_name_validation'; + if (!validateLayoutNameAndLayoutSetName(newLayoutSetId)) + return 'validation_errors.file_name_invalid'; if (layoutSets.sets.some((set) => StringUtils.areCaseInsensitiveEqual(set.id, newLayoutSetId))) return 'process_editor.configuration_panel_layout_set_id_not_unique'; return null; From af6ffaba7ef6392364ec16eefcfe0edf5df3888f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B8rild=20D=C3=B8hl?= Date: Fri, 3 Jan 2025 14:25:44 +0100 Subject: [PATCH 2/3] Update frontend/language/src/nb.json Bytt ut "Den" med "Det", siden det referer til "navnet". Co-authored-by: Konrad-Simso --- frontend/language/src/nb.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/language/src/nb.json b/frontend/language/src/nb.json index 0d5517a3531..a72bc76a8e7 100644 --- a/frontend/language/src/nb.json +++ b/frontend/language/src/nb.json @@ -1,7 +1,7 @@ { "api_errors.AD_01": "En annen sidegruppe har allerede dette navnet.", "api_errors.AD_02": "Det finnes allerede en sidegruppe med denne oppgaven.", - "api_errors.AD_03": "Navnet på sidegruppen er ugyldig. Du kan bruke tall, understrek, bindestrek, og store/små bokstaver fra det engelske alfabetet.", + "api_errors.AD_03": "Navnet på sidegruppen er ugyldig. Den må være mellom 2 og 28 tegn og kan inneholde tall, understrek, bindestrek, og store/små bokstaver fra det engelske alfabetet.", "api_errors.DM_01": "Kunne ikke bygge datamodellen.", "api_errors.DM_05": "Kunne ikke lese ugyldig XML.", "api_errors.DM_CsharpCompiler_NameCollision": "Navnet {{nodeName}} er det samme som på et overordnet element. Gi ett av elementene et annet navn.", From 639482388c83fd242bbb37547ca1455eee4973a4 Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Fri, 3 Jan 2025 16:03:00 +0100 Subject: [PATCH 3/3] fix typo --- frontend/language/src/nb.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/language/src/nb.json b/frontend/language/src/nb.json index a72bc76a8e7..d68daaab64d 100644 --- a/frontend/language/src/nb.json +++ b/frontend/language/src/nb.json @@ -1,7 +1,7 @@ { "api_errors.AD_01": "En annen sidegruppe har allerede dette navnet.", "api_errors.AD_02": "Det finnes allerede en sidegruppe med denne oppgaven.", - "api_errors.AD_03": "Navnet på sidegruppen er ugyldig. Den må være mellom 2 og 28 tegn og kan inneholde tall, understrek, bindestrek, og store/små bokstaver fra det engelske alfabetet.", + "api_errors.AD_03": "Navnet på sidegruppen er ugyldig. Det må ha mellom 2 og 28 tegn og kan inneholde tall, understrek, bindestrek, og store/små bokstaver fra det engelske alfabetet.", "api_errors.DM_01": "Kunne ikke bygge datamodellen.", "api_errors.DM_05": "Kunne ikke lese ugyldig XML.", "api_errors.DM_CsharpCompiler_NameCollision": "Navnet {{nodeName}} er det samme som på et overordnet element. Gi ett av elementene et annet navn.",