Skip to content

Commit

Permalink
Merge branch 'main' into adjust-text-resource-component-for-input-table
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasEng authored Nov 29, 2024
2 parents 578b250 + 2761798 commit 526f86e
Show file tree
Hide file tree
Showing 77 changed files with 1,128 additions and 208 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-approve-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
if: github.event.label.name == 'skip-manual-testing'
steps:
- name: Checkout PR code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
run: yarn test:ci

- name: 'Upload coverage reports to Codecov'
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
Expand Down
11 changes: 11 additions & 0 deletions backend/src/Designer/Controllers/AppDevelopmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,17 @@ public async Task<IActionResult> GetLayoutSets(string org, string app, Cancellat
return Ok(layoutSets);
}

[HttpGet("layout-sets/extended")]
[UseSystemTextJson]
public async Task<LayoutSetsModel> GetLayoutSetsExtended(string org, string app, CancellationToken cancellationToken)
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer);

LayoutSetsModel layoutSetsModel = await _appDevelopmentService.GetLayoutSetsExtended(editingContext, cancellationToken);
return layoutSetsModel;
}

/// <summary>
/// Add a new layout set
/// </summary>
Expand Down
20 changes: 15 additions & 5 deletions backend/src/Designer/Controllers/ResourceAdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Altinn.Studio.Designer.ModelBinding.Constants;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Services.Interfaces;
using Altinn.Studio.Designer.Services.Models;
using Altinn.Studio.Designer.TypedHttpClients.ResourceRegistryOptions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -34,18 +35,18 @@ public class ResourceAdminController : ControllerBase
private readonly CacheSettings _cacheSettings;
private readonly IOrgService _orgService;
private readonly IResourceRegistry _resourceRegistry;
private readonly ResourceRegistryIntegrationSettings _resourceRegistrySettings;
private readonly IEnvironmentsService _environmentsService;

public ResourceAdminController(IGitea gitea, IRepository repository, IResourceRegistryOptions resourceRegistryOptions, IMemoryCache memoryCache, IOptions<CacheSettings> cacheSettings, IOrgService orgService, IOptions<ResourceRegistryIntegrationSettings> resourceRegistryEnvironment, IResourceRegistry resourceRegistry)
public ResourceAdminController(IGitea gitea, IRepository repository, IResourceRegistryOptions resourceRegistryOptions, IMemoryCache memoryCache, IOptions<CacheSettings> cacheSettings, IOrgService orgService, IResourceRegistry resourceRegistry, IEnvironmentsService environmentsService)
{
_giteaApi = gitea;
_repository = repository;
_resourceRegistryOptions = resourceRegistryOptions;
_memoryCache = memoryCache;
_cacheSettings = cacheSettings.Value;
_orgService = orgService;
_resourceRegistrySettings = resourceRegistryEnvironment.Value;
_resourceRegistry = resourceRegistry;
_environmentsService = environmentsService;
}

[HttpPost]
Expand Down Expand Up @@ -175,12 +176,14 @@ public async Task<ActionResult<List<ListviewServiceResource>>> GetRepositoryReso

