Skip to content

Commit

Permalink
Portal apps: Remove get PortalApps as objects endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kjetilhau committed Nov 5, 2024
1 parent 9e99aee commit eb71f18
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Net.Mime;
using Equinor.ProjectExecutionPortal.Application.Queries.Portals.GetPortal;
using Equinor.ProjectExecutionPortal.Application.Queries.Portals.GetPortalAppKeys;
using Equinor.ProjectExecutionPortal.Application.Queries.Portals.GetPortalApps;
using Equinor.ProjectExecutionPortal.Application.Queries.Portals.GetPortalConfiguration;
using Equinor.ProjectExecutionPortal.Application.Queries.Portals.GetPortalOnboardedApp;
using Equinor.ProjectExecutionPortal.Application.Queries.Portals.GetPortalOnboardedApps;
Expand Down Expand Up @@ -204,10 +203,10 @@ public async Task<ActionResult<ApiPortalOnboardedApp>> PortalOnboardedApp([FromR
return new ApiPortalOnboardedApp(portalOnboardedAppDto);
}

// App Keys
// Apps

// TODO: Rename to /apps
[HttpGet("{portalId:guid}/appkeys")]
[HttpGet("{portalId:guid}/apps")]
[HttpGet("{portalId:guid}/appkeys")] // TODO: DEPRECATED
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
public async Task<ActionResult<List<string>>> PortalAppKeys([FromRoute] Guid portalId)
Expand All @@ -228,8 +227,8 @@ public async Task<ActionResult<List<string>>> PortalAppKeys([FromRoute] Guid por
}
}

// TODO Rename to /apps
[HttpGet("{portalId:guid}/contexts/{contextId:guid}/appkeys")]
[HttpGet("{portalId:guid}/contexts/{contextId:guid}/apps")]
[HttpGet("{portalId:guid}/contexts/{contextId:guid}/appkeys")] // TODO: DEPRECATED
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
public async Task<ActionResult<List<string>>> PortalAppKeys([FromRoute] Guid portalId, [FromRoute] Guid contextId)
Expand All @@ -250,52 +249,6 @@ public async Task<ActionResult<List<string>>> PortalAppKeys([FromRoute] Guid por
}
}

// Apps

// TODO: Remove
[HttpGet("{portalId:guid}/apps")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
public async Task<ActionResult<List<ApiPortalApp>>> PortalApps([FromRoute] Guid portalId)
{
try
{
var portalAppsDto = await Mediator.Send(new GetGlobalAppsForPortalQuery(portalId));

return Ok(portalAppsDto.Select(portalAppDto => new ApiPortalApp(portalAppDto)).ToList());
}
catch (NotFoundException ex)
{
return FusionApiError.NotFound(portalId, ex.Message);
}
catch (Exception)
{
return FusionApiError.InvalidOperation("500", "An error occurred");
}
}

// TODO: Remove
[HttpGet("{portalId:guid}/contexts/{contextId:guid}/apps")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
public async Task<ActionResult<List<ApiPortalApp>>> PortalApps([FromRoute] Guid portalId, [FromRoute] Guid contextId)
{
try
{
var portalAppsDto = await Mediator.Send(new GetContextualAndGlobalAppsByPortalAndContextQuery(portalId, contextId));

return Ok(portalAppsDto.Select(portalAppDto => new ApiPortalApp(portalAppDto)).ToList());
}
catch (NotFoundException ex)
{
return FusionApiError.NotFound(portalId, ex.Message);
}
catch (Exception)
{
return FusionApiError.InvalidOperation("500", "An error occurred");
}
}

[HttpPost("{portalId:guid}/apps")]
[Authorize(Policy = Policies.ProjectPortal.Admin)]
[Consumes(MediaTypeNames.Application.Json)]
Expand Down Expand Up @@ -478,4 +431,4 @@ public async Task<ActionResult> RemoveContextType([FromRoute] Guid portalId, [Fr

return Ok();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Equinor.ProjectExecutionPortal.WebApi.ViewModels.PortalApp;

// TODO: Should be removed
public class ApiPortalApp
{
#pragma warning disable CS8618 // For integration tests only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,13 @@ public async Task Delete_PortalApp_AsAdministrator_ShouldReturnOk()
var appToDelete = apps.First();

// Act
var response = await DeletePortalApp(portalToTest.Id, appToDelete.AppKey, UserType.Administrator);
var response = await DeletePortalApp(portalToTest.Id, appToDelete, UserType.Administrator);

// Assert
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

// Verify the app is actually deleted
var deletedApp = await AssertGetPortalApp(portalToTest.Id, appToDelete.AppKey, UserType.Authenticated, HttpStatusCode.NotFound);
var deletedApp = await AssertGetPortalApp(portalToTest.Id, appToDelete, UserType.Authenticated, HttpStatusCode.NotFound);
Assert.IsNull(deletedApp);
}

Expand All @@ -558,7 +558,7 @@ public async Task Delete_PortalApp_AsAuthenticatedUser_ShouldReturnForbidden()
var appToDelete = apps.First();

// Act
var response = await DeletePortalApp(portalToTest.Id, appToDelete.AppKey, UserType.Authenticated);
var response = await DeletePortalApp(portalToTest.Id, appToDelete, UserType.Authenticated);

// Assert
Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode);
Expand All @@ -580,7 +580,7 @@ public async Task Delete_PortalApp_AsAnonymousUser_ShouldReturnUnauthorized()
var appToDelete = apps.First();

// Act
var response = await DeletePortalApp(portalToTest.Id, appToDelete.AppKey, UserType.Anonymous);
var response = await DeletePortalApp(portalToTest.Id, appToDelete, UserType.Anonymous);

// Assert
Assert.AreEqual(HttpStatusCode.Unauthorized, response.StatusCode);
Expand Down Expand Up @@ -708,30 +708,30 @@ public async Task Delete_PortalApp_AsAnonymousUser_ShouldReturnUnauthorized()
return appKeys;
}

private static async Task<IList<ApiPortalApp>?> AssertGetAppsForPortal(Guid portalId, Guid? contextId, UserType userType, HttpStatusCode expectedStatusCode)
private static async Task<IList<string>?> AssertGetAppsForPortal(Guid portalId, Guid? contextId, UserType userType, HttpStatusCode expectedStatusCode)
{
// Act
var response = await GetAppsForPortal(portalId, contextId, userType);
var content = await response.Content.ReadAsStringAsync();
var apps = JsonConvert.DeserializeObject<IList<ApiPortalApp>>(content);
var appKeys = JsonConvert.DeserializeObject<IList<string>>(content);

// Assert
Assert.AreEqual(expectedStatusCode, response.StatusCode);

if (response.StatusCode != HttpStatusCode.OK)
{
return apps;
return appKeys;
}

Assert.IsNotNull(content);
Assert.IsNotNull(apps);
Assert.IsNotNull(appKeys);

foreach (var app in apps)
foreach (var appKey in appKeys)
{
AssertHelpers.AssertPortalAppValues(app);
Assert.IsNotNull(appKey);
}

return apps;
return appKeys;
}

private static async Task<HttpResponseMessage> CreatePortal(UserType userType, ApiCreatePortalRequest createdPortal)
Expand Down

0 comments on commit eb71f18

Please sign in to comment.