Skip to content

Commit

Permalink
Merge branch 'main' into refactor/replace-designsystemet-components-w…
Browse files Browse the repository at this point in the history
…ith-studio
  • Loading branch information
JamalAlabdullah authored Feb 27, 2025
2 parents 0f69c35 + 21f546a commit da6d385
Show file tree
Hide file tree
Showing 41 changed files with 619 additions and 199 deletions.
42 changes: 2 additions & 40 deletions backend/src/Designer/Controllers/PreviewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Altinn.Platform.Storage.Interface.Models;
using Altinn.Studio.Designer.Filters;
using Altinn.Studio.Designer.Helpers;
using Altinn.Studio.Designer.Helpers.Preview;
using Altinn.Studio.Designer.Infrastructure.GitRepository;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Models.App;
Expand Down Expand Up @@ -61,8 +62,6 @@ public class PreviewController(IHttpContextAccessor httpContextAccessor,

// This value will be overridden to act as the task number for apps that use layout sets
private const int PartyId = 51001;
private const string MINIMUM_NUGET_VERSION = "8.0.0.0";
private const int MINIMUM_PREVIEW_NUGET_VERSION = 15;

/// <summary>
/// Default action for the preview.
Expand Down Expand Up @@ -142,7 +141,7 @@ public async Task<ActionResult<ApplicationMetadata>> ApplicationMetadata(string
ApplicationMetadata applicationMetadata = await altinnAppGitRepository.GetApplicationMetadata(cancellationToken);
string appNugetVersionString = _appDevelopmentService.GetAppLibVersion(AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer)).ToString();
// This property is populated at runtime by the apps, so we need to mock it here
applicationMetadata.AltinnNugetVersion = GetMockedAltinnNugetBuildFromVersion(appNugetVersionString);
applicationMetadata.AltinnNugetVersion = NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion(appNugetVersionString);
applicationMetadata = SetMockedPartyTypesAllowedAsAllFalse(applicationMetadata);
return Ok(applicationMetadata);
}
Expand Down Expand Up @@ -695,29 +694,6 @@ private static string ReplaceIndexToFetchCorrectOrgAppInCshtml(string originalCo
return modifiedContent;
}

/// <summary>
/// Method to get the mocked altinn nuget build from the version
/// We are returnning the minimum BUILD version of the nuget package that is required for app frontend to work
/// from v4 and above.
/// </summary>
/// <param name="version">The version of the nuget package</param>
/// <returns>The minimum build version of the nuget package</returns>
private string GetMockedAltinnNugetBuildFromVersion(string version)
{

string[] versionParts = version.Split('.');
if (!IsValidSemVerVersion(versionParts))
{
return string.Empty;
}

if (IsPreviewVersion(versionParts) && GetPreviewVersion(versionParts) < MINIMUM_PREVIEW_NUGET_VERSION)
{
return string.Empty;
}

return MINIMUM_NUGET_VERSION;
}

/// <summary>
/// Method to override the partyTypesAllowed in app metadata to bypass the check in app-frontend for a valid party during instantiation.
Expand All @@ -733,19 +709,5 @@ private static ApplicationMetadata SetMockedPartyTypesAllowedAsAllFalse(Applicat
return applicationMetadata;
}

private bool IsValidSemVerVersion(string[] versionParts)
{
return versionParts.Length >= 3 && Convert.ToInt32(versionParts[0]) >= 8;
}

private bool IsPreviewVersion(string[] versionParts)
{
return versionParts[2].Contains("-preview") && versionParts.Length == 4;
}

private int GetPreviewVersion(string[] versionParts)
{
return Convert.ToInt32(versionParts[3]);
}
}
}
69 changes: 69 additions & 0 deletions backend/src/Designer/Helpers/Preview/NugetVersionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Diagnostics.Contracts;
using System.Linq;