if (includeEnvResources)
{
foreach (string environment in _resourceRegistrySettings.Keys)
IEnumerable<string> environments = await GetEnvironmentsForOrg(org);
foreach (string environment in environments)
{
string cacheKey = $"resourcelist_${environment}";
if (!_memoryCache.TryGetValue(cacheKey, out List<ServiceResource> environmentResources))
{
environmentResources = await _resourceRegistry.GetResourceList(environment, false);

var cacheEntryOptions = new MemoryCacheEntryOptions()
.SetPriority(CacheItemPriority.High)
.SetAbsoluteExpiration(new TimeSpan(0, _cacheSettings.DataNorgeApiCacheTimeout, 0));
Expand Down Expand Up @@ -239,7 +242,8 @@ public async Task<ActionResult<ServiceResourceStatus>> GetPublishStatusById(stri
PublishedVersions = []
};

foreach (string envir in _resourceRegistrySettings.Keys)
IEnumerable<string> environments = await GetEnvironmentsForOrg(org);
foreach (string envir in environments)
{
resourceStatus.PublishedVersions.Add(await AddEnvironmentResourceStatus(envir, id));
}
Expand Down Expand Up @@ -643,5 +647,11 @@ private string GetRepositoryName(string org)
{
return string.Format("{0}-resources", org);
}

private async Task<IEnumerable<string>> GetEnvironmentsForOrg(string org)
{
IEnumerable<EnvironmentModel> environments = await _environmentsService.GetOrganizationEnvironments(org);
return environments.Select(environment => environment.Name == "production" ? "prod" : environment.Name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Serialization;
using Altinn.App.Core.Internal.Process.Elements;
using Altinn.Studio.Designer.Configuration;
using Altinn.Studio.Designer.Exceptions.AppDevelopment;
using Altinn.Studio.Designer.Helpers;
Expand Down Expand Up @@ -804,6 +806,13 @@ public Stream GetProcessDefinitionFile()
return OpenStreamByRelativePath(ProcessDefinitionFilePath);
}

public Definitions GetDefinitions()
{
Stream processDefinitionStream = GetProcessDefinitionFile();
XmlSerializer serializer = new(typeof(Definitions));
return (Definitions)serializer.Deserialize(processDefinitionStream);
}

/// <summary>
/// Checks if image already exists in wwwroot
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions backend/src/Designer/Models/Dto/LayoutSetModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Text.Json.Serialization;

namespace Altinn.Studio.Designer.Models.Dto;

public class LayoutSetModel
{
[JsonPropertyName("id")]
public string id { get; set; }
[JsonPropertyName("dataType")]
public string dataType { get; set; }
[JsonPropertyName("type")]
public string type { get; set; }
[JsonPropertyName("task")]
public TaskModel task { get; set; }
}

10 changes: 10 additions & 0 deletions backend/src/Designer/Models/Dto/LayoutSets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Altinn.Studio.Designer.Models.Dto;

public class LayoutSetsModel
{
[JsonPropertyName("sets")]
public List<LayoutSetModel> sets { get; set; } = [];
}
12 changes: 12 additions & 0 deletions backend/src/Designer/Models/Dto/TaskModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace Altinn.Studio.Designer.Models.Dto;

public class TaskModel
{
[JsonPropertyName("id")]
public string id { get; set; }
[JsonPropertyName("type")]
public string type { get; set; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Altinn.App.Core.Internal.Process.Elements;
using Altinn.App.Core.Models;
using Altinn.Studio.DataModeling.Metamodel;
using Altinn.Studio.Designer.Exceptions.AppDevelopment;
using Altinn.Studio.Designer.Helpers;
using Altinn.Studio.Designer.Infrastructure.GitRepository;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Models.Dto;
using Altinn.Studio.Designer.Services.Interfaces;
using Microsoft.AspNetCore.Http;
using NuGet.Versioning;
Expand Down Expand Up @@ -265,6 +267,43 @@ public async Task<LayoutSets> GetLayoutSets(AltinnRepoEditingContext altinnRepoE
"No layout set found for this app.");
}

private static string TaskTypeFromDefinitions(Definitions definitions, string taskId)
{
return definitions.Process.Tasks.FirstOrDefault(task => task.Id == taskId)?.ExtensionElements?.TaskExtension?.TaskType ?? string.Empty;
}

public async Task<LayoutSetsModel> GetLayoutSetsExtended(AltinnRepoEditingContext altinnRepoEditingContext, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(altinnRepoEditingContext.Org, altinnRepoEditingContext.Repo, altinnRepoEditingContext.Developer);

LayoutSets layoutSetsFile = await altinnAppGitRepository.GetLayoutSetsFile(cancellationToken);
Definitions definitions = altinnAppGitRepository.GetDefinitions();

LayoutSetsModel layoutSetsModel = new();
layoutSetsFile.Sets.ForEach(set =>
{
LayoutSetModel layoutSetModel = new()
{
id = set.Id,
dataType = set.DataType,
type = set.Type,
};
string taskId = set.Tasks?[0];
if (taskId != null)
{
string taskType = TaskTypeFromDefinitions(definitions, taskId);
layoutSetModel.task = new TaskModel
{
id = taskId,
type = taskType
};
}
layoutSetsModel.sets.Add(layoutSetModel);
});
return layoutSetsModel;
}

/// <inheritdoc />
public async Task<LayoutSetConfig> GetLayoutSetConfig(AltinnRepoEditingContext altinnRepoEditingContext, string layoutSetId,
CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Altinn.Studio.DataModeling.Metamodel;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Models.Dto;
using JetBrains.Annotations;

namespace Altinn.Studio.Designer.Services.Interfaces
Expand Down Expand Up @@ -106,6 +107,13 @@ public Task<ModelMetadata> GetModelMetadata(
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is canceled.</param>
public Task<LayoutSets> GetLayoutSets(AltinnRepoEditingContext altinnRepoEditingContext, CancellationToken cancellationToken = default);

/// <summary>
/// Extended version of layout sets with the intention of adding information not included in the raw layout-sets.json file.
/// </summary>
/// <param name="altinnRepoEditingContext">An <see cref="AltinnRepoEditingContext"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is canceled.</param>
public Task<LayoutSetsModel> GetLayoutSetsExtended(AltinnRepoEditingContext altinnRepoEditingContext, CancellationToken cancellationToken = default);

/// <summary>
/// Gets a layoutSet config.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions backend/src/Designer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
}
},
"ResourceRegistryIntegrationSettings": {
"YT01": {
"ResourceRegistryEnvBaseUrl": "https://platform.yt01.altinn.cloud"
},
"AT22": {
"ResourceRegistryEnvBaseUrl": "https://platform.at22.altinn.cloud",
"SblBridgeBaseUrl": "https://at22.altinn.cloud/sblbridge/"
Expand Down
2 changes: 1 addition & 1 deletion charts/altinn-loadbalancer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ loadbalancerIP:
sidecar:
enabled: true
name: "exporter"
image: "ghcr.io/martin-helmich/prometheus-nginxlog-exporter/exporter@sha256:2174507adfc841990d4c51e6b73a4b948d16a4010845c74109b6858a3d0d2242"
image: "ghcr.io/martin-helmich/prometheus-nginxlog-exporter/exporter@sha256:62987d855bb07edc5d126b926751c733e6683a6a6d2844026d3af332bac654be"
args:
- "-config-file"
- "/etc/prometheus-nginxlog-exporter/config.hcl"
Expand Down
4 changes: 2 additions & 2 deletions eidlogger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>no.altinn</groupId>
Expand All @@ -15,7 +15,7 @@
<description>Eid event logger</description>
<properties>
<java.version>21</java.version>
<springdoc.version>2.6.0</springdoc.version>
<springdoc.version>2.7.0</springdoc.version>
<log-event.version>1.2.2</log-event.version>
<spring-cloud-azure.version>5.18.0</spring-cloud-azure.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderHookWithProviders } from '../test/mocks';
import {
queryParamKey,
openSettingsModalWithTabQueryKey,
useOpenSettingsModalBasedQueryParam,
} from './useOpenSettingsModalBasedQueryParam';
import { useSearchParams } from 'react-router-dom';
Expand Down Expand Up @@ -44,7 +44,7 @@ function setupSearchParamMock(searchParams: URLSearchParams): jest.Mock {

function buildSearchParams(queryParamValue: string): URLSearchParams {
const searchParams: URLSearchParams = new URLSearchParams();
searchParams.set(queryParamKey, queryParamValue);
searchParams.set(openSettingsModalWithTabQueryKey, queryParamValue);
return searchParams;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSettingsModalContext } from '../contexts/SettingsModalContext';
import type { SettingsModalTabId } from '../types/SettingsModalTabId';
import { useSettingsModalMenuTabConfigs } from '../layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/hooks/useSettingsModalMenuTabConfigs';

export const queryParamKey: string = 'openSettingsModalWithTab';
export const openSettingsModalWithTabQueryKey: string = 'openSettingsModalWithTab';

export function useOpenSettingsModalBasedQueryParam(): void {
const [searchParams] = useSearchParams();
Expand All @@ -14,7 +14,9 @@ export function useOpenSettingsModalBasedQueryParam(): void {
const tabIds = settingsModalTabs.map(({ tabId }) => tabId);

useEffect((): void => {
const tabToOpen: SettingsModalTabId = searchParams.get(queryParamKey) as SettingsModalTabId;
const tabToOpen: SettingsModalTabId = searchParams.get(
openSettingsModalWithTabQueryKey,
) as SettingsModalTabId;
const shouldOpenModal: boolean = isValidTab(tabToOpen, tabIds);
if (shouldOpenModal) {
settingsRef.current.openSettings(tabToOpen);
Expand Down
3 changes: 3 additions & 0 deletions frontend/app-development/layout/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { useRepoStatusQuery } from 'app-shared/hooks/queries';
import { appContentWrapperId } from '@studio/testing/testids';

i18next.use(initReactI18next).init({
ns: 'translation',
defaultNS: 'translation',
fallbackNS: 'translation',
lng: DEFAULT_LANGUAGE,
resources: {
nb: { translation: nb },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { AnsattportenLogin } from './AnsattportenLogin';
import { AnsattportenLogin, getRedirectUrl } from './AnsattportenLogin';
import { textMock } from '@studio/testing/mocks/i18nMock';

jest.mock('app-shared/api/paths');
Expand Down Expand Up @@ -40,10 +40,22 @@ describe('AnsattportenLogin', () => {
});
});

describe('getRedirectUrl', () => {
it('should build and return correct redirect url', () => {
mockWindowLocationHref();
const result = getRedirectUrl();
expect(result).toBe('/path/to/page?openSettingsModalWithTab=maskinporten');
});
});

function mockWindowLocationHref(): jest.Mock {
const hrefMock = jest.fn();
delete window.location;
window.location = { href: '' } as Location;
window.location = {
href: '',
origin: 'https://unit-test-com',
pathname: '/path/to/page',
} as Location;
Object.defineProperty(window.location, 'href', {
set: hrefMock,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { useTranslation } from 'react-i18next';
import { StudioButton, StudioParagraph } from '@studio/components';
import { EnterIcon } from '@studio/icons';
import { loginWithAnsattPorten } from 'app-shared/api/paths';
import { openSettingsModalWithTabQueryKey } from '../../../../../../../../../hooks/useOpenSettingsModalBasedQueryParam';
import type { SettingsModalTabId } from '../../../../../../../../../types/SettingsModalTabId';

export const AnsattportenLogin = (): ReactElement => {
const { t } = useTranslation();

const handleLoginWithAnsattporten = (): void => {
window.location.href = loginWithAnsattPorten(window.location.pathname + window.location.search);
window.location.href = loginWithAnsattPorten(getRedirectUrl());
};

return (
Expand Down Expand Up @@ -39,3 +41,10 @@ const LoginIcon = (): ReactElement => {
</div>
);
};

export function getRedirectUrl(): string {
const maskinportenTab: SettingsModalTabId = 'maskinporten';
const url = new URL(window.location.origin + window.location.pathname);
url.searchParams.set(openSettingsModalWithTabQueryKey, maskinportenTab);
return url.pathname + url.search;
}
Loading

0 comments on commit 526f86e

Please sign in to comment.