From 8ebc5bb483b67861a195b53e261c57bd8b9344f1 Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Thu, 23 May 2024 14:54:31 +0200 Subject: [PATCH 1/4] Add endpoint in preview to get footer --- .../Designer/Controllers/PreviewController.cs | 8 ++++-- .../GitRepository/AltinnAppGitRepository.cs | 15 ++++++++++ backend/src/Designer/Models/FooterFile.cs | 28 +++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 backend/src/Designer/Models/FooterFile.cs diff --git a/backend/src/Designer/Controllers/PreviewController.cs b/backend/src/Designer/Controllers/PreviewController.cs index ce8f93184c4..9e514ae338e 100644 --- a/backend/src/Designer/Controllers/PreviewController.cs +++ b/backend/src/Designer/Controllers/PreviewController.cs @@ -933,12 +933,16 @@ public IActionResult UpdateAttachmentWithTag(string org, string app, [FromQuery] /// /// Unique identifier of the organisation responsible for the app. /// Application identifier which is unique within an organisation. + /// A that observes if operation is cancelled. /// Empty response [HttpGet] [Route("api/v1/footer")] - public IActionResult Footer(string org, string app) + public async Task Footer(string org, string app, CancellationToken cancellationToken) { - return Ok(); + string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext); + AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer); + FooterFile footerFile = await altinnAppGitRepository.GetFooter(cancellationToken); + return Ok(footerFile); } /// diff --git a/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs b/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs index fa52a336c6f..2692d036ab0 100644 --- a/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs +++ b/backend/src/Designer/Infrastructure/GitRepository/AltinnAppGitRepository.cs @@ -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"; @@ -598,6 +599,15 @@ public async Task SaveLayoutSets(LayoutSets layoutSets) } } + public async Task GetFooter(CancellationToken cancellationToken = default) + { + string footerFilePath = GetPathToFooterFile(); + cancellationToken.ThrowIfCancellationRequested(); + string fileContent = await ReadTextByRelativePathAsync(footerFilePath, cancellationToken); + FooterFile footerFileFile = JsonSerializer.Deserialize(fileContent, JsonOptions); + return footerFileFile; + } + /// /// Saves the RuleHandler.js for a specific layout set /// @@ -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() ? diff --git a/backend/src/Designer/Models/FooterFile.cs b/backend/src/Designer/Models/FooterFile.cs new file mode 100644 index 00000000000..b3ef7d7dbc2 --- /dev/null +++ b/backend/src/Designer/Models/FooterFile.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Altinn.Studio.Designer.Models; + +public class FooterFile +{ + [JsonPropertyName("$schema")] + public string Schema { get; set; } + + [JsonPropertyName("footer")] + public List Footer { get; set; } +} + +public class FooterConfig +{ + [JsonPropertyName("type")] + public string Type { get; set; } + + [JsonPropertyName("icon")] + public string Icon { get; set; } + + [JsonPropertyName("title")] + public string Title { get; set; } + + [JsonPropertyName("target")] + public string Target { get; set; } +} From 00571f1076177f67f6fa5cfddbce0308c56d98be Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Fri, 24 May 2024 09:44:17 +0200 Subject: [PATCH 2/4] Add tests --- .../Designer/Controllers/PreviewController.cs | 18 +++++-- backend/src/Designer/Models/FooterFile.cs | 8 ++- .../ApplicationMetadataTests.cs | 8 +-- .../ApplicationSettingsTests.cs | 2 +- .../PreviewController/DatamodelTests.cs | 4 +- .../GetApplicationLanguagesTests.cs | 2 +- .../PreviewController/GetFooterTests.cs | 49 +++++++++++++++++++ .../PreviewController/GetFormDataTests.cs | 6 +-- .../PreviewController/GetFormLayoutsTests.cs | 4 +- .../PreviewController/GetImageTests.cs | 12 ++--- .../PreviewController/GetOptionsTests.cs | 2 +- .../GetRuleConfigurationTests.cs | 2 +- .../PreviewController/LanguageTests.cs | 2 +- .../PreviewControllerTestsBase.cs | 3 +- .../PreviewController/TextResourcesTests.cs | 2 +- .../app-with-layoutsets/App/ui/footer.json | 11 +++++ 16 files changed, 104 insertions(+), 31 deletions(-) create mode 100644 backend/tests/Designer.Tests/Controllers/PreviewController/GetFooterTests.cs create mode 100644 backend/tests/Designer.Tests/_TestData/Repositories/testUser/ttd/app-with-layoutsets/App/ui/footer.json diff --git a/backend/src/Designer/Controllers/PreviewController.cs b/backend/src/Designer/Controllers/PreviewController.cs index 9e514ae338e..bba6d2991b6 100644 --- a/backend/src/Designer/Controllers/PreviewController.cs +++ b/backend/src/Designer/Controllers/PreviewController.cs @@ -937,12 +937,20 @@ public IActionResult UpdateAttachmentWithTag(string org, string app, [FromQuery] /// Empty response [HttpGet] [Route("api/v1/footer")] - public async Task Footer(string org, string app, CancellationToken cancellationToken) + public async Task> Footer(string org, string app, CancellationToken cancellationToken) { - string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext); - AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer); - FooterFile footerFile = await altinnAppGitRepository.GetFooter(cancellationToken); - return Ok(footerFile); + 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(); + } } /// diff --git a/backend/src/Designer/Models/FooterFile.cs b/backend/src/Designer/Models/FooterFile.cs index b3ef7d7dbc2..b828daf4288 100644 --- a/backend/src/Designer/Models/FooterFile.cs +++ b/backend/src/Designer/Models/FooterFile.cs @@ -9,20 +9,24 @@ public class FooterFile public string Schema { get; set; } [JsonPropertyName("footer")] - public List Footer { get; set; } + public List