Add card reporting page and account deletion to admin panel

- /reports/cards: filterable report of all cards with columns for 3D
  model (+ AI badge), 2D art, abilities, SFX, and prebuilt deck membership.
  All entries link to card editor and deck detail pages.
- AccountDetail: danger-zone Delete Account section that cascades through
  collection, bazaar, chat, game lobbies/presets, and identity data.
  Requires typing DELETE to confirm; preserves game session history.
- NavMenu: Reports section wired up.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-04-07 21:57:44 -04:00
co-authored by Claude Happy
parent d109cd7c0d
commit f59f0af514
3 changed files with 550 additions and 0 deletions
@@ -151,6 +151,18 @@
</li>
</ul>
</li>
<li class="nav-item">
<NavLink class="nav-link text-white" href="/reports/cards" Match="NavLinkMatch.All">
<i class="bi bi-bar-chart-line me-2"></i>Reports
</NavLink>
<ul class="nav nav-pills flex-column gap-1 ps-3 mt-1">
<li class="nav-item">
<NavLink class="nav-link text-white-50 py-1" href="/reports/cards">
<i class="bi bi-collection me-2"></i>Cards
</NavLink>
</li>
</ul>
</li>
<li class="nav-item">
<NavLink class="nav-link text-white" href="/feature-flags">
<i class="bi bi-toggles me-2"></i>Feature Flags
@@ -2,6 +2,9 @@
@inject SorIdentityDbContext Db
@inject CatalogDbContext CatalogDb
@inject CollectionDbContext CollectionDb
@inject BazaarDbContext BazaarDb
@inject ChatDbContext ChatDb
@inject GameDbContext GameDb
@inject UserManager<Account> UserManager
@inject NavigationManager Nav
@inject IConnectionMultiplexer Redis
@@ -502,6 +505,54 @@ else
</div>
</div>
</div>
<!-- Delete Account -->
<div class="col-12">
<div class="card shadow-sm border-danger">
<div class="card-header fw-medium text-danger">
<i class="bi bi-trash me-2"></i>Delete Account
</div>
<div class="card-body">
<p class="text-muted small mb-3">
Permanently deletes this account and all associated data: cards, decks, cosmetics,
purchase records, chat data, matchmaking history, lobby presets, and the account itself.
Game session history is preserved for record-keeping.
<strong class="text-danger">This cannot be undone.</strong>
</p>
@if (!_showDeleteConfirm)
{
<button class="btn btn-sm btn-outline-danger" @onclick="() => _showDeleteConfirm = true">
<i class="bi bi-trash me-1"></i>Delete Account…
</button>
}
else
{
<div class="alert alert-danger py-2 mb-3">
Type <strong>DELETE</strong> to confirm permanent deletion of
<strong>@(_account?.DisplayName ?? _account?.Email)</strong>.
</div>
<div class="d-flex gap-2 align-items-center">
<input @bind="_deleteConfirmText" type="text" class="form-control form-control-sm"
style="width:140px" placeholder="DELETE" />
<button class="btn btn-sm btn-danger" @onclick="DeleteAccountAsync"
disabled="@(_deleteConfirmText != "DELETE" || _deleting)">
@if (_deleting)
{
<span class="spinner-border spinner-border-sm me-1"></span>
}
else
{
<i class="bi bi-trash me-1"></i>
}
Confirm Delete
</button>
<button class="btn btn-sm btn-outline-secondary" @onclick="() => { _showDeleteConfirm = false; _deleteConfirmText = string.Empty; }">
Cancel
</button>
</div>
}
</div>
</div>
</div>
</div>
}
@@ -537,6 +588,11 @@ else
// Award OP
private int _awardOpAmount = 100;
// Delete account
private bool _showDeleteConfirm;
private string _deleteConfirmText = string.Empty;
private bool _deleting;
// Account properties
private List<AccountProperty> _props = new();
private Guid _editingPropId = Guid.Empty;
@@ -910,4 +966,98 @@ else
_message = $"Property \"{key}\" added.";
_isError = false;
}
// ── Delete Account ────────────────────────────────────────────────────────
private async Task DeleteAccountAsync()
{
if (_account == null || _deleteConfirmText != "DELETE") return;
_deleting = true;
try
{
var id = _account.Id;
var now = DateTimeOffset.UtcNow;
// 1. Force logout — revoke Redis sessions and DB sessions.
var cache = Redis.GetDatabase();
var userKey = RedisKeys.UserSessions(id.ToString());
var members = await cache.SetMembersAsync(userKey);
foreach (var m in members)
await cache.KeyDeleteAsync(RedisKeys.Session(m!));
await cache.KeyDeleteAsync(userKey);
// 2. Collection — DeckCards first (FK dependency on Decks).
var deckIds = await CollectionDb.Decks
.Where(d => d.AccountId == id)
.Select(d => d.Id)
.ToListAsync();
if (deckIds.Count > 0)
await CollectionDb.DeckCards
.Where(dc => deckIds.Contains(dc.DeckId))
.ExecuteDeleteAsync();
await CollectionDb.Decks.Where(d => d.AccountId == id).ExecuteDeleteAsync();
await CollectionDb.PlayerCards.Where(c => c.AccountId == id).ExecuteDeleteAsync();
await CollectionDb.PlayerCosmetics.Where(c => c.AccountId == id).ExecuteDeleteAsync();
// 3. Bazaar — bids and transactions reference listings, so delete bids first.
await BazaarDb.AuctionBids
.Where(b => b.BidderAccountId == id)
.ExecuteDeleteAsync();
await BazaarDb.Transactions
.Where(t => t.BuyerAccountId == id || t.SellerAccountId == id)
.ExecuteDeleteAsync();
await BazaarDb.Listings
.Where(l => l.SellerAccountId == id)
.ExecuteDeleteAsync();
await BazaarDb.PurchaseRecords
.Where(p => p.AccountId == id)
.ExecuteDeleteAsync();
// 4. Chat.
await ChatDb.Messages
.Where(m => m.SenderAccountId == id)
.ExecuteDeleteAsync();
await ChatDb.Members
.Where(m => m.AccountId == id)
.ExecuteDeleteAsync();
await ChatDb.FriendRequests
.Where(f => f.RequesterAccountId == id || f.RecipientAccountId == id)
.ExecuteDeleteAsync();
await ChatDb.BlockedUsers
.Where(b => b.BlockerAccountId == id || b.BlockedAccountId == id)
.ExecuteDeleteAsync();
await ChatDb.AccountPresences
.Where(p => p.AccountId == id)
.ExecuteDeleteAsync();
await ChatDb.Notifications
.Where(n => n.RecipientAccountId == id)
.ExecuteDeleteAsync();
// 5. Game — lobbies and presets; NOT sessions (historical record).
await GameDb.MatchmakingEntries
.Where(e => e.AccountId == id)
.ExecuteDeleteAsync();
await GameDb.LobbyPresets
.Where(p => p.OwnerAccountId == id)
.ExecuteDeleteAsync();
await GameDb.CustomLobbies
.Where(l => l.HostAccountId == id || l.GuestAccountId == id)
.ExecuteDeleteAsync();
// 6. Identity properties and sessions.
await Db.AccountProperties.Where(p => p.AccountId == id).ExecuteDeleteAsync();
await Db.AccountSessions.Where(s => s.AccountId == id).ExecuteDeleteAsync();
// 7. The account itself.
await UserManager.DeleteAsync(_account);
Nav.NavigateTo("/accounts");
}
catch (Exception ex)
{
_message = $"Delete failed: {ex.Message}";
_isError = true;
_deleting = false;
}
}
}
@@ -0,0 +1,388 @@
@page "/reports/cards"
@inject CatalogDbContext CatalogDb
@inject BazaarDbContext BazaarDb
@using SOR.Database.Entities.Catalog
@using SOR.Database.Entities.Bazaar
@using SOR.Database.Enums
<PageTitle>Card Report – SOR Admin</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="mb-0">Card Report</h1>
@if (_rows != null)
{
<span class="text-muted small">@_filtered.Count of @_rows.Count cards</span>
}
</div>
<div class="card shadow-sm mb-3">
<div class="card-body py-2">
<div class="row g-2 align-items-end">
<div class="col-md-3">
<label class="form-label form-label-sm mb-1">Name</label>
<input value="@_search"
@oninput="e => { _search = e.Value?.ToString() ?? string.Empty; Filter(); }"
class="form-control form-control-sm" placeholder="Search…" />
</div>
<div class="col-md-2">
<label class="form-label form-label-sm mb-1">Type</label>
<select @bind="_filterType" @bind:after="Filter" class="form-select form-select-sm">
<option value="">All types</option>
@foreach (var t in Enum.GetValues<CardType>())
{
<option value="@t">@t</option>
}
</select>
</div>
<div class="col-md-2">
<label class="form-label form-label-sm mb-1">Affinity</label>
<select @bind="_filterAffinity" @bind:after="Filter" class="form-select form-select-sm">
<option value="">All affinities</option>
@foreach (var a in Enum.GetValues<Affinity>())
{
<option value="@a">@a</option>
}
</select>
</div>
<div class="col-md-2">
<label class="form-label form-label-sm mb-1">Set</label>
<select @bind="_filterSetId" @bind:after="Filter" class="form-select form-select-sm">
<option value="">All sets</option>
<option value="none">— No set —</option>
@foreach (var s in _sets)
{
<option value="@s.Id">@s.Name</option>
}
</select>
</div>
<div class="col-md-2">
<label class="form-label form-label-sm mb-1">Rarity</label>
<select @bind="_filterRarity" @bind:after="Filter" class="form-select form-select-sm">
<option value="">All rarities</option>
@foreach (var r in Enum.GetValues<CardRarity>())
{
<option value="@r">@r</option>
}
</select>
</div>
<div class="col-md-1">
<label class="form-label form-label-sm mb-1">Published</label>
<select @bind="_filterPublished" @bind:after="Filter" class="form-select form-select-sm">
<option value="">All</option>
<option value="true">Published</option>
<option value="false">Draft</option>
</select>
</div>
</div>
<div class="row g-2 align-items-end mt-1">
<div class="col-md-2">
<label class="form-label form-label-sm mb-1">3D Model</label>
<select @bind="_filter3dModel" @bind:after="Filter" class="form-select form-select-sm">
<option value="">All</option>
<option value="yes">Has model</option>
<option value="no">No model</option>
</select>
</div>
<div class="col-md-2">
<label class="form-label form-label-sm mb-1">AI Model</label>
<select @bind="_filterAiModel" @bind:after="Filter" class="form-select form-select-sm">
<option value="">All</option>
<option value="yes">AI generated</option>
<option value="no">Not AI</option>
</select>
</div>
<div class="col-md-2">
<label class="form-label form-label-sm mb-1">2D Art</label>
<select @bind="_filter2dArt" @bind:after="Filter" class="form-select form-select-sm">
<option value="">All</option>
<option value="yes">Has art</option>
<option value="no">No art</option>
</select>
</div>
<div class="col-md-2">
<label class="form-label form-label-sm mb-1">Abilities</label>
<select @bind="_filterAbilities" @bind:after="Filter" class="form-select form-select-sm">
<option value="">All</option>
<option value="yes">Has abilities</option>
<option value="no">No abilities</option>
</select>
</div>
<div class="col-md-2">
<label class="form-label form-label-sm mb-1">Sound Effects</label>
<select @bind="_filterSfx" @bind:after="Filter" class="form-select form-select-sm">
<option value="">All</option>
<option value="yes">Has SFX</option>
<option value="no">No SFX</option>
</select>
</div>
<div class="col-md-2">
<label class="form-label form-label-sm mb-1">Prebuilt Decks</label>
<select @bind="_filterInDeck" @bind:after="Filter" class="form-select form-select-sm">
<option value="">All</option>
<option value="yes">In a deck</option>
<option value="no">Not in any deck</option>
</select>
</div>
</div>
</div>
</div>
<div class="card shadow-sm">
<div class="card-body p-0">
@if (_rows == null)
{
<p class="p-3 text-muted">Loading…</p>
}
else if (_filtered.Count == 0)
{
<p class="p-3 text-muted">No cards match the current filters.</p>
}
else
{
<div style="overflow-x:auto;">
<table class="table table-hover table-sm align-middle mb-0">
<thead class="table-dark">
<tr>
<th>Name</th>
<th>Type</th>
<th>Affinity</th>
<th>Set</th>
<th>Rarity</th>
<th>Published</th>
<th style="white-space:nowrap">3D Model</th>
<th style="white-space:nowrap">2D Art</th>
<th>Abilities</th>
<th>SFX</th>
<th>Prebuilt Decks</th>
</tr>
</thead>
<tbody>
@foreach (var row in _filtered)
{
<tr>
<td class="fw-medium">
<a href="/cards/@row.Card.Id" class="text-decoration-none">@row.Card.Name</a>
</td>
<td><span class="badge bg-secondary">@row.Card.CardType</span></td>
<td>@row.Card.Affinity</td>
<td>
@if (row.Card.Set != null)
{
<span class="badge bg-dark" title="@row.Card.Set.Name">@row.Card.Set.Code</span>
}
else
{
<span class="text-muted">—</span>
}
</td>
<td>@row.Card.Rarity</td>
<td>
@if (row.Card.IsPublished)
{
<span class="badge bg-success">Published</span>
}
else
{
<span class="badge bg-warning text-dark">Draft</span>
}
</td>
<td>
@if (row.Has3dModel)
{
<span class="text-success" title="Has 3D model">✓</span>
@if (row.ModelAiGenerated)
{
<span class="badge bg-info text-dark ms-1" style="font-size:10px">AI</span>
}
}
else
{
<span class="text-danger">✗</span>
}
</td>
<td>
@if (row.Has2dArt)
{
<span class="text-success">✓</span>
}
else
{
<span class="text-danger">✗</span>
}
</td>
<td>
@if (row.HasAbilities)
{
<span class="text-success">✓</span>
}
else
{
<span class="text-danger">✗</span>
}
</td>
<td>
@if (row.HasSfx)
{
<span class="text-success">✓</span>
}
else
{
<span class="text-danger">✗</span>
}
</td>
<td>
@if (row.InDecks.Count == 0)
{
<span class="text-muted">—</span>
}
else
{
@for (var i = 0; i < row.InDecks.Count; i++)
{
var deck = row.InDecks[i];
<a href="/bazaar/decks/@deck.Id" class="text-decoration-none small">@deck.Name</a>
@if (i < row.InDecks.Count - 1)
{
<span class="text-muted">, </span>
}
}
}
</td>
</tr>
}
</tbody>
</table>
</div>
}
</div>
</div>
@code {
private record CardRow(
CardDefinition Card,
bool Has3dModel,
bool ModelAiGenerated,
bool Has2dArt,
bool HasAbilities,
bool HasSfx,
IReadOnlyList<(Guid Id, string Name)> InDecks);
private List<CardRow>? _rows;
private List<CardRow> _filtered = new();
private List<CardSet> _sets = new();
private string _search = string.Empty;
private string _filterType = string.Empty;
private string _filterAffinity = string.Empty;
private string _filterSetId = string.Empty;
private string _filterRarity = string.Empty;
private string _filterPublished = string.Empty;
private string _filter3dModel = string.Empty;
private string _filterAiModel = string.Empty;
private string _filter2dArt = string.Empty;
private string _filterAbilities = string.Empty;
private string _filterSfx = string.Empty;
private string _filterInDeck = string.Empty;
protected override async Task OnInitializedAsync()
{
_sets = await CatalogDb.CardSets
.OrderBy(s => s.Name)
.ToListAsync();
var cards = await CatalogDb.CardDefinitions
.Include(c => c.Assets)
.Include(c => c.Set)
.OrderBy(c => c.Name)
.ToListAsync();
var prebuiltDecks = await BazaarDb.PrebuiltDecks
.Include(d => d.Cards)
.ToListAsync();
// Build card → [deck] lookup.
var cardToDecks = new Dictionary<Guid, List<(Guid, string)>>();
foreach (var deck in prebuiltDecks)
{
foreach (var dc in deck.Cards)
{
if (!cardToDecks.TryGetValue(dc.CardDefinitionId, out var list))
cardToDecks[dc.CardDefinitionId] = list = new();
list.Add((deck.Id, deck.Name));
}
}
_rows = cards.Select(c =>
{
var model = c.Assets.Where(a => a.AssetType == CardAssetType.Model3D).ToList();
var art = c.Assets.Where(a => a.AssetType == CardAssetType.Art2D).ToList();
var hasSfx = c.MoveSoundUrl != null || c.DamagedSoundUrl != null
|| c.BlockedSoundUrl != null || c.AttackSoundUrl != null || c.DeathSoundUrl != null;
var hasAbilities = !string.IsNullOrEmpty(c.AbilitiesJson) || !string.IsNullOrEmpty(c.EffectsJson);
cardToDecks.TryGetValue(c.Id, out var decks);
return new CardRow(
Card: c,
Has3dModel: model.Count > 0,
ModelAiGenerated: model.Any(a => a.IsAiGenerated),
Has2dArt: art.Count > 0,
HasAbilities: hasAbilities,
HasSfx: hasSfx,
InDecks: (decks ?? new()).AsReadOnly());
}).ToList();
Filter();
}
private void Filter()
{
if (_rows == null) return;
_filtered = _rows.Where(row =>
{
var c = row.Card;
if (!string.IsNullOrEmpty(_search) &&
!c.Name.Contains(_search, StringComparison.OrdinalIgnoreCase))
return false;
if (!string.IsNullOrEmpty(_filterType) &&
c.CardType.ToString() != _filterType)
return false;
if (!string.IsNullOrEmpty(_filterAffinity) &&
c.Affinity.ToString() != _filterAffinity)
return false;
if (_filterSetId == "none" && c.SetId != null) return false;
if (_filterSetId != "none" && !string.IsNullOrEmpty(_filterSetId) &&
Guid.TryParse(_filterSetId, out var sid) && c.SetId != sid)
return false;
if (!string.IsNullOrEmpty(_filterRarity) &&
c.Rarity.ToString() != _filterRarity)
return false;
if (_filterPublished == "true" && !c.IsPublished) return false;
if (_filterPublished == "false" && c.IsPublished) return false;
if (_filter3dModel == "yes" && !row.Has3dModel) return false;
if (_filter3dModel == "no" && row.Has3dModel) return false;
if (_filterAiModel == "yes" && !row.ModelAiGenerated) return false;
if (_filterAiModel == "no" && row.ModelAiGenerated) return false;
if (_filter2dArt == "yes" && !row.Has2dArt) return false;
if (_filter2dArt == "no" && row.Has2dArt) return false;
if (_filterAbilities == "yes" && !row.HasAbilities) return false;
if (_filterAbilities == "no" && row.HasAbilities) return false;
if (_filterSfx == "yes" && !row.HasSfx) return false;
if (_filterSfx == "no" && row.HasSfx) return false;
if (_filterInDeck == "yes" && row.InDecks.Count == 0) return false;
if (_filterInDeck == "no" && row.InDecks.Count > 0) return false;
return true;
}).ToList();
}
}