namespace Altinn.Studio.Designer.Helpers.Preview
{
public static class NugetVersionHelper
{
private const string MINIMUM_NUGET_VERSION = "8.0.0.0";
private const int MINIMUM_PREVIEW_NUGET_VERSION = 15;

/// <summary>
/// Method to get the mocked altinn nuget build from the version
/// We are returnning the minimum BUILD version of the nuget package that is required for app frontend to work
/// from v4 and above.
/// </summary>
/// <param name="version">The version of the nuget package</param>
/// <returns>The minimum build version of the nuget package</returns>
public static string GetMockedAltinnNugetBuildFromVersion(string version)
{

string[] versionParts = version.Split('.');
if (!IsValidSemVerVersion(versionParts))
{
return string.Empty;
}

string normalVersion = version.Split('-').First();
int[] numberVersion = [.. normalVersion.Split('.').Take(3).Select((split) => Convert.ToInt32(split))];
if (IsVersionOrBelow(numberVersion, [8, 0, 0]) && IsPreviewVersion(versionParts) && GetPreviewVersion(versionParts) < MINIMUM_PREVIEW_NUGET_VERSION)
{
return string.Empty;
}

return MINIMUM_NUGET_VERSION;
}

private static bool IsValidSemVerVersion(string[] versionParts)
{
return versionParts.Length >= 3 && Convert.ToInt32(versionParts[0]) >= 8;
}

// <exception cref="FormatException"></exception>
// <exception cref="OverflowException"></exception>
private static bool IsVersionOrBelow(int[] versionParts, int[] breakpoint)
{
Contract.Requires(versionParts.Length == 3);
Contract.Requires(breakpoint.Length == 3);
for (int i = 0; i < 3; i++)
{
if (versionParts[i] > breakpoint[i])
{
return false;
}
}
return true;
}

private static bool IsPreviewVersion(string[] versionParts)
{
return versionParts[2].Contains("-preview") && versionParts.Length == 4;
}

private static int GetPreviewVersion(string[] versionParts)
{
return Convert.ToInt32(versionParts[3]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Altinn.Studio.Designer.Helpers.Preview;
using Xunit;

namespace Designer.Tests.Helpers.Preview
{

public class NugetVersionHelperTests
{
[Fact]
public void GetMockedAltinnNugetBuildFromVersion_ShouldReturnEmptyStringForVersionsBelowBreakpoint()
{
Assert.Equal("", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("1.1.1"));
Assert.Equal("", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("1.1.1-preview.150"));
Assert.Equal("", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("1.1.1-preview.0"));
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.1.1-preview.14"));
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.8.8-preview.0"));
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.18.1238"));
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.18.1238"));
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.8.8-preview.342"));
Assert.Equal("8.0.0.0", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.0.0-preview.15"));
Assert.Equal("", NugetVersionHelper.GetMockedAltinnNugetBuildFromVersion("8.0.0-preview.14"));
}
}
}
5 changes: 5 additions & 0 deletions frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@
"code_list_editor.text_resource.label.select": "Finn ledetekst for kode nummer {{number}}",
"code_list_editor.text_resource.label.value": "Oppgi ledetekst for kode nummer {{number}}",
"code_list_editor.text_resource.no_text_resource_option_label": "Ikke oppgitt",
"code_list_editor.type_selector_description": "Kodenes datatype. Du kan bare endre denne når kodelisten er tom.",
"code_list_editor.type_selector_label": "Type",
"code_list_editor.type_selector_option_boolean": "Boolsk",
"code_list_editor.type_selector_option_number": "Tall",
"code_list_editor.type_selector_option_string": "Tekst",
"code_list_editor.value_item": "Kode nummer {{number}}",
"contact.altinn_servicedesk.content": "Er du tjenesteeier og har du behov for hjelp? Ta kontakt med oss!",
"contact.altinn_servicedesk.heading": "Altinn Servicedesk",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ export const WithoutTextResources: Story = {
texts,
},
};

export const Empty: Story = {
args: {
codeList: [],
texts,
},
};
Loading

0 comments on commit da6d385

Please sign in to comment.