diff --git a/Signum.Engine.Extensions/Alerts/AlertLogic.cs b/Signum.Engine.Extensions/Alerts/AlertLogic.cs index f1daef16b3..0368b9b5d5 100644 --- a/Signum.Engine.Extensions/Alerts/AlertLogic.cs +++ b/Signum.Engine.Extensions/Alerts/AlertLogic.cs @@ -62,6 +62,7 @@ public static void Start(SchemaBuilder sb, params Type[] registerExpressionsFor) a.Title, Text = a.Text!.Etc(100), a.Target, + a.ParentTarget, a.Recipient, a.CreationDate, a.CreatedBy, @@ -294,12 +295,12 @@ public static void RegisterAlertType(AlertTypeSymbol alertType, AlertTypeOptions SystemAlertTypes.Add(alertType, options ?? new AlertTypeOptions()); } - public static AlertEntity? CreateAlert(this IEntity entity, AlertTypeSymbol alertType, string? text = null, string?[]? textArguments = null, DateTime? alertDate = null, Lite? createdBy = null, string? title = null, Lite? recipient = null) + public static AlertEntity? CreateAlert(this IEntity entity, AlertTypeSymbol alertType, string? text = null, string?[]? textArguments = null, DateTime? alertDate = null, Lite? createdBy = null, string? title = null, Lite? recipient = null, Lite? parentTarget = null) { - return CreateAlert(entity.ToLiteFat(), alertType, text, textArguments, alertDate, createdBy, title, recipient); + return CreateAlert(entity.ToLiteFat(), alertType, text, textArguments, alertDate, createdBy, title, recipient, parentTarget); } - public static AlertEntity? CreateAlert(this Lite entity, AlertTypeSymbol alertType, string? text = null, string?[]? textArguments = null, DateTime? alertDate = null, Lite? createdBy = null, string? title = null, Lite? recipient = null) + public static AlertEntity? CreateAlert(this Lite entity, AlertTypeSymbol alertType, string? text = null, string?[]? textArguments = null, DateTime? alertDate = null, Lite? createdBy = null, string? title = null, Lite? recipient = null, Lite? parentTarget = null) { if (Started == false) return null; @@ -314,6 +315,7 @@ public static void RegisterAlertType(AlertTypeSymbol alertType, AlertTypeOptions TextArguments = textArguments?.ToString("\n###\n"), TextField = text, Target = (Lite)entity, + ParentTarget = parentTarget, AlertType = alertType, Recipient = recipient }; @@ -413,6 +415,10 @@ public static void DeleteAllAlerts(Lite target) Database.Query() .Where(a => a.Target.Is(target)) .UnsafeDelete(); + + Database.Query() + .Where(a => a.ParentTarget.Is(target)) + .UnsafeDelete(); } } diff --git a/Signum.Engine.Extensions/Authorization/ActiveDirectoryAuthorizer.cs b/Signum.Engine.Extensions/Authorization/ActiveDirectoryAuthorizer.cs index 78cbfa440c..184ccb1ff1 100644 --- a/Signum.Engine.Extensions/Authorization/ActiveDirectoryAuthorizer.cs +++ b/Signum.Engine.Extensions/Authorization/ActiveDirectoryAuthorizer.cs @@ -212,11 +212,13 @@ public virtual UserEntity CreateUserInternal(IAutoCreateUserContext ctx) var config = GetConfig(); if (ctx is DirectoryServiceAutoCreateUserContext ds) { - var groups = ds.GetUserPrincipal().GetGroups(ds.PrincipalContext); + var groups = ds.GetUserPrincipal().GetGroups(ds.PrincipalContext).ToList(); var role = config.RoleMapping.FirstOrDefault(m => { Guid.TryParse(m.ADNameOrGuid, out var guid); - return groups.Any(g => g.Name == m.ADNameOrGuid || g.Guid == guid); + var found = groups.Any(g => g.Name == m.ADNameOrGuid || g.Guid == guid); + + return found; })?.Role ?? config.DefaultRole; if (role != null) diff --git a/Signum.Engine.Extensions/UserQueries/UserQueryLogic.cs b/Signum.Engine.Extensions/UserQueries/UserQueryLogic.cs index a4340c5d55..ffeb72769c 100644 --- a/Signum.Engine.Extensions/UserQueries/UserQueryLogic.cs +++ b/Signum.Engine.Extensions/UserQueries/UserQueryLogic.cs @@ -253,19 +253,19 @@ public static void RegisterRoleTypeCondition(SchemaBuilder sb, TypeConditionSymb { using (DelayedConsole.Delay(() => Console.WriteLine(" Filters:"))) { - foreach (var item in uq.Filters.ToList()) + foreach (var filter in uq.Filters.ToList()) { - if (item.Token == null) + if (filter.Token == null) continue; - QueryTokenEmbedded token = item.Token; - switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, options | SubTokensOptions.CanAnyAll, " {0} {1}".FormatWith(item.Operation, item.ValueString), allowRemoveToken: true, allowReCreate: false)) + QueryTokenEmbedded token = filter.Token; + switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, options | SubTokensOptions.CanAnyAll, " {0} {1}".FormatWith(filter.Operation, filter.ValueString), allowRemoveToken: true, allowReCreate: false)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(uq, u => u.Guid == uq.Guid); - case FixTokenResult.RemoveToken: uq.Filters.Remove(item); break; + case FixTokenResult.RemoveToken: uq.Filters.Remove(filter); break; case FixTokenResult.SkipEntity: return null; - case FixTokenResult.Fix: item.Token = token; break; + case FixTokenResult.Fix: filter.Token = token; break; default: break; } } @@ -276,18 +276,32 @@ public static void RegisterRoleTypeCondition(SchemaBuilder sb, TypeConditionSymb { using (DelayedConsole.Delay(() => Console.WriteLine(" Columns:"))) { - foreach (var item in uq.Columns.ToList()) + foreach (var col in uq.Columns.ToList()) { - QueryTokenEmbedded token = item.Token; - switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, options, item.DisplayName.HasText() ? " '{0}'".FormatWith(item.DisplayName) : null, allowRemoveToken: true, allowReCreate: false)) + QueryTokenEmbedded token = col.Token; + switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, options, col.DisplayName.HasText() ? " '{0}' (Summary)".FormatWith(col.DisplayName) : null, allowRemoveToken: true, allowReCreate: false)) { case FixTokenResult.Nothing: break; - case FixTokenResult.DeleteEntity:; return table.DeleteSqlSync(uq, u => u.Guid == uq.Guid); - case FixTokenResult.RemoveToken: uq.Columns.Remove(item); break; + case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(uq, u => u.Guid == uq.Guid); + case FixTokenResult.RemoveToken: uq.Columns.Remove(col); break; case FixTokenResult.SkipEntity: return null; - case FixTokenResult.Fix: item.Token = token; break; + case FixTokenResult.Fix: col.Token = token; break; default: break; } + + if(col.SummaryToken != null) + { + QueryTokenEmbedded sumToken = col.SummaryToken; + switch (QueryTokenSynchronizer.FixToken(replacements, ref sumToken, qd, options | SubTokensOptions.CanAggregate, col.DisplayName.HasText() ? " '{0}'".FormatWith(col.DisplayName) : null, allowRemoveToken: true, allowReCreate: false)) + { + case FixTokenResult.Nothing: break; + case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(uq, u => u.Guid == uq.Guid); + case FixTokenResult.RemoveToken: col.SummaryToken = null; break; + case FixTokenResult.SkipEntity: return null; + case FixTokenResult.Fix: col.SummaryToken = sumToken; break; + default: break; + } + } } } } @@ -296,16 +310,16 @@ public static void RegisterRoleTypeCondition(SchemaBuilder sb, TypeConditionSymb { using (DelayedConsole.Delay(() => Console.WriteLine(" Orders:"))) { - foreach (var item in uq.Orders.ToList()) + foreach (var ord in uq.Orders.ToList()) { - QueryTokenEmbedded token = item.Token; - switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, options, " " + item.OrderType.ToString(), allowRemoveToken: true, allowReCreate: false)) + QueryTokenEmbedded token = ord.Token; + switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, options, " " + ord.OrderType.ToString(), allowRemoveToken: true, allowReCreate: false)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(uq, u => u.Guid == uq.Guid); - case FixTokenResult.RemoveToken: uq.Orders.Remove(item); break; + case FixTokenResult.RemoveToken: uq.Orders.Remove(ord); break; case FixTokenResult.SkipEntity: return null; - case FixTokenResult.Fix: item.Token = token; break; + case FixTokenResult.Fix: ord.Token = token; break; default: break; } } diff --git a/Signum.Engine.Extensions/Word/HtmlToWordConverter.cs b/Signum.Engine.Extensions/Word/HtmlToWordConverter.cs index 8f44a832c2..d0713c9a78 100644 --- a/Signum.Engine.Extensions/Word/HtmlToWordConverter.cs +++ b/Signum.Engine.Extensions/Word/HtmlToWordConverter.cs @@ -1,4 +1,5 @@ using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using HtmlAgilityPack; using System; @@ -6,7 +7,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; - +using System.Web; + namespace Signum.Engine.Word; public static class HtmlToWordConverter @@ -20,6 +22,7 @@ public static IEnumerable HtmlToWord(string html, WordTemplatePa htmlDoc.LoadHtml(html); var currentParagraph = p.CurrentTokenNode!.Ancestors().FirstEx(); + var elements = HtmlToWordPrivate(htmlDoc.DocumentNode, rp => { @@ -29,7 +32,7 @@ public static IEnumerable HtmlToWord(string html, WordTemplatePa { currentParagraph.ParagraphProperties.CopyTo(pp); - }).ToList(); + }, p.Document).ToList(); if (elements.Any(a => a is Paragraph)) elements.RemoveAll(a => a is Run r && string.IsNullOrWhiteSpace(r.InnerText)); @@ -37,55 +40,227 @@ public static IEnumerable HtmlToWord(string html, WordTemplatePa return elements; } - private static IEnumerable HtmlToWordPrivate(HtmlNode htmlNode, Action? addRunProperties, Action? addParagraphProperties) + private static IEnumerable HtmlToWordPrivate(HtmlNode htmlNode, Action? addRunProperties, Action? addParagraphProperties, OpenXmlPackage document) { switch (htmlNode.Name) { case "#document": - return htmlNode.ChildNodes.SelectMany(c => HtmlToWordPrivate(c, addRunProperties, addParagraphProperties)).ToArray(); + return htmlNode.ChildNodes.SelectMany(c => HtmlToWordPrivate(c, addRunProperties, addParagraphProperties, document)).ToArray(); + case "li": case "p": - - var paragraphProperties = new ParagraphProperties(); - addParagraphProperties?.Invoke(paragraphProperties); - var childrens = htmlNode.ChildNodes.SelectMany(c => HtmlToWordPrivate(c, addRunProperties, addParagraphProperties)).ToList(); - childrens.Insert(0, paragraphProperties); - return new[] { new Paragraph(childrens) }; - + { + var pp = new ParagraphProperties(); + addParagraphProperties?.Invoke(pp); + var childrens = htmlNode.ChildNodes.SelectMany(c => HtmlToWordPrivate(c, addRunProperties, addParagraphProperties, document)).ToList(); + childrens.Insert(0, pp); + return new[] { new Paragraph(childrens) }; + } case "em": return htmlNode.ChildNodes.SelectMany(c => HtmlToWordPrivate(c, addRunProperties + ((RunProperties rp) => { rp.Append(new Italic(), new ItalicComplexScript()); - }), addParagraphProperties)); + }), addParagraphProperties, document)); case "strong": return htmlNode.ChildNodes.SelectMany(c => HtmlToWordPrivate(c, addRunProperties + ((RunProperties rp) => { rp.Append(new Bold(), new BoldComplexScript()); - }), addParagraphProperties)); + }), addParagraphProperties, document)); case "ins": case "u": return htmlNode.ChildNodes.SelectMany(c => HtmlToWordPrivate(c, addRunProperties + ((RunProperties rp) => { rp.Append(new Underline() { Val = UnderlineValues.Single }); - }), addParagraphProperties)); - + }), addParagraphProperties, document)); + + + case "h1": + case "h2": + case "h3": + case "h4": + { + var mainDocument = document.GetPartsOfType().SingleEx(); + + var hi = htmlNode.Name.After("h"); + + + Style headingStyle; + { + var styles = mainDocument.GetPartsOfType().FirstOrDefault(); + if (styles == null) + { + styles = mainDocument.AddNewPart(); + styles.Styles = new Styles(); + } + + headingStyle = styles.Styles!.Elements