Skip to content

Commit

Permalink
Merge branch 'main' into feat/13686-support-access-packages-in-policy…
Browse files Browse the repository at this point in the history
…-editor-v1
  • Loading branch information
mgunnerud authored Nov 18, 2024
2 parents 4601a44 + 0aa6a45 commit 99838b4
Show file tree
Hide file tree
Showing 275 changed files with 4,512 additions and 2,405 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-designer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
artifact-environment: ${{ matrix.environment == 'preapproved-prod' && 'prod' || matrix.environment }}
config-chart-name: altinn-designer-config
artifact-name: altinn-designer
helm-set-arguments: environmentName=${{ matrix.environment == 'preapproved-prod' && 'prod' || matrix.environment }},chartVersion=0.1.0+${{ needs.determine-tag.outputs.tag }},imageTag=${{ needs.determine-tag.outputs.tag }},dbMigrationsTag=${{ needs.determine-tag.outputs.tag }}
helm-set-arguments: environmentName=${{ matrix.environment == 'preapproved-prod' && 'prod' || matrix.environment }},chartVersion=0.1.0+${{ needs.determine-tag.outputs.tag }},imageTag=${{ needs.determine-tag.outputs.tag }},dbMigrationsTag=${{ needs.determine-tag.outputs.tag }},replicas=${{ matrix.environment == 'dev' && 1 || 2 }}
trace-workflow: true
trace-team-name: 'team-studio'
secrets:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/designer-dotnet-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/dotnet-migrations-ensure-compatibility.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Ensure Migrations Compatibility
on:
pull_request:
branches: [ main ]
types: [opened, synchronize, reopened]
paths:
- 'backend/**'
- '.github/workflows/dotnet-migrations-ensure-compatibility.yaml'
workflow_dispatch:

jobs:
ensure-migrations-compatibility:
name: Try to generate script and to add a new migrations
runs-on: ubuntu-latest
env:
OidcLoginSettings__FetchClientIdAndSecretFromRootEnvFile: 'false'
OidcLoginSettings__ClientId: 'dummyRequired'
OidcLoginSettings__ClientSecret: 'dummyRequired'
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.0.x
- uses: actions/checkout@v4

- name: Install dotnet ef # Version should be the same as Migrations docker file and project
run: dotnet tool install --version 8.0.7 --global dotnet-ef

- name: Check if migrations script can be generated
run: |
dotnet ef migrations script --project backend/src/Designer
- name: Check if it's possible to add a new migration
run: |
dotnet ef migrations add Test --project backend/src/Designer
2 changes: 1 addition & 1 deletion .github/workflows/gitea-designer-integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ COPY . .
RUN yarn build

# Building the backend
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS generate-studio-backend
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS generate-studio-backend
ARG DESIGNER_VERSION=''
WORKDIR /build
COPY backend .
Expand All @@ -52,7 +52,7 @@ WORKDIR /version
RUN echo "{\"designerVersion\":\"$DESIGNER_VERSION\",\"appTemplateVersion\":\"$(curl -s https://api.github.com/repos/Altinn/app-template-dotnet/releases/latest | jq -r .tag_name)\"}" > version.json

# Building the final image
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS final
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine AS final
EXPOSE 80
WORKDIR /app
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ See deployment for notes on how to deploy the project on a live system.

### Prerequisites

1. Newest [.NET 8 SDK][5]
1. Newest [.NET 9 SDK][5]
2. [Node.js][6] (Latest LTS version, v20.\*)
3. Newest [Git][7]
4. A code editor - we like [Visual Studio Code][8]
Expand Down Expand Up @@ -184,10 +184,10 @@ See also the [list of contributors][26] who participated in this project.
This project is licensed under the 3-Clause BSD License - see the [LICENSE.md](LICENSE.md) file for details.

