Skip to content

Commit

Permalink
Can delete access package delegation from info modal (#1184)
Browse files Browse the repository at this point in the history
* created new revoke endpoint

* delete on button click and remember opened areas

* fixed bug with modal closing on delete

* bff tests

* change tag name

* Update backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Core/Services/Interfaces/IAccessPackageService.cs

Co-authored-by: Sondre Wittek <[email protected]>

* fixed mix in parameters

---------

Co-authored-by: Vedeler <[email protected]>
Co-authored-by: Sondre Wittek <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2024
1 parent 0bf7310 commit e345a9d
Show file tree
Hide file tree
Showing 27 changed files with 789 additions and 566 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ public async Task<Dictionary<string, List<AccessPackageDelegation>>> GetDelegati
return sortedAccesses;
}

/// <inheritdoc />
public Task<HttpResponseMessage> RevokeAccessPackage(Guid from, Guid to, string packageId)
{
return _accessManagementClient.RevokeAccessPackage(from, to, packageId);
}

/// <inheritdoc/>
public async Task<HttpResponseMessage> CreateDelegation(string party, Guid to, string packageId, string languageCode)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
using Altinn.AccessManagement.UI.Core.Models;
using Altinn.AccessManagement.UI.Core.Models.AccessPackage;
using Altinn.AccessManagement.UI.Core.Models.AccessPackage.Frontend;

