da2c0d714e
LdapMappings: flex header, search filter, per-row Edit + kebab Delete,
@key, dropped Site-Scope-Rules cell in favor of a {n rule(s)} badge.
LdapMappingForm: two stacked cards (Mapping then Site Scope Rules);
scope rules render as removable chips with an inline "Add scope rule"
form; create-mode disables the scope card with an explainer; role
select gets form-text help.
DataConnections: <h4> in flex header, Bulk actions dropdown holding
Expand/Collapse, hover-visible kebab on tree nodes mirroring the
right-click context menu, aria-labels, "No connections match the
filter." inline empty state.
DataConnectionForm: Site rendered as readonly plaintext + lock-after-
creation note in edit mode; parallel Primary endpoint / Backup endpoint
headings; "Optional" badge on Backup when null; form-text on
FailoverRetryCount.
ApiKeys: search filter, Status column dropped (state now lives in the
kebab menu label "Disable"/"Enable"), Edit + kebab actions, @key,
aria-labels.
ApiKeyForm: nested card removed; fixed-text Back header; real
clipboard copy via IJSRuntime + toast confirmation.
Test selector fix in DataConnectionFormTests for the new Site
readonly-plaintext rendering.
229 lines
8.1 KiB
Plaintext
229 lines
8.1 KiB
Plaintext
@page "/admin/ldap-mappings/create"
|
|
@page "/admin/ldap-mappings/{Id:int}/edit"
|
|
@using ScadaLink.Commons.Entities.Security
|
|
@using ScadaLink.Commons.Entities.Sites
|
|
@using ScadaLink.Commons.Interfaces.Repositories
|
|
@using ScadaLink.Security
|
|
@attribute [Authorize(Policy = AuthorizationPolicies.RequireAdmin)]
|
|
@inject ISecurityRepository SecurityRepository
|
|
@inject ISiteRepository SiteRepository
|
|
@inject NavigationManager NavigationManager
|
|
|
|
<div class="container-fluid mt-3">
|
|
<div class="mb-3">
|
|
<button class="btn btn-outline-secondary btn-sm"
|
|
aria-label="Back to LDAP mappings"
|
|
@onclick="GoBack">
|
|
← Back
|
|
</button>
|
|
</div>
|
|
|
|
<ConfirmDialog @ref="_confirmDialog" ConfirmButtonClass="btn-danger" />
|
|
|
|
<div class="card mb-3">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Mapping</h5>
|
|
<div class="mb-2">
|
|
<label class="form-label small">LDAP Group Name</label>
|
|
<input type="text" class="form-control form-control-sm" @bind="_formGroupName" />
|
|
</div>
|
|
<div class="mb-2">
|
|
<label class="form-label small">Role</label>
|
|
<select class="form-select form-select-sm" @bind="_formRole">
|
|
<option value="">Select role...</option>
|
|
<option value="Admin">Admin</option>
|
|
<option value="Design">Design</option>
|
|
<option value="Deployment">Deployment</option>
|
|
</select>
|
|
<div class="form-text">Deployment role: configure site scope below after saving.</div>
|
|
</div>
|
|
@if (_formError != null)
|
|
{
|
|
<div class="text-danger small mt-2">@_formError</div>
|
|
}
|
|
<div class="mt-3">
|
|
<button class="btn btn-success btn-sm me-1" @onclick="SaveMapping">Save</button>
|
|
<button class="btn btn-outline-secondary btn-sm" @onclick="GoBack">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card mb-3">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Site Scope Rules</h5>
|
|
|
|
@if (!IsEditMode)
|
|
{
|
|
<p class="text-muted small mb-0">Save the mapping first to configure site scope.</p>
|
|
}
|
|
else
|
|
{
|
|
@if (_scopeRules.Count > 0)
|
|
{
|
|
<div class="d-flex flex-wrap gap-2 mb-3">
|
|
@foreach (var rule in _scopeRules)
|
|
{
|
|
var siteName = _siteLookup.GetValueOrDefault(rule.SiteId)?.Name ?? $"Site {rule.SiteId}";
|
|
<span class="badge bg-info text-dark d-inline-flex align-items-center">
|
|
@siteName
|
|
<button type="button"
|
|
class="btn-close btn-close-white ms-2"
|
|
style="font-size: 0.6rem;"
|
|
aria-label="@($"Remove scope rule for {siteName}")"
|
|
@onclick="() => DeleteScopeRule(rule)"></button>
|
|
</span>
|
|
}
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<p class="text-muted small mb-3">All sites (no restrictions)</p>
|
|
}
|
|
|
|
<div class="row g-2 align-items-end">
|
|
<div class="col-auto">
|
|
<label class="form-label small">Site</label>
|
|
<select class="form-select form-select-sm" @bind="_scopeRuleSiteId">
|
|
<option value="0">Select site...</option>
|
|
@foreach (var site in _sites)
|
|
{
|
|
<option value="@site.Id">@site.Name</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
<div class="col-auto">
|
|
<button class="btn btn-success btn-sm" @onclick="AddScopeRule">Add scope rule</button>
|
|
</div>
|
|
</div>
|
|
@if (_scopeRuleError != null)
|
|
{
|
|
<div class="text-danger small mt-2">@_scopeRuleError</div>
|
|
}
|
|
}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter] public int? Id { get; set; }
|
|
|
|
private bool IsEditMode => Id.HasValue;
|
|
|
|
private LdapGroupMapping? _editingMapping;
|
|
private string _formGroupName = string.Empty;
|
|
private string _formRole = string.Empty;
|
|
private string? _formError;
|
|
|
|
private List<SiteScopeRule> _scopeRules = new();
|
|
private List<Site> _sites = new();
|
|
private Dictionary<int, Site> _siteLookup = new();
|
|
private int _scopeRuleSiteId;
|
|
private string? _scopeRuleError;
|
|
|
|
private ConfirmDialog _confirmDialog = default!;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
_sites = (await SiteRepository.GetAllSitesAsync()).ToList();
|
|
_siteLookup = _sites.ToDictionary(s => s.Id);
|
|
|
|
if (Id.HasValue)
|
|
{
|
|
_editingMapping = await SecurityRepository.GetMappingByIdAsync(Id.Value);
|
|
if (_editingMapping != null)
|
|
{
|
|
_formGroupName = _editingMapping.LdapGroupName;
|
|
_formRole = _editingMapping.Role;
|
|
_scopeRules = (await SecurityRepository.GetScopeRulesForMappingAsync(Id.Value)).ToList();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void GoBack()
|
|
{
|
|
NavigationManager.NavigateTo("/admin/ldap-mappings");
|
|
}
|
|
|
|
private async Task SaveMapping()
|
|
{
|
|
_formError = null;
|
|
|
|
if (string.IsNullOrWhiteSpace(_formGroupName))
|
|
{
|
|
_formError = "LDAP Group Name is required.";
|
|
return;
|
|
}
|
|
if (string.IsNullOrWhiteSpace(_formRole))
|
|
{
|
|
_formError = "Role is required.";
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
if (_editingMapping != null)
|
|
{
|
|
_editingMapping.LdapGroupName = _formGroupName.Trim();
|
|
_editingMapping.Role = _formRole;
|
|
await SecurityRepository.UpdateMappingAsync(_editingMapping);
|
|
}
|
|
else
|
|
{
|
|
var mapping = new LdapGroupMapping(_formGroupName.Trim(), _formRole);
|
|
await SecurityRepository.AddMappingAsync(mapping);
|
|
}
|
|
|
|
await SecurityRepository.SaveChangesAsync();
|
|
NavigationManager.NavigateTo("/admin/ldap-mappings");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_formError = $"Save failed: {ex.Message}";
|
|
}
|
|
}
|
|
|
|
private async Task AddScopeRule()
|
|
{
|
|
_scopeRuleError = null;
|
|
|
|
if (_scopeRuleSiteId <= 0)
|
|
{
|
|
_scopeRuleError = "Select a site to add a scope rule.";
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
var rule = new SiteScopeRule { LdapGroupMappingId = Id!.Value, SiteId = _scopeRuleSiteId };
|
|
await SecurityRepository.AddScopeRuleAsync(rule);
|
|
await SecurityRepository.SaveChangesAsync();
|
|
_scopeRules = (await SecurityRepository.GetScopeRulesForMappingAsync(Id.Value)).ToList();
|
|
_scopeRuleSiteId = 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_scopeRuleError = $"Save failed: {ex.Message}";
|
|
}
|
|
}
|
|
|
|
private async Task DeleteScopeRule(SiteScopeRule rule)
|
|
{
|
|
var siteName = _siteLookup.GetValueOrDefault(rule.SiteId)?.Name ?? $"Site {rule.SiteId}";
|
|
var confirmed = await _confirmDialog.ShowAsync(
|
|
$"Remove scope rule for '{siteName}'?",
|
|
"Remove Scope Rule");
|
|
if (!confirmed) return;
|
|
|
|
try
|
|
{
|
|
await SecurityRepository.DeleteScopeRuleAsync(rule.Id);
|
|
await SecurityRepository.SaveChangesAsync();
|
|
_scopeRules = (await SecurityRepository.GetScopeRulesForMappingAsync(Id!.Value)).ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_scopeRuleError = $"Delete failed: {ex.Message}";
|
|
}
|
|
}
|
|
}
|