[1]: https://docs.altinn.studio/
[2]: https://docs.altinn.studio/app/getting-started/
[3]: https://docs.altinn.studio/app/app-dev-course/
[2]: https://docs.altinn.studio/altinn-studio/getting-started/
[3]: https://docs.altinn.studio/altinn-studio/getting-started/app-dev-course/
[4]: https://github.com/Altinn/app-localtest
[5]: https://dotnet.microsoft.com/download/dotnet/8.0
[5]: https://dotnet.microsoft.com/download/dotnet/9.0
[6]: https://nodejs.org
[7]: https://git-scm.com/downloads
[8]: https://code.visualstudio.com/Download
Expand Down
2 changes: 1 addition & 1 deletion backend/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Company>Altinn</Company>
<Product>Altinn Studio</Product>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion backend/Migrations.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build

WORKDIR /app

Expand Down
13 changes: 7 additions & 6 deletions backend/packagegroups/NuGet.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,33 @@
<PackageReference Update="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Update="Microsoft.AspNetCore.DataProtection.AzureKeyVault" Version="3.1.24" />
<PackageReference Update="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.10" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.0" />
<PackageReference Update="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Update="Microsoft.Azure.Security.KeyVault.Secrets" Version="4.5.0" />
<PackageReference Update="Microsoft.Azure.Services.AppAuthentication" Version="1.6.2" />
<PackageReference Update="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.24" />
<PackageReference Update="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.10" />
<PackageReference Update="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.0" />
<PackageReference Update="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Update="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageReference Update="HtmlAgilityPack" Version="1.11.67" />
<PackageReference Update="Microsoft.DiaSymReader.Native" Version="1.7.0" />
<PackageReference Update="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10" />
<PackageReference Update="Microsoft.FeatureManagement.AspNetCore" Version="3.5.0" />
<PackageReference Update="Scrutor" Version="4.2.2" />
<PackageReference Update="Swashbuckle.AspNetCore" Version="6.8.1" />
<PackageReference Update="Polly" Version="8.4.2" />
<PackageReference Update="Altinn.Authorization.ABAC" Version="0.0.8" />
<PackageReference Update="Altinn.ApiClients.Maskinporten" Version="9.2.0" />
<PackageReference Update="MediatR" Version="12.4.1" />
<PackageReference Update="DotNetEnv" Version="3.1.1" />
<PackageReference Update="NuGet.Versioning" Version="6.11.1" />
<PackageReference Update="DistributedLock.Postgres" Version="1.2.0" />
<PackageReference Update="Community.Microsoft.Extensions.Caching.PostgreSql" Version="4.0.6" />
</ItemGroup>

<ItemGroup Label="Packages used for testing">
<PackageReference Update="FluentAssertions" Version="6.12.1" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.10" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<!-- Do not upgrade Moq version from 4.18.4 -->
<PackageReference Update="Moq" Version="4.18.4" />
Expand All @@ -58,8 +59,8 @@
<PackageReference Update="Microsoft.CodeAnalysis.Common" Version="4.9.2" />
<PackageReference Update="Testcontainers" Version="3.10.0" />
<PackageReference Update="Testcontainers.PostgreSql" Version="3.10.0" />
<PackageReference Update="Microsoft.AspNetCore.SignalR.Client" Version="8.0.10" />
<PackageReference Update="Microsoft.Extensions.DependencyModel" Version="8.0.2" />
<PackageReference Update="Microsoft.AspNetCore.SignalR.Client" Version="9.0.0" />
<PackageReference Update="Microsoft.Extensions.DependencyModel" Version="9.0.0" />
<PackageReference Update="WireMock.Net" Version="1.6.7" />
<PackageReference Update="DistributedLock.FileSystem" Version="1.0.2" />
</ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions backend/src/Designer/Controllers/AppDevelopmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ await _mediator.Publish(new ComponentIdChangedEvent
}
if (!formLayouts.ContainsKey(layoutName))
{
LayoutSetConfig layoutSetConfig = await _appDevelopmentService.GetLayoutSetConfig(editingContext, layoutSetName, cancellationToken);
await _mediator.Publish(new LayoutPageAddedEvent
{
LayoutSetConfig = layoutSetConfig,
LayoutName = layoutName,
EditingContext = editingContext,
}, cancellationToken);
}
Expand Down Expand Up @@ -347,6 +350,11 @@ public async Task<ActionResult> AddLayoutSet(string org, string app, [FromBody]
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer);
bool layoutIsInitialForPaymentTask = layoutSetPayload.TaskType == TaskType.Payment;
LayoutSets layoutSets = await _appDevelopmentService.AddLayoutSet(editingContext, layoutSetPayload.LayoutSetConfig, layoutIsInitialForPaymentTask, cancellationToken);
await _mediator.Publish(new LayoutSetCreatedEvent
{
EditingContext = editingContext,
LayoutSet = layoutSetPayload.LayoutSetConfig
}, cancellationToken);
return Ok(layoutSets);
}

