Skip to content

Commit

Permalink
chore(resource-adm): Remove AT21 choice from resourceadm frontend (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
mgunnerud authored Nov 29, 2024
1 parent 86fb29c commit 0b31e03
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 39 deletions.
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);
}
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const resourcePublishStatus = {
policyVersion: null,
resourceVersion: '1',
publishedVersions: [
{
version: null,
environment: 'at21',
},
{
version: '1',
environment: 'at22',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ describe('ImportResourceModal', () => {
textMock('resourceadm.dashboard_import_modal_select_env'),
);
await user.click(environmentSelect);
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at21_env') }));
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at22_env') }));

await waitFor(() =>
expect(environmentSelect).toHaveValue(textMock('resourceadm.deploy_at21_env')),
expect(environmentSelect).toHaveValue(textMock('resourceadm.deploy_at22_env')),
);
expect(importButton).toHaveAttribute('aria-disabled', 'true');

Expand Down Expand Up @@ -103,7 +103,7 @@ describe('ImportResourceModal', () => {
textMock('resourceadm.dashboard_import_modal_select_env'),
);
await user.click(environmentSelect);
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at21_env') }));
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at22_env') }));

// wait for the second combobox to appear, instead of waiting for the spinner to disappear.
// (sometimes the spinner disappears) too quick and the test will fail
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('ImportResourceModal', () => {
textMock('resourceadm.dashboard_import_modal_select_env'),
);
await user.click(environmentSelect);
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at21_env') }));
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at22_env') }));

// wait for the second combobox to appear, instead of waiting for the spinner to disappear.
// (sometimes the spinner disappears) too quick and the test will fail
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('ImportResourceModal', () => {
textMock('resourceadm.dashboard_import_modal_select_env'),
);
await user.click(environmentSelect);
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at21_env') }));
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at22_env') }));

// wait for the second combobox to appear, instead of waiting for the spinner to disappear.
// (sometimes the spinner disappears) too quick and the test will fail
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('ImportResourceModal', () => {
textMock('resourceadm.dashboard_import_modal_select_env'),
);
await user.click(environmentSelect);
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at21_env') }));
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at22_env') }));

// wait for the second combobox to appear, instead of waiting for the spinner to disappear.
// (sometimes the spinner disappears) too quick and the test will fail
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('ImportResourceModal', () => {
textMock('resourceadm.dashboard_import_modal_select_env'),
);
await user.click(environmentSelect);
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at21_env') }));
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at22_env') }));

// wait for the second combobox to appear, instead of waiting for the spinner to disappear.
// (sometimes the spinner disappears) too quick and the test will fail
Expand Down Expand Up @@ -286,7 +286,7 @@ describe('ImportResourceModal', () => {
textMock('resourceadm.dashboard_import_modal_select_env'),
);
await user.click(environmentSelect);
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at21_env') }));
await user.click(screen.getByRole('option', { name: textMock('resourceadm.deploy_at22_env') }));

// wait for the second combobox to appear, instead of waiting for the spinner to disappear.
// (sometimes the spinner disappears) too quick and the test will fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ describe('MigrationPage', () => {
policyVersion: null,
resourceVersion: '1',
publishedVersions: [
{
version: null,
environment: 'at21',
},
{
version: null,
environment: 'at22',
Expand Down Expand Up @@ -62,10 +58,6 @@ describe('MigrationPage', () => {
policyVersion: null,
resourceVersion: '2',
publishedVersions: [
{
version: null,
environment: 'at21',
},
{
version: null,
environment: 'at22',
Expand Down
2 changes: 1 addition & 1 deletion frontend/resourceadm/types/EnvironmentType.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type EnvironmentType = 'AT21' | 'AT22' | 'AT23' | 'AT24' | 'TT02' | 'PROD';
export type EnvironmentType = 'AT22' | 'AT23' | 'AT24' | 'TT02' | 'PROD';
2 changes: 1 addition & 1 deletion frontend/resourceadm/utils/mapperUtils/mapperUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Altinn2LinkService } from 'app-shared/types/Altinn2LinkService';
import type { ResourceListItem } from 'app-shared/types/ResourceAdm';

const EnvOrder = ['prod', 'tt02', 'at21', 'at22', 'at23', 'at24', 'gitea'];
const EnvOrder = ['prod', 'tt02', 'at22', 'at23', 'at24', 'gitea'];
/**
* Sorts a resource list by the date so the newest is at the top
*
Expand Down
14 changes: 2 additions & 12 deletions frontend/resourceadm/utils/resourceUtils/resourceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const availableForTypeMap: Record<ResourceAvailableForTypeOption, string>
SelfRegisteredUser: 'resourceadm.about_resource_available_for_type_self_registered',
};

export type EnvId = 'tt02' | 'prod' | 'at21' | 'at22' | 'at23' | 'at24';
export type EnvId = 'tt02' | 'prod' | 'at22' | 'at23' | 'at24';
export type EnvType = 'test' | 'prod';
export type Environment = {
id: EnvId;
Expand All @@ -54,11 +54,6 @@ export type Environment = {
};

const environments: Record<EnvId, Environment> = {
['at21']: {
id: 'at21' as EnvId,
label: 'resourceadm.deploy_at21_env',
envType: 'test' as EnvType,
},
['at22']: {
id: 'at22' as EnvId,
label: 'resourceadm.deploy_at22_env',
Expand Down Expand Up @@ -89,12 +84,7 @@ const environments: Record<EnvId, Environment> = {
export const getAvailableEnvironments = (org: string): Environment[] => {
const availableEnvs = [environments['tt02'], environments['prod']];
if (org === 'ttd') {
availableEnvs.push(
environments['at21'],
environments['at22'],
environments['at23'],
environments['at24'],
);
availableEnvs.push(environments['at22'], environments['at23'], environments['at24']);
}
return availableEnvs;
};
Expand Down

0 comments on commit 0b31e03

Please sign in to comment.