From ef586cecc2fc995b40c9472a4e8b6638d47da806 Mon Sep 17 00:00:00 2001 From: Johannes Haukland <42615991+HauklandJ@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:49:41 +0200 Subject: [PATCH] Update interface to include sub form prop (#477) * add property for allowing a datatype to be used in a sub form * migration changes * fix test issue * Revert "migration changes" This reverts commit 5ca3c75aced9c77c14fb3e7b68d5b90458f53809. --- .../Models/ApplicationLogic.cs | 9 +++- .../AllowInSubform/AllowInSubformTests.cs | 25 ++++++++++ .../applicationMetadata_afterChange.json | 50 +++++++++++++++++++ .../applicationMetadata_beforeChange.json | 49 ++++++++++++++++++ ...nn.Platform.Storage.Interface.Tests.csproj | 5 +- 5 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/AllowInSubformTests.cs create mode 100644 test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/applicationMetadata_afterChange.json create mode 100644 test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/applicationMetadata_beforeChange.json diff --git a/src/Storage.Interface/Models/ApplicationLogic.cs b/src/Storage.Interface/Models/ApplicationLogic.cs index 001ccaec..1eca57a9 100644 --- a/src/Storage.Interface/Models/ApplicationLogic.cs +++ b/src/Storage.Interface/Models/ApplicationLogic.cs @@ -53,7 +53,14 @@ public class ApplicationLogic /// [JsonProperty(PropertyName = "allowUserDelete")] public bool AllowUserDelete { get; set; } - + + /// + /// Specifies whether the data type is compatible with sub form usage. + /// Defaults to false if not specified. + /// + [JsonProperty(PropertyName = "allowInSubform")] + public bool AllowInSubform { get; set; } + /// /// Gets or sets a property containing configuration for shadow fields for the data type. /// diff --git a/test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/AllowInSubformTests.cs b/test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/AllowInSubformTests.cs new file mode 100644 index 00000000..682cc837 --- /dev/null +++ b/test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/AllowInSubformTests.cs @@ -0,0 +1,25 @@ +using System.Linq; +using Altinn.Platform.Storage.Interface.Models; +using FluentAssertions; +using Xunit; + +namespace Altinn.Platform.Storage.Interface.Tests.AllowInSubform; + +public class AllowInSubformTests +{ + [Fact] + public void MetadataWithoutShadowFields_ShouldBeFalse() + { + Application applicationBefore = TestdataHelper.LoadDataFromEmbeddedResourceAsType("AllowInSubform.applicationMetadata_beforeChange.json"); + + applicationBefore.DataTypes.First(d => d.Id == "Veileder").AppLogic.AllowInSubform.Should().BeFalse(); + } + + [Fact] + public void MetadataWithShadowFields_ShouldBeTrue() + { + Application applicationBefore = TestdataHelper.LoadDataFromEmbeddedResourceAsType("AllowInSubform.applicationMetadata_afterChange.json"); + + applicationBefore.DataTypes.First(d => d.Id == "Veileder").AppLogic.AllowInSubform.Should().BeTrue(); + } +} diff --git a/test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/applicationMetadata_afterChange.json b/test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/applicationMetadata_afterChange.json new file mode 100644 index 00000000..fd6e8558 --- /dev/null +++ b/test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/applicationMetadata_afterChange.json @@ -0,0 +1,50 @@ +{ + "id": "ttd/anonymous-stateless", + "org": "ttd", + "title": { + "nb": "anonymous-stateless", + "en": "Oppstart av bedrift" + }, + "dataTypes": [ + { + "id": "ref-data-as-pdf", + "allowedContentTypes": [ + "application/pdf" + ], + "maxCount": 0, + "minCount": 0, + "enablePdfCreation": true + }, + { + "id": "Veileder", + "allowedContentTypes": [ + "application/xml" + ], + "appLogic": { + "autoCreate": true, + "classRef": "Altinn.App.Models.StarteBedrift", + "allowUserCreate": true, + "allowUserDelete": true, + "allowInSubform": true + }, + "taskId": "Task_1", + "maxCount": 1, + "minCount": 1, + "enablePdfCreation": true + } + ], + "onEntry": { + "show": "stateless" + }, + "partyTypesAllowed": { + "bankruptcyEstate": false, + "organisation": false, + "person": false, + "subUnit": false + }, + "autoDeleteOnProcessEnd": false, + "created": "2022-04-27T08:00:46.5336752Z", + "createdBy": "Ronny", + "lastChanged": "2022-04-27T08:00:46.533678Z", + "lastChangedBy": "Ronny" +} \ No newline at end of file diff --git a/test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/applicationMetadata_beforeChange.json b/test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/applicationMetadata_beforeChange.json new file mode 100644 index 00000000..4e6e3934 --- /dev/null +++ b/test/Altinn.Platform.Storage.Interface.Tests/AllowInSubform/applicationMetadata_beforeChange.json @@ -0,0 +1,49 @@ +{ + "id": "ttd/anonymous-stateless", + "org": "ttd", + "title": { + "nb": "anonymous-stateless", + "en": "Oppstart av bedrift" + }, + "dataTypes": [ + { + "id": "ref-data-as-pdf", + "allowedContentTypes": [ + "application/pdf" + ], + "maxCount": 0, + "minCount": 0, + "enablePdfCreation": true + }, + { + "id": "Veileder", + "allowedContentTypes": [ + "application/xml" + ], + "appLogic": { + "autoCreate": true, + "classRef": "Altinn.App.Models.StarteBedrift", + "allowUserCreate": true, + "allowUserDelete": true + }, + "taskId": "Task_1", + "maxCount": 1, + "minCount": 1, + "enablePdfCreation": true + } + ], + "onEntry": { + "show": "stateless" + }, + "partyTypesAllowed": { + "bankruptcyEstate": false, + "organisation": false, + "person": false, + "subUnit": false + }, + "autoDeleteOnProcessEnd": false, + "created": "2022-04-27T08:00:46.5336752Z", + "createdBy": "Ronny", + "lastChanged": "2022-04-27T08:00:46.533678Z", + "lastChangedBy": "Ronny" +} \ No newline at end of file diff --git a/test/Altinn.Platform.Storage.Interface.Tests/Altinn.Platform.Storage.Interface.Tests.csproj b/test/Altinn.Platform.Storage.Interface.Tests/Altinn.Platform.Storage.Interface.Tests.csproj index 62b8f8d5..1ae222c8 100644 --- a/test/Altinn.Platform.Storage.Interface.Tests/Altinn.Platform.Storage.Interface.Tests.csproj +++ b/test/Altinn.Platform.Storage.Interface.Tests/Altinn.Platform.Storage.Interface.Tests.csproj @@ -42,12 +42,11 @@ - - - + +