Files
Khaemhat/src/Khaemhat.Data/SystemDatabase/SecurityMaps.cs
T
Alby96andClaude Opus 5.5 f415dc37a8 feat: in-app help, notifications panel and global search (#32)
F1 and "?" now open the wiki page of the screen inside the application
(/aiuto, mockup 011) from a copy of the wiki shipped next to the program,
so help works offline and always matches the installed version. Markdown
is converted in-house and fully encoded; images of the repository are
served from the copy. KHAEMHAT_HELP_URL sets the online wiki behind
"Apri nel wiki"; "Segnala un problema" opens a new issue of that repo.
A test checks that every page and menu entry has an existing wiki page.

The bell opens a notifications panel (mockup 010) with all/unread
filters and mark read. Broadcast notifications are now read per user
through sys_notification_reads / notification_reads instead of one
shared read_at.

The global search asks ISearchProvider implementations through
GlobalSearchService after a short pause; the first provider finds help
pages and sections, # and @ say which modules will fill them.

Escape also closes a side panel when the focus fell out of it.
Decisions in ADR 0023.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 19:39:17 +01:00

218 lines
6.9 KiB
C#

using Khaemhat.Core.Instance;
using Khaemhat.Core.Security;
using Khaemhat.Data.Mapping;
namespace Khaemhat.Data.SystemDatabase;
/// <summary>The account columns shared by <c>sys_users</c> and <c>users</c>.</summary>
internal static class AccountColumns
{
public static void Configure<T>(EntityMap<T> map)
where T : class, IAccount, new()
{
map.Map(x => x.UserName).MaxLength(100);
map.Map(x => x.DisplayName).MaxLength(200);
map.Map(x => x.Email).MaxLength(254);
map.Map(x => x.PasswordHash).MaxLength(200);
map.Map(x => x.PasswordHistory).Json();
map.Map(x => x.TotpRecoveryCodes).Json();
map.Map(x => x.RecoveryTokenHash).MaxLength(64);
}
}
/// <summary>Map of <see cref="SystemUser"/> to <c>sys_users</c>.</summary>
public sealed class SystemUserMap : EntityMap<SystemUser>
{
/// <summary>Creates the map.</summary>
public SystemUserMap()
{
ToTable("sys_users");
AccountColumns.Configure(this);
Map(x => x.LinkedCompanyCode).MaxLength(20);
}
}
/// <summary>Map of <see cref="SystemSession"/> to <c>sys_sessions</c>.</summary>
public sealed class SystemSessionMap : EntityMap<SystemSession>
{
/// <summary>Creates the map.</summary>
public SystemSessionMap()
{
ToTable("sys_sessions");
SessionColumns.Configure(this);
}
}
/// <summary>The session columns shared by <c>sys_sessions</c> and <c>user_sessions</c>.</summary>
internal static class SessionColumns
{
public static void Configure<T>(EntityMap<T> map)
where T : SessionRecord, new()
{
map.Map(x => x.TokenHash).MaxLength(64);
map.Map(x => x.CompanyCode).MaxLength(20);
map.Map(x => x.IpAddress).MaxLength(64);
map.Map(x => x.UserAgent).MaxLength(400);
map.Map(x => x.RevokedReason).MaxLength(100);
}
}
/// <summary>Map of <see cref="RoleTemplate"/> to <c>sys_roles_templates</c>.</summary>
public sealed class RoleTemplateMap : EntityMap<RoleTemplate>
{
/// <summary>Creates the map.</summary>
public RoleTemplateMap()
{
ToTable("sys_roles_templates");
Map(x => x.Code).MaxLength(50);
Map(x => x.Name).MaxLength(100);
Map(x => x.Permissions).Json();
}
}
/// <summary>Map of <see cref="LicenseRecord"/> to <c>sys_licenses</c>.</summary>
public sealed class LicenseRecordMap : EntityMap<LicenseRecord>
{
/// <summary>Creates the map.</summary>
public LicenseRecordMap()
{
ToTable("sys_licenses");
Map(x => x.Licensee).MaxLength(200);
Map(x => x.Modules).MaxLength(400);
}
}
/// <summary>Map of <see cref="LicenseActivation"/> to <c>sys_license_activations</c>.</summary>
public sealed class LicenseActivationMap : EntityMap<LicenseActivation>
{
/// <summary>Creates the map.</summary>
public LicenseActivationMap()
{
ToTable("sys_license_activations");
Map(x => x.Action).MaxLength(40);
Map(x => x.Modules).MaxLength(400);
Map(x => x.Outcome).MaxLength(60);
}
}
/// <summary>Map of <see cref="DataProtectionKey"/> to <c>sys_data_protection_keys</c>.</summary>
public sealed class DataProtectionKeyMap : EntityMap<DataProtectionKey>
{
/// <summary>Creates the map.</summary>
public DataProtectionKeyMap()
{
ToTable("sys_data_protection_keys");
Map(x => x.FriendlyName).MaxLength(200);
}
}
/// <summary>Map of <see cref="LogEntry"/> to <c>sys_log</c>.</summary>
public sealed class LogEntryMap : EntityMap<LogEntry>
{
/// <summary>Creates the map.</summary>
public LogEntryMap()
{
ToTable("sys_log");
Map(x => x.Level).MaxLength(20);
Map(x => x.Section).MaxLength(40);
Map(x => x.Source).MaxLength(200);
Map(x => x.UserName).MaxLength(100);
Map(x => x.CompanyCode).MaxLength(20);
Map(x => x.TraceId).MaxLength(64);
Map(x => x.Request).MaxLength(400);
Map(x => x.Entity).MaxLength(100);
Map(x => x.EntityId).MaxLength(100);
Map(x => x.Data).Json();
}
}
/// <summary>Map of <see cref="SecurityAuditEntry"/> to <c>sys_security_audit</c>.</summary>
public sealed class SecurityAuditEntryMap : EntityMap<SecurityAuditEntry>
{
/// <summary>Creates the map.</summary>
public SecurityAuditEntryMap()
{
ToTable("sys_security_audit");
Map(x => x.Action).MaxLength(100);
Map(x => x.UserName).MaxLength(100);
Map(x => x.CompanyCode).MaxLength(20);
Map(x => x.IpAddress).MaxLength(64);
Map(x => x.Target).MaxLength(200);
Map(x => x.Details).Json();
Map(x => x.PreviousHash).MaxLength(64);
Map(x => x.Hash).MaxLength(64);
}
}
/// <summary>Map of <see cref="ScheduledTask"/> to <c>sys_scheduled_tasks</c>.</summary>
public sealed class ScheduledTaskMap : EntityMap<ScheduledTask>
{
/// <summary>Creates the map.</summary>
public ScheduledTaskMap()
{
ToTable("sys_scheduled_tasks");
Map(x => x.Code).MaxLength(100);
Map(x => x.Name).MaxLength(200);
Map(x => x.JobType).MaxLength(100);
Map(x => x.CompanyCode).MaxLength(20);
Map(x => x.Cron).MaxLength(100);
Map(x => x.TimeZone).MaxLength(64);
Map(x => x.Parameters).Json();
}
}
/// <summary>Map of <see cref="JobRun"/> to <c>sys_job_runs</c>.</summary>
public sealed class JobRunMap : EntityMap<JobRun>
{
/// <summary>Creates the map.</summary>
public JobRunMap()
{
ToTable("sys_job_runs");
Map(x => x.TaskCode).MaxLength(100);
Map(x => x.TraceId).MaxLength(64);
}
}
/// <summary>Map of <see cref="JobLock"/> to <c>sys_job_locks</c>.</summary>
public sealed class JobLockMap : EntityMap<JobLock>
{
/// <summary>Creates the map.</summary>
public JobLockMap()
{
ToTable("sys_job_locks");
HasKey(x => x.Id, identity: false);
Map(x => x.Id).MaxLength(100);
Map(x => x.Owner).MaxLength(100);
}
}
/// <summary>Map of <see cref="SystemNotification"/> to <c>sys_notifications</c>.</summary>
public sealed class SystemNotificationMap : EntityMap<SystemNotification>
{
/// <summary>Creates the map.</summary>
public SystemNotificationMap()
{
ToTable("sys_notifications");
NotificationColumns.Configure(this);
}
}
/// <summary>Map of <see cref="SystemNotificationRead"/> to <c>sys_notification_reads</c>.</summary>
public sealed class SystemNotificationReadMap : EntityMap<SystemNotificationRead>
{
/// <summary>Creates the map.</summary>
public SystemNotificationReadMap() => ToTable("sys_notification_reads");
}
/// <summary>The notification columns shared by <c>sys_notifications</c> and <c>notifications</c>.</summary>
internal static class NotificationColumns
{
public static void Configure<T>(EntityMap<T> map)
where T : NotificationRecord, new()
{
map.Map(x => x.Category).MaxLength(40);
map.Map(x => x.Title).MaxLength(200);
map.Map(x => x.Link).MaxLength(400);
}
}