Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 12784-implement-selec…
Browse files Browse the repository at this point in the history
…tion-of-datatypestosign-for-signing-tasks-in-process-config-panel
  • Loading branch information
mlqn committed Jun 6, 2024
2 parents bf6144a + 7ff8ad8 commit 9f6c920
Show file tree
Hide file tree
Showing 404 changed files with 5,930 additions and 13,017 deletions.
18 changes: 9 additions & 9 deletions backend/packagegroups/NuGet.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<ItemGroup Label="Altinn specific packages">
<PackageReference Update="Altinn.App.Core" Version="8.0.0-rc1" />
<PackageReference Update="Altinn.Common.AccessToken" Version="4.4.1" />
<PackageReference Update="Altinn.Common.AccessTokenClient" Version="3.0.2" />
<PackageReference Update="Altinn.Platform.Storage.Interface" Version="3.25.0" />
<PackageReference Update="Altinn.Common.AccessToken" Version="4.4.2" />
<PackageReference Update="Altinn.Common.AccessTokenClient" Version="3.0.3" />
<PackageReference Update="Altinn.Platform.Storage.Interface" Version="3.26.0" />
</ItemGroup>

<ItemGroup Label="Shared nuget packages">
Expand All @@ -19,7 +19,7 @@
<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="7.0.19" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.20" />
<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" />
Expand All @@ -29,7 +29,7 @@
<PackageReference Update="Microsoft.DiaSymReader.Native" Version="1.7.0" />
<PackageReference Update="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.16" />
<PackageReference Update="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Tools" Version="8.0.5" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6" />
<PackageReference Update="Scrutor" Version="4.2.2" />
<PackageReference Update="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Update="Polly" Version="8.4.0" />
Expand All @@ -40,12 +40,12 @@

<ItemGroup Label="Packages used for testing">
<PackageReference Update="FluentAssertions" Version="6.12.0" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.19" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.20" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<!-- Do not upgrade Moq version from 4.18.4 -->
<PackageReference Update="Moq" Version="4.18.4" />
<PackageReference Update="xunit" Version="2.8.0" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.8.0" />
<PackageReference Update="xunit" Version="2.8.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.8.1" />
<PackageReference Update="coverlet.collector" Version="6.0.2" />
<PackageReference Update="Basic.Reference.Assemblies" Version="1.7.2" />
<PackageReference Update="Fare" Version="2.2.1" />
Expand All @@ -54,7 +54,7 @@
<PackageReference Update="Microsoft.CodeAnalysis.Common" Version="4.9.2" />
<PackageReference Update="Testcontainers" Version="3.8.0" />
<PackageReference Update="Testcontainers.PostgreSql" Version="3.8.0" />
<PackageReference Update="Microsoft.AspNetCore.SignalR.Client" Version="8.0.5" />
<PackageReference Update="Microsoft.AspNetCore.SignalR.Client" Version="8.0.6" />
<PackageReference Update="Microsoft.Extensions.DependencyModel" Version="8.0.0" />
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions backend/src/Designer/Constants/General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ public static class General
/// The name of the cookie used for asp authentication in designer application
/// </summary>
public const string DesignerCookieName = "AltinnStudioDesigner";

/// <summary>
/// The identifying name for a custom receipt at process end in the application
/// </summary>
public const string CustomReceiptId = "CustomReceipt";
}
}
21 changes: 19 additions & 2 deletions backend/src/Designer/Controllers/PreviewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -933,12 +933,24 @@ public IActionResult UpdateAttachmentWithTag(string org, string app, [FromQuery]
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="app">Application identifier which is unique within an organisation.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
/// <returns>Empty response</returns>
[HttpGet]
[Route("api/v1/footer")]
public IActionResult Footer(string org, string app)
public async Task<ActionResult<FooterFile>> Footer(string org, string app, CancellationToken cancellationToken)
{
return Ok();
try
{
string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);
AltinnAppGitRepository altinnAppGitRepository =
_altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
FooterFile footerFile = await altinnAppGitRepository.GetFooter(cancellationToken);
return Ok(footerFile);
}
catch (FileNotFoundException)
{
return Ok();
}
}

