-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to specify username to send notifications to (#16073)
Co-authored-by: Zoltán Lehóczky <[email protected]>
- Loading branch information
1 parent
07ddde9
commit 0f57494
Showing
11 changed files
with
167 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 35 additions & 8 deletions
43
src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,68 @@ | ||
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<NotifyUserTask> | ||
{ | ||
private readonly ISession _session; | ||
|
||
public NotifyUserTask( | ||
INotificationService notificationCoordinator, | ||
IWorkflowExpressionEvaluator expressionEvaluator, | ||
HtmlEncoder htmlEncoder, | ||
ILogger<NotifyUserTask> logger, | ||
IStringLocalizer<NotifyUserTask> localizer | ||
IStringLocalizer<NotifyUserTask> stringLocalizer, | ||
ISession session | ||
) : base(notificationCoordinator, | ||
expressionEvaluator, | ||
htmlEncoder, | ||
logger, | ||
localizer) | ||
stringLocalizer) | ||
{ | ||
_session = session; | ||
} | ||
|
||
public override LocalizedString DisplayText => S["Notify User Task"]; | ||
public override LocalizedString DisplayText => S["Notify Specific Users Task"]; | ||
|
||
public WorkflowExpression<string> UserNames | ||
{ | ||
get => GetProperty(() => new WorkflowExpression<string>()); | ||
set => SetProperty(value); | ||
} | ||
|
||
protected override Task<IEnumerable<IUser>> GetUsersAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext) | ||
protected override async Task<IEnumerable<IUser>> 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<IEnumerable<IUser>>(new[] { user }); | ||
var expression = await _expressionEvaluator.EvaluateAsync(UserNames, workflowContext, null); | ||
|
||
var userNames = expression.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); | ||
|
||
if (userNames.Length > 0) | ||
{ | ||
var users = new List<User>(); | ||
|
||
foreach (var page in userNames.PagesOf(1000)) | ||
{ | ||
users.AddRange(await _session.Query<User, UserIndex>(user => user.NormalizedUserName.IsIn(page)).ListAsync()); | ||
} | ||
|
||
return users; | ||
} | ||
} | ||
|
||
return Task.FromResult(Enumerable.Empty<IUser>()); | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/NotifyUserTaskViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace OrchardCore.Notifications.ViewModels; | ||
|
||
public class NotifyUserTaskViewModel | ||
{ | ||
public string UserNames { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...chardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Edit.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@model NotifyUserTaskViewModel | ||
|
||
<div class="mb-3" asp-validation-class-for="UserNames"> | ||
<label asp-for="UserNames" class="form-label">@T["User names"]</label> | ||
<input type="text" asp-for="UserNames" class="form-control" /> | ||
<span asp-validation-for="UserNames"></span> | ||
<span class="hint">@T["Please provide a comma separated list of user names. You may use Liquid syntax."]</span> | ||
</div> |
4 changes: 2 additions & 2 deletions
4
...Core.Modules/OrchardCore.Notifications/Views/Items/NotifyUserTask.Fields.Thumbnail.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<h4 class="card-title"><i class="fa-solid fa-envelope" aria-hidden="true"></i>@T["Notify user"]</h4> | ||
<p>@T["Notify user"]</p> | ||
<h4 class="card-title"><i class="fa-solid fa-envelope" aria-hidden="true"></i>@T["Notify Specific Users"]</h4> | ||
<p>@T["Notify specific users"]</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.