Expand Down
2 changes: 1 addition & 1 deletion backend/src/Designer/Controllers/OptionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task<ActionResult<List<Option>>> GetOptionsList(string org, string
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[Route("{optionsListId}")]
public async Task<ActionResult> CreateOrOverwriteOptionsList(string org, string repo, [FromRoute] string optionsListId, [FromBody] List<Option> payload, CancellationToken cancellationToken = default)
public async Task<ActionResult<Dictionary<string, List<Option>>>> CreateOrOverwriteOptionsList(string org, string repo, [FromRoute] string optionsListId, [FromBody] List<Option> payload, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
Expand Down
5 changes: 3 additions & 2 deletions backend/src/Designer/Designer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<PackageReference Include="Altinn.Common.AccessTokenClient" />
<PackageReference Include="Altinn.Platform.Storage.Interface" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" />
<PackageReference Include="Community.Microsoft.Extensions.Caching.PostgreSql" />
<PackageReference Include="CompilerAttributes" />
<PackageReference Include="DistributedLock.Postgres" />
<PackageReference Include="DotNetEnv" />
Expand All @@ -40,6 +41,7 @@
<PackageReference Include="Microsoft.AspNetCore.DataProtection.AzureKeyVault" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
<PackageReference Include="Microsoft.Azure.KeyVault" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
Expand All @@ -57,7 +59,6 @@
<PackageReference Include="NuGet.Versioning" />
<PackageReference Include="Polly" />
<PackageReference Include="Scrutor" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(CodeAnalisysCompatibleVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="$(CodeAnalisysCompatibleVersion)" />
</ItemGroup>
Expand Down Expand Up @@ -167,7 +168,7 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Migrations/InitialSqlScripts/*.sql" />
<EmbeddedResource Include="Migrations/SqlScripts/**/*.sql" />
</ItemGroup>

<Target Name="AfterPublishScript" AfterTargets="Publish">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -68,29 +69,37 @@ private void FindIdOccurrencesRecursive(JsonNode node, string oldComponentId, st
// Should we check if node is string to avoid unnecessary upcoming checks?
if (node is JsonObject jsonObject)
{
if (jsonObject[oldComponentId] is not null)
foreach (var property in jsonObject.ToList())
{
// When componentId is the propertyName
UpdateComponentIdActingAsPropertyName(jsonObject, oldComponentId, newComponentId);
}
else if (jsonObject["component"] is not null)
{
// Objects that references components i.e. in `rowsAfter` in RepeatingGroup
UpdateComponentIdActingAsCellMemberInRepeatingGroup(jsonObject, oldComponentId, newComponentId);
}
else if (jsonObject["tableHeaders"] is JsonArray tableHeadersArray)
{
// Objects that references components in `tableHeaders` in RepeatingGroup
UpdateComponentIdActingAsTableHeaderInRepeatingGroup(tableHeadersArray, oldComponentId, newComponentId);
}
else if (jsonObject["componentRef"] is not null)
{
// Components that are used in summary components will have this ref
UpdateComponentIdActingAsComponentRefInSummary(jsonObject, oldComponentId, newComponentId);
}
foreach (var property in jsonObject)
{
FindIdOccurrencesRecursive(property.Value, oldComponentId, newComponentId);
switch (property.Key)
{
case "component": // Objects that references components i.e. in `rowsAfter` in RepeatingGroup
case "componentRef": // Components that are used in summary components will have this ref
if (property.Value?.ToString() == oldComponentId)
{
jsonObject[property.Key] = newComponentId;
}
break;
case "tableHeaders":
if (property.Value is JsonArray tableHeadersArray)
{
// Objects that references components in `tableHeaders` in RepeatingGroup
UpdateComponentIdActingAsTableHeaderInRepeatingGroup(tableHeadersArray, oldComponentId, newComponentId);
}
break;
case "tableColumns":
if (jsonObject["type"]?.ToString() == "RepeatingGroup"
&& property.Value is JsonObject tableColumns
&& tableColumns[oldComponentId] is not null
)
{
UpdateComponentIdActingAsPropertyName(tableColumns, oldComponentId, newComponentId);
}
break;
default:
FindIdOccurrencesRecursive(property.Value, oldComponentId, newComponentId);
break;
}
}
}
else if (node is JsonArray jsonArray)
Expand Down Expand Up @@ -126,14 +135,6 @@ private void UpdateComponentIdActingAsExpressionMember(JsonArray jsonArray, stri
jsonArray[1] = newComponentId;
}

private void UpdateComponentIdActingAsCellMemberInRepeatingGroup(JsonNode jsonNode, string oldComponentId, string newComponentId)
{
if (jsonNode["component"]?.ToString() == oldComponentId)
{
jsonNode["component"] = newComponentId;
}
}

private void UpdateComponentIdActingAsTableHeaderInRepeatingGroup(JsonArray jsonArray, string oldComponentId, string newComponentId)
{
for (int i = 0; i < jsonArray.Count; i++)
Expand All @@ -151,13 +152,4 @@ private void UpdateComponentIdActingAsTableHeaderInRepeatingGroup(JsonArray json
}
}
}

private void UpdateComponentIdActingAsComponentRefInSummary(JsonNode jsonNode, string oldComponentId, string newComponentId)
{
if (jsonNode["componentRef"]?.ToString() == oldComponentId)
{
jsonNode["componentRef"] = newComponentId;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Events;
using Altinn.Studio.Designer.Hubs.SyncHub;
using Altinn.Studio.Designer.Services.Interfaces;
using MediatR;

namespace Altinn.Studio.Designer.EventHandlers.LayoutPageAdded;

public class SubformCreatedHandler(
IAppDevelopmentService appDevelopmentService,
IFileSyncHandlerExecutor fileSyncHandlerExecutor
) : INotificationHandler<LayoutPageAddedEvent>
{
public async Task Handle(
LayoutPageAddedEvent notification,
CancellationToken cancellationToken)
{

await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification(
notification.EditingContext,
SyncErrorCodes.LayoutSetSubFormButtonSyncError,
"layouts",
async () =>
{
if (notification.LayoutSetConfig.Type == "subform")
{
Guid guid = Guid.NewGuid();
string randomId = guid.ToString().Split('-')[0];
object buttonComponent = new
{
id = $"CloseSubformButton-{randomId}",
type = "CustomButton",
actions = new[] {
new {
type = "ClientAction",
id = "closeSubform"
}},
};
await appDevelopmentService.AddComponentToLayout(notification.EditingContext, notification.LayoutSetConfig.Id, notification.LayoutName, buttonComponent, cancellationToken);
return true;
}
return false;
});
}
}
Loading

0 comments on commit 99838b4

Please sign in to comment.