-
Notifications
You must be signed in to change notification settings - Fork 24
feat: instance contextual layout fetching #1544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jondyr
wants to merge
12
commits into
main
Choose a base branch
from
feat/instance-contextual-layout-fetching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5ce876f
add feature flag
Jondyr 3218e40
add service using `AsyncLocal` for instance context across request
Jondyr ca3b07d
Use optional service for custom layouts if implemented by app
Jondyr 271ca38
add xml comments
Jondyr 301807c
add tests
Jondyr 733ec02
add spec verification file
Jondyr cf8a7aa
update controller endpoint
Jondyr ec066af
use xunit assertions
Jondyr fad3f05
Merge branch 'main' into feat/instance-contextual-layout-fetching
Jondyr 0bfe1ba
feat: add layout settings endpoint to ICustomLayoutForInstance interface
Jondyr 6adad98
Merge branch 'main' into feat/instance-contextual-layout-fetching
JamalAlabdullah 668ffdc
Merge branch 'main' into feat/instance-contextual-layout-fetching
JamalAlabdullah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Altinn.App.Core/Internal/App/ICustomLayoutForInstance.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using Altinn.App.Core.Features; | ||
|
|
||
| namespace Altinn.App.Core.Internal.App; | ||
|
|
||
| /// <summary> | ||
| /// Interface for getting custom layouts for an instance. | ||
| /// </summary> | ||
| [ImplementableByApps] | ||
| public interface ICustomLayoutForInstance | ||
| { | ||
| /// <summary> | ||
| /// Gets the custom layout | ||
| /// </summary> | ||
| /// <param name="layoutSetId">The layout set ID</param> | ||
| /// <param name="instanceOwnerPartyId">The instance owner party ID</param> | ||
| /// <param name="instanceGuid">The instance GUID</param> | ||
| Task<string?> GetCustomLayoutForInstance(string layoutSetId, int instanceOwnerPartyId, Guid instanceGuid); | ||
|
|
||
| /// <summary> | ||
| /// Gets the custom layout settings | ||
| /// </summary> | ||
| /// <param name="layoutSetId">The layout set ID</param> | ||
| /// <param name="instanceOwnerPartyId">The instance owner party ID</param> | ||
| /// <param name="instanceGuid">The instance GUID</param> | ||
| Task<string?> GetCustomLayoutSettingsForInstance(string layoutSetId, int instanceOwnerPartyId, Guid instanceGuid); | ||
| } |
131 changes: 131 additions & 0 deletions
131
test/Altinn.App.Api.Tests/Controllers/ResourceController_CustomLayoutTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| using System.Net; | ||
| using System.Text.Json; | ||
| using Altinn.App.Api.Tests.Data; | ||
| using Altinn.App.Core.Internal.App; | ||
| using Microsoft.AspNetCore.Mvc.Testing; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Altinn.App.Api.Tests.Controllers; | ||
|
|
||
| public class ResourceController_CustomLayoutTests : ApiTestBase, IClassFixture<WebApplicationFactory<Program>> | ||
| { | ||
| public ResourceController_CustomLayoutTests(WebApplicationFactory<Program> factory, ITestOutputHelper outputHelper) | ||
| : base(factory, outputHelper) { } | ||
|
|
||
| private class CustomLayoutForInstance : ICustomLayoutForInstance | ||
| { | ||
| public Task<string?> GetCustomLayoutForInstance(string layoutSetId, int instanceOwnerPartyId, Guid instanceId) | ||
| { | ||
| return Task.FromResult<string?>(instanceId.ToString()); | ||
| } | ||
|
|
||
| public Task<string?> GetCustomLayoutSettingsForInstance( | ||
| string layoutSetId, | ||
| int instanceOwnerPartyId, | ||
| Guid instanceId | ||
| ) | ||
| { | ||
| return Task.FromResult<string?>(instanceId.ToString()); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetLayoutsForSet_WithCustomLayoutForInstanceService_ReturnsOk() | ||
| { | ||
| OverrideServicesForThisTest = (services) => | ||
| { | ||
| services.AddSingleton<ICustomLayoutForInstance, CustomLayoutForInstance>(); | ||
| }; | ||
|
|
||
| string org = "tdd"; | ||
| string app = "contributer-restriction"; | ||
| int instanceOwnerPartyId = 500600; | ||
| Guid instanceGuid = Guid.Parse("cff1cb24-5bc1-4888-8e06-c634753c5144"); | ||
| string layoutSetId = "default"; | ||
| using HttpClient client = GetRootedUserClient(org, app, 1337, instanceOwnerPartyId); | ||
|
|
||
| TestData.PrepareInstance(org, app, instanceOwnerPartyId, instanceGuid); | ||
| var response = await client.GetAsync( | ||
| $"/{org}/{app}/instances/{instanceOwnerPartyId}/{instanceGuid}/layouts/{layoutSetId}" | ||
| ); | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| var content = await response.Content.ReadAsStringAsync(); | ||
| Assert.Equal(instanceGuid.ToString(), content); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetLayoutsForSet_WithoutCustomLayoutForInstanceService_ReturnsOk() | ||
| { | ||
| string org = "tdd"; | ||
| string app = "contributer-restriction"; | ||
| int instanceOwnerPartyId = 500600; | ||
| Guid instanceGuid = Guid.Parse("cff1cb24-5bc1-4888-8e06-c634753c5144"); | ||
| string layoutSetId = "default"; | ||
| using HttpClient client = GetRootedUserClient(org, app, 1337, instanceOwnerPartyId); | ||
|
|
||
| TestData.PrepareInstance(org, app, instanceOwnerPartyId, instanceGuid); | ||
| var response = await client.GetAsync( | ||
| $"/{org}/{app}/instances/{instanceOwnerPartyId}/{instanceGuid}/layouts/{layoutSetId}" | ||
| ); | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| var content = await response.Content.ReadAsStringAsync(); | ||
| using var jsonDoc = JsonDocument.Parse(content); | ||
| var root = jsonDoc.RootElement; | ||
| Assert.Equal(JsonValueKind.Object, root.ValueKind); | ||
| Assert.True(root.TryGetProperty("page", out var pageLayout)); | ||
| Assert.True(pageLayout.TryGetProperty("data", out var data)); | ||
| Assert.True(data.TryGetProperty("layout", out var layout)); | ||
| Assert.Equal(JsonValueKind.Array, layout.ValueKind); | ||
| Assert.True(layout.GetArrayLength() > 0); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetLayoutSettingsForSet_WithCustomLayoutForInstanceService_ReturnsOk() | ||
| { | ||
| OverrideServicesForThisTest = (services) => | ||
| { | ||
| services.AddSingleton<ICustomLayoutForInstance, CustomLayoutForInstance>(); | ||
| }; | ||
|
|
||
| string org = "tdd"; | ||
| string app = "contributer-restriction"; | ||
| int instanceOwnerPartyId = 500600; | ||
| Guid instanceGuid = Guid.Parse("cff1cb24-5bc1-4888-8e06-c634753c5144"); | ||
| string layoutSetId = "default"; | ||
| using HttpClient client = GetRootedUserClient(org, app, 1337, instanceOwnerPartyId); | ||
|
|
||
| TestData.PrepareInstance(org, app, instanceOwnerPartyId, instanceGuid); | ||
| var response = await client.GetAsync( | ||
| $"/{org}/{app}/instances/{instanceOwnerPartyId}/{instanceGuid}/layoutsettings/{layoutSetId}" | ||
| ); | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| var content = await response.Content.ReadAsStringAsync(); | ||
| Assert.Equal(instanceGuid.ToString(), content); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task GetLayoutSettingsForSet_WithoutCustomLayoutForInstanceService_ReturnsOk() | ||
| { | ||
| string org = "tdd"; | ||
| string app = "contributer-restriction"; | ||
| int instanceOwnerPartyId = 500600; | ||
| Guid instanceGuid = Guid.Parse("cff1cb24-5bc1-4888-8e06-c634753c5144"); | ||
| string layoutSetId = "default"; | ||
| using HttpClient client = GetRootedUserClient(org, app, 1337, instanceOwnerPartyId); | ||
|
|
||
| TestData.PrepareInstance(org, app, instanceOwnerPartyId, instanceGuid); | ||
| var response = await client.GetAsync( | ||
| $"/{org}/{app}/instances/{instanceOwnerPartyId}/{instanceGuid}/layoutsettings/{layoutSetId}" | ||
| ); | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| var content = await response.Content.ReadAsStringAsync(); | ||
| using var jsonDoc = JsonDocument.Parse(content); | ||
| var root = jsonDoc.RootElement; | ||
| Assert.Equal(JsonValueKind.Object, root.ValueKind); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.