Skip to content

Commit

Permalink
Hide dropdown selector for app, when http only support 1 app (#9553)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivar <[email protected]>
  • Loading branch information
ivarne and ivarne authored Jan 19, 2023
1 parent ecf5d7e commit 6209827
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
32 changes: 21 additions & 11 deletions src/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics;
using System.Text.Json;
using System.Security.Claims;
using System.Xml;

using Microsoft.AspNetCore.Authentication;
Expand All @@ -9,7 +8,6 @@
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Options;

using AltinnCore.Authentication.Constants;
using Altinn.Platform.Authorization.Services.Interface;
using Altinn.Platform.Profile.Models;
using Altinn.Platform.Storage.Interface.Models;
Expand Down Expand Up @@ -86,24 +84,32 @@ public async Task<IActionResult> LocalTestUsersRoundTrip()
[AllowAnonymous]
public async Task<IActionResult> Index()
{
StartAppModel model = new StartAppModel();
StartAppModel model = new StartAppModel()
{
AppModeIsHttp = _localPlatformSettings.LocalAppMode == "http",
AppPath = _localPlatformSettings.AppRepositoryBasePath,
StaticTestDataPath = _localPlatformSettings.LocalTestingStaticTestDataPath,
LocalAppUrl = _localPlatformSettings.LocalAppUrl,
LocalFrontendUrl = HttpContext.Request.Cookies[FRONTEND_URL_COOKIE_NAME],
};

try
{
model.TestApps = await GetAppsList();
if (model.AppModeIsHttp)
{
model.Org = model.TestApps[0].Value?.Split("/").FirstOrDefault();
model.App = model.TestApps[0].Value?.Split("/").LastOrDefault();
}
model.TestUsers = await GetTestUsersForList();
var defaultAuthLevel = _localPlatformSettings.LocalAppMode == "http" ? await GetAppAuthLevel(model.TestApps) : 2;
var defaultAuthLevel = await GetAppAuthLevel(model.AppModeIsHttp, model.TestApps);
model.AuthenticationLevels = GetAuthenticationLevels(defaultAuthLevel);
}
catch (HttpRequestException e)
{
model.HttpException = e;
}

model.AppPath = _localPlatformSettings.AppRepositoryBasePath;
model.StaticTestDataPath = _localPlatformSettings.LocalTestingStaticTestDataPath;
model.LocalAppUrl = _localPlatformSettings.LocalAppUrl;
model.AppModeIsHttp = _localPlatformSettings.LocalAppMode == "http";
model.LocalFrontendUrl = HttpContext.Request.Cookies[FRONTEND_URL_COOKIE_NAME];

if (!model.TestApps?.Any() ?? true)
{
Expand Down Expand Up @@ -141,7 +147,7 @@ public async Task<ActionResult> LogInTestUser(StartAppModel startAppModel)
CreateJwtCookieAndAppendToResponse(token);
}

if (startAppModel.AppPathSelection.Equals("accessmanagement"))
if (startAppModel.AppPathSelection?.Equals("accessmanagement") == true)
{
return Redirect($"/accessmanagement/ui/api-delegations");
}
Expand Down Expand Up @@ -314,8 +320,12 @@ private async Task<IEnumerable<SelectListItem>> GetTestUsersForList()
return userItems;
}

private async Task<int> GetAppAuthLevel(IEnumerable<SelectListItem> testApps)
private async Task<int> GetAppAuthLevel(bool isHttp, IEnumerable<SelectListItem> testApps)
{
if(!isHttp)
{
return 2;
}
try
{
var appId = testApps.Single().Value;
Expand Down
2 changes: 1 addition & 1 deletion src/Models/StartAppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class StartAppModel
/// <summary>
/// List of selectable Apps for dropdown
/// </summary>
public IEnumerable<SelectListItem> TestApps { get; set; }
public List<SelectListItem> TestApps { get; set; }

/// <summary>
/// List of possible authentication levels
Expand Down
11 changes: 7 additions & 4 deletions src/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@
<label for="exampleInputEmail1">Select test users</label>
@Html.DropDownListFor(model => model.UserId, Model.TestUsers, new { Class = "form-control" })
</div>
<div class="form-group">
<label for="exampleInputEmail1">Select app to test found in @Model.AppPath</label>
@Html.DropDownListFor(model => model.AppPathSelection, Model.TestApps, new { Class = "form-control" })
</div>
@if(!Model.AppModeIsHttp)
{
<div class="form-group">
<label for="exampleInputEmail1">Select app to test found in @Model.AppPath</label>
@Html.DropDownListFor(model => model.AppPathSelection, Model.TestApps, new { Class = "form-control" })
</div>
}
<div class="form-group">
<label for="exampleInputEmail1">Select your authentication level</label>
@Html.DropDownListFor(model => model.AuthenticationLevel, Model.AuthenticationLevels, new { Class = "form-control" })
Expand Down

0 comments on commit 6209827

Please sign in to comment.