namespace Altinn.AccessManagement.UI.Core.Services.Interfaces
{
/// <summary>
/// Servoice for access package logic
/// </summary>
public interface IAccessPackageService
{
/// <summary>
/// Performs a search for access packages based on the provided parameters and sorts them into a list of areas for frontend to display
/// Servoice for access package logic
/// </summary>
/// <param name="languageCode">languageCode.</param>
/// <param name="searchString">searchString.</param>
/// <returns>the resources that match the filters and search string corresponding to the provided page.</returns>
Task<List<AccessAreaFE>> GetSearch(string languageCode, string searchString);
public interface IAccessPackageService
{
/// <summary>
/// Performs a search for access packages based on the provided parameters and sorts them into a list of areas for frontend to display
/// </summary>
/// <param name="languageCode">languageCode.</param>
/// <param name="searchString">searchString.</param>
/// <returns>the resources that match the filters and search string corresponding to the provided page.</returns>
Task<List<AccessAreaFE>> GetSearch(string languageCode, string searchString);

/// <summary>
/// Gets all access package delegations a specified right holder has on behalf of a specified party
/// </summary>
/// <param name="rightHolderUuid">the uuid of one who has received the delegated access</param>
/// <param name="rightOwnerUuid">The uuid of the party whose rights have been delegated to the right holder</param>
/// <param name="languageCode">The code of the language on which texts are to be returned</param>
/// <returns>A dictionary of lists (sorted by access area) containing all access package delegations that the right holder has on behalf of the specified right owner</returns>
Task<Dictionary<string, List<AccessPackageDelegation>>> GetDelegationsToRightHolder(Guid rightHolderUuid, Guid rightOwnerUuid, string languageCode);
/// <summary>
/// Gets all access package delegations a specified right holder has on behalf of a specified party
/// </summary>
/// <param name="rightHolderUuid">the uuid of one who has received the delegated access</param>
/// <param name="rightOwnerUuid">The uuid of the party whose rights have been delegated to the right holder</param>
/// <param name="languageCode">The code of the language on which texts are to be returned</param>
/// <returns>A dictionary of lists (sorted by access area) containing all access package delegations that the right holder has on behalf of the specified right owner</returns>
Task<Dictionary<string, List<AccessPackageDelegation>>> GetDelegationsToRightHolder(Guid rightHolderUuid, Guid rightOwnerUuid, string languageCode);

/// <summary>
/// Creates a new delegation of an access package
/// </summary>
/// <param name="party">Identifies the selected party the authenticated user is acting on behalf of.</param>
/// <param name="to">The id of the right holder that will recieve the delegation</param>
/// <param name="packageId">The id of the package to be delegated</param>
/// <param name="languageCode">The code of the language on which texts are to be returned</param>
/// <returns></returns>
Task<HttpResponseMessage> CreateDelegation(string party, Guid to, string packageId, string languageCode);
}
/// <summary>
/// Revokes access to a given package for a right holder (to) on behalf of a party (from)
/// </summary>
/// <param name="from">The party which has granted access to the package to the right holder</param>
/// <param name="to">The right holder which currently has access to the access package</param>
/// <param name="packageId">The access package which the right holder is to lose access to on behalf of the given party (from)</param>
/// <returns>A HttpResponseMessage denoting whether or not the action was successfull.</returns>
Task<HttpResponseMessage> RevokeAccessPackage(Guid from, Guid to, string packageId);

/// <summary>
/// Creates a new delegation of an access package
/// </summary>
/// <param name="party">Identifies the selected party the authenticated user is acting on behalf of.</param>
/// <param name="to">The id of the right holder that will recieve the delegation</param>
/// <param name="packageId">The id of the package to be delegated</param>
/// <param name="languageCode">The code of the language on which texts are to be returned</param>
/// <returns></returns>
Task<HttpResponseMessage> CreateDelegation(string party, Guid to, string packageId, string languageCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,22 @@ public async Task<List<AccessPackageAccess>> GetAccessPackageAccesses(string to,
return await ClientUtils.DeserializeIfSuccessfullStatusCode<List<AccessPackageAccess>>(response);
}

/// <inheritdoc />
public async Task<HttpResponseMessage> RevokeAccessPackage(Guid from, Guid to, string packageId)
{
string endpointUrl = $"todo/enduser/access/accesspackages/{packageId}?to={to}&from={from}"; // TODO: Switch with actual backend endpoint when available
string token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _platformSettings.JwtCookieName);
HttpResponseMessage response = await _client.DeleteAsync(token, endpointUrl);

if (response.IsSuccessStatusCode)
{
return response;
}

_logger.LogError("Revoke resource delegation from accessmanagement failed with {StatusCode}", response.StatusCode);
throw new HttpStatusException("StatusError", "Unexpected response status from Access Management", response.StatusCode, Activity.Current?.Id ?? _httpContextAccessor.HttpContext?.TraceIdentifier);
}

/// <inheritdoc />
public async Task<HttpResponseMessage> CreateAccessPackageDelegation(string party, Guid to, string packageId, string languageCode)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"AccessPackage": {
"Id": "3490203E-876E-4EF9-B774-9A0CD9B7E9CC",
"Id": "annleggadmin",
"Name": "Annleggsadministrasjon",
"Description": "Denne tilgangspakken gir fullmakter til tjenester knyttet til kjøp og salg av eiendom. Ved regelverksendringer eller innføring av nye digitale tjenester kan det bli endringer i tilganger som fullmakten gir.",
"Tags": [
Expand Down Expand Up @@ -52,7 +52,7 @@
},
{
"AccessPackage": {
"Id": "3490203E-876E-4EF9-B774-9A0CD9B7E9CD",
"Id": "eiendom_kjop",
"Name": "Kjøp og salg av eiendom",
"Description": "Denne tilgangspakken gir fullmakter til tjenester knyttet til kjøp og salg av eiendom. Ved regelverksendringer eller innføring av nye digitale tjenester kan det bli endringer i tilganger som fullmakten gir.",
"Tags": [
Expand Down Expand Up @@ -107,7 +107,7 @@
},
{
"AccessPackage": {
"Id": "3490203E-876E-4EF9-B774-9A0CD9B7E9CFG",
"Id": "magibruk",
"Name": "Magibruk",
"Description": "Cat ipsum dolor sit amet, i will ruin the couch with my claws and have secret plans so pretend not to be evil.",
"Tags": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
[
{
"AccessPackage": {
"Id": "3490203E-876E-4EF9-B774-9A0CD9B7E9CC",
"Name": "Annleggsadministrasjon",
"Description": "Denne tilgangspakken gir fullmakter til tjenester knyttet til kjøp og salg av eiendom. Ved regelverksendringer eller innføring av nye digitale tjenester kan det bli endringer i tilganger som fullmakten gir.",
"Tags": [
{
"Id": "F28F5F92-0F72-4595-A166-C723E978E690",
"Name": "Eiendom"
}
],
"EntityType": {
"Id": "EEC6B868-3DA0-4721-87B2-63C5686014C6",
"Name": "Organisasjon"
},
"Area": {
"Id": "589217CF-6070-474F-9989-8C5359C740F4",
"Name": "Bygg og anlegg",
"Description": "For de som bygger med anlegg",
"IconUrl": "https://www.svgrepo.com/show/437004/hammer.svg",
"Group": {
"Id": "",
"Name": "Bransje",
"Description": "....."
}
},
"Provider": {
"Id": "181C5364-2988-4F48-925C-62844576B5B0",
"Name": "Digdir"
},
"Resources": [
{
"Id": "appid-512",
"Name": "Lønningsoversikt"
}
]
"Id": "annleggadmin",
"Name": "Annleggsadministrasjon",
"Description": "Denne tilgangspakken gir fullmakter til tjenester knyttet til kjøp og salg av eiendom. Ved regelverksendringer eller innføring av nye digitale tjenester kan det bli endringer i tilganger som fullmakten gir.",
"Tags": [
{
"Id": "F28F5F92-0F72-4595-A166-C723E978E690",
"Name": "Eiendom"
}
],
"EntityType": {
"Id": "EEC6B868-3DA0-4721-87B2-63C5686014C6",
"Name": "Organisasjon"
},
"Area": {
"Id": "589217CF-6070-474F-9989-8C5359C740F4",
"Name": "Bygg og anlegg",
"Description": "For de som bygger med anlegg",
"IconUrl": "https://www.svgrepo.com/show/437004/hammer.svg",
"Group": {
"Id": "",
"Name": "Bransje",
"Description": "....."
}
},
"Provider": {
"Id": "181C5364-2988-4F48-925C-62844576B5B0",
"Name": "Digdir"
},
"Resources": [
{
"Id": "appid-512",
"Name": "Lønningsoversikt"
}
]
},
"To": {
"Name": "Intelligent Albatross",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"packageId": "annleggadmin",
"success": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"packageId": "annleggadmin",
"success": true
}
Loading

0 comments on commit e345a9d

Please sign in to comment.