Files
vtuber-awards/Backend/Data/SeedSiteSettingsBootstrapper.cs
T
AzuTear 18b61bed52 Improve admin candidate modal UX and add clip menu visibility toggle
- Widen AdminCandidateEditorModal to size lg for better readability
- Rename "Clip-Compilation" section to "Clip / Compilation", update copy to reflect single clips too, drop upload hint and Clip-Plattform field, rename label to "Link"
- Fix NativeSelect dropdown clipping inside overflow-y-auto modals by teleporting the menu to body with fixed positioning, flip-up logic, and dynamic maxHeight capped to viewport
- Add ClipAdminMenuVisible setting (backend domain, contracts, endpoint, migration) with matching frontend types, defaults, form wiring, and toggle in the Clip-Workflow modal — hides the Clips nav item from the admin sidebar when disabled

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-27 18:39:35 +02:00

147 lines
4.9 KiB
C#

using System.Text.Json;
using Backend.Services;
using Microsoft.EntityFrameworkCore;
namespace Backend.Data;
public static partial class SeedDataBootstrapper
{
private static async Task EnsureSiteSettingsAsync(AwardsDbContext db)
{
var settings = await db.SiteSettings.FirstOrDefaultAsync(item => item.Id == 1);
if (settings is null)
{
return;
}
if (!HasValidSiteArray(settings.FaqJson, "question", "answer"))
{
settings.FaqJson = JsonSerializer.Serialize(SeedCatalog.SiteFaqSeeds.Select(item => new
{
question = item.Question,
answer = item.Answer,
}));
}
if (!HasValidSiteArray(settings.SocialLinksJson, "label", "platform", "url"))
{
settings.SocialLinksJson = JsonSerializer.Serialize(SeedCatalog.SiteSocialSeeds.Select(item => new
{
label = item.Label,
platform = item.Platform,
url = item.Url,
icon = item.Icon,
showOnHost = true,
showOnCommunity = true,
}));
}
if (!HasValidRiskRules(settings.RiskRulesJson))
{
settings.RiskRulesJson = RiskRuleSettings.Serialize(RiskRuleSettings.Defaults);
}
if (!HasValidWorkflowRules(settings.WorkflowRulesJson))
{
settings.WorkflowRulesJson = WorkflowRuleSettings.Serialize(WorkflowRuleSettings.Defaults);
}
if (!HasValidNominationLinkBlacklist(settings.NominationLinkBlacklistJson))
{
settings.NominationLinkBlacklistJson = NominationLinkBlacklistSettings.Serialize(NominationLinkBlacklistSettings.Defaults);
}
if (string.IsNullOrWhiteSpace(settings.ClipSubmissionDisabledMessage))
{
settings.ClipSubmissionDisabledMessage = "Clip-Einreichungen sind aktuell geschlossen.";
}
if (string.IsNullOrWhiteSpace(settings.ShowactApplicationDisabledMessage))
{
settings.ShowactApplicationDisabledMessage = "Showact-Bewerbungen sind aktuell geschlossen.";
}
if (string.IsNullOrWhiteSpace(settings.ImprintContent))
{
settings.ImprintContent = SeedCatalog.DefaultImprintContent;
}
if (string.IsNullOrWhiteSpace(settings.ContactContent))
{
settings.ContactContent = SeedCatalog.DefaultContactContent;
}
if (string.IsNullOrWhiteSpace(settings.SponsorsContent))
{
settings.SponsorsContent = SeedCatalog.DefaultSponsorsContent;
}
if (string.IsNullOrWhiteSpace(settings.ShowactsUrl))
{
settings.ShowactsUrl = "https://vtuber-star-awards.de/showacts";
}
if (string.IsNullOrWhiteSpace(settings.ShowactsContent))
{
settings.ShowactsContent = "Informationen zu Showact-Bewerbungen, Ablauf und Kontakt fuer die Award-Show.";
}
}
private static bool HasValidSiteArray(string? json, params string[] requiredKeys)
{
if (string.IsNullOrWhiteSpace(json))
{
return false;
}
try
{
using var document = JsonDocument.Parse(json);
if (document.RootElement.ValueKind != JsonValueKind.Array)
{
return false;
}
return document.RootElement.EnumerateArray().Any(item =>
item.ValueKind == JsonValueKind.Object
&& requiredKeys.All(key =>
item.TryGetProperty(key, out var value)
&& value.ValueKind == JsonValueKind.String
&& !string.IsNullOrWhiteSpace(value.GetString())));
}
catch (JsonException)
{
return false;
}
}
private static bool HasValidRiskRules(string? json) =>
RiskRuleSettings.Read(new Backend.Domain.SiteSettings { RiskRulesJson = json ?? string.Empty }).Length == RiskRuleSettings.Defaults.Length;
private static bool HasValidWorkflowRules(string? json) =>
WorkflowRuleSettings.Read(new Backend.Domain.SiteSettings { WorkflowRulesJson = json ?? string.Empty }).Length == WorkflowRuleSettings.Defaults.Length;
private static bool HasValidNominationLinkBlacklist(string? json)
{
if (string.IsNullOrWhiteSpace(json))
{
return false;
}
try
{
using var document = JsonDocument.Parse(json);
return document.RootElement.ValueKind == JsonValueKind.Array
&& document.RootElement.EnumerateArray().Any(item =>
item.ValueKind == JsonValueKind.Object
&& item.TryGetProperty("Url", out var url)
&& url.ValueKind == JsonValueKind.String
&& !string.IsNullOrWhiteSpace(url.GetString()));
}
catch (JsonException)
{
return false;
}
}
}