diff --git a/src/Altinn.ResourceRegistry.Core/Services/IAltinn2Services.cs b/src/Altinn.ResourceRegistry.Core/Services/IAltinn2Services.cs
index 2b4d1de6..c0af1da7 100644
--- a/src/Altinn.ResourceRegistry.Core/Services/IAltinn2Services.cs
+++ b/src/Altinn.ResourceRegistry.Core/Services/IAltinn2Services.cs
@@ -33,5 +33,11 @@ public interface IAltinn2Services
/// Request delegations
///
Task ExportDelegations(ExportDelegationsRequestBE exportDelegationsRequestBE, CancellationToken cancellationToken = default);
+
+ ///
+ /// Set service edition as expired
+ ///
+ ///
+ Task SetServiceEditionExpired(string externalServiceCode, int externalServiceEditionCode, CancellationToken cancellationToken = default);
}
}
diff --git a/src/Altinn.ResourceRegistry.Integration/Clients/Altinn2ServicesClient.cs b/src/Altinn.ResourceRegistry.Integration/Clients/Altinn2ServicesClient.cs
index 582ce4ab..c90d80be 100644
--- a/src/Altinn.ResourceRegistry.Integration/Clients/Altinn2ServicesClient.cs
+++ b/src/Altinn.ResourceRegistry.Integration/Clients/Altinn2ServicesClient.cs
@@ -1,5 +1,6 @@
using System.Net.Http.Json;
using System.Text.Json;
+using System.Threading;
using System.Xml;
using Altinn.Authorization.ABAC.Utils;
using Altinn.Authorization.ABAC.Xacml;
@@ -122,5 +123,14 @@ public async Task ExportDelegations(ExportDelegationsRequestBE exportDelegations
return policy;
}
+
+ ///
+ public async Task SetServiceEditionExpired(string externalServiceCode, int externalServiceEditionCode, CancellationToken cancellationToken = default)
+ {
+ string bridgeBaseUrl = _settings.BridgeApiEndpoint;
+ string url = $"{bridgeBaseUrl}metadata/api/setserviceeditionexpired?externalServiceCode={externalServiceCode}&externalServiceEditionCode={externalServiceEditionCode}";
+ HttpResponseMessage response = await _client.GetAsync(url, cancellationToken);
+ response.EnsureSuccessStatusCode();
+ }
}
}
diff --git a/src/Altinn.ResourceRegistry/Controllers/Altinn2ExportController.cs b/src/Altinn.ResourceRegistry/Controllers/Altinn2ExportController.cs
index d4215e65..72755f67 100644
--- a/src/Altinn.ResourceRegistry/Controllers/Altinn2ExportController.cs
+++ b/src/Altinn.ResourceRegistry/Controllers/Altinn2ExportController.cs
@@ -113,6 +113,18 @@ public async Task ExportDelegations([FromBody] ExportDelegationsRe
return Created();
}
+ ///
+ /// Sets a given service expired to hide delegation functionality. Proxy for bridge functionality. Called by Altinn Studio and used as part of the migration of delegation process
+ ///
+ ///
+ [Authorize(Policy = AuthzConstants.POLICY_ADMIN)]
+ [HttpGet("setserviceeditionexpired")]
+ public async Task SetServiceEditionExpired([FromQueryAttribute] string externalServiceCode, [FromQueryAttribute] int externalServiceEditionCode, CancellationToken cancellationToken = default)
+ {
+ await _altinn2ServicesClient.SetServiceEditionExpired(externalServiceCode, externalServiceEditionCode, cancellationToken);
+ return Ok();
+ }
+
[NonAction]
private async Task ValidateMatchingOrgForDelegaton(ExportDelegationsRequestBE exportRequest, string org, CancellationToken cancellationToken = default)
{
diff --git a/test/Altinn.ResourceRegistry.Tests/Altinn2ExportControllerTest.cs b/test/Altinn.ResourceRegistry.Tests/Altinn2ExportControllerTest.cs
index 6c36d4d0..a71bba0c 100644
--- a/test/Altinn.ResourceRegistry.Tests/Altinn2ExportControllerTest.cs
+++ b/test/Altinn.ResourceRegistry.Tests/Altinn2ExportControllerTest.cs
@@ -115,6 +115,45 @@ public async Task DelegationCount_WithoutToken()
Assert.Equal(System.Net.HttpStatusCode.Unauthorized, response.StatusCode);
}
+ ///
+ /// Calls SetExpired endpoint without token
+ ///
+ [Fact]
+ public async Task Setserviceeditionexpired_WithoutToken()
+ {
+ HttpClient client = CreateClient();
+ string requestUri = "resourceregistry/api/v1/altinn2export/setserviceeditionexpired?externalServiceCode=4485&externalServiceEditionCode=2021";
+
+ HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri)
+ {
+ };
+
+ HttpResponseMessage response = await client.SendAsync(httpRequestMessage);
+
+ Assert.Equal(System.Net.HttpStatusCode.Unauthorized, response.StatusCode);
+ }
+
+ ///
+ /// Calls SetExpired endpoint without token
+ ///
+ [Fact]
+ public async Task Setserviceeditionexpired_WithValidToken()
+ {
+ HttpClient client = CreateClient();
+ string token = PrincipalUtil.GetOrgToken("digdir", "991825827", "altinn:resourceregistry/resource.admin");
+ client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
+ string requestUri = "resourceregistry/api/v1/altinn2export/setserviceeditionexpired?externalServiceCode=4485&externalServiceEditionCode=2021";
+
+ HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri)
+ {
+ };
+
+ HttpResponseMessage response = await client.SendAsync(httpRequestMessage);
+
+ Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
+ }
+
+
///
/// Tries to trigger batch without Altinn Studio token
///
diff --git a/test/Altinn.ResourceRegistry.Tests/Mocks/Altinn2ServicesClientMock.cs b/test/Altinn.ResourceRegistry.Tests/Mocks/Altinn2ServicesClientMock.cs
index 6204d926..8cae0e99 100644
--- a/test/Altinn.ResourceRegistry.Tests/Mocks/Altinn2ServicesClientMock.cs
+++ b/test/Altinn.ResourceRegistry.Tests/Mocks/Altinn2ServicesClientMock.cs
@@ -106,5 +106,10 @@ public Task ExportDelegations(ExportDelegationsRequestBE exportDelegationsReques
{
return Task.CompletedTask;
}
+
+ public Task SetServiceEditionExpired(string externalServiceCode, int externalServiceEditionCode, CancellationToken cancellationToken = default)
+ {
+ return Task.CompletedTask;
+ }
}
}