diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs index 3abf427168d..ff5282fc90b 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Controllers/DashboardController.cs @@ -19,14 +19,13 @@ namespace OrchardCore.AdminDashboard.Controllers { [Admin] - public class DashboardController : Controller + public class DashboardController : Controller, IUpdateModel { private readonly IAuthorizationService _authorizationService; private readonly IAdminDashboardService _adminDashboardService; private readonly IContentManager _contentManager; private readonly IContentItemDisplayManager _contentItemDisplayManager; private readonly IContentDefinitionManager _contentDefinitionManager; - private readonly IUpdateModelAccessor _updateModelAccessor; private readonly YesSql.ISession _session; public DashboardController( @@ -35,7 +34,6 @@ public DashboardController( IContentManager contentManager, IContentItemDisplayManager contentItemDisplayManager, IContentDefinitionManager contentDefinitionManager, - IUpdateModelAccessor updateModelAccessor, YesSql.ISession session) { _authorizationService = authorizationService; @@ -43,7 +41,6 @@ public DashboardController( _contentManager = contentManager; _contentItemDisplayManager = contentItemDisplayManager; _contentDefinitionManager = contentDefinitionManager; - _updateModelAccessor = updateModelAccessor; _session = session; } @@ -75,7 +72,7 @@ public async Task Index() wrappers.Add(new DashboardWrapper { Dashboard = widget, - Content = await _contentItemDisplayManager.BuildDisplayAsync(widget, _updateModelAccessor.ModelUpdater, "DetailAdmin") + Content = await _contentItemDisplayManager.BuildDisplayAsync(widget, this, "DetailAdmin") }); } @@ -127,7 +124,7 @@ public async Task Manage() var wrapper = new DashboardWrapper { Dashboard = widget, - Content = await _contentItemDisplayManager.BuildDisplayAsync(widget, _updateModelAccessor.ModelUpdater, "DetailAdmin") + Content = await _contentItemDisplayManager.BuildDisplayAsync(widget, this, "DetailAdmin") }; wrappers.Add(wrapper); diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Controllers/MenuController.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Controllers/MenuController.cs index 639adf36476..cd0c9ab2cf8 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Controllers/MenuController.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Controllers/MenuController.cs @@ -27,10 +27,7 @@ public class MenuController : Controller private readonly IAuthorizationService _authorizationService; private readonly IAdminMenuService _adminMenuService; - private readonly PagerOptions _pagerOptions; - private readonly IShapeFactory _shapeFactory; private readonly INotifier _notifier; - private readonly ILogger _logger; protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; @@ -38,31 +35,30 @@ public class MenuController : Controller public MenuController( IAuthorizationService authorizationService, IAdminMenuService adminMenuService, - IOptions pagerOptions, - IShapeFactory shapeFactory, INotifier notifier, IStringLocalizer stringLocalizer, - IHtmlLocalizer htmlLocalizer, - ILogger logger) + IHtmlLocalizer htmlLocalizer) { _authorizationService = authorizationService; _adminMenuService = adminMenuService; - _pagerOptions = pagerOptions.Value; - _shapeFactory = shapeFactory; _notifier = notifier; S = stringLocalizer; H = htmlLocalizer; - _logger = logger; } - public async Task List(ContentOptions options, PagerParameters pagerParameters) + public async Task List( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + [FromServices] ILogger logger, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdminMenu)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var adminMenuList = (await _adminMenuService.GetAdminMenuListAsync()).AdminMenu; @@ -86,7 +82,7 @@ public async Task List(ContentOptions options, PagerParameters pa } catch (Exception ex) { - _logger.LogError(ex, "Error when retrieving the list of admin menus."); + logger.LogError(ex, "Error when retrieving the list of admin menus."); await _notifier.ErrorAsync(H["Error when retrieving the list of admin menus."]); } @@ -98,7 +94,7 @@ public async Task List(ContentOptions options, PagerParameters pa routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, adminMenuList.Count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, adminMenuList.Count, routeData); var model = new AdminMenuListViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Controllers/NodeController.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Controllers/NodeController.cs index 56567072107..5466269ae6d 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Controllers/NodeController.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Controllers/NodeController.cs @@ -15,16 +15,15 @@ namespace OrchardCore.AdminMenu.Controllers { [Admin("AdminMenu/Node/{action}", "AdminMenuNode{action}")] - public class NodeController : Controller + public class NodeController : Controller, IUpdateModel { private readonly IAuthorizationService _authorizationService; private readonly IDisplayManager _displayManager; private readonly IEnumerable _factories; private readonly IAdminMenuService _adminMenuService; private readonly INotifier _notifier; - protected readonly IHtmlLocalizer H; - private readonly IUpdateModelAccessor _updateModelAccessor; + protected readonly IHtmlLocalizer H; public NodeController( IAuthorizationService authorizationService, @@ -32,15 +31,13 @@ public NodeController( IEnumerable factories, IAdminMenuService adminMenuService, IHtmlLocalizer htmlLocalizer, - INotifier notifier, - IUpdateModelAccessor updateModelAccessor) + INotifier notifier) { _displayManager = displayManager; _factories = factories; _adminMenuService = adminMenuService; _authorizationService = authorizationService; _notifier = notifier; - _updateModelAccessor = updateModelAccessor; H = htmlLocalizer; } @@ -109,7 +106,7 @@ public async Task Create(string id, string type) AdminNode = treeNode, AdminNodeId = treeNode.UniqueId, AdminNodeType = type, - Editor = await _displayManager.BuildEditorAsync(treeNode, updater: _updateModelAccessor.ModelUpdater, isNew: true, "", "") + Editor = await _displayManager.BuildEditorAsync(treeNode, updater: this, isNew: true, string.Empty, string.Empty) }; return View(model); @@ -187,7 +184,7 @@ public async Task Edit(string id, string treeNodeId) AdminNodeType = treeNode.GetType().Name, Priority = treeNode.Priority, Position = treeNode.Position, - Editor = await _displayManager.BuildEditorAsync(treeNode, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", "") + Editor = await _displayManager.BuildEditorAsync(treeNode, updater: this, isNew: false, string.Empty, string.Empty) }; model.Editor.TreeNode = treeNode; @@ -218,7 +215,7 @@ public async Task Edit(AdminNodeEditViewModel model) return NotFound(); } - var editor = await _displayManager.UpdateEditorAsync(treeNode, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", ""); + var editor = await _displayManager.UpdateEditorAsync(treeNode, updater: this, isNew: false, string.Empty, string.Empty); if (ModelState.IsValid) { diff --git a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Controllers/AdminController.cs index 257ea9ed920..1912c1a5fb3 100644 --- a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Controllers/AdminController.cs @@ -18,33 +18,25 @@ namespace OrchardCore.AuditTrail.Controllers { - public class AdminController : Controller + public class AdminController : Controller, IUpdateModel { - private readonly PagerOptions _pagerOptions; - private readonly IShapeFactory _shapeFactory; private readonly IAuditTrailManager _auditTrailManager; - private readonly IUpdateModelAccessor _updateModelAccessor; private readonly IAuthorizationService _authorizationService; private readonly IAuditTrailAdminListQueryService _auditTrailAdminListQueryService; private readonly IDisplayManager _displayManager; private readonly IDisplayManager _auditTrailOptionsDisplayManager; + protected readonly IStringLocalizer S; public AdminController( - IOptions pagerOptions, - IShapeFactory shapeFactory, IAuditTrailManager auditTrailManager, - IUpdateModelAccessor updateModelAccessor, IAuthorizationService authorizationService, IAuditTrailAdminListQueryService auditTrailAdminListQueryService, IDisplayManager displayManager, IDisplayManager auditTrailOptionsDisplayManager, IStringLocalizer stringLocalizer) { - _pagerOptions = pagerOptions.Value; - _shapeFactory = shapeFactory; _auditTrailManager = auditTrailManager; - _updateModelAccessor = updateModelAccessor; _authorizationService = authorizationService; _auditTrailAdminListQueryService = auditTrailAdminListQueryService; _displayManager = displayManager; @@ -53,7 +45,10 @@ public AdminController( } [Admin("AuditTrail/{correlationId?}", "AuditTrailIndex")] - public async Task Index([ModelBinder(BinderType = typeof(AuditTrailFilterEngineModelBinder), Name = "q")] QueryFilterResult queryFilterResult, PagerParameters pagerParameters, string correlationId = "") + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + [ModelBinder(BinderType = typeof(AuditTrailFilterEngineModelBinder), Name = "q")] QueryFilterResult queryFilterResult, PagerParameters pagerParameters, string correlationId = "") { if (!await _authorizationService.AuthorizeAsync(User, AuditTrailPermissions.ViewAuditTrail)) { @@ -78,7 +73,7 @@ public async Task Index([ModelBinder(BinderType = typeof(AuditTrai options.FilterResult.TryAddOrReplace(new CorrelationIdFilterNode(options.CorrelationId)); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); // With the options populated we filter the query, allowing the filters to alter the options. var result = await _auditTrailAdminListQueryService.QueryAsync(pager.Page, pager.PageSize, options); @@ -90,13 +85,13 @@ public async Task Index([ModelBinder(BinderType = typeof(AuditTrai // Populate route values to maintain previous route data when generating page links. options.RouteValues.TryAdd("q", options.FilterResult.ToString()); - var pagerShape = await _shapeFactory.PagerAsync(pager, result.TotalCount, options.RouteValues); + var pagerShape = await shapeFactory.PagerAsync(pager, result.TotalCount, options.RouteValues); var items = new List(); foreach (var auditTrailEvent in result.Events) { items.Add( - await _displayManager.BuildDisplayAsync(auditTrailEvent, updater: _updateModelAccessor.ModelUpdater, displayType: "SummaryAdmin") + await _displayManager.BuildDisplayAsync(auditTrailEvent, updater: this, displayType: "SummaryAdmin") ); } @@ -106,9 +101,9 @@ await _displayManager.BuildDisplayAsync(auditTrailEvent, updater: _updateModelAc options.EventsCount = items.Count; options.TotalItemCount = result.TotalCount; - var header = await _auditTrailOptionsDisplayManager.BuildEditorAsync(options, _updateModelAccessor.ModelUpdater, false, string.Empty, string.Empty); + var header = await _auditTrailOptionsDisplayManager.BuildEditorAsync(options, this, false, string.Empty, string.Empty); - var shapeViewModel = await _shapeFactory.CreateAsync("AuditTrailAdminList", viewModel => + var shapeViewModel = await shapeFactory.CreateAsync("AuditTrailAdminList", viewModel => { viewModel.Events = items; viewModel.Pager = pagerShape; @@ -123,7 +118,7 @@ await _displayManager.BuildDisplayAsync(auditTrailEvent, updater: _updateModelAc [FormValueRequired("submit.Filter")] public async Task IndexFilterPOST(AuditTrailIndexOptions options) { - await _auditTrailOptionsDisplayManager.UpdateEditorAsync(options, _updateModelAccessor.ModelUpdater, false, string.Empty, string.Empty); + await _auditTrailOptionsDisplayManager.UpdateEditorAsync(options, this, false, string.Empty, string.Empty); // When the user has typed something into the search input no further evaluation of the form post is required. if (!string.Equals(options.SearchText, options.OriginalSearchText, StringComparison.OrdinalIgnoreCase)) { @@ -131,7 +126,7 @@ public async Task IndexFilterPOST(AuditTrailIndexOptions options) } // Evaluate the values provided in the form post and map them to the filter result and route values. - await _auditTrailOptionsDisplayManager.UpdateEditorAsync(options, _updateModelAccessor.ModelUpdater, false, string.Empty, string.Empty); + await _auditTrailOptionsDisplayManager.UpdateEditorAsync(options, this, false, string.Empty, string.Empty); // The route value must always be added after the editors have updated the models. options.RouteValues.TryAdd("q", options.FilterResult.ToString()); @@ -154,7 +149,7 @@ public async Task Display(string auditTrailEventId) } - var shape = await _displayManager.BuildDisplayAsync(auditTrailEvent, updater: _updateModelAccessor.ModelUpdater, displayType: "DetailAdmin"); + var shape = await _displayManager.BuildDisplayAsync(auditTrailEvent, updater: this, displayType: "DetailAdmin"); return View(new AuditTrailItemViewModel { Shape = shape }); } diff --git a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Controllers/BackgroundTaskController.cs b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Controllers/BackgroundTaskController.cs index 68bf3b80fd2..c8860f33876 100644 --- a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Controllers/BackgroundTaskController.cs +++ b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/Controllers/BackgroundTaskController.cs @@ -29,9 +29,7 @@ public class BackgroundTaskController : Controller private readonly IAuthorizationService _authorizationService; private readonly IEnumerable _backgroundTasks; private readonly BackgroundTaskManager _backgroundTaskManager; - private readonly PagerOptions _pagerOptions; private readonly INotifier _notifier; - private readonly IShapeFactory _shapeFactory; protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; @@ -40,8 +38,6 @@ public BackgroundTaskController( IAuthorizationService authorizationService, IEnumerable backgroundTasks, BackgroundTaskManager backgroundTaskManager, - IOptions pagerOptions, - IShapeFactory shapeFactory, IHtmlLocalizer htmlLocalizer, IStringLocalizer stringLocalizer, INotifier notifier) @@ -49,15 +45,17 @@ public BackgroundTaskController( _authorizationService = authorizationService; _backgroundTasks = backgroundTasks; _backgroundTaskManager = backgroundTaskManager; - _pagerOptions = pagerOptions.Value; _notifier = notifier; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; } [Admin("BackgroundTasks", "BackgroundTasks")] - public async Task Index(AdminIndexOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + AdminIndexOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageBackgroundTasks)) { @@ -125,8 +123,8 @@ public async Task Index(AdminIndexOptions options, PagerParameter routeData.Values.TryAdd(_optionsStatus, options.Status); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); - var pagerShape = await _shapeFactory.PagerAsync(pager, taskItems.Count, routeData); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); + var pagerShape = await shapeFactory.PagerAsync(pager, taskItems.Count, routeData); var model = new BackgroundTaskIndexViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/LocalizationSetContentPickerAdminController.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/LocalizationSetContentPickerAdminController.cs index 8e0f2101a2b..24992cde63a 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/LocalizationSetContentPickerAdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Controllers/LocalizationSetContentPickerAdminController.cs @@ -14,7 +14,6 @@ using OrchardCore.Modules; using YesSql; using YesSql.Services; -using IHttpContextAccessor = Microsoft.AspNetCore.Http.IHttpContextAccessor; namespace OrchardCore.ContentFields.Controllers { @@ -27,22 +26,19 @@ public class LocalizationSetContentPickerAdminController : Controller private readonly IContentManager _contentManager; private readonly ISession _session; private readonly IAuthorizationService _authorizationService; - private readonly IHttpContextAccessor _httpContextAccessor; public LocalizationSetContentPickerAdminController( IContentDefinitionManager contentDefinitionManager, IContentLocalizationManager contentLocalizationManager, IContentManager contentManager, ISession session, - IAuthorizationService authorizationService, - IHttpContextAccessor httpContextAccessor) + IAuthorizationService authorizationService) { _contentDefinitionManager = contentDefinitionManager; _contentLocalizationManager = contentLocalizationManager; _contentManager = contentManager; _session = session; _authorizationService = authorizationService; - _httpContextAccessor = httpContextAccessor; } [HttpGet] @@ -80,7 +76,7 @@ public async Task SearchLocalizationSets(string part, string fiel foreach (var contentItem in cleanedContentItems) { - if (await _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext.User, CommonPermissions.ViewContent, contentItem)) + if (await _authorizationService.AuthorizeAsync(User, CommonPermissions.ViewContent, contentItem)) { results.Add(new VueMultiselectItemViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/AdminController.cs index f54879c561e..0285c84216a 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/AdminController.cs @@ -18,6 +18,7 @@ public class AdminController : Controller private readonly IContentLocalizationManager _contentLocalizationManager; private readonly INotifier _notifier; private readonly IAuthorizationService _authorizationService; + protected readonly IHtmlLocalizer H; public AdminController( diff --git a/src/OrchardCore.Modules/OrchardCore.ContentPreview/Controllers/PreviewController.cs b/src/OrchardCore.Modules/OrchardCore.ContentPreview/Controllers/PreviewController.cs index db53aebb116..ca1cc616266 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentPreview/Controllers/PreviewController.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentPreview/Controllers/PreviewController.cs @@ -14,29 +14,26 @@ namespace OrchardCore.ContentPreview.Controllers { - public class PreviewController : Controller + public class PreviewController : Controller, IUpdateModel { private readonly IContentManager _contentManager; private readonly IContentManagerSession _contentManagerSession; private readonly IContentItemDisplayManager _contentItemDisplayManager; private readonly IAuthorizationService _authorizationService; private readonly IClock _clock; - private readonly IUpdateModelAccessor _updateModelAccessor; public PreviewController( IContentManager contentManager, IContentItemDisplayManager contentItemDisplayManager, IContentManagerSession contentManagerSession, IAuthorizationService authorizationService, - IClock clock, - IUpdateModelAccessor updateModelAccessor) + IClock clock) { _authorizationService = authorizationService; _clock = clock; _contentItemDisplayManager = contentItemDisplayManager; _contentManager = contentManager; _contentManagerSession = contentManagerSession; - _updateModelAccessor = updateModelAccessor; } public IActionResult Index() @@ -77,7 +74,7 @@ public async Task Render() contentItem.Published = true; // TODO: we should probably get this value from the main editor as it might impact validators. - _ = await _contentItemDisplayManager.UpdateEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, true); + _ = await _contentItemDisplayManager.UpdateEditorAsync(contentItem, this, true); if (!ModelState.IsValid) { @@ -112,7 +109,7 @@ public async Task Render() return Ok(); } - var model = await _contentItemDisplayManager.BuildDisplayAsync(contentItem, _updateModelAccessor.ModelUpdater, "Detail"); + var model = await _contentItemDisplayManager.BuildDisplayAsync(contentItem, this, "Detail"); return View(model); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs index 7fd9f421fb5..deb9c56da7f 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs @@ -21,17 +21,17 @@ namespace OrchardCore.ContentTypes.Controllers { - public class AdminController : Controller + public class AdminController : Controller, IUpdateModel { private readonly IContentDefinitionService _contentDefinitionService; private readonly IContentDefinitionManager _contentDefinitionManager; private readonly IAuthorizationService _authorizationService; private readonly IDocumentStore _documentStore; private readonly IContentDefinitionDisplayManager _contentDefinitionDisplayManager; + private readonly INotifier _notifier; + protected readonly IHtmlLocalizer H; protected readonly IStringLocalizer S; - private readonly INotifier _notifier; - private readonly IUpdateModelAccessor _updateModelAccessor; public AdminController( IContentDefinitionDisplayManager contentDefinitionDisplayManager, @@ -41,8 +41,7 @@ public AdminController( IDocumentStore documentStore, IHtmlLocalizer htmlLocalizer, IStringLocalizer stringLocalizer, - INotifier notifier, - IUpdateModelAccessor updateModelAccessor) + INotifier notifier) { _notifier = notifier; _contentDefinitionDisplayManager = contentDefinitionDisplayManager; @@ -50,7 +49,6 @@ public AdminController( _authorizationService = authorizationService; _contentDefinitionService = contentDefinitionService; _contentDefinitionManager = contentDefinitionManager; - _updateModelAccessor = updateModelAccessor; H = htmlLocalizer; S = stringLocalizer; @@ -165,7 +163,7 @@ public async Task Edit(string id) return NotFound(); } - typeViewModel.Editor = await _contentDefinitionDisplayManager.BuildTypeEditorAsync(typeViewModel.TypeDefinition, _updateModelAccessor.ModelUpdater); + typeViewModel.Editor = await _contentDefinitionDisplayManager.BuildTypeEditorAsync(typeViewModel.TypeDefinition, this); return View(typeViewModel); } @@ -189,7 +187,7 @@ public async Task EditPOST(string id, EditTypeViewModel viewModel) viewModel.Settings = contentTypeDefinition.Settings; viewModel.TypeDefinition = contentTypeDefinition; viewModel.DisplayName = contentTypeDefinition.DisplayName; - viewModel.Editor = await _contentDefinitionDisplayManager.UpdateTypeEditorAsync(contentTypeDefinition, _updateModelAccessor.ModelUpdater); + viewModel.Editor = await _contentDefinitionDisplayManager.UpdateTypeEditorAsync(contentTypeDefinition, this); if (!ModelState.IsValid) { @@ -529,7 +527,7 @@ public async Task EditPart(string id) var viewModel = new EditPartViewModel(contentPartDefinition) { - Editor = await _contentDefinitionDisplayManager.BuildPartEditorAsync(contentPartDefinition, _updateModelAccessor.ModelUpdater), + Editor = await _contentDefinitionDisplayManager.BuildPartEditorAsync(contentPartDefinition, this), }; return View(viewModel); @@ -553,7 +551,7 @@ public async Task EditPartPOST(string id, string[] orderedFieldNam var viewModel = new EditPartViewModel(contentPartDefinition) { - Editor = await _contentDefinitionDisplayManager.UpdatePartEditorAsync(contentPartDefinition, _updateModelAccessor.ModelUpdater), + Editor = await _contentDefinitionDisplayManager.UpdatePartEditorAsync(contentPartDefinition, this), }; if (!ModelState.IsValid) @@ -739,7 +737,7 @@ public async Task EditField(string id, string name, string returnU DisplayMode = partFieldDefinition.DisplayMode(), DisplayName = partFieldDefinition.DisplayName(), PartFieldDefinition = partFieldDefinition, - Shape = await _contentDefinitionDisplayManager.BuildPartFieldEditorAsync(partFieldDefinition, _updateModelAccessor.ModelUpdater) + Shape = await _contentDefinitionDisplayManager.BuildPartFieldEditorAsync(partFieldDefinition, this) }; ViewData["ReturnUrl"] = returnUrl; @@ -794,7 +792,7 @@ public async Task EditFieldPOST(string id, EditFieldViewModel view if (!ModelState.IsValid) { // Calls update to build editor shape with the display name validation failures, and other validation errors. - viewModel.Shape = await _contentDefinitionDisplayManager.UpdatePartFieldEditorAsync(field, _updateModelAccessor.ModelUpdater); + viewModel.Shape = await _contentDefinitionDisplayManager.UpdatePartFieldEditorAsync(field, this); await _documentStore.CancelAsync(); ViewData["ReturnUrl"] = returnUrl; @@ -809,7 +807,7 @@ public async Task EditFieldPOST(string id, EditFieldViewModel view // Refresh the local field variable in case it has been altered field = (await _contentDefinitionManager.LoadPartDefinitionAsync(id)).Fields.FirstOrDefault(x => string.Equals(x.Name, viewModel.Name, StringComparison.OrdinalIgnoreCase)); - viewModel.Shape = await _contentDefinitionDisplayManager.UpdatePartFieldEditorAsync(field, _updateModelAccessor.ModelUpdater); + viewModel.Shape = await _contentDefinitionDisplayManager.UpdatePartFieldEditorAsync(field, this); if (!ModelState.IsValid) { @@ -908,7 +906,7 @@ public async Task EditTypePart(string id, string name) DisplayName = typePartDefinition.DisplayName(), Description = typePartDefinition.Description(), TypePartDefinition = typePartDefinition, - Shape = await _contentDefinitionDisplayManager.BuildTypePartEditorAsync(typePartDefinition, _updateModelAccessor.ModelUpdater) + Shape = await _contentDefinitionDisplayManager.BuildTypePartEditorAsync(typePartDefinition, this) }; return View(typePartViewModel); @@ -963,7 +961,7 @@ public async Task EditTypePartPOST(string id, EditTypePartViewMode if (!ModelState.IsValid) { - viewModel.Shape = await _contentDefinitionDisplayManager.UpdateTypePartEditorAsync(part, _updateModelAccessor.ModelUpdater); + viewModel.Shape = await _contentDefinitionDisplayManager.UpdateTypePartEditorAsync(part, this); await _documentStore.CancelAsync(); return View(viewModel); } @@ -975,7 +973,7 @@ public async Task EditTypePartPOST(string id, EditTypePartViewMode // Refresh the local part variable in case it has been altered part = (await _contentDefinitionManager.LoadTypeDefinitionAsync(id)).Parts.FirstOrDefault(x => string.Equals(x.Name, viewModel.Name, StringComparison.OrdinalIgnoreCase)); - viewModel.Shape = await _contentDefinitionDisplayManager.UpdateTypePartEditorAsync(part, _updateModelAccessor.ModelUpdater); + viewModel.Shape = await _contentDefinitionDisplayManager.UpdateTypePartEditorAsync(part, this); if (!ModelState.IsValid) { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Controllers/AuditTrailContentController.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Controllers/AuditTrailContentController.cs index 50694720921..ebcfb9a3255 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Controllers/AuditTrailContentController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Controllers/AuditTrailContentController.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Localization; -using Microsoft.Extensions.Logging; using OrchardCore.Admin; using OrchardCore.AuditTrail.Indexes; using OrchardCore.AuditTrail.Models; @@ -19,35 +18,30 @@ namespace OrchardCore.Contents.AuditTrail.Controllers { [RequireFeatures("OrchardCore.AuditTrail")] [Admin("AuditTrail/Content/{action}/{auditTrailEventId}", "{action}AuditTrailContent")] - public class AuditTrailContentController : Controller + public class AuditTrailContentController : Controller, IUpdateModel { private readonly ISession _session; private readonly IContentManager _contentManager; - private readonly IUpdateModelAccessor _updateModelAccessor; private readonly IAuthorizationService _authorizationService; private readonly IContentItemDisplayManager _contentItemDisplayManager; private readonly INotifier _notifier; + protected readonly IHtmlLocalizer H; - private readonly ILogger _logger; public AuditTrailContentController( ISession session, IContentManager contentManager, - IUpdateModelAccessor updateModelAccessor, IAuthorizationService authorizationService, IContentItemDisplayManager contentItemDisplayManager, INotifier notifier, - IHtmlLocalizer htmlLocalizer, - ILogger logger) + IHtmlLocalizer htmlLocalizer) { _session = session; _contentManager = contentManager; - _updateModelAccessor = updateModelAccessor; _authorizationService = authorizationService; _contentItemDisplayManager = contentItemDisplayManager; _notifier = notifier; H = htmlLocalizer; - _logger = logger; } public async Task Display(string auditTrailEventId) @@ -82,7 +76,7 @@ public async Task Display(string auditTrailEventId) auditTrailPart.ShowComment = true; } - var model = await _contentItemDisplayManager.BuildEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, false); + var model = await _contentItemDisplayManager.BuildEditorAsync(contentItem, this, false); model.Properties["VersionNumber"] = auditTrailContentEvent.VersionNumber; @@ -119,7 +113,7 @@ public async Task Restore(string auditTrailEventId) foreach (var error in result.Errors) { // Pass ErrorMessage as an argument to ensure it is encoded - await _notifier.WarningAsync(new LocalizedHtmlString(nameof(AuditTrailContentController.Restore), "{0}", false, error.ErrorMessage)); + await _notifier.WarningAsync(new LocalizedHtmlString(nameof(Restore), "{0}", false, error.ErrorMessage)); } return RedirectToAction("Index", "Admin", new { area = "OrchardCore.AuditTrail" }); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/AddToDeploymentPlanController.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/AddToDeploymentPlanController.cs index a156987b30e..23dcea586bc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/AddToDeploymentPlanController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/AddToDeploymentPlanController.cs @@ -24,6 +24,7 @@ public class AddToDeploymentPlanController : Controller private readonly ISession _session; private readonly IEnumerable _factories; private readonly INotifier _notifier; + protected readonly IHtmlLocalizer H; public AddToDeploymentPlanController( diff --git a/src/OrchardCore.Modules/OrchardCore.Cors/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Cors/Controllers/AdminController.cs index 629ee0e7d6d..72ff9198f53 100644 --- a/src/OrchardCore.Modules/OrchardCore.Cors/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Cors/Controllers/AdminController.cs @@ -22,6 +22,7 @@ public class AdminController : Controller private readonly IAuthorizationService _authorizationService; private readonly CorsService _corsService; private readonly INotifier _notifier; + protected readonly IHtmlLocalizer H; public AdminController( @@ -115,7 +116,7 @@ public async Task IndexPOST() AllowedOrigins = settingViewModel.AllowedOrigins, IsDefaultPolicy = settingViewModel.IsDefaultPolicy }); - + if (settingViewModel.AllowAnyOrigin && settingViewModel.AllowCredentials) { policyWarnings.Add(settingViewModel.Name); @@ -134,7 +135,7 @@ public async Task IndexPOST() if (policyWarnings.Count > 0) { - await _notifier.WarningAsync(H["Specifying {0} and {1} is an insecure configuration and can result in cross-site request forgery. The CORS service returns an invalid CORS response when an app is configured with both methods.
Affected policies: {2}
Refer to docs:https://learn.microsoft.com/en-us/aspnet/core/security/cors", "AllowAnyOrigin", "AllowCredentias", string.Join(", ", policyWarnings) ]); + await _notifier.WarningAsync(H["Specifying {0} and {1} is an insecure configuration and can result in cross-site request forgery. The CORS service returns an invalid CORS response when an app is configured with both methods.
Affected policies: {2}
Refer to docs:https://learn.microsoft.com/en-us/aspnet/core/security/cors", "AllowAnyOrigin", "AllowCredentias", string.Join(", ", policyWarnings)]); } return View(model); diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentApiController.cs b/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentApiController.cs index 09ba8def915..0151f47e7e1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentApiController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentApiController.cs @@ -14,7 +14,9 @@ public class ContentApiController : Controller private readonly IAuthorizationService _authorizationService; private readonly IContentManager _contentManager; - public ContentApiController(IAuthorizationService authorizationService, IContentManager contentManager) + public ContentApiController( + IAuthorizationService authorizationService, + IContentManager contentManager) { _authorizationService = authorizationService; _contentManager = contentManager; diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentController.cs b/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentController.cs index d51165bdfb8..50015fd3ab0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Demo/Controllers/ContentController.cs @@ -7,33 +7,26 @@ using OrchardCore.Contents; using OrchardCore.DisplayManagement.ModelBinding; using YesSql; -using IHttpContextAccessor = Microsoft.AspNetCore.Http.IHttpContextAccessor; namespace OrchardCore.Demo.Controllers { - public class ContentController : Controller + public class ContentController : Controller, IUpdateModel { private readonly IContentItemDisplayManager _contentDisplay; private readonly IContentManager _contentManager; private readonly ISession _session; - private readonly IUpdateModelAccessor _updateModelAccessor; private readonly IAuthorizationService _authorizationService; - private readonly IHttpContextAccessor _httpContextAccessor; public ContentController( IContentManager contentManager, IContentItemDisplayManager contentDisplay, ISession session, - IUpdateModelAccessor updateModelAccessor, - IAuthorizationService authorizationService, - IHttpContextAccessor httpContextAccessor) + IAuthorizationService authorizationService) { _contentManager = contentManager; _contentDisplay = contentDisplay; _session = session; - _updateModelAccessor = updateModelAccessor; _authorizationService = authorizationService; - _httpContextAccessor = httpContextAccessor; } public async Task Display(string contentItemId) @@ -45,12 +38,12 @@ public async Task Display(string contentItemId) return NotFound(); } - if (!await _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext.User, CommonPermissions.ViewContent, contentItem)) + if (!await _authorizationService.AuthorizeAsync(User, CommonPermissions.ViewContent, contentItem)) { return Forbid(); } - var shape = await _contentDisplay.BuildDisplayAsync(contentItem, _updateModelAccessor.ModelUpdater); + var shape = await _contentDisplay.BuildDisplayAsync(contentItem, this); return View(shape); } @@ -64,12 +57,12 @@ public async Task Edit(string contentItemId) return NotFound(); } - if (!await _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext.User, CommonPermissions.EditContent, contentItem)) + if (!await _authorizationService.AuthorizeAsync(User, CommonPermissions.EditContent, contentItem)) { return Forbid(); } - var shape = await _contentDisplay.BuildEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, false); + var shape = await _contentDisplay.BuildEditorAsync(contentItem, this, false); return View(shape); } @@ -83,12 +76,12 @@ public async Task EditPost(string contentItemId) return NotFound(); } - if (!await _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext.User, CommonPermissions.EditContent, contentItem)) + if (!await _authorizationService.AuthorizeAsync(User, CommonPermissions.EditContent, contentItem)) { return Forbid(); } - var shape = await _contentDisplay.UpdateEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, false); + var shape = await _contentDisplay.UpdateEditorAsync(contentItem, this, false); if (!ModelState.IsValid) { diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/ExportRemoteInstanceController.cs b/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/ExportRemoteInstanceController.cs index 750c2912e1c..552f4190a96 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/ExportRemoteInstanceController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/ExportRemoteInstanceController.cs @@ -26,6 +26,7 @@ public class ExportRemoteInstanceController : Controller private readonly RemoteInstanceService _service; private readonly INotifier _notifier; private readonly IHttpClientFactory _httpClientFactory; + protected readonly IHtmlLocalizer H; public ExportRemoteInstanceController( diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/RemoteClientController.cs b/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/RemoteClientController.cs index 98893f63274..415fc7f396b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/RemoteClientController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/RemoteClientController.cs @@ -28,8 +28,6 @@ public class RemoteClientController : Controller private readonly IDataProtector _dataProtector; private readonly IAuthorizationService _authorizationService; - private readonly PagerOptions _pagerOptions; - private readonly IShapeFactory _shapeFactory; private readonly RemoteClientService _remoteClientService; private readonly INotifier _notifier; @@ -40,16 +38,12 @@ public RemoteClientController( IDataProtectionProvider dataProtectionProvider, RemoteClientService remoteClientService, IAuthorizationService authorizationService, - IOptions pagerOptions, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer, INotifier notifier ) { _authorizationService = authorizationService; - _pagerOptions = pagerOptions.Value; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; _notifier = notifier; @@ -57,14 +51,18 @@ INotifier notifier _dataProtector = dataProtectionProvider.CreateProtector("OrchardCore.Deployment").ToTimeLimitedDataProtector(); } - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageRemoteClients)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var remoteClients = (await _remoteClientService.GetRemoteClientListAsync()).RemoteClients; @@ -86,7 +84,7 @@ public async Task Index(ContentOptions options, PagerParameters p routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, count, routeData); var model = new RemoteClientIndexViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/RemoteInstanceController.cs b/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/RemoteInstanceController.cs index 4009ae9dfdf..1f7ce10ca61 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/RemoteInstanceController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/Controllers/RemoteInstanceController.cs @@ -25,8 +25,6 @@ public class RemoteInstanceController : Controller private const string _optionsSearch = "Options.Search"; private readonly IAuthorizationService _authorizationService; - private readonly PagerOptions _pagerOptions; - private readonly IShapeFactory _shapeFactory; private readonly INotifier _notifier; private readonly RemoteInstanceService _service; @@ -36,30 +34,30 @@ public class RemoteInstanceController : Controller public RemoteInstanceController( RemoteInstanceService service, IAuthorizationService authorizationService, - IOptions pagerOptions, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer, INotifier notifier ) { _authorizationService = authorizationService; - _pagerOptions = pagerOptions.Value; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; _notifier = notifier; _service = service; } - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageRemoteInstances)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var remoteInstances = (await _service.GetRemoteInstanceListAsync()).RemoteInstances; @@ -79,7 +77,7 @@ public async Task Index(ContentOptions options, PagerParameters p routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, remoteInstances.Count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, remoteInstances.Count, routeData); var model = new RemoteInstanceIndexViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/DeploymentPlanController.cs b/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/DeploymentPlanController.cs index 73d0435b812..5a424f6a591 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/DeploymentPlanController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/DeploymentPlanController.cs @@ -23,7 +23,7 @@ namespace OrchardCore.Deployment.Controllers { [Admin("DeploymentPlan/{action}/{id?}", "DeploymentPlan{action}")] - public class DeploymentPlanController : Controller + public class DeploymentPlanController : Controller, IUpdateModel { private const string _optionsSearch = "Options.Search"; @@ -31,10 +31,7 @@ public class DeploymentPlanController : Controller private readonly IDisplayManager _displayManager; private readonly IEnumerable _factories; private readonly ISession _session; - private readonly PagerOptions _pagerOptions; private readonly INotifier _notifier; - private readonly IUpdateModelAccessor _updateModelAccessor; - private readonly IShapeFactory _shapeFactory; protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; @@ -44,26 +41,24 @@ public DeploymentPlanController( IDisplayManager displayManager, IEnumerable factories, ISession session, - IOptions pagerOptions, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer, - INotifier notifier, - IUpdateModelAccessor updateModelAccessor) + INotifier notifier) { _displayManager = displayManager; _factories = factories; _authorizationService = authorizationService; _session = session; - _pagerOptions = pagerOptions.Value; _notifier = notifier; - _updateModelAccessor = updateModelAccessor; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; } - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageDeploymentPlan)) { @@ -75,7 +70,7 @@ public async Task Index(ContentOptions options, PagerParameters p return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var deploymentPlans = _session.Query(); @@ -100,7 +95,7 @@ public async Task Index(ContentOptions options, PagerParameters p routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, count, routeData); var model = new DeploymentPlanIndexViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/ImportController.cs b/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/ImportController.cs index 34d2b5a3357..39d95d7f738 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/ImportController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/ImportController.cs @@ -22,6 +22,7 @@ public class ImportController : Controller private readonly IDeploymentManager _deploymentManager; private readonly IAuthorizationService _authorizationService; private readonly INotifier _notifier; + protected readonly IHtmlLocalizer H; protected readonly IStringLocalizer S; diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/StepController.cs b/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/StepController.cs index 1818f16fbd4..7871ed4edb4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/StepController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment/Controllers/StepController.cs @@ -15,14 +15,13 @@ namespace OrchardCore.Deployment.Controllers { [Admin] - public class StepController : Controller + public class StepController : Controller, IUpdateModel { private readonly IAuthorizationService _authorizationService; private readonly IDisplayManager _displayManager; private readonly IEnumerable _factories; private readonly ISession _session; private readonly INotifier _notifier; - private readonly IUpdateModelAccessor _updateModelAccessor; protected readonly IHtmlLocalizer H; @@ -32,15 +31,13 @@ public StepController( IEnumerable factories, ISession session, IHtmlLocalizer htmlLocalizer, - INotifier notifier, - IUpdateModelAccessor updateModelAccessor) + INotifier notifier) { _displayManager = displayManager; _factories = factories; _authorizationService = authorizationService; _session = session; _notifier = notifier; - _updateModelAccessor = updateModelAccessor; H = htmlLocalizer; } @@ -74,7 +71,7 @@ public async Task Create(long id, string type) DeploymentStep = step, DeploymentStepId = step.Id, DeploymentStepType = type, - Editor = await _displayManager.BuildEditorAsync(step, updater: _updateModelAccessor.ModelUpdater, isNew: true, string.Empty, string.Empty) + Editor = await _displayManager.BuildEditorAsync(step, updater: this, isNew: true, string.Empty, string.Empty) }; model.Editor.DeploymentStep = step; @@ -151,7 +148,7 @@ public async Task Edit(long id, string stepId) DeploymentStep = step, DeploymentStepId = step.Id, DeploymentStepType = step.GetType().Name, - Editor = await _displayManager.BuildEditorAsync(step, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", "") + Editor = await _displayManager.BuildEditorAsync(step, updater: this, isNew: false, string.Empty, string.Empty) }; model.Editor.DeploymentStep = step; @@ -181,7 +178,7 @@ public async Task Edit(EditDeploymentPlanStepViewModel model) return NotFound(); } - var editor = await _displayManager.UpdateEditorAsync(step, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", ""); + var editor = await _displayManager.UpdateEditorAsync(step, updater: this, isNew: false, string.Empty, string.Empty); if (ModelState.IsValid) { diff --git a/src/OrchardCore.Modules/OrchardCore.Feeds/Controllers/FeedController.cs b/src/OrchardCore.Modules/OrchardCore.Feeds/Controllers/FeedController.cs index 8607f8d1103..71f6736e762 100644 --- a/src/OrchardCore.Modules/OrchardCore.Feeds/Controllers/FeedController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Feeds/Controllers/FeedController.cs @@ -8,31 +8,28 @@ namespace OrchardCore.Feeds.Controllers { - public class FeedController : Controller + public class FeedController : Controller, IUpdateModel { private readonly IEnumerable _feedFormatProviders; private readonly IEnumerable _feedQueryProviders; private readonly IFeedItemBuilder _feedItemBuilder; private readonly IServiceProvider _serviceProvider; - private readonly IUpdateModelAccessor _updateModelAccessor; public FeedController( IEnumerable feedQueryProviders, IEnumerable feedFormatProviders, IFeedItemBuilder feedItemBuilder, - IServiceProvider serviceProvider, - IUpdateModelAccessor updateModelAccessor) + IServiceProvider serviceProvider) { _feedQueryProviders = feedQueryProviders; _feedFormatProviders = feedFormatProviders; _feedItemBuilder = feedItemBuilder; _serviceProvider = serviceProvider; - _updateModelAccessor = updateModelAccessor; } public async Task Index(string format) { - var context = new FeedContext(_updateModelAccessor.ModelUpdater, format); + var context = new FeedContext(this, format); var bestFormatterMatch = _feedFormatProviders .Select(provider => provider.Match(context)) diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Flows/Controllers/AdminController.cs index db2c0cd9e69..18f7dce0b88 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Controllers/AdminController.cs @@ -16,29 +16,33 @@ namespace OrchardCore.Flows.Controllers { [Admin("Flows/{action}", "Flows.{action}")] - public class AdminController : Controller + public class AdminController : Controller, IUpdateModel { private readonly IContentManager _contentManager; private readonly IContentDefinitionManager _contentDefinitionManager; private readonly IContentItemDisplayManager _contentItemDisplayManager; - private readonly IShapeFactory _shapeFactory; - private readonly IUpdateModelAccessor _updateModelAccessor; public AdminController( IContentManager contentManager, IContentDefinitionManager contentDefinitionManager, - IContentItemDisplayManager contentItemDisplayManager, - IShapeFactory shapeFactory, - IUpdateModelAccessor updateModelAccessor) + IContentItemDisplayManager contentItemDisplayManager) { _contentManager = contentManager; _contentDefinitionManager = contentDefinitionManager; _contentItemDisplayManager = contentItemDisplayManager; - _shapeFactory = shapeFactory; - _updateModelAccessor = updateModelAccessor; } - public async Task BuildEditor(string id, string prefix, string prefixesName, string contentTypesName, string contentItemsName, string targetId, bool flowMetadata, string parentContentType, string partName) + public async Task BuildEditor( + [FromServices] IShapeFactory shapeFactory, + string id, + string prefix, + string prefixesName, + string contentTypesName, + string contentItemsName, + string targetId, + bool flowMetadata, + string parentContentType, + string partName) { if (string.IsNullOrWhiteSpace(id)) { @@ -69,7 +73,7 @@ public async Task BuildEditor(string id, string prefix, string pr // Create a Card Shape var contentCard = await _shapeFactory.New.ContentCard( // Updater is the controller for AJAX Requests - Updater: _updateModelAccessor.ModelUpdater, + Updater: this, // Shape Specific CollectionShapeType: cardCollectionType, ContentItem: contentItem, diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs index 81e53934b67..f9d4a357081 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs @@ -28,7 +28,7 @@ namespace OrchardCore.Layers.Controllers { [Admin("Layers/{action}/{id?}", "Layers.{action}")] - public class AdminController : Controller + public class AdminController : Controller, IUpdateModel { private readonly IContentDefinitionManager _contentDefinitionManager; private readonly IContentManager _contentManager; @@ -37,17 +37,17 @@ public class AdminController : Controller private readonly ILayerService _layerService; private readonly IAuthorizationService _authorizationService; private readonly ISession _session; - private readonly IUpdateModelAccessor _updateModelAccessor; private readonly IVolatileDocumentManager _layerStateManager; private readonly IDisplayManager _conditionDisplayManager; private readonly IDisplayManager _ruleDisplayManager; private readonly IConditionIdGenerator _conditionIdGenerator; private readonly IEnumerable _conditionFactories; - protected readonly IStringLocalizer S; - protected readonly IHtmlLocalizer H; private readonly INotifier _notifier; private readonly ILogger _logger; + protected readonly IStringLocalizer S; + protected readonly IHtmlLocalizer H; + public AdminController( IContentDefinitionManager contentDefinitionManager, IContentManager contentManager, @@ -56,7 +56,6 @@ public AdminController( ILayerService layerService, IAuthorizationService authorizationService, ISession session, - IUpdateModelAccessor updateModelAccessor, IVolatileDocumentManager layerStateManager, IDisplayManager conditionDisplayManager, IDisplayManager ruleDisplayManager, @@ -74,7 +73,6 @@ public AdminController( _layerService = layerService; _authorizationService = authorizationService; _session = session; - _updateModelAccessor = updateModelAccessor; _layerStateManager = layerStateManager; _conditionDisplayManager = conditionDisplayManager; _ruleDisplayManager = ruleDisplayManager; @@ -116,7 +114,7 @@ public async Task Index() if (contentDefinitions.Any(c => c.Name == widget.ContentItem.ContentType)) { - list.Add(await _contentItemDisplayManager.BuildDisplayAsync(widget.ContentItem, _updateModelAccessor.ModelUpdater, "SummaryAdmin")); + list.Add(await _contentItemDisplayManager.BuildDisplayAsync(widget.ContentItem, this, "SummaryAdmin")); } else { @@ -205,6 +203,7 @@ public async Task Edit(string name) foreach (var factory in _conditionFactories) { var condition = factory.Create(); + var thumbnail = await _conditionDisplayManager.BuildDisplayAsync(condition, _updateModelAccessor.ModelUpdater, "Thumbnail"); thumbnail.Properties["Condition"] = condition; thumbnail.Properties["TargetUrl"] = Url.ActionLink("Create", "LayerRule", new { name, type = factory.Name }); diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/LayerRuleController.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/LayerRuleController.cs index 0e72e66b1fe..c2e5c1a1eac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/LayerRuleController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/LayerRuleController.cs @@ -17,7 +17,7 @@ namespace OrchardCore.Layers.Controllers { [Admin("Layers/Rules/{action}", "Layers.Rules.{action}")] - public class LayerRuleController : Controller + public class LayerRuleController : Controller, IUpdateModel { private readonly IAuthorizationService _authorizationService; private readonly IDisplayManager _displayManager; @@ -25,7 +25,6 @@ public class LayerRuleController : Controller private readonly ILayerService _layerService; private readonly IConditionIdGenerator _conditionIdGenerator; private readonly INotifier _notifier; - private readonly IUpdateModelAccessor _updateModelAccessor; protected readonly IHtmlLocalizer H; @@ -36,8 +35,7 @@ public LayerRuleController( ILayerService layerService, IConditionIdGenerator conditionIdGenerator, IHtmlLocalizer htmlLocalizer, - INotifier notifier, - IUpdateModelAccessor updateModelAccessor) + INotifier notifier) { _displayManager = displayManager; _factories = factories; @@ -45,7 +43,6 @@ public LayerRuleController( _layerService = layerService; _conditionIdGenerator = conditionIdGenerator; _notifier = notifier; - _updateModelAccessor = updateModelAccessor; H = htmlLocalizer; } @@ -83,7 +80,7 @@ public async Task Create(string name, string type, string conditi Name = name, ConditionGroupId = conditionGroup.ConditionId, ConditionType = type, - Editor = await _displayManager.BuildEditorAsync(condition, updater: _updateModelAccessor.ModelUpdater, isNew: true, string.Empty, string.Empty) + Editor = await _displayManager.BuildEditorAsync(condition, updater: this, isNew: true, string.Empty, string.Empty) }; return View(model); @@ -119,7 +116,7 @@ public async Task Create(LayerRuleCreateViewModel model) return NotFound(); } - var editor = await _displayManager.UpdateEditorAsync(condition, updater: _updateModelAccessor.ModelUpdater, isNew: true, "", ""); + var editor = await _displayManager.UpdateEditorAsync(condition, updater: this, isNew: true, "", ""); if (ModelState.IsValid) { @@ -161,7 +158,7 @@ public async Task Edit(string name, string conditionId) var model = new LayerRuleEditViewModel { Name = name, - Editor = await _displayManager.BuildEditorAsync(condition, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", "") + Editor = await _displayManager.BuildEditorAsync(condition, updater: this, isNew: false, "", "") }; return View(model); @@ -190,7 +187,7 @@ public async Task Edit(LayerRuleEditViewModel model) return NotFound(); } - var editor = await _displayManager.UpdateEditorAsync(condition, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", ""); + var editor = await _displayManager.UpdateEditorAsync(condition, updater: this, isNew: false, "", ""); if (ModelState.IsValid) { diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/Controllers/OrderController.cs b/src/OrchardCore.Modules/OrchardCore.Lists/Controllers/OrderController.cs index 8564d23fd04..88627f4ad01 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/Controllers/OrderController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/Controllers/OrderController.cs @@ -17,7 +17,9 @@ public class OrderController : Controller private readonly IContainerService _containerService; private readonly IAuthorizationService _authorizationService; - public OrderController(IContainerService containerService, IAuthorizationService authorizationService) + public OrderController( + IContainerService containerService, + IAuthorizationService authorizationService) { _containerService = containerService; _authorizationService = authorizationService; diff --git a/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Controllers/AdminController.cs index 3db2145da07..e62b773e54e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/Controllers/AdminController.cs @@ -15,6 +15,7 @@ public class AdminController : Controller private readonly IAuthorizationService _authorizationService; private readonly AwsStorageOptions _options; private readonly INotifier _notifier; + protected readonly IHtmlLocalizer H; public AdminController( @@ -35,7 +36,7 @@ public async Task Options() { return Forbid(); } - + if (_options.Validate().Any()) { await _notifier.ErrorAsync(H["The Amazon S3 Media feature is enabled, but it was not configured with appsettings.json."]); diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Media/Controllers/AdminController.cs index 4085af7b85d..c6280908a92 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Controllers/AdminController.cs @@ -23,20 +23,21 @@ namespace OrchardCore.Media.Controllers public class AdminController : Controller { private static readonly char[] _invalidFolderNameCharacters = ['\\', '/']; - private static readonly char[] _extensionSeperator = [' ', ',']; + private static readonly char[] _extensionSeparator = [' ', ',']; private readonly IMediaFileStore _mediaFileStore; private readonly IMediaNameNormalizerService _mediaNameNormalizerService; private readonly IAuthorizationService _authorizationService; private readonly IContentTypeProvider _contentTypeProvider; private readonly ILogger _logger; - protected readonly IStringLocalizer S; private readonly MediaOptions _mediaOptions; private readonly IUserAssetFolderNameProvider _userAssetFolderNameProvider; private readonly IChunkFileUploadService _chunkFileUploadService; private readonly IFileVersionProvider _fileVersionProvider; private readonly IServiceProvider _serviceProvider; + protected readonly IStringLocalizer S; + public AdminController( IMediaFileStore mediaFileStore, IMediaNameNormalizerService mediaNameNormalizerService, @@ -489,7 +490,7 @@ private HashSet GetRequestedExtensions(string exts, bool fallback) { if (!string.IsNullOrWhiteSpace(exts)) { - var extensions = exts.Split(_extensionSeperator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + var extensions = exts.Split(_extensionSeparator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); var requestedExtensions = _mediaOptions.AllowedFileExtensions .Intersect(extensions) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Controllers/MediaCacheController.cs b/src/OrchardCore.Modules/OrchardCore.Media/Controllers/MediaCacheController.cs index 2f7399159d5..81ae3654a7c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Controllers/MediaCacheController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Controllers/MediaCacheController.cs @@ -18,6 +18,7 @@ public class MediaCacheController : Controller private readonly IAuthorizationService _authorizationService; private readonly IMediaFileStoreCache _mediaFileStoreCache; private readonly INotifier _notifier; + protected readonly IHtmlLocalizer H; public MediaCacheController( diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Controllers/MediaProfilesController.cs b/src/OrchardCore.Modules/OrchardCore.Media/Controllers/MediaProfilesController.cs index 172502aad50..467ed23967d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Controllers/MediaProfilesController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Controllers/MediaProfilesController.cs @@ -29,9 +29,7 @@ public class MediaProfilesController : Controller private readonly IAuthorizationService _authorizationService; private readonly MediaProfilesManager _mediaProfilesManager; private readonly MediaOptions _mediaOptions; - private readonly PagerOptions _pagerOptions; private readonly INotifier _notifier; - private readonly IShapeFactory _shapeFactory; protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; @@ -40,9 +38,7 @@ public MediaProfilesController( IAuthorizationService authorizationService, MediaProfilesManager mediaProfilesManager, IOptions mediaOptions, - IOptions pagerOptions, INotifier notifier, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer ) @@ -50,22 +46,24 @@ IHtmlLocalizer htmlLocalizer _authorizationService = authorizationService; _mediaProfilesManager = mediaProfilesManager; _mediaOptions = mediaOptions.Value; - _pagerOptions = pagerOptions.Value; _notifier = notifier; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; } [Admin("MediaProfiles", "MediaProfiles.Index")] - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageMediaProfiles)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var mediaProfilesDocument = await _mediaProfilesManager.GetMediaProfilesDocumentAsync(); var mediaProfiles = mediaProfilesDocument.MediaProfiles.ToList(); @@ -90,7 +88,7 @@ public async Task Index(ContentOptions options, PagerParameters p routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, count, routeData); var model = new MediaProfileIndexViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs index a624d60a69a..b5d264d55dd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs @@ -18,7 +18,7 @@ namespace OrchardCore.Menu.Controllers { [Admin("Menu/{action}/{id?}", "Menu{action}")] - public class AdminController : Controller + public class AdminController : Controller, IUpdateModel { private readonly IContentManager _contentManager; private readonly IAuthorizationService _authorizationService; @@ -26,8 +26,8 @@ public class AdminController : Controller private readonly IContentDefinitionManager _contentDefinitionManager; private readonly ISession _session; private readonly INotifier _notifier; + protected readonly IHtmlLocalizer H; - private readonly IUpdateModelAccessor _updateModelAccessor; public AdminController( ISession session, @@ -36,8 +36,7 @@ public AdminController( IContentItemDisplayManager contentItemDisplayManager, IContentDefinitionManager contentDefinitionManager, INotifier notifier, - IHtmlLocalizer localizer, - IUpdateModelAccessor updateModelAccessor) + IHtmlLocalizer localizer) { _contentManager = contentManager; _authorizationService = authorizationService; @@ -45,7 +44,6 @@ public AdminController( _contentDefinitionManager = contentDefinitionManager; _session = session; _notifier = notifier; - _updateModelAccessor = updateModelAccessor; H = localizer; } diff --git a/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs index 8bcb805bd34..a3dad969a82 100644 --- a/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Notifications/Controllers/AdminController.cs @@ -36,8 +36,6 @@ public class AdminController : Controller, IUpdateModel private readonly INotificationsAdminListQueryService _notificationsAdminListQueryService; private readonly IDisplayManager _notificationOptionsDisplayManager; private readonly INotifier _notifier; - private readonly IShapeFactory _shapeFactory; - private readonly PagerOptions _pagerOptions; private readonly IClock _clock; protected readonly IStringLocalizer S; @@ -46,14 +44,11 @@ public class AdminController : Controller, IUpdateModel public AdminController( IAuthorizationService authorizationService, ISession session, - - IOptions pagerOptions, IDisplayManager notificationDisplayManager, INotificationsAdminListQueryService notificationsAdminListQueryService, IDisplayManager notificationOptionsDisplayManager, INotifier notifier, IClock clock, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer) { @@ -63,8 +58,6 @@ public AdminController( _notificationsAdminListQueryService = notificationsAdminListQueryService; _notificationOptionsDisplayManager = notificationOptionsDisplayManager; _notifier = notifier; - _shapeFactory = shapeFactory; - _pagerOptions = pagerOptions.Value; _clock = clock; S = stringLocalizer; @@ -73,6 +66,8 @@ public AdminController( [Admin("notifications", "ListNotifications")] public async Task List( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, [ModelBinder(BinderType = typeof(NotificationFilterEngineModelBinder), Name = "q")] QueryFilterResult queryFilterResult, PagerParameters pagerParameters, ListNotificationOptions options) @@ -108,7 +103,7 @@ public async Task List( new(S["Remove"], nameof(NotificationBulkAction.Remove)), ]; - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var queryResult = await _notificationsAdminListQueryService.QueryAsync(pager.Page, pager.PageSize, options, this); @@ -132,7 +127,7 @@ public async Task List( var header = await _notificationOptionsDisplayManager.BuildEditorAsync(options, this, false, string.Empty, string.Empty); - var shapeViewModel = await _shapeFactory.CreateAsync("NotificationsAdminList", viewModel => + var shapeViewModel = await shapeFactory.CreateAsync("NotificationsAdminList", viewModel => { viewModel.Options = options; viewModel.Header = header; diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ApplicationController.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ApplicationController.cs index cc977896dcc..85fe34a7613 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ApplicationController.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ApplicationController.cs @@ -28,8 +28,6 @@ namespace OrchardCore.OpenId.Controllers public class ApplicationController : Controller { private readonly IAuthorizationService _authorizationService; - private readonly IShapeFactory _shapeFactory; - private readonly PagerOptions _pagerOptions; private readonly IOpenIdApplicationManager _applicationManager; private readonly IOpenIdScopeManager _scopeManager; private readonly INotifier _notifier; @@ -39,8 +37,6 @@ public class ApplicationController : Controller protected readonly IHtmlLocalizer H; public ApplicationController( - IShapeFactory shapeFactory, - IOptions pagerOptions, IStringLocalizer stringLocalizer, IAuthorizationService authorizationService, IOpenIdApplicationManager applicationManager, @@ -49,8 +45,6 @@ public ApplicationController( INotifier notifier, ShellDescriptor shellDescriptor) { - _shapeFactory = shapeFactory; - _pagerOptions = pagerOptions.Value; S = stringLocalizer; H = htmlLocalizer; _authorizationService = authorizationService; @@ -61,19 +55,22 @@ public ApplicationController( } [Admin("OpenId/Application", "OpenIdApplication")] - public async Task Index(PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageApplications)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var count = await _applicationManager.CountAsync(); var model = new OpenIdApplicationsIndexViewModel { - Pager = await _shapeFactory.PagerAsync(pager, (int)count), + Pager = await shapeFactory.PagerAsync(pager, (int)count), }; await foreach (var application in _applicationManager.ListAsync(pager.PageSize, pager.GetStartIndex())) diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ScopeController.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ScopeController.cs index 7b5461825c3..d73cf6e78bb 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ScopeController.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ScopeController.cs @@ -24,8 +24,6 @@ public class ScopeController : Controller { private readonly IAuthorizationService _authorizationService; private readonly IOpenIdScopeManager _scopeManager; - private readonly IShapeFactory _shapeFactory; - private readonly PagerOptions _pagerOptions; private readonly INotifier _notifier; private readonly ShellDescriptor _shellDescriptor; private readonly ShellSettings _shellSettings; @@ -35,8 +33,6 @@ public class ScopeController : Controller public ScopeController( IOpenIdScopeManager scopeManager, - IShapeFactory shapeFactory, - IOptions pagerOptions, IStringLocalizer stringLocalizer, IAuthorizationService authorizationService, INotifier notifier, @@ -45,8 +41,6 @@ public ScopeController( IShellHost shellHost) { _scopeManager = scopeManager; - _shapeFactory = shapeFactory; - _pagerOptions = pagerOptions.Value; S = stringLocalizer; _authorizationService = authorizationService; _notifier = notifier; @@ -56,19 +50,22 @@ public ScopeController( } [Admin("OpenId/Scope", "OpenIdScope")] - public async Task Index(PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageScopes)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var count = await _scopeManager.CountAsync(); var model = new OpenIdScopeIndexViewModel { - Pager = await _shapeFactory.PagerAsync(pager, (int)count), + Pager = await shapeFactory.PagerAsync(pager, (int)count), }; await foreach (var scope in _scopeManager.ListAsync(pager.PageSize, pager.GetStartIndex())) diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ServerConfigurationController.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ServerConfigurationController.cs index f6c408a2b51..e1ffc35ec10 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ServerConfigurationController.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ServerConfigurationController.cs @@ -16,7 +16,7 @@ namespace OrchardCore.OpenId.Controllers { [Admin, Feature(OpenIdConstants.Features.Server)] - public class ServerConfigurationController : Controller + public class ServerConfigurationController : Controller, IUpdateModel { private readonly IAuthorizationService _authorizationService; private readonly INotifier _notifier; @@ -24,7 +24,7 @@ public class ServerConfigurationController : Controller private readonly IDisplayManager _serverSettingsDisplayManager; private readonly IShellHost _shellHost; private readonly ShellSettings _shellSettings; - private readonly IUpdateModelAccessor _updateModelAccessor; + protected readonly IHtmlLocalizer H; public ServerConfigurationController( @@ -34,8 +34,7 @@ public ServerConfigurationController( IOpenIdServerService serverService, IDisplayManager serverSettingsDisplayManager, IShellHost shellHost, - ShellSettings shellSettings, - IUpdateModelAccessor updateModelAccessor) + ShellSettings shellSettings) { _authorizationService = authorizationService; H = htmlLocalizer; @@ -44,7 +43,6 @@ public ServerConfigurationController( _serverSettingsDisplayManager = serverSettingsDisplayManager; _shellHost = shellHost; _shellSettings = shellSettings; - _updateModelAccessor = updateModelAccessor; } [Admin("OpenId/ServerConfiguration", "OpenIdServerConfiguration")] @@ -56,7 +54,7 @@ public async Task Index() } var settings = await _serverService.GetSettingsAsync(); - var shape = await _serverSettingsDisplayManager.BuildEditorAsync(settings, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", ""); + var shape = await _serverSettingsDisplayManager.BuildEditorAsync(settings, updater: this, isNew: false, string.Empty, string.Empty); return View(shape); } @@ -71,7 +69,7 @@ public async Task IndexPost() } var settings = await _serverService.GetSettingsAsync(); - var shape = await _serverSettingsDisplayManager.UpdateEditorAsync(settings, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", ""); + var shape = await _serverSettingsDisplayManager.UpdateEditorAsync(settings, updater: this, isNew: false, string.Empty, string.Empty); if (!ModelState.IsValid) { diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ValidationConfigurationController.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ValidationConfigurationController.cs index 7935372dea5..2b58abe02c1 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ValidationConfigurationController.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ValidationConfigurationController.cs @@ -16,7 +16,7 @@ namespace OrchardCore.OpenId.Controllers { [Admin, Feature(OpenIdConstants.Features.Validation)] - public class ValidationConfigurationController : Controller + public class ValidationConfigurationController : Controller, IUpdateModel { private readonly IAuthorizationService _authorizationService; private readonly INotifier _notifier; @@ -24,7 +24,7 @@ public class ValidationConfigurationController : Controller private readonly IDisplayManager _validationSettingsDisplayManager; private readonly IShellHost _shellHost; private readonly ShellSettings _shellSettings; - private readonly IUpdateModelAccessor _updateModelAccessor; + protected readonly IHtmlLocalizer H; public ValidationConfigurationController( @@ -34,8 +34,7 @@ public ValidationConfigurationController( IOpenIdValidationService validationService, IDisplayManager validationSettingsDisplayManager, IShellHost shellHost, - ShellSettings shellSettings, - IUpdateModelAccessor updateModelAccessor) + ShellSettings shellSettings) { _authorizationService = authorizationService; H = htmlLocalizer; @@ -44,7 +43,6 @@ public ValidationConfigurationController( _validationSettingsDisplayManager = validationSettingsDisplayManager; _shellHost = shellHost; _shellSettings = shellSettings; - _updateModelAccessor = updateModelAccessor; } [Admin("OpenId/ValidationConfiguration", "OpenIdValidationConfiguration")] @@ -56,7 +54,7 @@ public async Task Index() } var settings = await _validationService.GetSettingsAsync(); - var shape = await _validationSettingsDisplayManager.BuildEditorAsync(settings, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", ""); + var shape = await _validationSettingsDisplayManager.BuildEditorAsync(settings, updater: this, isNew: false, string.Empty, string.Empty); return View(shape); } @@ -71,7 +69,7 @@ public async Task IndexPost() } var settings = await _validationService.GetSettingsAsync(); - var shape = await _validationSettingsDisplayManager.UpdateEditorAsync(settings, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", ""); + var shape = await _validationSettingsDisplayManager.UpdateEditorAsync(settings, updater: this, isNew: false, string.Empty, string.Empty); if (!ModelState.IsValid) { diff --git a/src/OrchardCore.Modules/OrchardCore.Placements/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Placements/Controllers/AdminController.cs index 674c73ec045..dfb18b4cf24 100644 --- a/src/OrchardCore.Modules/OrchardCore.Placements/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Placements/Controllers/AdminController.cs @@ -32,8 +32,6 @@ public class AdminController : Controller private readonly IAuthorizationService _authorizationService; private readonly PlacementsManager _placementsManager; private readonly INotifier _notifier; - private readonly IShapeFactory _shapeFactory; - private readonly PagerOptions _pagerOptions; protected readonly IHtmlLocalizer H; protected readonly IStringLocalizer S; @@ -44,30 +42,30 @@ public AdminController( PlacementsManager placementsManager, IHtmlLocalizer htmlLocalizer, IStringLocalizer stringLocalizer, - INotifier notifier, - IOptions pagerOptions, - IShapeFactory shapeFactory) + INotifier notifier) { _logger = logger; _authorizationService = authorizationService; _placementsManager = placementsManager; _notifier = notifier; - _shapeFactory = shapeFactory; - _pagerOptions = pagerOptions.Value; H = htmlLocalizer; S = stringLocalizer; } [Admin("Placements", "Placements.Index")] - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManagePlacements)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var shapeTypes = await _placementsManager.ListShapePlacementsAsync(); @@ -95,7 +93,7 @@ public async Task Index(ContentOptions options, PagerParameters p routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, count, routeData); var model = new ListShapePlacementsViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Queries/Controllers/AdminController.cs index bb5f1dbaa2d..c161dbdfecb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/Controllers/AdminController.cs @@ -20,18 +20,15 @@ namespace OrchardCore.Queries.Controllers { [Admin("Queries/{action}/{id?}", "Queries{action}")] - public class AdminController : Controller + public class AdminController : Controller, IUpdateModel { private const string _optionsSearch = "Options.Search"; private readonly IAuthorizationService _authorizationService; - private readonly PagerOptions _pagerOptions; private readonly INotifier _notifier; private readonly IQueryManager _queryManager; private readonly IEnumerable _querySources; private readonly IDisplayManager _displayManager; - private readonly IUpdateModelAccessor _updateModelAccessor; - private readonly IShapeFactory _shapeFactory; protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; @@ -39,35 +36,33 @@ public class AdminController : Controller public AdminController( IDisplayManager displayManager, IAuthorizationService authorizationService, - IOptions pagerOptions, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer, INotifier notifier, IQueryManager queryManager, - IEnumerable querySources, - IUpdateModelAccessor updateModelAccessor) + IEnumerable querySources) { _displayManager = displayManager; _authorizationService = authorizationService; - _pagerOptions = pagerOptions.Value; _queryManager = queryManager; _querySources = querySources; - _updateModelAccessor = updateModelAccessor; - _shapeFactory = shapeFactory; _notifier = notifier; S = stringLocalizer; H = htmlLocalizer; } - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageQueries)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var queries = await _queryManager.ListQueriesAsync(); queries = queries.OrderBy(x => x.Name); @@ -94,7 +89,7 @@ public async Task Index(ContentOptions options, PagerParameters p { Queries = [], Options = options, - Pager = await _shapeFactory.PagerAsync(pager, queries.Count(), routeData), + Pager = await shapeFactory.PagerAsync(pager, queries.Count(), routeData), QuerySourceNames = _querySources.Select(x => x.Name).ToList() }; @@ -103,7 +98,7 @@ public async Task Index(ContentOptions options, PagerParameters p model.Queries.Add(new QueryEntry { Query = query, - Shape = await _displayManager.BuildDisplayAsync(query, _updateModelAccessor.ModelUpdater, "SummaryAdmin") + Shape = await _displayManager.BuildDisplayAsync(query, this, "SummaryAdmin") }); } @@ -139,7 +134,7 @@ public async Task Create(string id) var model = new QueriesCreateViewModel { - Editor = await _displayManager.BuildEditorAsync(query, updater: _updateModelAccessor.ModelUpdater, isNew: true, "", ""), + Editor = await _displayManager.BuildEditorAsync(query, updater: this, isNew: true, string.Empty, string.Empty), SourceName = id }; @@ -161,7 +156,7 @@ public async Task CreatePost(QueriesCreateViewModel model) return NotFound(); } - var editor = await _displayManager.UpdateEditorAsync(query, updater: _updateModelAccessor.ModelUpdater, isNew: true, "", ""); + var editor = await _displayManager.UpdateEditorAsync(query, updater: this, isNew: true, string.Empty, string.Empty); if (ModelState.IsValid) { @@ -196,7 +191,7 @@ public async Task Edit(string id) SourceName = query.Source, Name = query.Name, Schema = query.Schema, - Editor = await _displayManager.BuildEditorAsync(query, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", "") + Editor = await _displayManager.BuildEditorAsync(query, updater: this, isNew: false, string.Empty, string.Empty) }; return View(model); @@ -217,7 +212,7 @@ public async Task EditPost(QueriesEditViewModel model) return NotFound(); } - var editor = await _displayManager.UpdateEditorAsync(query, updater: _updateModelAccessor.ModelUpdater, isNew: false, string.Empty, string.Empty); + var editor = await _displayManager.UpdateEditorAsync(query, updater: this, isNew: false, string.Empty, string.Empty); if (ModelState.IsValid) { diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/Sql/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Queries/Sql/Controllers/AdminController.cs index e725dd18a30..829c9598af0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/Sql/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/Sql/Controllers/AdminController.cs @@ -25,16 +25,16 @@ public class AdminController : Controller private readonly IAuthorizationService _authorizationService; private readonly IStore _store; private readonly ILiquidTemplateManager _liquidTemplateManager; - protected readonly IStringLocalizer S; private readonly TemplateOptions _templateOptions; + protected readonly IStringLocalizer S; + public AdminController( IAuthorizationService authorizationService, IStore store, ILiquidTemplateManager liquidTemplateManager, IStringLocalizer stringLocalizer, IOptions templateOptions) - { _authorizationService = authorizationService; _store = store; @@ -46,7 +46,7 @@ public AdminController( [Admin("Queries/Sql/Query", "QueriesRunSql")] public Task Query(string query) { - query = string.IsNullOrWhiteSpace(query) ? "" : System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(query)); + query = string.IsNullOrWhiteSpace(query) ? string.Empty : System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(query)); return Query(new AdminQueryViewModel { DecodedQuery = query, diff --git a/src/OrchardCore.Modules/OrchardCore.Recipes/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Recipes/Controllers/AdminController.cs index 6f1513a2b52..298c3ee8c1d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Recipes/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Recipes/Controllers/AdminController.cs @@ -30,9 +30,10 @@ public class AdminController : Controller private readonly IRecipeExecutor _recipeExecutor; private readonly IEnumerable _environmentProviders; private readonly INotifier _notifier; - protected readonly IHtmlLocalizer H; private readonly ILogger _logger; + protected readonly IHtmlLocalizer H; + public AdminController( IShellHost shellHost, ShellSettings shellSettings, diff --git a/src/OrchardCore.Modules/OrchardCore.Roles/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Roles/Controllers/AdminController.cs index d779b29abf4..eddf7623d1f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Roles/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Roles/Controllers/AdminController.cs @@ -30,6 +30,7 @@ public class AdminController : Controller private readonly ITypeFeatureProvider _typeFeatureProvider; private readonly IRoleService _roleService; private readonly INotifier _notifier; + protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/Controllers/AdminController.cs index f32a1c1db43..2ee114e1d83 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/Controllers/AdminController.cs @@ -37,7 +37,6 @@ public class AdminController : Controller private readonly AzureAISearchIndexManager _indexManager; private readonly AzureAISearchIndexSettingsService _indexSettingsService; private readonly IContentManager _contentManager; - private readonly IShapeFactory _shapeFactory; private readonly AzureAIIndexDocumentManager _azureAIIndexDocumentManager; private readonly AzureAISearchDefaultOptions _azureAIOptions; private readonly INotifier _notifier; @@ -53,7 +52,6 @@ public AdminController( AzureAISearchIndexManager indexManager, AzureAISearchIndexSettingsService indexSettingsService, IContentManager contentManager, - IShapeFactory shapeFactory, AzureAIIndexDocumentManager azureAIIndexDocumentManager, IOptions azureAIOptions, INotifier notifier, @@ -68,7 +66,6 @@ IHtmlLocalizer htmlLocalizer _indexManager = indexManager; _indexSettingsService = indexSettingsService; _contentManager = contentManager; - _shapeFactory = shapeFactory; _azureAIIndexDocumentManager = azureAIIndexDocumentManager; _azureAIOptions = azureAIOptions.Value; _notifier = notifier; @@ -78,7 +75,10 @@ IHtmlLocalizer htmlLocalizer H = htmlLocalizer; } - public async Task Index(AzureAIIndexOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IShapeFactory shapeFactory, + AzureAIIndexOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, AzureAISearchIndexPermissionHelper.ManageAzureAISearchIndexes)) { @@ -120,7 +120,7 @@ public async Task Index(AzureAIIndexOptions options, PagerParamet { Indexes = indexes, Options = options, - Pager = await _shapeFactory.PagerAsync(pager, totalIndexes, routeData) + Pager = await shapeFactory.PagerAsync(pager, totalIndexes, routeData) }; model.Options.ContentsBulkAction = diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs index 3f0022a270d..a44c78b8953 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Controllers/AdminController.cs @@ -55,7 +55,6 @@ public class AdminController : Controller private readonly ILogger _logger; private readonly IOptions _templateOptions; private readonly ElasticConnectionOptions _elasticConnectionOptions; - private readonly IShapeFactory _shapeFactory; private readonly ILocalizationService _localizationService; protected readonly IStringLocalizer S; @@ -77,7 +76,6 @@ public AdminController( ILogger logger, IOptions templateOptions, IOptions elasticConnectionOptions, - IShapeFactory shapeFactory, ILocalizationService localizationService, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer) @@ -97,13 +95,15 @@ public AdminController( _logger = logger; _templateOptions = templateOptions; _elasticConnectionOptions = elasticConnectionOptions.Value; - _shapeFactory = shapeFactory; _localizationService = localizationService; S = stringLocalizer; H = htmlLocalizer; } - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageElasticIndexes)) { @@ -141,7 +141,7 @@ public async Task Index(ContentOptions options, PagerParameters p routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, totalIndexes, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, totalIndexes, routeData); var model = new AdminIndexViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs index 03fdec5f624..981377442f6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Controllers/AdminController.cs @@ -48,9 +48,7 @@ public class AdminController : Controller private readonly ILuceneQueryService _queryService; private readonly ILiquidTemplateManager _liquidTemplateManager; private readonly IContentDefinitionManager _contentDefinitionManager; - private readonly PagerOptions _pagerOptions; private readonly JavaScriptEncoder _javaScriptEncoder; - private readonly IShapeFactory _shapeFactory; private readonly ILogger _logger; private readonly IOptions _templateOptions; private readonly ILocalizationService _localizationService; @@ -69,9 +67,7 @@ public AdminController( ILuceneQueryService queryService, ILiquidTemplateManager liquidTemplateManager, INotifier notifier, - IOptions pagerOptions, JavaScriptEncoder javaScriptEncoder, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer, ILogger logger, @@ -88,9 +84,7 @@ public AdminController( _liquidTemplateManager = liquidTemplateManager; _contentDefinitionManager = contentDefinitionManager; _notifier = notifier; - _pagerOptions = pagerOptions.Value; _javaScriptEncoder = javaScriptEncoder; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; _logger = logger; @@ -98,7 +92,11 @@ public AdminController( _localizationService = localizationService; } - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IShapeFactory shapeFactory, + [FromServices] IOptions pagerOptions, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageLuceneIndexes)) { @@ -107,7 +105,7 @@ public async Task Index(ContentOptions options, PagerParameters p var indexes = (await _luceneIndexSettingsService.GetSettingsAsync()).Select(i => new IndexViewModel { Name = i.IndexName }); - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var count = indexes.Count(); var results = indexes; @@ -133,7 +131,7 @@ public async Task Index(ContentOptions options, PagerParameters p { Indexes = results, Options = options, - Pager = await _shapeFactory.PagerAsync(pager, count, routeData) + Pager = await shapeFactory.PagerAsync(pager, count, routeData) }; model.Options.ContentsBulkAction = diff --git a/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs b/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs index b6b1d00ade2..59c9509bedd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs @@ -30,7 +30,6 @@ public class SearchController : Controller private readonly IServiceProvider _serviceProvider; private readonly INotifier _notifier; private readonly IEnumerable _searchHandlers; - private readonly IShapeFactory _shapeFactory; private readonly ILogger _logger; protected readonly IHtmlLocalizer H; @@ -43,7 +42,6 @@ public SearchController( INotifier notifier, IHtmlLocalizer htmlLocalizer, IEnumerable searchHandlers, - IShapeFactory shapeFactory, ILogger logger ) { @@ -54,11 +52,13 @@ ILogger logger _notifier = notifier; H = htmlLocalizer; _searchHandlers = searchHandlers; - _shapeFactory = shapeFactory; _logger = logger; } - public async Task Search(SearchViewModel viewModel, PagerSlimParameters pagerParameters) + public async Task Search( + [FromServices] IShapeFactory shapeFactory, + SearchViewModel viewModel, + PagerSlimParameters pagerParameters) { var searchServices = _serviceProvider.GetServices(); @@ -206,7 +206,7 @@ public async Task Search(SearchViewModel viewModel, PagerSlimPara .Take(pager.PageSize) .ToList(), }, - Pager = await _shapeFactory.PagerSlimAsync(pager, new Dictionary() + Pager = await shapeFactory.PagerSlimAsync(pager, new Dictionary() { { nameof(viewModel.Terms), viewModel.Terms }, { nameof(viewModel.Index), viewModel.Index }, diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Settings/Controllers/AdminController.cs index fac76003b44..fd42299efb5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Settings/Controllers/AdminController.cs @@ -13,14 +13,14 @@ namespace OrchardCore.Settings.Controllers { - public class AdminController : Controller + public class AdminController : Controller, IUpdateModel { private readonly IDisplayManager _siteSettingsDisplayManager; private readonly ISiteService _siteService; private readonly INotifier _notifier; private readonly IAuthorizationService _authorizationService; - private readonly IUpdateModelAccessor _updateModelAccessor; private readonly CultureOptions _cultureOptions; + protected readonly IHtmlLocalizer H; public AdminController( @@ -28,17 +28,15 @@ public AdminController( IDisplayManager siteSettingsDisplayManager, IAuthorizationService authorizationService, INotifier notifier, - IHtmlLocalizer h, - IOptions cultureOptions, - IUpdateModelAccessor updateModelAccessor) + IHtmlLocalizer htmlLocalizer, + IOptions cultureOptions) { _siteSettingsDisplayManager = siteSettingsDisplayManager; _siteService = siteService; _notifier = notifier; _authorizationService = authorizationService; - _updateModelAccessor = updateModelAccessor; _cultureOptions = cultureOptions.Value; - H = h; + H = htmlLocalizer; } [Admin("Settings/{groupId}", "AdminSettings")] @@ -54,7 +52,7 @@ public async Task Index(string groupId) var viewModel = new AdminIndexViewModel { GroupId = groupId, - Shape = await _siteSettingsDisplayManager.BuildEditorAsync(site, _updateModelAccessor.ModelUpdater, false, groupId, "") + Shape = await _siteSettingsDisplayManager.BuildEditorAsync(site, this, false, groupId, string.Empty) }; return View(viewModel); @@ -74,7 +72,7 @@ public async Task IndexPost(string groupId) var viewModel = new AdminIndexViewModel { GroupId = groupId, - Shape = await _siteSettingsDisplayManager.UpdateEditorAsync(site, _updateModelAccessor.ModelUpdater, false, groupId, "") + Shape = await _siteSettingsDisplayManager.UpdateEditorAsync(site, this, false, groupId, string.Empty) }; if (ModelState.IsValid) diff --git a/src/OrchardCore.Modules/OrchardCore.Setup/Controllers/SetupController.cs b/src/OrchardCore.Modules/OrchardCore.Setup/Controllers/SetupController.cs index d96ec02a46a..e4948d1969a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Setup/Controllers/SetupController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Setup/Controllers/SetupController.cs @@ -30,6 +30,7 @@ public class SetupController : Controller private readonly IEmailAddressValidator _emailAddressValidator; private readonly IEnumerable _databaseProviders; private readonly ILogger _logger; + protected readonly IStringLocalizer S; public SetupController( diff --git a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Controllers/AdminController.cs index 4024dc02aa9..509770dc52b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Controllers/AdminController.cs @@ -33,9 +33,7 @@ public class AdminController : Controller private readonly IAuthorizationService _authorizationService; private readonly ShortcodeTemplatesManager _shortcodeTemplatesManager; private readonly ILiquidTemplateManager _liquidTemplateManager; - private readonly PagerOptions _pagerOptions; private readonly INotifier _notifier; - private readonly IShapeFactory _shapeFactory; private readonly IHtmlSanitizerService _htmlSanitizerService; protected readonly IStringLocalizer S; @@ -45,9 +43,7 @@ public AdminController( IAuthorizationService authorizationService, ShortcodeTemplatesManager shortcodeTemplatesManager, ILiquidTemplateManager liquidTemplateManager, - IOptions pagerOptions, INotifier notifier, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer, IHtmlSanitizerService htmlSanitizerService @@ -56,23 +52,25 @@ IHtmlSanitizerService htmlSanitizerService _authorizationService = authorizationService; _shortcodeTemplatesManager = shortcodeTemplatesManager; _liquidTemplateManager = liquidTemplateManager; - _pagerOptions = pagerOptions.Value; _notifier = notifier; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; _htmlSanitizerService = htmlSanitizerService; } [Admin("Shortcodes", "Shortcodes.Index")] - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageShortcodeTemplates)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var shortcodeTemplatesDocument = await _shortcodeTemplatesManager.GetShortcodeTemplatesDocumentAsync(); var shortcodeTemplates = shortcodeTemplatesDocument.ShortcodeTemplates.ToList(); @@ -96,7 +94,7 @@ public async Task Index(ContentOptions options, PagerParameters p routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, count, routeData); var model = new ShortcodeTemplateIndexViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/AdminController.cs index 7f6fd000557..184e35af91c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/AdminController.cs @@ -22,7 +22,7 @@ namespace OrchardCore.Sitemaps.Controllers { [Admin("Sitemaps/{action}/{sitemapId?}", "Sitemaps{action}")] - public class AdminController : Controller + public class AdminController : Controller, IUpdateModel { private const string _optionsSearch = "Options.Search"; @@ -32,10 +32,7 @@ public class AdminController : Controller private readonly IEnumerable _sourceFactories; private readonly ISitemapManager _sitemapManager; private readonly ISitemapIdGenerator _sitemapIdGenerator; - private readonly PagerOptions _pagerOptions; - private readonly IUpdateModelAccessor _updateModelAccessor; private readonly INotifier _notifier; - private readonly IShapeFactory _shapeFactory; protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; @@ -47,10 +44,7 @@ public AdminController( IEnumerable sourceFactories, ISitemapManager sitemapManager, ISitemapIdGenerator sitemapIdGenerator, - IOptions pagerOptions, - IUpdateModelAccessor updateModelAccessor, INotifier notifier, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer) { @@ -60,22 +54,23 @@ public AdminController( _authorizationService = authorizationService; _sitemapManager = sitemapManager; _sitemapIdGenerator = sitemapIdGenerator; - _pagerOptions = pagerOptions.Value; - _updateModelAccessor = updateModelAccessor; _notifier = notifier; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; } - public async Task List(ContentOptions options, PagerParameters pagerParameters) + public async Task List( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var sitemaps = (await _sitemapManager.GetSitemapsAsync()) .OfType(); @@ -104,7 +99,7 @@ public async Task List(ContentOptions options, PagerParameters pa { Sitemaps = results.Select(sm => new SitemapListEntry { SitemapId = sm.SitemapId, Name = sm.Name, Enabled = sm.Enabled }).ToList(), Options = options, - Pager = await _shapeFactory.PagerAsync(pager, count, routeData) + Pager = await shapeFactory.PagerAsync(pager, count, routeData) }; model.Options.ContentsBulkAction = @@ -195,7 +190,7 @@ public async Task Create(CreateSitemapViewModel model) model.Path = _sitemapService.GetSitemapSlug(model.Name); } - await _sitemapService.ValidatePathAsync(model.Path, _updateModelAccessor.ModelUpdater); + await _sitemapService.ValidatePathAsync(model.Path, this); } if (ModelState.IsValid) @@ -264,7 +259,7 @@ public async Task Edit(EditSitemapViewModel model) model.Path = _sitemapService.GetSitemapSlug(model.Name); } - await _sitemapService.ValidatePathAsync(model.Path, _updateModelAccessor.ModelUpdater, model.SitemapId); + await _sitemapService.ValidatePathAsync(model.Path, this, model.SitemapId); } if (ModelState.IsValid) diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapCacheController.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapCacheController.cs index 9f364545d89..0b8476bb9b2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapCacheController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapCacheController.cs @@ -16,6 +16,7 @@ public class SitemapCacheController : Controller private readonly IAuthorizationService _authorizationService; private readonly ISitemapCacheProvider _sitemapCacheProvider; private readonly INotifier _notifier; + protected readonly IHtmlLocalizer H; public SitemapCacheController( diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapIndexController.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapIndexController.cs index d381f0532a4..6119a1fd2c7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapIndexController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SitemapIndexController.cs @@ -22,7 +22,7 @@ namespace OrchardCore.Sitemaps.Controllers { [Admin("SitemapIndexes/{action}/{sitemapId?}", "SitemapIndexes{action}")] - public class SitemapIndexController : Controller + public class SitemapIndexController : Controller, IUpdateModel { private const string _optionsSearch = "Options.Search"; @@ -30,10 +30,7 @@ public class SitemapIndexController : Controller private readonly IAuthorizationService _authorizationService; private readonly ISitemapIdGenerator _sitemapIdGenerator; private readonly ISitemapManager _sitemapManager; - private readonly PagerOptions _pagerOptions; - private readonly IUpdateModelAccessor _updateModelAccessor; private readonly INotifier _notifier; - private readonly IShapeFactory _shapeFactory; protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; @@ -43,9 +40,6 @@ public SitemapIndexController( IAuthorizationService authorizationService, ISitemapIdGenerator sitemapIdGenerator, ISitemapManager sitemapManager, - IOptions pagerOptions, - IUpdateModelAccessor updateModelAccessor, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer, INotifier notifier) @@ -54,22 +48,23 @@ public SitemapIndexController( _authorizationService = authorizationService; _sitemapIdGenerator = sitemapIdGenerator; _sitemapManager = sitemapManager; - _pagerOptions = pagerOptions.Value; - _updateModelAccessor = updateModelAccessor; _notifier = notifier; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; } - public async Task List(ContentOptions options, PagerParameters pagerParameters) + public async Task List( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var sitemaps = (await _sitemapManager.GetSitemapsAsync()) .OfType(); @@ -94,7 +89,7 @@ public async Task List(ContentOptions options, PagerParameters pa routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, count, routeData); var model = new ListSitemapIndexViewModel { @@ -170,7 +165,7 @@ public async Task Create(CreateSitemapIndexViewModel model) if (ModelState.IsValid) { - await _sitemapService.ValidatePathAsync(model.Path, _updateModelAccessor.ModelUpdater); + await _sitemapService.ValidatePathAsync(model.Path, this); } @@ -260,7 +255,7 @@ public async Task Edit(EditSitemapIndexViewModel model) if (ModelState.IsValid) { - await _sitemapService.ValidatePathAsync(model.Path, _updateModelAccessor.ModelUpdater, sitemap.SitemapId); + await _sitemapService.ValidatePathAsync(model.Path, this, sitemap.SitemapId); } // Path validation may invalidate model state. diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SourceController.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SourceController.cs index 89140252c0b..92fe70c35af 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SourceController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Controllers/SourceController.cs @@ -17,13 +17,12 @@ namespace OrchardCore.Sitemaps.Controllers { [Admin] - public class SourceController : Controller + public class SourceController : Controller, IUpdateModel { private readonly IAuthorizationService _authorizationService; private readonly IDisplayManager _displayManager; private readonly IEnumerable _factories; private readonly ISitemapManager _sitemapManager; - private readonly IUpdateModelAccessor _updateModelAccessor; private readonly INotifier _notifier; protected readonly IStringLocalizer S; @@ -34,7 +33,6 @@ public SourceController( IDisplayManager displayManager, IEnumerable factories, ISitemapManager sitemapManager, - IUpdateModelAccessor updateModelAccessor, INotifier notifier, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer) @@ -43,7 +41,6 @@ public SourceController( _factories = factories; _authorizationService = authorizationService; _sitemapManager = sitemapManager; - _updateModelAccessor = updateModelAccessor; _notifier = notifier; S = stringLocalizer; H = htmlLocalizer; @@ -77,7 +74,7 @@ public async Task Create(string sitemapId, string sourceType) SitemapSource = source, SitemapSourceId = source.Id, SitemapSourceType = sourceType, - Editor = await _displayManager.BuildEditorAsync(source, updater: _updateModelAccessor.ModelUpdater, isNew: true, "", "") + Editor = await _displayManager.BuildEditorAsync(source, updater: this, isNew: true, string.Empty, string.Empty) }; model.Editor.SitemapSource = source; @@ -154,7 +151,7 @@ public async Task Edit(string sitemapId, string sourceId) SitemapId = sitemapId, SitemapSource = source, SitemapSourceId = source.Id, - Editor = await _displayManager.BuildEditorAsync(source, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", "") + Editor = await _displayManager.BuildEditorAsync(source, updater: this, isNew: false, string.Empty, string.Empty) }; model.Editor.SitemapSource = source; @@ -184,7 +181,7 @@ public async Task Edit(EditSourceViewModel model) return NotFound(); } - var editor = await _displayManager.UpdateEditorAsync(source, updater: _updateModelAccessor.ModelUpdater, isNew: false, "", ""); + var editor = await _displayManager.UpdateEditorAsync(source, updater: this, isNew: false, string.Empty, string.Empty); if (ModelState.IsValid) { diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs index feb5cda7f2c..ab8ec13215e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs @@ -18,7 +18,7 @@ namespace OrchardCore.Taxonomies.Controllers { [Admin] - public class AdminController : Controller + public class AdminController : Controller, IUpdateModel { private readonly IContentManager _contentManager; private readonly IAuthorizationService _authorizationService; @@ -26,7 +26,6 @@ public class AdminController : Controller private readonly IContentDefinitionManager _contentDefinitionManager; private readonly ISession _session; private readonly INotifier _notifier; - private readonly IUpdateModelAccessor _updateModelAccessor; protected readonly IHtmlLocalizer H; @@ -37,8 +36,7 @@ public AdminController( IContentItemDisplayManager contentItemDisplayManager, IContentDefinitionManager contentDefinitionManager, INotifier notifier, - IHtmlLocalizer localizer, - IUpdateModelAccessor updateModelAccessor) + IHtmlLocalizer localizer) { _contentManager = contentManager; _authorizationService = authorizationService; @@ -46,7 +44,6 @@ public AdminController( _contentDefinitionManager = contentDefinitionManager; _session = session; _notifier = notifier; - _updateModelAccessor = updateModelAccessor; H = localizer; } diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/PreviewController.cs b/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/PreviewController.cs index 6704c665dd4..b64e00f9f2c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/PreviewController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/PreviewController.cs @@ -12,14 +12,13 @@ namespace OrchardCore.Templates.Controllers { - public class PreviewController : Controller + public class PreviewController : Controller, IUpdateModel { private readonly IContentManager _contentManager; private readonly IContentHandleManager _contentHandleManager; private readonly IContentItemDisplayManager _contentItemDisplayManager; private readonly IAuthorizationService _authorizationService; private readonly ISiteService _siteService; - private readonly IUpdateModelAccessor _updateModelAccessor; private readonly string _homeUrl; public PreviewController( @@ -27,17 +26,14 @@ public PreviewController( IContentHandleManager contentHandleManager, IContentItemDisplayManager contentItemDisplayManager, IAuthorizationService authorizationService, - ISiteService siteService, - IUpdateModelAccessor updateModelAccessor, - IHttpContextAccessor httpContextAccessor) + ISiteService siteService) { _contentManager = contentManager; _contentHandleManager = contentHandleManager; _contentItemDisplayManager = contentItemDisplayManager; _authorizationService = authorizationService; _siteService = siteService; - _updateModelAccessor = updateModelAccessor; - _homeUrl = httpContextAccessor.HttpContext.Request.PathBase.Add("/"); + _homeUrl = HttpContext.Request.PathBase.Add("/"); } public IActionResult Index() @@ -94,7 +90,7 @@ public async Task Render() return NotFound(); } - var model = await _contentItemDisplayManager.BuildDisplayAsync(contentItem, _updateModelAccessor.ModelUpdater, "Detail"); + var model = await _contentItemDisplayManager.BuildDisplayAsync(contentItem, this, "Detail"); return View(model); } diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/TemplateController.cs b/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/TemplateController.cs index 679c39b5e8f..dc7581eca7d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/TemplateController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Templates/Controllers/TemplateController.cs @@ -11,6 +11,7 @@ using Microsoft.Extensions.Options; using OrchardCore.Admin; using OrchardCore.DisplayManagement; +using OrchardCore.DisplayManagement.ModelBinding; using OrchardCore.DisplayManagement.Notify; using OrchardCore.Navigation; using OrchardCore.Routing; @@ -21,15 +22,13 @@ namespace OrchardCore.Templates.Controllers { [Admin("Templates/{action}/{name?}", "Templates.{action}")] - public class TemplateController : Controller + public class TemplateController : Controller, IUpdateModel { private const string _optionsSearch = "Options.Search"; private readonly IAuthorizationService _authorizationService; private readonly TemplatesManager _templatesManager; private readonly AdminTemplatesManager _adminTemplatesManager; - private readonly IShapeFactory _shapeFactory; - private readonly PagerOptions _pagerOptions; private readonly INotifier _notifier; protected readonly IStringLocalizer S; @@ -39,8 +38,6 @@ public TemplateController( IAuthorizationService authorizationService, TemplatesManager templatesManager, AdminTemplatesManager adminTemplatesManager, - IShapeFactory shapeFactory, - IOptions pagerOptions, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer, INotifier notifier) @@ -48,23 +45,29 @@ public TemplateController( _authorizationService = authorizationService; _templatesManager = templatesManager; _adminTemplatesManager = adminTemplatesManager; - _shapeFactory = shapeFactory; - _pagerOptions = pagerOptions.Value; _notifier = notifier; S = stringLocalizer; H = htmlLocalizer; } - public Task Admin(ContentOptions options, PagerParameters pagerParameters) + public Task Admin( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { options.AdminTemplates = true; // Used to provide a different url such that the Admin Templates menu entry doesn't collide with the Templates ones. - return Index(options, pagerParameters); + return Index(pagerOptions, shapeFactory, options, pagerParameters); } [Admin("Templates", "Templates.Index")] - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!options.AdminTemplates && !await _authorizationService.AuthorizeAsync(User, Permissions.ManageTemplates)) { @@ -76,7 +79,7 @@ public async Task Index(ContentOptions options, PagerParameters p return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var templatesDocument = options.AdminTemplates ? await _adminTemplatesManager.GetTemplatesDocumentAsync() : await _templatesManager.GetTemplatesDocumentAsync() @@ -103,7 +106,7 @@ public async Task Index(ContentOptions options, PagerParameters p routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, count, routeData); var model = new TemplateIndexViewModel { Templates = templates.Select(x => new TemplateEntry { Name = x.Key, Template = x.Value }).ToList(), diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/AdminController.cs index 294d926dfda..c8970559d5b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/AdminController.cs @@ -42,10 +42,8 @@ public class AdminController : Controller private readonly IClock _clock; private readonly INotifier _notifier; private readonly ITenantValidator _tenantValidator; - private readonly PagerOptions _pagerOptions; private readonly TenantsOptions _tenantsOptions; private readonly ILogger _logger; - private readonly IShapeFactory _shapeFactory; protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; @@ -63,10 +61,8 @@ public AdminController( IClock clock, INotifier notifier, ITenantValidator tenantValidator, - IOptions pagerOptions, IOptions tenantsOptions, ILogger logger, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer) { @@ -82,16 +78,18 @@ public AdminController( _clock = clock; _notifier = notifier; _tenantValidator = tenantValidator; - _pagerOptions = pagerOptions.Value; _tenantsOptions = tenantsOptions.Value; _logger = logger; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; } [Admin("Tenants", "Tenants")] - public async Task Index(TenantIndexOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + TenantIndexOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageTenants)) { @@ -106,7 +104,7 @@ public async Task Index(TenantIndexOptions options, PagerParamete var allSettings = _shellHost.GetAllSettings().OrderBy(s => s.Name); var dataProtector = _dataProtectorProvider.CreateProtector("Tokens").ToTimeLimitedDataProtector(); - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var entries = allSettings.Select(settings => { @@ -173,7 +171,7 @@ public async Task Index(TenantIndexOptions options, PagerParamete routeData.Values.TryAdd("Options.Search", options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, entries.Count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, entries.Count, routeData); var model = new AdminIndexViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/ApiController.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/ApiController.cs index 50759932fb9..5a7e1d833ba 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/ApiController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/ApiController.cs @@ -47,9 +47,10 @@ public class ApiController : Controller private readonly TenantsOptions _tenantsOptions; private readonly IEnumerable _databaseProviders; private readonly ITenantValidator _tenantValidator; - protected readonly IStringLocalizer S; private readonly ILogger _logger; + protected readonly IStringLocalizer S; + public ApiController( IShellHost shellHost, ShellSettings currentShellSettings, diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/FeatureProfilesController.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/FeatureProfilesController.cs index 7b50c1b44a7..9c88e889091 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/FeatureProfilesController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/FeatureProfilesController.cs @@ -32,8 +32,6 @@ public class FeatureProfilesController : Controller private readonly IAuthorizationService _authorizationService; private readonly FeatureProfilesManager _featureProfilesManager; private readonly INotifier _notifier; - private readonly PagerOptions _pagerOptions; - private readonly IShapeFactory _shapeFactory; protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; @@ -42,8 +40,6 @@ public FeatureProfilesController( IAuthorizationService authorizationService, FeatureProfilesManager featureProfilesManager, INotifier notifier, - IOptions pagerOptions, - IShapeFactory shapeFactory, IStringLocalizer stringLocalizer, IHtmlLocalizer htmlLocalizer ) @@ -51,21 +47,23 @@ IHtmlLocalizer htmlLocalizer _authorizationService = authorizationService; _featureProfilesManager = featureProfilesManager; _notifier = notifier; - _pagerOptions = pagerOptions.Value; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; } [Admin("TenantFeatureProfiles", "TenantFeatureProfilesIndex")] - public async Task Index(ContentOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + ContentOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageTenantFeatureProfiles)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var featureProfilesDocument = await _featureProfilesManager.GetFeatureProfilesDocumentAsync(); var featureProfiles = featureProfilesDocument.FeatureProfiles.ToList(); @@ -89,7 +87,7 @@ public async Task Index(ContentOptions options, PagerParameters p routeData.Values.TryAdd(_optionsSearch, options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, count, routeData); var model = new FeatureProfilesIndexViewModel { diff --git a/src/OrchardCore.Modules/OrchardCore.Themes/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Themes/Controllers/AdminController.cs index 1862947547f..991d42c8502 100644 --- a/src/OrchardCore.Modules/OrchardCore.Themes/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Themes/Controllers/AdminController.cs @@ -24,6 +24,7 @@ public class AdminController : Controller private readonly IShellFeaturesManager _shellFeaturesManager; private readonly IAuthorizationService _authorizationService; private readonly INotifier _notifier; + protected readonly IHtmlLocalizer H; public AdminController( @@ -39,7 +40,6 @@ public AdminController( _shellFeaturesManager = shellFeaturesManager; _authorizationService = authorizationService; _notifier = notifier; - H = localizer; } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AdminController.cs index f696343d4d4..4cf85f00353 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AdminController.cs @@ -30,21 +30,18 @@ namespace OrchardCore.Users.Controllers { [Admin("Users/{action}/{id?}", "Users{action}")] - public class AdminController : Controller + public class AdminController : Controller, IUpdateModel { private readonly UserManager _userManager; private readonly IDisplayManager _userOptionsDisplayManager; private readonly SignInManager _signInManager; private readonly ISession _session; private readonly IAuthorizationService _authorizationService; - private readonly PagerOptions _pagerOptions; private readonly IDisplayManager _userDisplayManager; private readonly INotifier _notifier; private readonly IUserService _userService; private readonly IRoleService _roleService; private readonly IUsersAdminListQueryService _usersAdminListQueryService; - private readonly IUpdateModelAccessor _updateModelAccessor; - private readonly IShapeFactory _shapeFactory; private readonly ILogger _logger; protected readonly IHtmlLocalizer H; @@ -61,12 +58,9 @@ public AdminController( IRoleService roleService, IUsersAdminListQueryService usersAdminListQueryService, INotifier notifier, - IOptions pagerOptions, - IShapeFactory shapeFactory, ILogger logger, IHtmlLocalizer htmlLocalizer, - IStringLocalizer stringLocalizer, - IUpdateModelAccessor updateModelAccessor) + IStringLocalizer stringLocalizer) { _userDisplayManager = userDisplayManager; _userOptionsDisplayManager = userOptionsDisplayManager; @@ -75,18 +69,19 @@ public AdminController( _session = session; _userManager = userManager; _notifier = notifier; - _pagerOptions = pagerOptions.Value; _userService = userService; _roleService = roleService; _usersAdminListQueryService = usersAdminListQueryService; - _updateModelAccessor = updateModelAccessor; - _shapeFactory = shapeFactory; _logger = logger; H = htmlLocalizer; S = stringLocalizer; } - public async Task Index([ModelBinder(BinderType = typeof(UserFilterEngineModelBinder), Name = "q")] QueryFilterResult queryFilterResult, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + [ModelBinder(BinderType = typeof(UserFilterEngineModelBinder), Name = "q")] QueryFilterResult queryFilterResult, + PagerParameters pagerParameters) { // Check a dummy user account to see if the current user has permission to view users. if (!await _authorizationService.AuthorizeAsync(User, CommonPermissions.ListUsers, new User())) @@ -97,13 +92,13 @@ public async Task Index([ModelBinder(BinderType = typeof(UserFilte var options = new UserIndexOptions { // Populate route values to maintain previous route data when generating page links - // await _userOptionsDisplayManager.UpdateEditorAsync(options, _updateModelAccessor.ModelUpdater, false); + // await _userOptionsDisplayManager.UpdateEditorAsync(options, this, false); FilterResult = queryFilterResult }; options.FilterResult.MapTo(options); // With the options populated we filter the query, allowing the filters to alter the options. - var users = await _usersAdminListQueryService.QueryAsync(options, _updateModelAccessor.ModelUpdater); + var users = await _usersAdminListQueryService.QueryAsync(options, this); // The search text is provided back to the UI. options.SearchText = options.FilterResult.ToString(); @@ -112,7 +107,7 @@ public async Task Index([ModelBinder(BinderType = typeof(UserFilte // Populate route values to maintain previous route data when generating page links. options.RouteValues.TryAdd("q", options.FilterResult.ToString()); - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var count = await users.CountAsync(); @@ -130,7 +125,7 @@ public async Task Index([ModelBinder(BinderType = typeof(UserFilte userEntries.Add(new UserEntry { UserId = user.UserId, - Shape = await _userDisplayManager.BuildDisplayAsync(user, updater: _updateModelAccessor.ModelUpdater, displayType: "SummaryAdmin") + Shape = await _userDisplayManager.BuildDisplayAsync(user, updater: this, displayType: "SummaryAdmin") }); } @@ -195,9 +190,9 @@ .. roleNames.Select(roleName => options.UsersCount = userEntries.Count; options.TotalItemCount = count; - var header = await _userOptionsDisplayManager.BuildEditorAsync(options, _updateModelAccessor.ModelUpdater, false, string.Empty, string.Empty); + var header = await _userOptionsDisplayManager.BuildEditorAsync(options, this, false, string.Empty, string.Empty); - var shapeViewModel = await _shapeFactory.CreateAsync("UsersAdminList", viewModel => + var shapeViewModel = await shapeFactory.CreateAsync("UsersAdminList", viewModel => { viewModel.Users = userEntries; viewModel.Pager = pagerShape; @@ -219,7 +214,7 @@ public async Task IndexFilterPOST(UserIndexOptions options) } // Evaluate the values provided in the form post and map them to the filter result and route values. - await _userOptionsDisplayManager.UpdateEditorAsync(options, _updateModelAccessor.ModelUpdater, false, string.Empty, string.Empty); + await _userOptionsDisplayManager.UpdateEditorAsync(options, this, false, string.Empty, string.Empty); // The route value must always be added after the editors have updated the models. options.RouteValues.TryAdd("q", options.FilterResult.ToString()); @@ -300,7 +295,7 @@ public async Task Create() return Forbid(); } - var shape = await _userDisplayManager.BuildEditorAsync(user, updater: _updateModelAccessor.ModelUpdater, isNew: true, string.Empty, string.Empty); + var shape = await _userDisplayManager.BuildEditorAsync(user, updater: this, isNew: true, string.Empty, string.Empty); return View(shape); } @@ -316,7 +311,7 @@ public async Task CreatePost([Bind(Prefix = "User.Password")] str return Forbid(); } - var shape = await _userDisplayManager.UpdateEditorAsync(user, updater: _updateModelAccessor.ModelUpdater, isNew: true, string.Empty, string.Empty); + var shape = await _userDisplayManager.UpdateEditorAsync(user, updater: this, isNew: true, string.Empty, string.Empty); if (!ModelState.IsValid) { @@ -359,7 +354,7 @@ public async Task Edit(string id, string returnUrl) return Forbid(); } - var shape = await _userDisplayManager.BuildEditorAsync(user, updater: _updateModelAccessor.ModelUpdater, isNew: false, string.Empty, string.Empty); + var shape = await _userDisplayManager.BuildEditorAsync(user, updater: this, isNew: false, string.Empty, string.Empty); ViewData["ReturnUrl"] = returnUrl; @@ -392,7 +387,7 @@ public async Task EditPost(string id, string returnUrl) return Forbid(); } - var shape = await _userDisplayManager.UpdateEditorAsync(user, updater: _updateModelAccessor.ModelUpdater, isNew: false, string.Empty, string.Empty); + var shape = await _userDisplayManager.UpdateEditorAsync(user, updater: this, isNew: false, string.Empty, string.Empty); if (!ModelState.IsValid) { @@ -448,7 +443,7 @@ public async Task Display(string id) return Forbid(); } - var model = await _userDisplayManager.BuildDisplayAsync(user, _updateModelAccessor.ModelUpdater, "DetailAdmin"); + var model = await _userDisplayManager.BuildDisplayAsync(user, this, "DetailAdmin"); return View(model); } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs index 965e620d918..9699f1daec8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs @@ -18,6 +18,7 @@ public class ChangeEmailController : Controller private readonly IUserService _userService; private readonly UserManager _userManager; private readonly ISiteService _siteService; + protected readonly IStringLocalizer S; public ChangeEmailController( diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs index fd8aee15ab5..c4b1355bcef 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs @@ -22,6 +22,7 @@ public class RegistrationController : Controller private readonly ISiteService _siteService; private readonly INotifier _notifier; private readonly ILogger _logger; + protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs index 31cb64985a1..16ffd788b30 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs @@ -24,6 +24,7 @@ public class ResetPasswordController : Controller private readonly ISiteService _siteService; private readonly IEnumerable _passwordRecoveryFormEvents; private readonly ILogger _logger; + protected readonly IStringLocalizer S; public ResetPasswordController( @@ -37,7 +38,6 @@ public ResetPasswordController( _userService = userService; _userManager = userManager; _siteService = siteService; - S = stringLocalizer; _logger = logger; _passwordRecoveryFormEvents = passwordRecoveryFormEvents; diff --git a/src/OrchardCore.Modules/OrchardCore.Widgets/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Widgets/Controllers/AdminController.cs index aa616ab6d58..b2fabe4e5d4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Widgets/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Widgets/Controllers/AdminController.cs @@ -11,26 +11,31 @@ namespace OrchardCore.Widgets.Controllers { [Admin("Widgets/{action}/{id?}", "Widgets.{action}")] - public class AdminController : Controller + public class AdminController : Controller, IUpdateModel { private readonly IContentManager _contentManager; private readonly IContentItemDisplayManager _contentItemDisplayManager; - private readonly IShapeFactory _shapeFactory; - private readonly IUpdateModelAccessor _updateModelAccessor; public AdminController( IContentManager contentManager, - IContentItemDisplayManager contentItemDisplayManager, - IShapeFactory shapeFactory, - IUpdateModelAccessor updateModelAccessor) + IContentItemDisplayManager contentItemDisplayManager) { _contentItemDisplayManager = contentItemDisplayManager; _contentManager = contentManager; - _shapeFactory = shapeFactory; - _updateModelAccessor = updateModelAccessor; } - public async Task BuildEditor(string id, string prefix, string prefixesName, string contentTypesName, string contentItemsName, string zonesName, string zone, string targetId, string parentContentType, string partName) + public async Task BuildEditor( + [FromServices] IShapeFactory shapeFactory, + string id, + string prefix, + string prefixesName, + string contentTypesName, + string contentItemsName, + string zonesName, + string zone, + string targetId, + string parentContentType, + string partName) { if (string.IsNullOrWhiteSpace(id)) { @@ -44,9 +49,9 @@ public async Task BuildEditor(string id, string prefix, string pr var cardCollectionType = nameof(WidgetsListPart); // Create a Card Shape - dynamic contentCard = await _shapeFactory.New.ContentCard( + dynamic contentCard = await shapeFactory.New.ContentCard( // Updater is the controller for AJAX Requests - Updater: _updateModelAccessor.ModelUpdater, + Updater: this, // Shape Specific CollectionShapeType: cardCollectionType, ContentItem: contentItem, diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/ActivityController.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/ActivityController.cs index 7624fe8362c..996545a23e8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/ActivityController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/ActivityController.cs @@ -14,7 +14,7 @@ namespace OrchardCore.Workflows.Controllers { [Admin] - public class ActivityController : Controller + public class ActivityController : Controller, IUpdateModel { private readonly ISession _session; private readonly IActivityLibrary _activityLibrary; @@ -23,7 +23,7 @@ public class ActivityController : Controller private readonly IAuthorizationService _authorizationService; private readonly IActivityDisplayManager _activityDisplayManager; private readonly INotifier _notifier; - private readonly IUpdateModelAccessor _updateModelAccessor; + protected readonly IHtmlLocalizer H; public ActivityController @@ -35,8 +35,7 @@ public ActivityController IAuthorizationService authorizationService, IActivityDisplayManager activityDisplayManager, INotifier notifier, - IHtmlLocalizer h, - IUpdateModelAccessor updateModelAccessor) + IHtmlLocalizer stringLocalizer) { _session = session; _activityLibrary = activityLibrary; @@ -45,8 +44,7 @@ public ActivityController _authorizationService = authorizationService; _activityDisplayManager = activityDisplayManager; _notifier = notifier; - _updateModelAccessor = updateModelAccessor; - H = h; + H = stringLocalizer; } [Admin("Workflows/Types/{workflowTypeId}/Activity/{activityName}/Add", "AddActivity")] @@ -59,7 +57,7 @@ public async Task Create(string activityName, long workflowTypeId var activity = _activityLibrary.InstantiateActivity(activityName); var activityId = _activityIdGenerator.GenerateUniqueId(new ActivityRecord()); - var activityEditor = await _activityDisplayManager.BuildEditorAsync(activity, _updateModelAccessor.ModelUpdater, isNew: true, "", ""); + var activityEditor = await _activityDisplayManager.BuildEditorAsync(activity, this, isNew: true, string.Empty, string.Empty); activityEditor.Metadata.Type = "Activity_Edit"; @@ -91,7 +89,7 @@ public async Task Create(string activityName, ActivityEditViewMod var workflowType = await _session.GetAsync(model.WorkflowTypeId); var activity = _activityLibrary.InstantiateActivity(activityName); - var activityEditor = await _activityDisplayManager.UpdateEditorAsync(activity, _updateModelAccessor.ModelUpdater, isNew: true, "", ""); + var activityEditor = await _activityDisplayManager.UpdateEditorAsync(activity, this, isNew: true, string.Empty, string.Empty); if (!ModelState.IsValid) { @@ -126,7 +124,7 @@ public async Task Edit(long workflowTypeId, string activityId, st var workflowType = await _session.GetAsync(workflowTypeId); var activityRecord = workflowType.Activities.Single(x => x.ActivityId == activityId); var activityContext = await _workflowManager.CreateActivityExecutionContextAsync(activityRecord, activityRecord.Properties); - var activityEditor = await _activityDisplayManager.BuildEditorAsync(activityContext.Activity, _updateModelAccessor.ModelUpdater, isNew: false, "", ""); + var activityEditor = await _activityDisplayManager.BuildEditorAsync(activityContext.Activity, this, isNew: false, string.Empty, string.Empty); activityEditor.Metadata.Type = "Activity_Edit"; @@ -153,7 +151,7 @@ public async Task Edit(ActivityEditViewModel model) var workflowType = await _session.GetAsync(model.WorkflowTypeId); var activityRecord = workflowType.Activities.Single(x => x.ActivityId == model.ActivityId); var activityContext = await _workflowManager.CreateActivityExecutionContextAsync(activityRecord, activityRecord.Properties); - var activityEditor = await _activityDisplayManager.UpdateEditorAsync(activityContext.Activity, _updateModelAccessor.ModelUpdater, isNew: false, "", ""); + var activityEditor = await _activityDisplayManager.UpdateEditorAsync(activityContext.Activity, this, isNew: false, string.Empty, string.Empty); if (!ModelState.IsValid) { diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/WorkflowController.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/WorkflowController.cs index 71409532e9b..a21dfc146c0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/WorkflowController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/WorkflowController.cs @@ -29,9 +29,8 @@ namespace OrchardCore.Workflows.Controllers { [Admin] - public class WorkflowController : Controller + public class WorkflowController : Controller, IUpdateModel { - private readonly PagerOptions _pagerOptions; private readonly ISession _session; private readonly IWorkflowManager _workflowManager; private readonly IWorkflowTypeStore _workflowTypeStore; @@ -39,29 +38,23 @@ public class WorkflowController : Controller private readonly IAuthorizationService _authorizationService; private readonly IActivityDisplayManager _activityDisplayManager; private readonly INotifier _notifier; - private readonly IUpdateModelAccessor _updateModelAccessor; - private readonly IShapeFactory _shapeFactory; private readonly IDistributedLock _distributedLock; protected readonly IHtmlLocalizer H; protected readonly IStringLocalizer S; public WorkflowController( - IOptions pagerOptions, ISession session, IWorkflowManager workflowManager, IWorkflowTypeStore workflowTypeStore, IWorkflowStore workflowStore, IAuthorizationService authorizationService, IActivityDisplayManager activityDisplayManager, - IShapeFactory shapeFactory, INotifier notifier, - IHtmlLocalizer htmlLocalizer, IDistributedLock distributedLock, - IStringLocalizer stringLocalizer, - IUpdateModelAccessor updateModelAccessor) + IHtmlLocalizer htmlLocalizer, + IStringLocalizer stringLocalizer) { - _pagerOptions = pagerOptions.Value; _session = session; _workflowManager = workflowManager; _workflowTypeStore = workflowTypeStore; @@ -69,15 +62,19 @@ public WorkflowController( _authorizationService = authorizationService; _activityDisplayManager = activityDisplayManager; _notifier = notifier; - _updateModelAccessor = updateModelAccessor; - _shapeFactory = shapeFactory; - H = htmlLocalizer; _distributedLock = distributedLock; + H = htmlLocalizer; S = stringLocalizer; } [Admin("Workflows/Types/{workflowTypeId}/Instances/{action}", "Workflows")] - public async Task Index(long workflowTypeId, WorkflowIndexViewModel model, PagerParameters pagerParameters, string returnUrl = null) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + long workflowTypeId, + WorkflowIndexViewModel model, + PagerParameters pagerParameters, + string returnUrl = null) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows)) { @@ -107,12 +104,12 @@ public async Task Index(long workflowTypeId, WorkflowIndexViewMod _ => query.OrderByDescending(x => x.CreatedUtc), }; - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); var routeData = new RouteData(); routeData.Values.Add("Filter", model.Options.Filter); - var pagerShape = await _shapeFactory.PagerAsync(pager, await query.CountAsync(), routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, await query.CountAsync(), routeData); var pageOfItems = await query.Skip(pager.GetStartIndex()).Take(pager.PageSize).ListAsync(); @@ -333,6 +330,7 @@ public async Task BulkEdit(long workflowTypeId, WorkflowIndexOpti private async Task BuildActivityDisplayAsync(ActivityContext activityContext, long workflowTypeId, bool isBlocking, string displayType) { var activityShape = await _activityDisplayManager.BuildDisplayAsync(activityContext.Activity, _updateModelAccessor.ModelUpdater, displayType); + activityShape.Metadata.Type = $"Activity_{displayType}ReadOnly"; activityShape.Properties["Activity"] = activityContext.Activity; activityShape.Properties["ActivityRecord"] = activityContext.ActivityRecord; diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/WorkflowTypeController.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/WorkflowTypeController.cs index c6258ce73b5..20ef94ea0fb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/WorkflowTypeController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Controllers/WorkflowTypeController.cs @@ -30,9 +30,8 @@ namespace OrchardCore.Workflows.Controllers { [Admin("Workflows/Types/{action}/{id?}", "WorkflowTypes{action}")] - public class WorkflowTypeController : Controller + public class WorkflowTypeController : Controller, IUpdateModel { - private readonly PagerOptions _pagerOptions; private readonly ISession _session; private readonly IActivityLibrary _activityLibrary; private readonly IWorkflowManager _workflowManager; @@ -42,15 +41,12 @@ public class WorkflowTypeController : Controller private readonly IActivityDisplayManager _activityDisplayManager; private readonly INotifier _notifier; private readonly ISecurityTokenService _securityTokenService; - private readonly IUpdateModelAccessor _updateModelAccessor; - private readonly IShapeFactory _shapeFactory; protected readonly IStringLocalizer S; protected readonly IHtmlLocalizer H; public WorkflowTypeController ( - IOptions pagerOptions, ISession session, IActivityLibrary activityLibrary, IWorkflowManager workflowManager, @@ -58,14 +54,11 @@ public WorkflowTypeController IWorkflowTypeIdGenerator workflowTypeIdGenerator, IAuthorizationService authorizationService, IActivityDisplayManager activityDisplayManager, - IShapeFactory shapeFactory, INotifier notifier, ISecurityTokenService securityTokenService, IStringLocalizer stringLocalizer, - IHtmlLocalizer htmlLocalizer, - IUpdateModelAccessor updateModelAccessor) + IHtmlLocalizer htmlLocalizer) { - _pagerOptions = pagerOptions.Value; _session = session; _activityLibrary = activityLibrary; _workflowManager = workflowManager; @@ -75,21 +68,23 @@ public WorkflowTypeController _activityDisplayManager = activityDisplayManager; _notifier = notifier; _securityTokenService = securityTokenService; - _updateModelAccessor = updateModelAccessor; - _shapeFactory = shapeFactory; S = stringLocalizer; H = htmlLocalizer; } [Admin("Workflows/Types", "WorkflowTypes")] - public async Task Index(WorkflowTypeIndexOptions options, PagerParameters pagerParameters) + public async Task Index( + [FromServices] IOptions pagerOptions, + [FromServices] IShapeFactory shapeFactory, + WorkflowTypeIndexOptions options, + PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows)) { return Forbid(); } - var pager = new Pager(pagerParameters, _pagerOptions.GetPageSize()); + var pager = new Pager(pagerParameters, pagerOptions.Value.GetPageSize()); options ??= new WorkflowTypeIndexOptions(); @@ -142,7 +137,7 @@ public async Task Index(WorkflowTypeIndexOptions options, PagerPa routeData.Values.TryAdd("Options.Search", options.Search); } - var pagerShape = await _shapeFactory.PagerAsync(pager, count, routeData); + var pagerShape = await shapeFactory.PagerAsync(pager, count, routeData); var model = new WorkflowTypeIndexViewModel { WorkflowTypes = workflowTypes @@ -516,6 +511,7 @@ private async Task BuildActivityDisplay(IActivity activity, int index, string localId, string displayType) { var activityShape = await _activityDisplayManager.BuildDisplayAsync(activity, _updateModelAccessor.ModelUpdater, displayType); + activityShape.Metadata.Type = $"Activity_{displayType}"; activityShape.Properties["Activity"] = activity; activityShape.Properties["WorkflowTypeId"] = workflowTypeId; @@ -533,6 +529,7 @@ private async Task BuildActivityDisplay(ActivityContext activityContext string localId, string displayType) { var activityShape = await _activityDisplayManager.BuildDisplayAsync(activityContext.Activity, _updateModelAccessor.ModelUpdater, displayType); + activityShape.Metadata.Type = $"Activity_{displayType}"; activityShape.Properties["Activity"] = activityContext.Activity; activityShape.Properties["ActivityRecord"] = activityContext.ActivityRecord; diff --git a/src/OrchardCore/OrchardCore.DisplayManagement.Abstractions/ModelBinding/IUpdateModelAccessor.cs b/src/OrchardCore/OrchardCore.DisplayManagement.Abstractions/ModelBinding/IUpdateModelAccessor.cs index 2adeb7df6ae..81c5dac17d0 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement.Abstractions/ModelBinding/IUpdateModelAccessor.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement.Abstractions/ModelBinding/IUpdateModelAccessor.cs @@ -1,7 +1,6 @@ -namespace OrchardCore.DisplayManagement.ModelBinding +namespace OrchardCore.DisplayManagement.ModelBinding; + +public interface IUpdateModelAccessor { - public interface IUpdateModelAccessor - { - IUpdateModel ModelUpdater { get; set; } - } + IUpdateModel ModelUpdater { get; set; } } diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/ModelBinding/ControllerModelUpdater.cs b/src/OrchardCore/OrchardCore.DisplayManagement/ModelBinding/ControllerModelUpdater.cs index f2ebe2dd9f9..5df476fb258 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/ModelBinding/ControllerModelUpdater.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/ModelBinding/ControllerModelUpdater.cs @@ -17,19 +17,22 @@ public ControllerModelUpdater(Controller controller) public ModelStateDictionary ModelState => _controller.ModelState; - public Task TryUpdateModelAsync(TModel model) where TModel : class + public Task TryUpdateModelAsync(TModel model) + where TModel : class { - return _controller.TryUpdateModelAsync(model); + return _controller.TryUpdateModelAsync(model); } - public Task TryUpdateModelAsync(TModel model, string prefix) where TModel : class + public Task TryUpdateModelAsync(TModel model, string prefix) + where TModel : class { - return _controller.TryUpdateModelAsync(model, prefix); + return _controller.TryUpdateModelAsync(model, prefix); } - public Task TryUpdateModelAsync(TModel model, string prefix, params Expression>[] includeExpressions) where TModel : class + public Task TryUpdateModelAsync(TModel model, string prefix, params Expression>[] includeExpressions) + where TModel : class { - return _controller.TryUpdateModelAsync(model, prefix, includeExpressions); + return _controller.TryUpdateModelAsync(model, prefix, includeExpressions); } public bool TryValidateModel(object model) diff --git a/test/OrchardCore.Tests/Modules/OrchardCore.OpenId/ApplicationControllerTests.cs b/test/OrchardCore.Tests/Modules/OrchardCore.OpenId/ApplicationControllerTests.cs index da001c03095..772888314d5 100644 --- a/test/OrchardCore.Tests/Modules/OrchardCore.OpenId/ApplicationControllerTests.cs +++ b/test/OrchardCore.Tests/Modules/OrchardCore.OpenId/ApplicationControllerTests.cs @@ -1,7 +1,5 @@ -using OrchardCore.DisplayManagement; using OrchardCore.DisplayManagement.Notify; using OrchardCore.Environment.Shell.Descriptor.Models; -using OrchardCore.Navigation; using OrchardCore.OpenId.Abstractions.Managers; using OrchardCore.OpenId.Controllers; using OrchardCore.OpenId.ViewModels; @@ -14,8 +12,6 @@ public class ApplicationControllerTests public async Task UsersShouldNotBeAbleToCreateIfNotAllowed() { var controller = new ApplicationController( - Mock.Of(), - Mock.Of>(), Mock.Of>(), Mock.Of(), Mock.Of(), @@ -35,8 +31,6 @@ public async Task UsersShouldBeAbleToCreateApplicationIfAllowed() var mockData = Array.Empty(); mockOpenIdScopeManager.Setup(m => m.ListAsync(null, null, default)).Returns(mockData.ToAsyncEnumerable()); var controller = new ApplicationController( - Mock.Of(), - Mock.Of>(), Mock.Of>(), MockAuthorizationServiceMock().Object, Mock.Of(), @@ -60,8 +54,6 @@ public async Task UsersShouldBeAbleToCreateApplicationIfAllowed() public async Task ConfidentionalClientNeedsSecret(string clientType, string clientSecret, bool allowAuthFlow, bool allowPasswordFlow, bool expectValidModel) { var controller = new ApplicationController( - Mock.Of(), - Mock.Of>(), MockStringLocalizer().Object, MockAuthorizationServiceMock().Object, Mock.Of(), @@ -101,8 +93,6 @@ public async Task RedirectUrisAreValid(string uris, bool expectValidModel) { // Arrange var controller = new ApplicationController( - Mock.Of(), - Mock.Of>(), MockStringLocalizer().Object, MockAuthorizationServiceMock().Object, Mock.Of(),