@page "/tenants" @using EntKube.Web.Data @using EntKube.Web.Services @using Microsoft.EntityFrameworkCore @rendermode InteractiveServer @inject TenantService TenantService @inject UserAccessService UserAccessService @inject AuthenticationStateProvider AuthStateProvider @inject NavigationManager Navigation Tenants @if (loaded) { Tenants Organizations and workspaces in your platform. @if (isAdmin) { { if (e.Key == "Enter" && !string.IsNullOrWhiteSpace(newTenantName)) await CreateTenant(); })" /> Create Tenant @if (!string.IsNullOrEmpty(errorMessage)) { @errorMessage } } @if (tenants is null || tenants.Count == 0) { } else { @foreach (Tenant tenant in tenants) { @tenant.Name @tenant.Slug @if (isAdmin) { confirmDeleteId = tenant.Id" title="Delete tenant"> } @if (isAdmin && confirmDeleteId == tenant.Id) { Delete this tenant? DeleteTenant(tenant.Id)">Delete confirmDeleteId = null">Cancel } } } } @code { private List? tenants; private string newTenantName = ""; private string? errorMessage; private Guid? confirmDeleteId; private bool isAdmin; private bool loaded; private string? userId; protected override async Task OnInitializedAsync() { AuthenticationState authState = await AuthStateProvider.GetAuthenticationStateAsync(); System.Security.Claims.ClaimsPrincipal user = authState.User; if (user.Identity?.IsAuthenticated != true) { Navigation.NavigateTo("/Account/Login", forceLoad: true); return; } userId = user.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value; if (userId is null) { Navigation.NavigateTo("/Account/Login", forceLoad: true); return; } isAdmin = await UserAccessService.IsGlobalAdminAsync(userId); bool hasMembership = isAdmin || await UserAccessService.HasAnyTenantMembershipAsync(userId); if (!hasMembership) { Navigation.NavigateTo("/portal"); return; } await LoadTenants(); loaded = true; } private async Task LoadTenants() { if (userId is null) return; tenants = await UserAccessService.GetAccessibleTenantsAsync(userId); } private async Task CreateTenant() { if (!isAdmin) return; errorMessage = null; try { await TenantService.CreateTenantAsync(newTenantName.Trim()); newTenantName = ""; await LoadTenants(); } catch (DbUpdateException) { errorMessage = "A tenant with that name already exists."; } } private async Task DeleteTenant(Guid id) { if (!isAdmin) return; confirmDeleteId = null; await TenantService.DeleteTenantAsync(id); await LoadTenants(); } }
Organizations and workspaces in your platform.
@tenant.Slug