Fix hidden add/remove template buttons, add per-template login filter
The add/remove template buttons sat directly below the fixed-height list with only 6px of margin to the tab's bottom edge - enough on this dev machine but not on the operator's real one (different DPI/font scale), so the buttons rendered off the visible area. Moved them above the list instead (visibility no longer depends on how much space is left at the bottom) and gave the whole "Шаблоны" tab substantially more vertical room throughout. Also added an optional per-template login regex filter (MailTemplateDefinition.LoginPattern): once a file's suffix matches a template, its login must also match that template's pattern (if any) or the row surfaces as a clear Error in the preview instead of silently going through - addresses "непонятно что будет работать". Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
804b9610ca
commit
6e823954a3
8 files changed
+385
-50
No files matched your search
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BulkArchiveMailer.Core
|
||||
{
|
||||
@@ -72,6 +73,25 @@ namespace BulkArchiveMailer.Core
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(matchedTemplate.LoginPattern) && !LoginMatchesPattern(parsed.Login, matchedTemplate.LoginPattern))
|
||||
{
|
||||
// Suffix matched, but the operator scoped this template
|
||||
// to a subset of logins (e.g. a per-team/per-suffix
|
||||
// custom template) and this file's login falls outside
|
||||
// it - surfaced next to the other per-file
|
||||
// "recognized but does not qualify" case (suffix
|
||||
// mismatch above) rather than silently picking a
|
||||
// different template or falling through to
|
||||
// byLogin/Ready.
|
||||
result.UnrecognizedFiles.Add(new SendJob
|
||||
{
|
||||
ArchivePath = filePath,
|
||||
Status = SendStatus.Error,
|
||||
ErrorMessage = $"Логин \"{parsed.Login}\" не соответствует фильтру шаблона \"{matchedTemplate.DisplayName}\" ({matchedTemplate.LoginPattern}): {fileName}",
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!byLogin.TryGetValue(parsed.Login, out var list))
|
||||
{
|
||||
list = new List<(string, string)>();
|
||||
@@ -151,5 +171,25 @@ namespace BulkArchiveMailer.Core
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether login satisfies the template's LoginPattern regex
|
||||
/// (case-insensitive). An invalid pattern (e.g. hand-edited
|
||||
/// config.json with broken regex syntax) is treated as "does not
|
||||
/// match" rather than throwing and aborting the whole folder scan -
|
||||
/// SettingsForm.btnSave_Click is where a bad pattern is meant to be
|
||||
/// caught, before it ever reaches disk.
|
||||
/// </summary>
|
||||
private static bool LoginMatchesPattern(string login, string pattern)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Regex.IsMatch(login, pattern, RegexOptions.IgnoreCase);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user