From ba647123c0078e9b0a2a004bdcef57ef0bb14cef Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 09:28:05 -0700 Subject: [PATCH 01/12] Add a way to specify username to notify Fix #14748 --- .../Activities/NotifyUserTask.cs | 34 +++++++-- .../NotifyUserTaskActivityDisplayDriver.cs | 3 +- .../Drivers/NotifyUserTaskDisplayDriver.cs | 37 +++++++++- .../ViewModels/NotifyUserTaskViewModel.cs | 6 ++ .../Items/NotifyUserTask.Fields.Edit.cshtml | 72 +++++++++++++++++++ 5 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs create mode 100644 src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs index c4a24145aa8..99c3937ff98 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs @@ -1,41 +1,61 @@ +using System; using System.Collections.Generic; -using System.Linq; using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using OrchardCore.Users; +using OrchardCore.Users.Indexes; using OrchardCore.Users.Models; using OrchardCore.Workflows.Models; using OrchardCore.Workflows.Services; +using YesSql; +using YesSql.Services; namespace OrchardCore.Notifications.Activities; public class NotifyUserTask : NotifyUserTaskActivity { + private readonly ISession _session; + public NotifyUserTask( INotificationService notificationCoordinator, IWorkflowExpressionEvaluator expressionEvaluator, HtmlEncoder htmlEncoder, ILogger logger, - IStringLocalizer localizer + IStringLocalizer stringLocalizer, + ISession session ) : base(notificationCoordinator, expressionEvaluator, htmlEncoder, logger, - localizer) + stringLocalizer) { + _session = session; } public override LocalizedString DisplayText => S["Notify User Task"]; - protected override Task> GetUsersAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext) + public WorkflowExpression Usernames + { + get => GetProperty(() => new WorkflowExpression()); + set => SetProperty(value); + } + + protected override async Task> GetUsersAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext) { - if (workflowContext.Input.TryGetValue("User", out var userObject) && userObject is User user && user.IsEnabled) + if (!string.IsNullOrEmpty(Usernames.Expression)) { - return Task.FromResult>(new[] { user }); + var expression = await _expressionEvaluator.EvaluateAsync(Usernames, workflowContext, null); + + var usernames = expression.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + + if (usernames.Length > 0) + { + return await _session.Query(user => user.NormalizedUserName.IsIn(usernames)).ListAsync(); + } } - return Task.FromResult(Enumerable.Empty()); + return []; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs index a6408af4151..b1de81c72ed 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; @@ -52,7 +51,7 @@ public async override Task UpdateAsync(TActivity model, IUpdateM { var viewModel = new TEditViewModel(); await updater.TryUpdateModelAsync(viewModel, Prefix); - + if (!_liquidTemplateManager.Validate(viewModel.Subject, out var subjectErrors)) { updater.ModelState.AddModelError(Prefix, nameof(viewModel.Subject), S["Subject field does not contain a valid Liquid expression. Details: {0}", string.Join(' ', subjectErrors)]); diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs index 680ec405072..8cb8b3b590a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs @@ -1,13 +1,20 @@ +using System; +using System.Threading.Tasks; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; +using OrchardCore.DisplayManagement.ModelBinding; +using OrchardCore.DisplayManagement.Views; using OrchardCore.Infrastructure.Html; using OrchardCore.Liquid; +using OrchardCore.Mvc.ModelBinding; using OrchardCore.Notifications.Activities; using OrchardCore.Notifications.Models; +using OrchardCore.Notifications.ViewModels; +using OrchardCore.Workflows.Models; namespace OrchardCore.Notifications.Drivers; -public class NotifyUserTaskDisplayDriver : NotifyUserTaskActivityDisplayDriver +public class NotifyUserTaskDisplayDriver : NotifyUserTaskActivityDisplayDriver { public NotifyUserTaskDisplayDriver( IHtmlSanitizerService htmlSanitizerService, @@ -17,4 +24,32 @@ public NotifyUserTaskDisplayDriver( : base(htmlSanitizerService, liquidTemplateManager, notificationOptions, stringLocalizer) { } + + protected override string EditShapeType { get; } = $"{typeof(NotifyUserTask).Name}_Fields_Edit"; + + public override async Task UpdateAsync(NotifyUserTask model, IUpdateModel updater) + { + var viewModel = new NotifyUserTaskViewModel(); + await updater.TryUpdateModelAsync(viewModel, Prefix); + + var usernames = viewModel.Usernames?.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + + if (usernames?.Length == 0) + { + updater.ModelState.AddModelError(Prefix, nameof(viewModel.Usernames), S["Please provide at least one username to notify."]); + } + else + { + model.Usernames = new WorkflowExpression(string.Join(',', usernames)); + } + + return await base.UpdateAsync(model, updater); + } + + protected override void EditActivity(NotifyUserTask activity, NotifyUserTaskViewModel model) + { + base.EditActivity(activity, model); + + model.Usernames = activity.Usernames.Expression; + } } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs new file mode 100644 index 00000000000..2c50d58cf3b --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs @@ -0,0 +1,6 @@ +namespace OrchardCore.Notifications.ViewModels; + +public class NotifyUserTaskViewModel : NotifyUserTaskActivityViewModel +{ + public string Usernames { get; set; } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml new file mode 100644 index 00000000000..7de7abd0f12 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml @@ -0,0 +1,72 @@ +@model NotifyUserTaskViewModel + +
+ + + + @T["Please provide a comma separated list of usernames. You may use Liquid syntax."] +
+ +
+ + + + @T["You may use Liquid syntax."] +
+ +
+ + + + @T["You may use Liquid syntax. Html is supported."] +
+ +
+ + + @T["This optional text body does not support HTML. You may use Liquid syntax."] +
+ +
+ + + @T["HTML message will only be sent if the notification provider supports it. You may use Liquid syntax."] +
+ +
+
+ + +
+ @T["When checked, the notification provider will use the HTML body if it supports HTML."] +
+ + + + + + + + + + + From 041e1bde285278ba45ca34a7c8c1f3ce2519a122 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 11:56:33 -0700 Subject: [PATCH 02/12] adding disctinct check --- .../OrchardCore.Notifications/Activities/NotifyUserTask.cs | 2 +- .../Drivers/NotifyUserTaskDisplayDriver.cs | 6 ++++-- .../Views/Items/NotifyUserTask.Fields.Design.cshtml | 2 +- .../Views/Items/NotifyUserTask.Fields.Thumbnail.cshtml | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs index 99c3937ff98..c7f520cc352 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs @@ -34,7 +34,7 @@ ISession session _session = session; } - public override LocalizedString DisplayText => S["Notify User Task"]; + public override LocalizedString DisplayText => S["Notify Specific Users Task"]; public WorkflowExpression Usernames { diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs index 8cb8b3b590a..9ac31ccdb25 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; @@ -32,9 +33,10 @@ public override async Task UpdateAsync(NotifyUserTask model, IUp var viewModel = new NotifyUserTaskViewModel(); await updater.TryUpdateModelAsync(viewModel, Prefix); - var usernames = viewModel.Usernames?.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + var usernames = viewModel.Usernames?.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries) + .Distinct(StringComparer.OrdinalIgnoreCase) ?? []; - if (usernames?.Length == 0) + if (!usernames.Any()) { updater.ModelState.AddModelError(Prefix, nameof(viewModel.Usernames), S["Please provide at least one username to notify."]); } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Design.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Design.cshtml index 58127278727..70c8ae981f0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Design.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Design.cshtml @@ -5,6 +5,6 @@ @model ActivityViewModel
-

@Model.Activity.GetTitleOrDefault(() => T["Notify user"])

+

@Model.Activity.GetTitleOrDefault(() => T["Notify Specific Users"])

"@Model.Activity.Subject" diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Thumbnail.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Thumbnail.cshtml index 978c71f827a..c1a1784c784 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Thumbnail.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Thumbnail.cshtml @@ -1,2 +1,2 @@ -

@T["Notify user"]

+

@T["Notify Specific Users"]

@T["Notify user"]

From 63047cfc7ed95f616efa530da11bc7660ebb056b Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 12:53:56 -0700 Subject: [PATCH 03/12] update the workflow to always inject the Notification fields so we don't have to repeat them --- .../NotifyUserTaskActivityDisplayDriver.cs | 45 ++++++++----- .../Items/NotifyUserTask.Fields.Edit.cshtml | 64 ------------------- .../NotifyUserTask.Fields.Thumbnail.cshtml | 2 +- 3 files changed, 29 insertions(+), 82 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs index b1de81c72ed..077d7d08610 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; @@ -19,13 +20,15 @@ public abstract class NotifyUserTaskActivityDisplayDriver $"{nameof(NotifyUserTaskActivity)}_Fields_Edit"; + protected virtual string EditShapeType { get; } = null; public NotifyUserTaskActivityDisplayDriver( IHtmlSanitizerService htmlSanitizerService, @@ -41,10 +44,26 @@ public NotifyUserTaskActivityDisplayDriver( public override IDisplayResult Edit(TActivity model) { - return Initialize(EditShapeType, viewModel => + var results = new List(); + + if (!string.IsNullOrEmpty(EditShapeType)) { - return EditActivityAsync(model, viewModel); - }).Location("Content"); + results.Add(Initialize(EditShapeType, viewModel => + { + return EditActivityAsync(model, viewModel); + }).Location("Content")); + } + + results.Add(Initialize("NotifyUserTaskActivity_Fields_Edit", viewModel => + { + viewModel.Subject = model.Subject.Expression; + viewModel.Summary = model.Summary.Expression; + viewModel.TextBody = model.TextBody.Expression; + viewModel.HtmlBody = model.HtmlBody.Expression; + viewModel.IsHtmlPreferred = model.IsHtmlPreferred; + }).Location("Content")); + + return Combine(results); } public async override Task UpdateAsync(TActivity model, IUpdateModel updater) @@ -72,10 +91,7 @@ public async override Task UpdateAsync(TActivity model, IUpdateM updater.ModelState.AddModelError(Prefix, nameof(viewModel.HtmlBody), S["HTML Body field does not contain a valid Liquid expression. Details: {0}", string.Join(' ', htmlBodyErrors)]); } - if (updater.ModelState.IsValid) - { - await UpdateActivityAsync(viewModel, model); - } + await UpdateActivityAsync(viewModel, model); return Edit(model); } @@ -95,15 +111,10 @@ protected override ValueTask EditActivityAsync(TActivity activity, TEditViewMode /// protected override void EditActivity(TActivity activity, TEditViewModel model) { - model.Subject = activity.Subject.Expression; - model.Summary = activity.Summary.Expression; - model.TextBody = activity.TextBody.Expression; - model.HtmlBody = activity.HtmlBody.Expression; - model.IsHtmlPreferred = activity.IsHtmlPreferred; } /// - /// Updates the activity when the view model is validated. + /// Updates the activity. /// protected override Task UpdateActivityAsync(TEditViewModel model, TActivity activity) { @@ -113,7 +124,7 @@ protected override Task UpdateActivityAsync(TEditViewModel model, TActivity acti } /// - /// Updates the activity when the view model is validated. + /// Updates the activity. /// protected override void UpdateActivity(TEditViewModel model, TActivity activity) { @@ -127,9 +138,9 @@ protected override void UpdateActivity(TEditViewModel model, TActivity activity) public override IDisplayResult Display(TActivity activity) { return Combine( - Shape($"{typeof(TActivity).Name}_Fields_Thumbnail", new ActivityViewModel(activity)) + Shape($"{_activityName}_Fields_Thumbnail", new ActivityViewModel(activity)) .Location("Thumbnail", "Content"), - Shape($"{typeof(TActivity).Name}_Fields_Design", new ActivityViewModel(activity)) + Shape($"{_activityName}_Fields_Design", new ActivityViewModel(activity)) .Location("Design", "Content") ); } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml index 7de7abd0f12..7409b9d9d1b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml @@ -6,67 +6,3 @@ @T["Please provide a comma separated list of usernames. You may use Liquid syntax."] - -
- - - - @T["You may use Liquid syntax."] -
- -
- - - - @T["You may use Liquid syntax. Html is supported."] -
- -
- - - @T["This optional text body does not support HTML. You may use Liquid syntax."] -
- -
- - - @T["HTML message will only be sent if the notification provider supports it. You may use Liquid syntax."] -
- -
-
- - -
- @T["When checked, the notification provider will use the HTML body if it supports HTML."] -
- - - - - - - - - - - diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Thumbnail.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Thumbnail.cshtml index c1a1784c784..b82b39c17a2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Thumbnail.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Thumbnail.cshtml @@ -1,2 +1,2 @@

@T["Notify Specific Users"]

-

@T["Notify user"]

+

@T["Notify specific users"]

From d8f9433b9f4ac31738a679d895bcaa9c841edb28 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 13:05:02 -0700 Subject: [PATCH 04/12] Cleanup --- .../Drivers/NotifyUserTaskActivityDisplayDriver.cs | 6 +++--- .../Drivers/NotifyUserTaskDisplayDriver.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs index 077d7d08610..4a60f3e915a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs @@ -20,7 +20,7 @@ public abstract class NotifyUserTaskActivityDisplayDriver(activity)) + Shape($"{ActivityName}_Fields_Thumbnail", new ActivityViewModel(activity)) .Location("Thumbnail", "Content"), - Shape($"{_activityName}_Fields_Design", new ActivityViewModel(activity)) + Shape($"{ActivityName}_Fields_Design", new ActivityViewModel(activity)) .Location("Design", "Content") ); } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs index 9ac31ccdb25..d94bcaf0daa 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs @@ -26,7 +26,7 @@ public NotifyUserTaskDisplayDriver( { } - protected override string EditShapeType { get; } = $"{typeof(NotifyUserTask).Name}_Fields_Edit"; + protected override string EditShapeType { get; } = $"{ActivityName}_Fields_Edit"; public override async Task UpdateAsync(NotifyUserTask model, IUpdateModel updater) { From 103ad43e9959e16f2585cfbf9827edfaacbf8008 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 14:09:14 -0700 Subject: [PATCH 05/12] Fix liquid validation issue and rename the Username --- .../Services/LiquidTemplateManager.cs | 11 ++++++++++- .../Activities/NotifyUserTask.cs | 6 +++--- .../Drivers/NotifyUserTaskActivityDisplayDriver.cs | 4 ++-- .../Drivers/NotifyUserTaskDisplayDriver.cs | 10 +++++----- .../ViewModels/NotifyUserTaskViewModel.cs | 2 +- .../Views/Items/NotifyUserTask.Fields.Edit.cshtml | 10 +++++----- .../Items/NotifyUserTaskActivity.Fields.Edit.cshtml | 2 ++ 7 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Liquid/Services/LiquidTemplateManager.cs b/src/OrchardCore.Modules/OrchardCore.Liquid/Services/LiquidTemplateManager.cs index e36e9b68026..eacc1ba7ddf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Liquid/Services/LiquidTemplateManager.cs +++ b/src/OrchardCore.Modules/OrchardCore.Liquid/Services/LiquidTemplateManager.cs @@ -124,8 +124,17 @@ public LiquidViewTemplate GetCachedTemplate(string source) public bool Validate(string template, out IEnumerable errors) { + if (string.IsNullOrEmpty(template)) + { + errors = []; + + return true; + } + var success = _liquidViewParser.TryParse(template, out _, out var error); - errors = new[] { error }; + + errors = [error]; + return success; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs index c7f520cc352..7bde79505b0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs @@ -36,7 +36,7 @@ ISession session public override LocalizedString DisplayText => S["Notify Specific Users Task"]; - public WorkflowExpression Usernames + public WorkflowExpression UserNames { get => GetProperty(() => new WorkflowExpression()); set => SetProperty(value); @@ -44,9 +44,9 @@ public WorkflowExpression Usernames protected override async Task> GetUsersAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext) { - if (!string.IsNullOrEmpty(Usernames.Expression)) + if (!string.IsNullOrEmpty(UserNames.Expression)) { - var expression = await _expressionEvaluator.EvaluateAsync(Usernames, workflowContext, null); + var expression = await _expressionEvaluator.EvaluateAsync(UserNames, workflowContext, null); var usernames = expression.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs index 4a60f3e915a..2cd92ffb3e3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs @@ -129,9 +129,9 @@ protected override Task UpdateActivityAsync(TEditViewModel model, TActivity acti protected override void UpdateActivity(TEditViewModel model, TActivity activity) { activity.Subject = new WorkflowExpression(model.Subject); - activity.Summary = new WorkflowExpression(_htmlSanitizerService.Sanitize(model.Summary)); + activity.Summary = new WorkflowExpression(_htmlSanitizerService.Sanitize(model.Summary ?? string.Empty)); activity.TextBody = new WorkflowExpression(model.TextBody); - activity.HtmlBody = new WorkflowExpression(_notificationOptions.DisableNotificationHtmlBodySanitizer ? model.HtmlBody : _htmlSanitizerService.Sanitize(model.HtmlBody)); + activity.HtmlBody = new WorkflowExpression(_notificationOptions.DisableNotificationHtmlBodySanitizer ? model.HtmlBody : _htmlSanitizerService.Sanitize(model.HtmlBody ?? string.Empty)); activity.IsHtmlPreferred = model.IsHtmlPreferred; } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs index d94bcaf0daa..3103bffb0c2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs @@ -33,16 +33,16 @@ public override async Task UpdateAsync(NotifyUserTask model, IUp var viewModel = new NotifyUserTaskViewModel(); await updater.TryUpdateModelAsync(viewModel, Prefix); - var usernames = viewModel.Usernames?.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries) + var userNames = viewModel.UserNames?.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries) .Distinct(StringComparer.OrdinalIgnoreCase) ?? []; - if (!usernames.Any()) + if (!userNames.Any()) { - updater.ModelState.AddModelError(Prefix, nameof(viewModel.Usernames), S["Please provide at least one username to notify."]); + updater.ModelState.AddModelError(Prefix, nameof(viewModel.UserNames), S["Please provide at least one username to notify."]); } else { - model.Usernames = new WorkflowExpression(string.Join(',', usernames)); + model.UserNames = new WorkflowExpression(string.Join(',', userNames)); } return await base.UpdateAsync(model, updater); @@ -52,6 +52,6 @@ protected override void EditActivity(NotifyUserTask activity, NotifyUserTaskView { base.EditActivity(activity, model); - model.Usernames = activity.Usernames.Expression; + model.UserNames = activity.UserNames.Expression; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs index 2c50d58cf3b..3c8c5107969 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs @@ -2,5 +2,5 @@ namespace OrchardCore.Notifications.ViewModels; public class NotifyUserTaskViewModel : NotifyUserTaskActivityViewModel { - public string Usernames { get; set; } + public string UserNames { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml index 7409b9d9d1b..652e6605aed 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml @@ -1,8 +1,8 @@ @model NotifyUserTaskViewModel -
- - - - @T["Please provide a comma separated list of usernames. You may use Liquid syntax."] +
+ + + + @T["Please provide a comma separated list of user names. You may use Liquid syntax."]
diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTaskActivity.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTaskActivity.Fields.Edit.cshtml index c88bd61e20f..a7954fdf7f0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTaskActivity.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTaskActivity.Fields.Edit.cshtml @@ -17,12 +17,14 @@
+ @T["This optional text body does not support HTML. You may use Liquid syntax."]
+ @T["HTML message will only be sent if the notification provider supports it. You may use Liquid syntax."]
From 1e4aa66e5bef4b63800410a544f54e97bec03223 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 14:12:17 -0700 Subject: [PATCH 06/12] Update src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- .../OrchardCore.Notifications/Activities/NotifyUserTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs index 7bde79505b0..2353c6c8c03 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs @@ -48,7 +48,7 @@ protected override async Task> GetUsersAsync(WorkflowExecutio { var expression = await _expressionEvaluator.EvaluateAsync(UserNames, workflowContext, null); - var usernames = expression.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + var userNames = expression.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); if (usernames.Length > 0) { From 847347ed8d499e8c6ccaf3136921f226a99dab1f Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 14:31:36 -0700 Subject: [PATCH 07/12] Fix build --- .../OrchardCore.Notifications/Activities/NotifyUserTask.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs index 2353c6c8c03..c61a2aeb9a4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs @@ -50,9 +50,9 @@ protected override async Task> GetUsersAsync(WorkflowExecutio var userNames = expression.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); - if (usernames.Length > 0) + if (userNames.Length > 0) { - return await _session.Query(user => user.NormalizedUserName.IsIn(usernames)).ListAsync(); + return await _session.Query(user => user.NormalizedUserName.IsIn(userNames)).ListAsync(); } } From 05fca73663f30da0b0bb852740a9a7a0e0f5e6d6 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 14:49:25 -0700 Subject: [PATCH 08/12] Simplify --- .../NotifyUserTaskActivityDisplayDriver.cs | 61 +++++++++++-------- .../ViewModels/NotifyUserTaskViewModel.cs | 2 +- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs index 2cd92ffb3e3..9e6102dd258 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs @@ -18,7 +18,7 @@ namespace OrchardCore.Notifications.Drivers; public abstract class NotifyUserTaskActivityDisplayDriver : ActivityDisplayDriver where TActivity : NotifyUserTaskActivity - where TEditViewModel : NotifyUserTaskActivityViewModel, new() + where TEditViewModel : class, new() { protected static readonly string ActivityName = typeof(TActivity).Name; @@ -42,7 +42,7 @@ public NotifyUserTaskActivityDisplayDriver( S = stringLocalizer; } - public override IDisplayResult Edit(TActivity model) + public override IDisplayResult Edit(TActivity activity) { var results = new List(); @@ -50,50 +50,59 @@ public override IDisplayResult Edit(TActivity model) { results.Add(Initialize(EditShapeType, viewModel => { - return EditActivityAsync(model, viewModel); + return EditActivityAsync(activity, viewModel); }).Location("Content")); } - results.Add(Initialize("NotifyUserTaskActivity_Fields_Edit", viewModel => + results.Add(Initialize("NotifyUserTaskActivity_Fields_Edit", model => { - viewModel.Subject = model.Subject.Expression; - viewModel.Summary = model.Summary.Expression; - viewModel.TextBody = model.TextBody.Expression; - viewModel.HtmlBody = model.HtmlBody.Expression; - viewModel.IsHtmlPreferred = model.IsHtmlPreferred; + model.Subject = activity.Subject.Expression; + model.Summary = activity.Summary.Expression; + model.TextBody = activity.TextBody.Expression; + model.HtmlBody = activity.HtmlBody.Expression; + model.IsHtmlPreferred = activity.IsHtmlPreferred; }).Location("Content")); return Combine(results); } - public async override Task UpdateAsync(TActivity model, IUpdateModel updater) + public async override Task UpdateAsync(TActivity activity, IUpdateModel updater) { - var viewModel = new TEditViewModel(); - await updater.TryUpdateModelAsync(viewModel, Prefix); + var model = new NotifyUserTaskActivityViewModel(); + await updater.TryUpdateModelAsync(model, Prefix); - if (!_liquidTemplateManager.Validate(viewModel.Subject, out var subjectErrors)) + if (!_liquidTemplateManager.Validate(model.Subject, out var subjectErrors)) { - updater.ModelState.AddModelError(Prefix, nameof(viewModel.Subject), S["Subject field does not contain a valid Liquid expression. Details: {0}", string.Join(' ', subjectErrors)]); + updater.ModelState.AddModelError(Prefix, nameof(model.Subject), S["Subject field does not contain a valid Liquid expression. Details: {0}", string.Join(' ', subjectErrors)]); } - if (!_liquidTemplateManager.Validate(viewModel.Summary, out var summaryErrors)) + if (!_liquidTemplateManager.Validate(model.Summary, out var summaryErrors)) { - updater.ModelState.AddModelError(Prefix, nameof(viewModel.Summary), S["Summary field does not contain a valid Liquid expression. Details: {0}", string.Join(' ', summaryErrors)]); + updater.ModelState.AddModelError(Prefix, nameof(model.Summary), S["Summary field does not contain a valid Liquid expression. Details: {0}", string.Join(' ', summaryErrors)]); } - if (!_liquidTemplateManager.Validate(viewModel.TextBody, out var textBodyErrors)) + if (!_liquidTemplateManager.Validate(model.TextBody, out var textBodyErrors)) { - updater.ModelState.AddModelError(Prefix, nameof(viewModel.TextBody), S["Text Body field does not contain a valid Liquid expression. Details: {0}", string.Join(' ', textBodyErrors)]); + updater.ModelState.AddModelError(Prefix, nameof(model.TextBody), S["Text Body field does not contain a valid Liquid expression. Details: {0}", string.Join(' ', textBodyErrors)]); } - if (!_liquidTemplateManager.Validate(viewModel.HtmlBody, out var htmlBodyErrors)) + if (!_liquidTemplateManager.Validate(model.HtmlBody, out var htmlBodyErrors)) { - updater.ModelState.AddModelError(Prefix, nameof(viewModel.HtmlBody), S["HTML Body field does not contain a valid Liquid expression. Details: {0}", string.Join(' ', htmlBodyErrors)]); + updater.ModelState.AddModelError(Prefix, nameof(model.HtmlBody), S["HTML Body field does not contain a valid Liquid expression. Details: {0}", string.Join(' ', htmlBodyErrors)]); } - await UpdateActivityAsync(viewModel, model); + activity.Subject = new WorkflowExpression(model.Subject); + activity.Summary = new WorkflowExpression(_htmlSanitizerService.Sanitize(model.Summary ?? string.Empty)); + activity.TextBody = new WorkflowExpression(model.TextBody); + activity.HtmlBody = new WorkflowExpression(_notificationOptions.DisableNotificationHtmlBodySanitizer ? model.HtmlBody : _htmlSanitizerService.Sanitize(model.HtmlBody ?? string.Empty)); + activity.IsHtmlPreferred = model.IsHtmlPreferred; + + var modelOfT = new TEditViewModel(); + await updater.TryUpdateModelAsync(modelOfT, Prefix); + + await UpdateActivityAsync(modelOfT, activity); - return Edit(model); + return Edit(activity); } /// @@ -128,11 +137,7 @@ protected override Task UpdateActivityAsync(TEditViewModel model, TActivity acti /// protected override void UpdateActivity(TEditViewModel model, TActivity activity) { - activity.Subject = new WorkflowExpression(model.Subject); - activity.Summary = new WorkflowExpression(_htmlSanitizerService.Sanitize(model.Summary ?? string.Empty)); - activity.TextBody = new WorkflowExpression(model.TextBody); - activity.HtmlBody = new WorkflowExpression(_notificationOptions.DisableNotificationHtmlBodySanitizer ? model.HtmlBody : _htmlSanitizerService.Sanitize(model.HtmlBody ?? string.Empty)); - activity.IsHtmlPreferred = model.IsHtmlPreferred; + } public override IDisplayResult Display(TActivity activity) @@ -157,4 +162,6 @@ public NotifyUserTaskActivityDisplayDriver( : base(htmlSanitizerService, liquidTemplateManager, notificationOptions, stringLocalizer) { } + + sealed protected override string EditShapeType { get; } = null; } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs index 3c8c5107969..f23c0022e80 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs @@ -1,6 +1,6 @@ namespace OrchardCore.Notifications.ViewModels; -public class NotifyUserTaskViewModel : NotifyUserTaskActivityViewModel +public class NotifyUserTaskViewModel { public string UserNames { get; set; } } From 6dd50f8e680d1c88047191befe1d39538511290e Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 14:50:12 -0700 Subject: [PATCH 09/12] rename --- .../Drivers/NotifyUserTaskDisplayDriver.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs index 3103bffb0c2..2969f66ddb7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs @@ -28,7 +28,7 @@ public NotifyUserTaskDisplayDriver( protected override string EditShapeType { get; } = $"{ActivityName}_Fields_Edit"; - public override async Task UpdateAsync(NotifyUserTask model, IUpdateModel updater) + public override async Task UpdateAsync(NotifyUserTask activity, IUpdateModel updater) { var viewModel = new NotifyUserTaskViewModel(); await updater.TryUpdateModelAsync(viewModel, Prefix); @@ -42,10 +42,10 @@ public override async Task UpdateAsync(NotifyUserTask model, IUp } else { - model.UserNames = new WorkflowExpression(string.Join(',', userNames)); + activity.UserNames = new WorkflowExpression(string.Join(',', userNames)); } - return await base.UpdateAsync(model, updater); + return await base.UpdateAsync(activity, updater); } protected override void EditActivity(NotifyUserTask activity, NotifyUserTaskViewModel model) From 78b636f1fe6b604eeb560360511acdd350d2c8fa Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 14:57:45 -0700 Subject: [PATCH 10/12] Use static names --- .../Drivers/NotifyUserTaskActivityDisplayDriver.cs | 4 ++-- .../Handlers/DisplayDriver.cs | 6 ++++-- .../Display/ActivityDisplayDriver.cs | 10 ++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs index 9e6102dd258..004fdbea412 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs @@ -20,8 +20,6 @@ public abstract class NotifyUserTaskActivityDisplayDriver UpdateAsync(TActivity activity, IUpdateModel updater) { var model = new NotifyUserTaskActivityViewModel(); + await updater.TryUpdateModelAsync(model, Prefix); if (!_liquidTemplateManager.Validate(model.Subject, out var subjectErrors)) @@ -98,6 +97,7 @@ public async override Task UpdateAsync(TActivity activity, IUpda activity.IsHtmlPreferred = model.IsHtmlPreferred; var modelOfT = new TEditViewModel(); + await updater.TryUpdateModelAsync(modelOfT, Prefix); await UpdateActivityAsync(modelOfT, activity); diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs index 947291efd71..3aadeb682e2 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs @@ -12,6 +12,8 @@ public abstract class DisplayDriver /// Returns true if the model can be handle by the current driver. /// @@ -116,11 +118,11 @@ protected virtual void BuildPrefix(TModel model, string htmlFieldPrefix) { if (!string.IsNullOrEmpty(htmlFieldPrefix)) { - Prefix = $"{htmlFieldPrefix}.{typeof(TModel).Name}"; + Prefix = $"{htmlFieldPrefix}.{ModelName}"; } else { - Prefix = typeof(TModel).Name; + Prefix = ModelName; } } } diff --git a/src/OrchardCore/OrchardCore.Workflows.Abstractions/Display/ActivityDisplayDriver.cs b/src/OrchardCore/OrchardCore.Workflows.Abstractions/Display/ActivityDisplayDriver.cs index e90d806cd77..d6f5c7c377c 100644 --- a/src/OrchardCore/OrchardCore.Workflows.Abstractions/Display/ActivityDisplayDriver.cs +++ b/src/OrchardCore/OrchardCore.Workflows.Abstractions/Display/ActivityDisplayDriver.cs @@ -12,13 +12,15 @@ namespace OrchardCore.Workflows.Display /// public abstract class ActivityDisplayDriver : DisplayDriver where TActivity : class, IActivity { - private static readonly string _thumbnailshapeType = $"{typeof(TActivity).Name}_Fields_Thumbnail"; - private static readonly string _designShapeType = $"{typeof(TActivity).Name}_Fields_Design"; + protected static readonly string ActivityName = typeof(TActivity).Name; + + private static readonly string _thumbnailShapeType = $"{ActivityName}_Fields_Thumbnail"; + private static readonly string _designShapeType = $"{ActivityName}_Fields_Design"; public override IDisplayResult Display(TActivity model) { return Combine( - Shape(_thumbnailshapeType, new ActivityViewModel(model)).Location("Thumbnail", "Content"), + Shape(_thumbnailShapeType, new ActivityViewModel(model)).Location("Thumbnail", "Content"), Shape(_designShapeType, new ActivityViewModel(model)).Location("Design", "Content") ); } @@ -29,7 +31,7 @@ public override IDisplayResult Display(TActivity model) /// public abstract class ActivityDisplayDriver : ActivityDisplayDriver where TActivity : class, IActivity where TEditViewModel : class, new() { - private static readonly string _editShapeType = $"{typeof(TActivity).Name}_Fields_Edit"; + private static readonly string _editShapeType = $"{ActivityName}_Fields_Edit"; public override IDisplayResult Edit(TActivity model) { From 228caa456a3aa546de8d3e145ca2cbc71d2a8ca0 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 15:40:39 -0700 Subject: [PATCH 11/12] Update src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- .../Drivers/NotifyUserTaskDisplayDriver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs index 2969f66ddb7..e8dc2cc75e8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskDisplayDriver.cs @@ -42,7 +42,7 @@ public override async Task UpdateAsync(NotifyUserTask activity, } else { - activity.UserNames = new WorkflowExpression(string.Join(',', userNames)); + activity.UserNames = new WorkflowExpression(string.Join(", ", userNames)); } return await base.UpdateAsync(activity, updater); From acd9569abd3d0676289dd0edfd8dd52e7816a5d7 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 16 May 2024 16:51:57 -0700 Subject: [PATCH 12/12] Paginate the usernames to avoid posible exceptions. --- .../Activities/NotifyUserTask.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs index c61a2aeb9a4..2b27a091650 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs @@ -52,7 +52,14 @@ protected override async Task> GetUsersAsync(WorkflowExecutio if (userNames.Length > 0) { - return await _session.Query(user => user.NormalizedUserName.IsIn(userNames)).ListAsync(); + var users = new List(); + + foreach (var page in userNames.PagesOf(1000)) + { + users.AddRange(await _session.Query(user => user.NormalizedUserName.IsIn(page)).ListAsync()); + } + + return users; } }