web: založení projektu Helpdesk.Web a layout aplikace

ASP.NET Core MVC (.NET 10) s Bootstrapem 5, layout s menu podle role,
chybové stránky, bezpečnostní hlavičky (CSP, Referrer-Policy) a česká kultura.

Refs #19, #20
This commit is contained in:
PatTheEvil committed 2026-12-02 00:20:49 +01:00
1 parent b402d9f92c
commit abd075287c
25 files changed
+523

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace Helpdesk.Web.Infrastructure;
/// <summary>Jednorázové zprávy přes přesměrování (vzor Post/Redirect/Get).</summary>
public static class Flash
{
public const string Success = "Flash.Success";
public const string Error = "Flash.Error";
public static void SetSuccess(this ITempDataDictionary tempData, string message) => tempData[Success] = message;
public static void SetError(this ITempDataDictionary tempData, string message) => tempData[Error] = message;
}
@@ -0,0 +1,25 @@
using System.Security.Claims;
using Helpdesk.Web.Auth;
namespace Helpdesk.Web.Infrastructure;
/// <summary>Položka hlavního menu. Bez rolí ji vidí každý přihlášený uživatel.</summary>
public sealed record NavItem(string Text, string Controller, string Action, params string[] Roles)
{
public bool IsVisibleTo(ClaimsPrincipal user) =>
user.Identity?.IsAuthenticated == true && (Roles.Length == 0 || Roles.Any(user.IsInRole));
}
/// <summary>
/// Hlavní menu na jednom místě. Viditelnost podle role je jen pohodlí pro uživatele –
/// oprávnění skutečně kontroluje API (kap. 9.3 návrhu).
/// </summary>
public static class Navigation
{
public static readonly IReadOnlyList<NavItem> Items =
[
new("Nástěnka", "Home", "Index"),
];
public static IEnumerable<NavItem> For(ClaimsPrincipal user) => Items.Where(i => i.IsVisibleTo(user));
}
@@ -0,0 +1,21 @@
namespace Helpdesk.Web.Infrastructure;
/// <summary>Bezpečnostní hlavičky pro všechny odpovědi webu.</summary>
public static class SecurityHeaders
{
// Všechny skripty a styly jsou ze stejného původu (wwwroot), takže CSP nepotřebuje žádné výjimky.
private const string ContentSecurityPolicy =
"default-src 'self'; img-src 'self' data: blob:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'";
public static IApplicationBuilder UseSecurityHeaders(this IApplicationBuilder app) =>
app.Use(async (context, next) =>
{
var headers = context.Response.Headers;
headers.ContentSecurityPolicy = ContentSecurityPolicy;
headers.XContentTypeOptions = "nosniff";
headers.XFrameOptions = "DENY";
// Odkazy z e-mailů nesou token v URL – nesmí uniknout v hlavičce Referer.
headers["Referrer-Policy"] = "no-referrer";
await next();
});
}