/// <summary>
Expand Down Expand Up @@ -1002,6 +1014,11 @@ private static ApplicationMetadata SetMockDataTypeIfMissing(ApplicationMetadata
LayoutSets layoutSetsWithMockedDataTypesIfMissing = AddDataTypesToReturnedLayoutSetsIfMissing(layoutSets);
layoutSetsWithMockedDataTypesIfMissing.Sets.ForEach(set =>
{
if (set.Tasks[0] == Constants.General.CustomReceiptId)
{
return;
}
if (!applicationMetadata.DataTypes.Any(dataType => dataType.Id == set.DataType))
{
applicationMetadata.DataTypes.Add(new DataType()
Expand Down
4 changes: 2 additions & 2 deletions backend/src/Designer/Controllers/ProcessModelingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ await _processModelingService.SaveProcessDefinitionFromTemplateAsync(editingCont
}

[HttpPost("data-type/{dataTypeId}")]
public async Task<ActionResult> AddDataTypeToApplicationMetadata(string org, string repo, [FromRoute] string dataTypeId, CancellationToken cancellationToken)
public async Task<ActionResult> AddDataTypeToApplicationMetadata(string org, string repo, [FromRoute] string dataTypeId, [FromQuery] string taskId, CancellationToken cancellationToken)
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, repo, developer);
await _processModelingService.AddDataTypeToApplicationMetadataAsync(editingContext, dataTypeId, cancellationToken);
await _processModelingService.AddDataTypeToApplicationMetadataAsync(editingContext, dataTypeId, taskId, cancellationToken);
return Ok();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ await _fileSyncHandlerExecutor.ExecuteWithExceptionHandling(
var applicationMetadata = await repository.GetApplicationMetadata(cancellationToken);
if (TryChangeDataType(applicationMetadata, notification.NewDataType, notification.ConnectedTaskId))
if (notification.ConnectedTaskId != Constants.General.CustomReceiptId && TryChangeDataType(applicationMetadata, notification.NewDataType, notification.ConnectedTaskId))
{
await repository.SaveApplicationMetadata(applicationMetadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class AltinnAppGitRepository : AltinnGitRepository
private const string LayoutSettingsFilename = "Settings.json";
private const string AppMetadataFilename = "applicationmetadata.json";
private const string LayoutSetsFilename = "layout-sets.json";
private const string FooterFilename = "footer.json";
private const string RuleHandlerFilename = "RuleHandler.js";
private const string RuleConfigurationFilename = "RuleConfiguration.json";
private const string ProcessDefinitionFilename = "process.bpmn";
Expand Down Expand Up @@ -598,6 +599,15 @@ public async Task SaveLayoutSets(LayoutSets layoutSets)
}
}

public async Task<FooterFile> GetFooter(CancellationToken cancellationToken = default)
{
string footerFilePath = GetPathToFooterFile();
cancellationToken.ThrowIfCancellationRequested();
string fileContent = await ReadTextByRelativePathAsync(footerFilePath, cancellationToken);
FooterFile footerFile = JsonSerializer.Deserialize<FooterFile>(fileContent, JsonOptions);
return footerFile;
}

/// <summary>
/// Saves the RuleHandler.js for a specific layout set
/// </summary>
Expand Down Expand Up @@ -838,6 +848,11 @@ private static string GetPathToLayoutSetsFile()
return Path.Combine(LayoutsFolderName, LayoutSetsFilename);
}

private static string GetPathToFooterFile()
{
return Path.Combine(LayoutsFolderName, FooterFilename);
}

private static string GetPathToRuleHandler(string layoutSetName)
{
return layoutSetName.IsNullOrEmpty() ?
Expand Down
50 changes: 50 additions & 0 deletions backend/src/Designer/Models/FooterFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using JetBrains.Annotations;

namespace Altinn.Studio.Designer.Models;
public class FooterFile
{
[JsonPropertyName("$schema")]
public string Schema { get; set; }

[JsonPropertyName("footer")]
public List<FooterLayout> Footer { get; set; }
}

public class FooterLayout
{
[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public ComponentType Type { get; set; }

[JsonPropertyName("title")]
public string Title { get; set; }

[JsonPropertyName("target")]
[CanBeNull]
public string Target { get; set; }

[JsonPropertyName("icon")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public IconType? Icon { get; set; }
}

public enum ComponentType
{
Email,
Link,
Phone,
Text
}

public enum IconType
{
[EnumMember(Value = "information")]
Information,
[EnumMember(Value = "email")]
Email,
[EnumMember(Value = "phone")]
Phone
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,17 @@ public async Task<List<Team>> GetTeams()
/// <inheritdoc/>
public async Task<bool> PutStarred(string org, string repository)
{
HttpRequestMessage request = new(HttpMethod.Put, $"user/starred/{org}/{repository}");
HttpResponseMessage response = await _httpClient.SendAsync(request);
using HttpRequestMessage request = new(HttpMethod.Put, $"user/starred/{org}/{repository}");
using HttpResponseMessage response = await _httpClient.SendAsync(request);

return response.StatusCode == HttpStatusCode.NoContent;
}

/// <inheritdoc/>
public async Task<bool> DeleteStarred(string org, string repository)
{
HttpRequestMessage request = new(HttpMethod.Delete, $"user/starred/{org}/{repository}");
HttpResponseMessage response = await _httpClient.SendAsync(request);
using HttpRequestMessage request = new(HttpMethod.Delete, $"user/starred/{org}/{repository}");
using HttpResponseMessage response = await _httpClient.SendAsync(request);

return response.StatusCode == HttpStatusCode.NoContent;
}
Expand Down Expand Up @@ -436,7 +436,7 @@ public async Task<Branch> CreateBranch(string org, string repository, string bra
private async Task<HttpResponseMessage> PostBranch(string org, string repository, string branchName)
{
string content = $"{{\"new_branch_name\":\"{branchName}\"}}";
HttpRequestMessage message = new(HttpMethod.Post, $"repos/{org}/{repository}/branches");
using HttpRequestMessage message = new(HttpMethod.Post, $"repos/{org}/{repository}/branches");
message.Content = new StringContent(content, Encoding.UTF8, "application/json");

return await _httpClient.SendAsync(message);
Expand Down Expand Up @@ -573,7 +573,7 @@ public async Task<List<FileSystemObject>> GetDirectoryAsync(string org, string a
public async Task<bool> CreatePullRequest(string org, string repository, CreatePullRequestOption createPullRequestOption)
{
string content = JsonSerializer.Serialize(createPullRequestOption);
HttpResponseMessage response = await _httpClient.PostAsync($"repos/{org}/{repository}/pulls", new StringContent(content, Encoding.UTF8, "application/json"));
using HttpResponseMessage response = await _httpClient.PostAsync($"repos/{org}/{repository}/pulls", new StringContent(content, Encoding.UTF8, "application/json"));

return response.IsSuccessStatusCode;
}
Expand Down Expand Up @@ -648,8 +648,8 @@ private async Task DeleteAllAppKeys(List<string> appKeys, string csrf)
formValues.Add(new KeyValuePair<string, string>("_csrf", csrf));
formValues.Add(new KeyValuePair<string, string>("id", key));

FormUrlEncodedContent content = new(formValues);
HttpResponseMessage response = await client.PostAsync(giteaUrl, content);
using FormUrlEncodedContent content = new(formValues);
using HttpResponseMessage response = await client.PostAsync(giteaUrl, content);
if (!response.StatusCode.Equals(HttpStatusCode.OK))
{
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class PreviewService : IPreviewService
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory;
public const string MockDataModelIdPrefix = "MockDataModel";
public const string MockDataTaskId = "test-datatask-id";
private const string CustomReceiptTaskId = "CustomReceipt";

/// <summary>
/// Constructor
Expand All @@ -37,7 +36,7 @@ public async Task<Instance> GetMockInstance(string org, string app, string devel
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
Application applicationMetadata = await altinnAppGitRepository.GetApplicationMetadata(cancellationToken);
string task = await GetTaskForLayoutSetName(org, app, developer, layoutSetName, cancellationToken);
bool shouldProcessActAsReceipt = task == CustomReceiptTaskId;
bool shouldProcessActAsReceipt = task == Constants.General.CustomReceiptId;
// RegEx for instance guid in app-frontend: [\da-f]{8}-[\da-f]{4}-[1-5][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}
string instanceGuid = "f1e23d45-6789-1bcd-8c34-56789abcdef0";
ProcessState processState = shouldProcessActAsReceipt
Expand Down Expand Up @@ -97,7 +96,7 @@ public async Task<List<string>> GetTasksForAllLayoutSets(string org, string app,
{
foreach (LayoutSetConfig layoutSet in layoutSets.Sets.Where(ls => !tasks.Contains(ls.Tasks[0])))
{
if (layoutSet.Tasks[0] == CustomReceiptTaskId)
if (layoutSet.Tasks[0] == Constants.General.CustomReceiptId)
{
continue;
}
Expand Down Expand Up @@ -158,7 +157,7 @@ private async Task<List<DataElement>> GetDataTypesForInstance(string org, string
private async Task<string> GetDataTypeForCustomReceipt(AltinnAppGitRepository altinnAppGitRepository)
{
LayoutSets layoutSets = await altinnAppGitRepository.GetLayoutSetsFile();
string dataType = layoutSets?.Sets?.Find(set => set.Tasks[0] == CustomReceiptTaskId)?.DataType;
string dataType = layoutSets?.Sets?.Find(set => set.Tasks[0] == Constants.General.CustomReceiptId)?.DataType;
return dataType ?? string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Stream GetProcessDefinitionStream(AltinnRepoEditingContext altinnRepoEdit
return altinnAppGitRepository.GetProcessDefinitionFile();
}

public async Task AddDataTypeToApplicationMetadataAsync(AltinnRepoEditingContext altinnRepoEditingContext, string dataTypeId, CancellationToken cancellationToken = default)
public async Task AddDataTypeToApplicationMetadataAsync(AltinnRepoEditingContext altinnRepoEditingContext, string dataTypeId, string taskId, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(altinnRepoEditingContext.Org, altinnRepoEditingContext.Repo, altinnRepoEditingContext.Developer);
Expand All @@ -67,6 +67,7 @@ public async Task AddDataTypeToApplicationMetadataAsync(AltinnRepoEditingContext
Id = dataTypeId,
AllowedContentTypes = ["application/json"],
MaxCount = 1,
TaskId = taskId,
EnablePdfCreation = false
});
await altinnAppGitRepository.SaveApplicationMetadata(applicationMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async Task<ActionResult> PublishServiceResource(ServiceResource serviceRe

if (policyPath != null)
{
MultipartFormDataContent content = new MultipartFormDataContent();
using MultipartFormDataContent content = new MultipartFormDataContent();

if (ResourceAdminHelper.ValidFilePath(policyPath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public async Task<string> BuildSchemaFromXsd(AltinnRepoEditingContext altinnRepo
cancellationToken.ThrowIfCancellationRequested();
var altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(altinnRepoEditingContext.Org, altinnRepoEditingContext.Repo, altinnRepoEditingContext.Developer);

MemoryStream xsdMemoryStream = new MemoryStream();
using MemoryStream xsdMemoryStream = new MemoryStream();
xsdStream.CopyTo(xsdMemoryStream);
string jsonContent;
AltinnRepositoryType altinnRepositoryType = await altinnAppGitRepository.GetRepositoryType();
Expand Down Expand Up @@ -412,18 +412,18 @@ private static async Task DeleteDatatypeFromApplicationMetadataAndLayoutSets(Alt

if (applicationMetadata.DataTypes != null)
{
DataType removeForm = applicationMetadata.DataTypes.Find(m => m.Id == id);
DataType dataTypeToDelete = applicationMetadata.DataTypes.Find(m => m.Id == id);
if (altinnAppGitRepository.AppUsesLayoutSets())
{
var layoutSets = await altinnAppGitRepository.GetLayoutSetsFile();
var layoutSet = layoutSets.Sets.Find(set => set.Tasks[0] == removeForm.TaskId);
if (layoutSet is not null)
List<LayoutSetConfig> layoutSetsWithDataTypeToDelete = layoutSets.Sets.FindAll(set => set.DataType == id);
foreach (LayoutSetConfig layoutSet in layoutSetsWithDataTypeToDelete)
{
layoutSet.DataType = null;
await altinnAppGitRepository.SaveLayoutSets(layoutSets);
}
await altinnAppGitRepository.SaveLayoutSets(layoutSets);
}
applicationMetadata.DataTypes.Remove(removeForm);
applicationMetadata.DataTypes.Remove(dataTypeToDelete);
await altinnAppGitRepository.SaveApplicationMetadata(applicationMetadata);
}
}
Expand Down
Loading

0 comments on commit 9f6c920

Please sign in to comment.