Skip to content

Commit

Permalink
Add page for uploading json files from tenor to configure persons and…
Browse files Browse the repository at this point in the history
… orgs (#61)

* Add page for uploading json files from tenor to configure persons and orgs

Now you can open a separate tab on the localtest site and upload tenor
kildedata to localtest internal storage. If there are relevant tenor files
in storage, those will replace Ola Nordmann and Sofie Salt as the localtest
users. You can also select a subset of the files to downoad testData.json
to be used as app local users.

In addtition to the user management page, I have included the following
changes.

* Cleanup of login page and use the menu on top instead of links
  scattered all over the login screen
* Use latest bootstrap (from CDN, per getboostrap.com instructions)
* Split HomeController into multiple smaller controllers.
* Move `Reauthenticate` button besides the login button and make it a
  less visible color.
* Loadbalancer redirects "/" and /Home/* to localtest, so all new
  controllers got a `/Home/[controller]/[action]` prefix
* use only spaces (not mixed with tabs) in nginx.conf.conf

* Fix wrong JsonPropertyName

* Small UI improvments

* Fix code review issues

The main fix is that `GetTenorStorageDirectory` will create the directory
if it does not exist.

* Improve Iframe behaviour of LocalPlatformStorage

* Don't let dotnet watch run add script to /LocalPlatformStorage

* Mark user adminsitration as preview

fix table layout
  • Loading branch information
ivarne authored Nov 2, 2023
1 parent acdcb84 commit fc95a47
Show file tree
Hide file tree
Showing 21 changed files with 1,445 additions and 161 deletions.
43 changes: 22 additions & 21 deletions loadbalancer/templates/nginx.conf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ http {

sendfile on;

upstream localtest {
upstream localtest {
server host.docker.internal:5101;
}

Expand All @@ -58,7 +58,7 @@ http {
}

server {
listen 80 default_server;
listen 80 default_server;
server_name ${TEST_DOMAIN};

proxy_redirect off;
Expand All @@ -68,52 +68,53 @@ http {

error_page 502 /502LocalTest.html;

location = / {
location = / {
proxy_pass http://localtest/Home/;
sub_filter '<script src="/_framework/aspnetcore-browser-refresh.js"></script>' '<script src="/Home/_framework/aspnetcore-browser-refresh.js"></script>';
}
}

location / {
location / {
#Support using Local js, when a cookie value is set
sub_filter_once off;
sub_filter 'https://altinncdn.no/toolkits/altinn-app-frontend/3/' $LOCAL_SUB_FILTER;
proxy_pass http://app/;
error_page 502 /502App.html;
proxy_cookie_domain altinn3local.no local.altinn.cloud;
}
}

location /Home/_framework/ {
proxy_pass http://localtest/_framework/;
proxy_pass http://localtest/_framework/;
}

location /Home/ {
proxy_pass http://localtest/Home/;
location /Home/ {
proxy_pass http://localtest/Home/;
sub_filter '<script src="/_framework/aspnetcore-browser-refresh.js"></script>' '<script src="/Home/_framework/aspnetcore-browser-refresh.js"></script>';
}
}

location /receipt/ {
proxy_pass http://receiptcomp/receipt/;
error_page 502 /502Receipt.html;
}
proxy_pass http://receiptcomp/receipt/;
error_page 502 /502Receipt.html;
}

location /accessmanagement/ {
proxy_pass http://accessmanagementcomp/accessmanagement/;
proxy_pass http://accessmanagementcomp/accessmanagement/;
error_page 502 /502Accessmanagement.html;
}
}

location /storage/ {
proxy_pass http://localtest/storage/;
}
proxy_pass http://localtest/storage/;
}

location /pdfservice/ {
proxy_pass http://pdfservice/;
}

location /localtestresources/ {
proxy_pass http://localtest/localtestresources/;
}
proxy_pass http://localtest/localtestresources/;
}
location /LocalPlatformStorage/ {
proxy_pass http://localtest/LocalPlatformStorage/;
proxy_pass http://localtest/LocalPlatformStorage/;
sub_filter '<script src="/_framework/aspnetcore-browser-refresh.js"></script>' '';
}
location /502LocalTest.html {
root /www;
Expand All @@ -128,5 +129,5 @@ http {
root /www;
}

}
}
}
2 changes: 2 additions & 0 deletions src/Configuration/LocalPlatformSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@ public string LocalTestingStaticTestDataPath {
public string RolesFolder { get; set; } = "roles/";

public string ClaimsFolder { get; set; } = "claims/";

public string TenorDataFolder { get; set; } = "tenorUsers";
}
}
65 changes: 65 additions & 0 deletions src/Controllers/DebugUsersController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#nullable enable

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;


using LocalTest.Configuration;

using LocalTest.Services.TestData;
using Microsoft.AspNetCore.Authorization;

namespace LocalTest.Controllers;

[Route("Home/[controller]/[action]")]
public class DebugUsersController : Controller
{
private readonly LocalPlatformSettings _localPlatformSettings;
private readonly TenorDataRepository _tenorDataRepository;

public DebugUsersController(
IOptions<LocalPlatformSettings> localPlatformSettings,
TenorDataRepository tenorDataRepository)
{
_localPlatformSettings = localPlatformSettings.Value;
_tenorDataRepository = tenorDataRepository;
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsersRaw()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);

return Json(localData);
}

//Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsers()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);
var constructedAppData = AppTestDataModel.FromTestDataModel(localData);

return Json(constructedAppData);
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsersRoundTrip()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);
var constructedAppData = AppTestDataModel.FromTestDataModel(localData);

return Json(constructedAppData.GetTestDataModel());
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> ShowTenorUsers()
{
var localData = await _tenorDataRepository.GetAppTestDataModel();

return Json(localData);
}
}
87 changes: 87 additions & 0 deletions src/Controllers/FrontendVersionController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#nullable enable
using System.Text.Json;

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

using LocalTest.Configuration;
using LocalTest.Models;
using LocalTest.Services.LocalApp.Interface;

using LocalTest.Services.TestData;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace LocalTest.Controllers;

[Route("Home/[controller]/[action]")]
public class FrontendVersionController : Controller
{
/// <summary>
/// See src\development\loadbalancer\nginx.conf
/// </summary>
public static readonly string FRONTEND_URL_COOKIE_NAME = "frontendVersion";

[HttpGet]
public async Task<ActionResult> Index([FromServices] HttpClient client)
{
var versionFromCookie = HttpContext.Request.Cookies[FRONTEND_URL_COOKIE_NAME];

var frontendVersion = new FrontendVersion()
{
Version = versionFromCookie,
Versions = new List<SelectListItem>()
{
new ()
{
Text = "Keep as is",
Value = "",
},
new ()
{
Text = "localhost:8080 (local dev)",
Value = "http://localhost:8080/"
}
}
};
var cdnVersionsString = await client.GetStringAsync("https://altinncdn.no/toolkits/altinn-app-frontend/index.json");
var groupCdnVersions = new SelectListGroup() { Name = "Specific version from cdn" };
var versions = JsonSerializer.Deserialize<List<string>>(cdnVersionsString)!;
versions.Reverse();
versions.ForEach(version =>
{
frontendVersion.Versions.Add(new()
{
Text = version,
Value = $"https://altinncdn.no/toolkits/altinn-app-frontend/{version}/",
Group = groupCdnVersions
});
});

return View(frontendVersion);
}
public ActionResult Index(FrontendVersion frontendVersion)
{
var options = new CookieOptions
{
Expires = DateTime.MaxValue,
HttpOnly = true,
};
ICookieManager cookieManager = new ChunkingCookieManager();
if (string.IsNullOrWhiteSpace(frontendVersion.Version))
{
cookieManager.DeleteCookie(HttpContext, FRONTEND_URL_COOKIE_NAME, options);
}
else
{
cookieManager.AppendResponseCookie(
HttpContext,
FRONTEND_URL_COOKIE_NAME,
frontendVersion.Version,
options
);
}

return RedirectToAction("Index", "Home");
}
}
Loading

0 comments on commit fc95a47

Please sign in to comment.