From 0c4991801d96d315c1a7dc1d08e34976da2ed266 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 22 Nov 2023 16:00:55 -0800 Subject: [PATCH 1/3] Cleanup notifications module --- .../Activities/NotifyUserTaskActivity.cs | 4 +- .../Controllers/AdminController.cs | 84 ++++++++++--------- .../Controllers/ApiController.cs | 4 +- .../ListNotificationOptionsDisplayDriver.cs | 29 ++++--- .../Drivers/NotificationDisplayDriver.cs | 9 +- .../NotificationNavbarDisplayDriver.cs | 4 +- .../NotifyUserTaskActivityDisplayDriver.cs | 6 +- ...otificationPreferencesPartDisplayDriver.cs | 11 ++- .../Handlers/CoreNotificationEventsHandler.cs | 4 +- .../UserNotificationMessageViewModel.cs | 4 +- ...otifyContentOwnerTask.Fields.Design.cshtml | 2 +- ...fyContentOwnerTask.Fields.Thumbnail.cshtml | 2 +- .../Views/NotificationsAdminList.cshtml | 2 +- .../NotificationsAdminListSummary.cshtml | 2 +- .../Models/ListNotificationOptions.cs | 2 +- .../NotificationQueryContext.cs | 3 +- .../NotificationMethodProviderAccessor.cs | 2 +- 17 files changed, 94 insertions(+), 80 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTaskActivity.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTaskActivity.cs index e94563fb5d7..3cdc7730e94 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTaskActivity.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Activities/NotifyUserTaskActivity.cs @@ -63,9 +63,7 @@ public bool IsHtmlPreferred } public override IEnumerable GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext) - { - return Outcomes(S["Done"], S["Failed"], S["Failed: no user found"]); - } + => Outcomes(S["Done"], S["Failed"], S["Failed: no user found"]); public override async Task ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext) { diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs index 989250e22c0..a9eeecea29d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs @@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Localization; -using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; @@ -32,42 +31,46 @@ public class AdminController : Controller, IUpdateModel { private readonly IAuthorizationService _authorizationService; private readonly ISession _session; - protected readonly dynamic New; - private readonly IDisplayManager _webNoticiationDisplayManager; + + private readonly IDisplayManager _notificationDisplayManager; private readonly INotificationsAdminListQueryService _notificationsAdminListQueryService; private readonly IDisplayManager _notificationOptionsDisplayManager; private readonly INotifier _notifier; - protected readonly IStringLocalizer S; - protected readonly IHtmlLocalizer H; private readonly IShapeFactory _shapeFactory; private readonly PagerOptions _pagerOptions; private readonly IClock _clock; + protected readonly dynamic New; + protected readonly IStringLocalizer S; + protected readonly IHtmlLocalizer H; + public AdminController( IAuthorizationService authorizationService, ISession session, - IShapeFactory shapeFactory, + IOptions pagerOptions, - IDisplayManager webNoticiationDisplayManager, + IDisplayManager notificationDisplayManager, INotificationsAdminListQueryService notificationsAdminListQueryService, IDisplayManager notificationOptionsDisplayManager, INotifier notifier, + IClock clock, + IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, - IHtmlLocalizer htmlLocalizer, - IClock clock) + IHtmlLocalizer htmlLocalizer) { _authorizationService = authorizationService; _session = session; - New = shapeFactory; - _webNoticiationDisplayManager = webNoticiationDisplayManager; + _notificationDisplayManager = notificationDisplayManager; _notificationsAdminListQueryService = notificationsAdminListQueryService; _notificationOptionsDisplayManager = notificationOptionsDisplayManager; _notifier = notifier; - S = stringLocalizer; - H = htmlLocalizer; _shapeFactory = shapeFactory; _pagerOptions = pagerOptions.Value; _clock = clock; + + New = shapeFactory; + S = stringLocalizer; + H = htmlLocalizer; } public async Task List( @@ -89,22 +92,22 @@ public async Task List( // Populate route values to maintain previous route data when generating page links. options.RouteValues.TryAdd("q", options.FilterResult.ToString()); - options.Statuses = new List() - { - new SelectListItem(S["Read"], NotificationStatus.Read.ToString()), - new SelectListItem(S["Unread"], NotificationStatus.Unread.ToString()), - }; - options.Sorts = new List() - { - new SelectListItem(S["Recently created"], NotificationOrder.Latest.ToString()), - new SelectListItem(S["Previously created"], NotificationOrder.Oldest.ToString()), - }; - options.BulkActions = new List() - { - new SelectListItem(S["Mark as read"], NotificationBulkAction.Read.ToString()), - new SelectListItem(S["Mark as unread"], NotificationBulkAction.Unread.ToString()), - new SelectListItem(S["Remove"], NotificationBulkAction.Remove.ToString()), - }; + options.Statuses = + [ + new(S["Read"], nameof(NotificationStatus.Read)), + new(S["Unread"], nameof(NotificationStatus.Unread)), + ]; + options.Sorts = + [ + new(S["Recently created"], nameof(NotificationOrder.Latest)), + new(S["Previously created"], nameof(NotificationOrder.Oldest)), + ]; + options.BulkActions = + [ + new(S["Mark as read"], nameof(NotificationBulkAction.Read)), + new(S["Mark as unread"], nameof(NotificationBulkAction.Unread)), + new(S["Remove"], nameof(NotificationBulkAction.Remove)), + ]; var routeData = new RouteData(options.RouteValues); var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); @@ -115,10 +118,10 @@ public async Task List( var notificationSummaries = new List(); - foreach (var notificaiton in queryResult.Notifications) + foreach (var notification in queryResult.Notifications) { - dynamic shape = await _webNoticiationDisplayManager.BuildDisplayAsync(notificaiton, this, "SummaryAdmin"); - shape.Notification = notificaiton; + dynamic shape = await _notificationDisplayManager.BuildDisplayAsync(notification, this, "SummaryAdmin"); + shape.Notification = notification; notificationSummaries.Add(shape); } @@ -126,7 +129,7 @@ public async Task List( var startIndex = (pagerShape.Page - 1) * pagerShape.PageSize + 1; options.StartIndex = startIndex; options.EndIndex = startIndex + notificationSummaries.Count - 1; - options.NotficationsItemsCount = notificationSummaries.Count; + options.NotificationsCount = notificationSummaries.Count; options.TotalItemCount = pagerShape.TotalItemCount; var header = await _notificationOptionsDisplayManager.BuildEditorAsync(options, this, false, string.Empty, string.Empty); @@ -165,6 +168,11 @@ public async Task ListFilterPOST(ListNotificationOptions options) [FormValueRequired("submit.BulkAction")] public async Task ListPOST(ListNotificationOptions options, IEnumerable itemIds) { + if (!await _authorizationService.AuthorizeAsync(HttpContext.User, NotificationPermissions.ManageNotifications)) + { + return Forbid(); + } + if (itemIds?.Count() > 0) { var notifications = await _session.Query(x => x.UserId == CurrentUserId() && x.NotificationId.IsIn(itemIds), collection: NotificationConstants.NotificationCollection).ListAsync(); @@ -320,12 +328,10 @@ public async Task Delete(string notificationId, string returnUrl) } private IActionResult RedirectTo(string returnUrl) - { - return !string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl) ? (IActionResult)this.LocalRedirect(returnUrl, true) : RedirectToAction(nameof(List)); - } + => !string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl) + ? (IActionResult)this.LocalRedirect(returnUrl, true) + : RedirectToAction(nameof(List)); private string CurrentUserId() - { - return User.FindFirstValue(ClaimTypes.NameIdentifier); - } + => User.FindFirstValue(ClaimTypes.NameIdentifier); } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/ApiController.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/ApiController.cs index f64f51be13b..502b8f07586 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/ApiController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/ApiController.cs @@ -71,7 +71,5 @@ public async Task Read(ReadNotificationViewModel viewModel) }); } private string CurrentUserId() - { - return User.FindFirstValue(ClaimTypes.NameIdentifier); - } + => User.FindFirstValue(ClaimTypes.NameIdentifier); } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/ListNotificationOptionsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/ListNotificationOptionsDisplayDriver.cs index 9328512b8db..def2ed388b7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/ListNotificationOptionsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/ListNotificationOptionsDisplayDriver.cs @@ -8,7 +8,7 @@ namespace OrchardCore.Notifications.Drivers; public class ListNotificationOptionsDisplayDriver : DisplayDriver { - // Maintain the Options prefix for compatability with binding. + // Maintain the Options prefix for compatibility with binding. protected override void BuildPrefix(ListNotificationOptions model, string htmlFieldPrefix) { Prefix = "Options"; @@ -17,9 +17,12 @@ protected override void BuildPrefix(ListNotificationOptions model, string htmlFi public override IDisplayResult Display(ListNotificationOptions model) { return Combine( - Initialize("NotificationsAdminListBulkActions", m => BuildOptionsViewModel(m, model)).Location("BulkActions", "Content:10"), - View("NotificationsAdminFilters_Thumbnail__Status", model).Location("Thumbnail", "Content:30"), - View("NotificationsAdminFilters_Thumbnail__Sort", model).Location("Thumbnail", "Content:40") + Initialize("NotificationsAdminListBulkActions", m => BuildOptionsViewModel(m, model)) + .Location("BulkActions", "Content:10"), + View("NotificationsAdminFilters_Thumbnail__Status", model) + .Location("Thumbnail", "Content:30"), + View("NotificationsAdminFilters_Thumbnail__Sort", model) + .Location("Thumbnail", "Content:40") ); } @@ -28,12 +31,18 @@ public override IDisplayResult Edit(ListNotificationOptions model) model.FilterResult.MapTo(model); return Combine( - Initialize("NotificationsAdminListBulkActions", m => BuildOptionsViewModel(m, model)).Location("BulkActions", "Content:10"), - Initialize("NotificationsAdminListSearch", m => BuildOptionsViewModel(m, model)).Location("Search:10"), - Initialize("NotificationsAdminListActionBarButtons", m => BuildOptionsViewModel(m, model)).Location("ActionBarButtons:10"), - Initialize("NotificationsAdminListSummary", m => BuildOptionsViewModel(m, model)).Location("Summary:10"), - Initialize("NotificationsAdminListFilters", m => BuildOptionsViewModel(m, model)).Location("Actions:10.1"), - Initialize("NotificationsAdminList_Fields_BulkActions", m => BuildOptionsViewModel(m, model)).Location("Actions:10.1") + Initialize("NotificationsAdminListBulkActions", m => BuildOptionsViewModel(m, model)) + .Location("BulkActions", "Content:10"), + Initialize("NotificationsAdminListSearch", m => BuildOptionsViewModel(m, model)) + .Location("Search:10"), + Initialize("NotificationsAdminListActionBarButtons", m => BuildOptionsViewModel(m, model)) + .Location("ActionBarButtons:10"), + Initialize("NotificationsAdminListSummary", m => BuildOptionsViewModel(m, model)) + .Location("Summary:10"), + Initialize("NotificationsAdminListFilters", m => BuildOptionsViewModel(m, model)) + .Location("Actions:10.1"), + Initialize("NotificationsAdminList_Fields_BulkActions", m => BuildOptionsViewModel(m, model)) + .Location("Actions:10.1") ); } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotificationDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotificationDisplayDriver.cs index 1ebc3156a2c..d2ff2897a82 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotificationDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotificationDisplayDriver.cs @@ -11,9 +11,12 @@ public override IDisplayResult Display(Notification notification) { var results = new List() { - Shape("NotificationsMeta_SummaryAdmin", new NotificationViewModel(notification)).Location("SummaryAdmin", "Meta:20"), - Shape("NotificationsActions_SummaryAdmin", new NotificationViewModel(notification)).Location("SummaryAdmin", "Actions:5"), - Shape("NotificationsButtonActions_SummaryAdmin", new NotificationViewModel(notification)).Location("SummaryAdmin", "ActionsMenu:10"), + Shape("NotificationsMeta_SummaryAdmin", new NotificationViewModel(notification)) + .Location("SummaryAdmin", "Meta:20"), + Shape("NotificationsActions_SummaryAdmin", new NotificationViewModel(notification)) + .Location("SummaryAdmin", "Actions:5"), + Shape("NotificationsButtonActions_SummaryAdmin", new NotificationViewModel(notification)) + .Location("SummaryAdmin", "ActionsMenu:10"), }; return Combine(results); diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotificationNavbarDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotificationNavbarDisplayDriver.cs index 4d9ae05fa2e..ef1b8fd1b85 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotificationNavbarDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotificationNavbarDisplayDriver.cs @@ -37,8 +37,8 @@ public override IDisplayResult Display(Navbar model) var userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); var notifications = (await _session.Query(x => x.UserId == userId && !x.IsRead, collection: NotificationConstants.NotificationCollection) .OrderByDescending(x => x.CreatedAtUtc) - .Take(MaxVisibleNotifications + 1) - .ListAsync()).ToList(); + .Take(MaxVisibleNotifications + 1) + .ListAsync()).ToList(); model.Notifications = notifications; model.MaxVisibleNotifications = MaxVisibleNotifications; diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs index 05a6f29c6d2..3823fcc91d7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/NotifyUserTaskActivityDisplayDriver.cs @@ -80,8 +80,10 @@ 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)).Location("Thumbnail", "Content"), - Shape($"{typeof(TActivity).Name}_Fields_Design", new ActivityViewModel(activity)).Location("Design", "Content") + Shape($"{typeof(TActivity).Name}_Fields_Thumbnail", new ActivityViewModel(activity)) + .Location("Thumbnail", "Content"), + Shape($"{typeof(TActivity).Name}_Fields_Design", new ActivityViewModel(activity)) + .Location("Design", "Content") ); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/UserNotificationPreferencesPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/UserNotificationPreferencesPartDisplayDriver.cs index 7bf40d4ca10..de90879412c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/UserNotificationPreferencesPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/UserNotificationPreferencesPartDisplayDriver.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -26,8 +25,8 @@ public override Task EditAsync(User user, UserNotificationPrefer { var result = Initialize("UserNotificationPreferencesPart_Edit", model => { - var sortedMethods = new List(part.Methods ?? Array.Empty()); - var optout = part.Optout ?? Array.Empty(); + var sortedMethods = new List(part.Methods ?? []); + var optout = part.Optout ?? []; // By default the use is opted into all available methods until explicitly optout. model.Methods = _notificationMethodProviders.Select(x => x.Method).Except(optout).ToArray(); @@ -61,11 +60,11 @@ public override async Task UpdateAsync(User user, UserNotificati if (await updater.TryUpdateModelAsync(model, Prefix)) { - var sortedMethods = new List(model.SortedMethods ?? Array.Empty()); + var sortedMethods = new List(model.SortedMethods ?? []); if (sortedMethods.Count > 0) { - // Important to execute this code only when selectedOrdrededMethods has at least one element to avoid exception. + // Important to execute this code only when sortedMethods has at least one element to avoid exception. // Store all methods in the same order they appear. part.Methods = _notificationMethodProviders .OrderBy(provider => sortedMethods.IndexOf(provider.Method)) @@ -80,7 +79,7 @@ public override async Task UpdateAsync(User user, UserNotificati .ToArray(); } - var selectedMethods = new List(model.Methods ?? Array.Empty()); + var selectedMethods = new List(model.Methods ?? []); // Store any method that is not selected as an optout. part.Optout = _notificationMethodProviders.Where(provider => !selectedMethods.Contains(provider.Method)) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Handlers/CoreNotificationEventsHandler.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Handlers/CoreNotificationEventsHandler.cs index 85a2f733030..0968b4973fa 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Handlers/CoreNotificationEventsHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Handlers/CoreNotificationEventsHandler.cs @@ -10,9 +10,7 @@ public class CoreNotificationEventsHandler : NotificationEventsHandler { public override Task CreatingAsync(NotificationContext context) { - var user = context.Notify as User; - - if (user != null) + if (context.Notify is User user) { context.Notification.UserId = user.UserId; } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/UserNotificationMessageViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/UserNotificationMessageViewModel.cs index 9b5f31f21fe..6f2a91ed11b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/UserNotificationMessageViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/ViewModels/UserNotificationMessageViewModel.cs @@ -1,4 +1,3 @@ -using System; using OrchardCore.ContentManagement; namespace OrchardCore.Notifications.ViewModels; @@ -19,5 +18,6 @@ public class UserNotificationMessageViewModel public string Url { get; set; } - public bool HasBody() => !string.IsNullOrWhiteSpace(Body); + public bool HasBody() + => !string.IsNullOrWhiteSpace(Body); } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyContentOwnerTask.Fields.Design.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyContentOwnerTask.Fields.Design.cshtml index 1c6305eb78e..2da252ed036 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyContentOwnerTask.Fields.Design.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyContentOwnerTask.Fields.Design.cshtml @@ -5,6 +5,6 @@ @model ActivityViewModel
-

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

+

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

"@Model.Activity.Subject" diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyContentOwnerTask.Fields.Thumbnail.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyContentOwnerTask.Fields.Thumbnail.cshtml index 2038b5e8174..4c26226b3e9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyContentOwnerTask.Fields.Thumbnail.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/Items/NotifyContentOwnerTask.Fields.Thumbnail.cshtml @@ -1,2 +1,2 @@ -

@T["Notify owner"]

+

@T["Notify Content Owner"]

@T["Notify content owner"]

diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml index 04c36ec8d63..6b262731865 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml @@ -22,7 +22,7 @@ }
- @if (Model.Header != null && (Model.Header.Summary != null || Model.Header.Actions != null)) + @if (Model.Header?.Summary != null || Model.Header?.Actions != null) {
diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminListSummary.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminListSummary.cshtml index f1dd15118df..8b7ba449959 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminListSummary.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminListSummary.cshtml @@ -5,7 +5,7 @@
- +
diff --git a/src/OrchardCore/OrchardCore.Notifications.Core/Models/ListNotificationOptions.cs b/src/OrchardCore/OrchardCore.Notifications.Core/Models/ListNotificationOptions.cs index a8ee8d9cce2..c3592c3fecd 100644 --- a/src/OrchardCore/OrchardCore.Notifications.Core/Models/ListNotificationOptions.cs +++ b/src/OrchardCore/OrchardCore.Notifications.Core/Models/ListNotificationOptions.cs @@ -26,7 +26,7 @@ public class ListNotificationOptions public int StartIndex { get; set; } [BindNever] - public int NotficationsItemsCount { get; set; } + public int NotificationsCount { get; set; } [BindNever] public int TotalItemCount { get; set; } diff --git a/src/OrchardCore/OrchardCore.Notifications.Core/NotificationQueryContext.cs b/src/OrchardCore/OrchardCore.Notifications.Core/NotificationQueryContext.cs index 2f2774400fc..baf1eb6ca16 100644 --- a/src/OrchardCore/OrchardCore.Notifications.Core/NotificationQueryContext.cs +++ b/src/OrchardCore/OrchardCore.Notifications.Core/NotificationQueryContext.cs @@ -7,7 +7,8 @@ namespace OrchardCore.Navigation.Core; public class NotificationQueryContext : QueryExecutionContext { - public NotificationQueryContext(IServiceProvider serviceProvider, IQuery query) : base(query) + public NotificationQueryContext(IServiceProvider serviceProvider, IQuery query) + : base(query) { ServiceProvider = serviceProvider; } diff --git a/src/OrchardCore/OrchardCore.Notifications.Core/Services/NotificationMethodProviderAccessor.cs b/src/OrchardCore/OrchardCore.Notifications.Core/Services/NotificationMethodProviderAccessor.cs index 7462fa3ab4f..08ee172d75d 100644 --- a/src/OrchardCore/OrchardCore.Notifications.Core/Services/NotificationMethodProviderAccessor.cs +++ b/src/OrchardCore/OrchardCore.Notifications.Core/Services/NotificationMethodProviderAccessor.cs @@ -32,7 +32,7 @@ public Task> GetProvidersAsync(object n if (selectedMethods.Count > 0) { return Task.FromResult>(methods - // Priority matters to horor user preferences. + // Priority matters to honor user preferences. .OrderBy(provider => selectedMethods.IndexOf(provider.Method)) .ThenBy(provider => provider.Name.ToString()) .ToList()); From 6d32ea07231c6f14baad41e84b1f4791f8135445 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 22 Nov 2023 16:38:55 -0800 Subject: [PATCH 2/3] cleanup --- .../Controllers/AdminController.cs | 12 +++++++---- .../ListNotificationOptionsDisplayDriver.cs | 3 +++ .../Views/NotificationsAdminList.cshtml | 21 ++++++++++++------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs index a9eeecea29d..94d66931d74 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs @@ -31,7 +31,6 @@ public class AdminController : Controller, IUpdateModel { private readonly IAuthorizationService _authorizationService; private readonly ISession _session; - private readonly IDisplayManager _notificationDisplayManager; private readonly INotificationsAdminListQueryService _notificationsAdminListQueryService; private readonly IDisplayManager _notificationOptionsDisplayManager; @@ -40,7 +39,6 @@ public class AdminController : Controller, IUpdateModel private readonly PagerOptions _pagerOptions; private readonly IClock _clock; - protected readonly dynamic New; protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; @@ -68,7 +66,6 @@ public AdminController( _pagerOptions = pagerOptions.Value; _clock = clock; - New = shapeFactory; S = stringLocalizer; H = htmlLocalizer; } @@ -114,7 +111,14 @@ public async Task List( var queryResult = await _notificationsAdminListQueryService.QueryAsync(pager.Page, pager.PageSize, options, this); - var pagerShape = (await New.Pager(pager)).TotalItemCount(queryResult.TotalCount).RouteData(routeData); + dynamic pagerShape = await _shapeFactory.CreateAsync("Pager", Arguments.From(new + { + pager.Page, + pager.PageSize, + TotalItemCount = queryResult.TotalCount + })); + + pagerShape.RouteData(routeData); var notificationSummaries = new List(); diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/ListNotificationOptionsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/ListNotificationOptionsDisplayDriver.cs index def2ed388b7..0f9a8c60bc8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/ListNotificationOptionsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Drivers/ListNotificationOptionsDisplayDriver.cs @@ -63,9 +63,12 @@ private static void BuildOptionsViewModel(ListNotificationOptions m, ListNotific m.Sorts = model.Sorts; m.Statuses = model.Statuses; m.BulkActions = model.BulkActions; + m.BulkAction = m.BulkAction; m.StartIndex = model.StartIndex; m.EndIndex = model.EndIndex; + m.NotificationsCount = model.NotificationsCount; m.TotalItemCount = model.TotalItemCount; m.OrderBy = model.OrderBy; + m.FilterResult = model.FilterResult; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml index 6b262731865..eefb6235275 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml @@ -5,17 +5,24 @@ @Html.HiddenFor(o => o.Options.BulkAction) -@if (Model.Header != null && Model.Header.Search != null) +@if (Model.Header?.Search != null || Model.Header?.ActionBarButtons) {
-
- @await DisplayAsync(Model.Header.Search) -
-
- @await DisplayAsync(Model.Header.ActionBarButtons) -
+ @if (Model.Header.Search != null) + { +
+ @await DisplayAsync(Model.Header.Search) +
+ } + + @if (Model.Header.ActionBarButtons != null) + { +
+ @await DisplayAsync(Model.Header.ActionBarButtons) +
+ }
From d73b646b70bc5b8306379049ea2cd8667a0000e0 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 23 Nov 2023 10:19:52 -0800 Subject: [PATCH 3/3] Fix #13277 --- .../OrchardCore.Notifications/Manifest.cs | 6 +++--- .../Views/NotificationsAdminList.cshtml | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Manifest.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Manifest.cs index 82fb00d608f..b1f8cc1d53d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Manifest.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Manifest.cs @@ -18,9 +18,9 @@ Name = "Email Notifications", Description = "Provides a way to send email notifications to users.", Category = "Notifications", - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.Notifications", "OrchardCore.Email", - } + ] )] diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml index eefb6235275..18addebccd6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Views/NotificationsAdminList.cshtml @@ -67,7 +67,8 @@ @await DisplayAsync(Model.Pager) - +