Replace hardcoded "system" user with actual logged-in user across all UI pages

All 22 occurrences of hardcoded "system" user string replaced with
GetCurrentUserAsync() which reads the Username claim from AuthenticationState.
Affected: Instances.razor (6), Sites.razor (2), Templates.razor (11),
SharedScripts.razor (3).
This commit is contained in:
Joseph Doherty
2026-03-17 14:09:04 -04:00
parent 1ae4d09614
commit 7dcdcc46c7
4 changed files with 68 additions and 22 deletions

View File

@@ -14,6 +14,7 @@
@inject IDeploymentManagerRepository DeploymentManagerRepository
@inject DeploymentService DeploymentService
@inject InstanceService InstanceService
@inject AuthenticationStateProvider AuthStateProvider
<div class="container-fluid mt-3">
<div class="d-flex justify-content-between align-items-center mb-3">
@@ -271,6 +272,12 @@
</div>
@code {
private async Task<string> GetCurrentUserAsync()
{
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
return authState.User.FindFirst("Username")?.Value ?? "unknown";
}
private List<Instance> _allInstances = new();
private List<Instance> _filteredInstances = new();
private List<Instance> _pagedInstances = new();
@@ -395,7 +402,7 @@
_actionInProgress = true;
try
{
var user = "system"; // Would come from auth context
var user = await GetCurrentUserAsync();
var result = await DeploymentService.EnableInstanceAsync(inst.Id, user);
if (result.IsSuccess)
{
@@ -424,7 +431,7 @@
_actionInProgress = true;
try
{
var user = "system";
var user = await GetCurrentUserAsync();
var result = await DeploymentService.DisableInstanceAsync(inst.Id, user);
if (result.IsSuccess)
{
@@ -448,7 +455,7 @@
_actionInProgress = true;
try
{
var user = "system";
var user = await GetCurrentUserAsync();
var result = await DeploymentService.DeployInstanceAsync(inst.Id, user);
if (result.IsSuccess)
{
@@ -477,7 +484,7 @@
_actionInProgress = true;
try
{
var user = "system";
var user = await GetCurrentUserAsync();
var result = await DeploymentService.DeleteInstanceAsync(inst.Id, user);
if (result.IsSuccess)
{
@@ -521,8 +528,9 @@
try
{
var user = await GetCurrentUserAsync();
var result = await InstanceService.CreateInstanceAsync(
_createName.Trim(), _createTemplateId, _createSiteId, null, "system");
_createName.Trim(), _createTemplateId, _createSiteId, null, user);
if (result.IsSuccess)
{
_showCreateForm = false;
@@ -616,8 +624,9 @@
.Select(kv => (kv.Key, kv.Value))
.ToList();
var user = await GetCurrentUserAsync();
var result = await InstanceService.SetConnectionBindingsAsync(
_bindingInstanceId, bindings, "system");
_bindingInstanceId, bindings, user);
if (result.IsSuccess)
{