From 5afc509d5e4c617212cdddb43f64d24cbdb2d72f Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 20 Apr 2021 14:26:25 +0200 Subject: [PATCH] Fix member cached macros and change macro rendering to be async --- src/Umbraco.Core/Macros/IMacroRenderer.cs | 3 +- .../Security/IMemberUserKeyProvider.cs | 7 --- .../Templates/IUmbracoComponentRenderer.cs | 8 ++-- .../Templates/UmbracoComponentRenderer.cs | 16 +++---- .../RteMacroRenderingValueConverter.cs | 4 +- .../cypress/integration/Settings/templates.ts | 2 +- .../Controllers/MacroRenderingController.cs | 15 +++--- .../UmbracoBuilderExtensions.cs | 2 - .../Macros/MacroRenderer.cs | 46 ++++++++++--------- .../Macros/MemberUserKeyProvider.cs | 14 ------ src/Umbraco.Web.Common/UmbracoHelper.cs | 12 ++--- .../src/common/services/macro.service.js | 32 ++++++------- .../common/services/macro-service.spec.js | 12 ++--- .../Views/Partials/grid/editors/macro.cshtml | 2 +- .../Macros/MemberUserKeyProvider.cs | 17 ------- src/Umbraco.Web/Umbraco.Web.csproj | 1 - src/Umbraco.Web/UmbracoHelper.cs | 6 +-- 17 files changed, 82 insertions(+), 117 deletions(-) delete mode 100644 src/Umbraco.Core/Security/IMemberUserKeyProvider.cs delete mode 100644 src/Umbraco.Web.Common/Macros/MemberUserKeyProvider.cs delete mode 100644 src/Umbraco.Web/Macros/MemberUserKeyProvider.cs diff --git a/src/Umbraco.Core/Macros/IMacroRenderer.cs b/src/Umbraco.Core/Macros/IMacroRenderer.cs index a969946340..96d450c1e3 100644 --- a/src/Umbraco.Core/Macros/IMacroRenderer.cs +++ b/src/Umbraco.Core/Macros/IMacroRenderer.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading.Tasks; using Umbraco.Cms.Core.Models.PublishedContent; namespace Umbraco.Cms.Core.Macros @@ -8,6 +9,6 @@ namespace Umbraco.Cms.Core.Macros /// public interface IMacroRenderer { - MacroContent Render(string macroAlias, IPublishedContent content, IDictionary macroParams); + Task RenderAsync(string macroAlias, IPublishedContent content, IDictionary macroParams); } } diff --git a/src/Umbraco.Core/Security/IMemberUserKeyProvider.cs b/src/Umbraco.Core/Security/IMemberUserKeyProvider.cs deleted file mode 100644 index 9808ecc9b6..0000000000 --- a/src/Umbraco.Core/Security/IMemberUserKeyProvider.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Umbraco.Cms.Core.Security -{ - public interface IMemberUserKeyProvider - { - object GetMemberProviderUserKey(); - } -} diff --git a/src/Umbraco.Core/Templates/IUmbracoComponentRenderer.cs b/src/Umbraco.Core/Templates/IUmbracoComponentRenderer.cs index a150337095..f67ab0a729 100644 --- a/src/Umbraco.Core/Templates/IUmbracoComponentRenderer.cs +++ b/src/Umbraco.Core/Templates/IUmbracoComponentRenderer.cs @@ -22,7 +22,7 @@ namespace Umbraco.Cms.Core.Templates /// /// The content id /// The alias. - IHtmlEncodedString RenderMacro(int contentId, string alias); + Task RenderMacroAsync(int contentId, string alias); /// /// Renders the macro with the specified alias, passing in the specified parameters. @@ -30,7 +30,7 @@ namespace Umbraco.Cms.Core.Templates /// The content id /// The alias. /// The parameters. - IHtmlEncodedString RenderMacro(int contentId, string alias, object parameters); + Task RenderMacroAsync(int contentId, string alias, object parameters); /// /// Renders the macro with the specified alias, passing in the specified parameters. @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Templates /// The content id /// The alias. /// The parameters. - IHtmlEncodedString RenderMacro(int contentId, string alias, IDictionary parameters); + Task RenderMacroAsync(int contentId, string alias, IDictionary parameters); /// /// Renders the macro with the specified alias, passing in the specified parameters. @@ -51,7 +51,7 @@ namespace Umbraco.Cms.Core.Templates /// Currently only used when the node is unpublished and unable to get the contentId item from the /// content cache as its unpublished. This deals with taking in a preview/draft version of the content node /// - IHtmlEncodedString RenderMacroForContent(IPublishedContent content, string alias, IDictionary parameters); + Task RenderMacroForContent(IPublishedContent content, string alias, IDictionary parameters); } } diff --git a/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs b/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs index 510fa70bcf..a440876b8f 100644 --- a/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs +++ b/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs @@ -54,13 +54,13 @@ namespace Umbraco.Cms.Core.Templates } /// - public IHtmlEncodedString RenderMacro(int contentId, string alias) => RenderMacro(contentId, alias, new { }); + public async Task RenderMacroAsync(int contentId, string alias) => await RenderMacroAsync(contentId, alias, new { }); /// - public IHtmlEncodedString RenderMacro(int contentId, string alias, object parameters) => RenderMacro(contentId, alias, parameters?.ToDictionary()); + public async Task RenderMacroAsync(int contentId, string alias, object parameters) => await RenderMacroAsync(contentId, alias, parameters?.ToDictionary()); /// - public IHtmlEncodedString RenderMacro(int contentId, string alias, IDictionary parameters) + public async Task RenderMacroAsync(int contentId, string alias, IDictionary parameters) { if (contentId == default) { @@ -74,24 +74,24 @@ namespace Umbraco.Cms.Core.Templates throw new InvalidOperationException("Cannot render a macro, no content found by id " + contentId); } - return RenderMacro(content, alias, parameters); + return await RenderMacroAsync(content, alias, parameters); } /// - public IHtmlEncodedString RenderMacroForContent(IPublishedContent content, string alias, IDictionary parameters) + public async Task RenderMacroForContent(IPublishedContent content, string alias, IDictionary parameters) { if(content == null) { throw new InvalidOperationException("Cannot render a macro, IPublishedContent is null"); } - return RenderMacro(content, alias, parameters); + return await RenderMacroAsync(content, alias, parameters); } /// /// Renders the macro with the specified alias, passing in the specified parameters. /// - private IHtmlEncodedString RenderMacro(IPublishedContent content, string alias, IDictionary parameters) + private async Task RenderMacroAsync(IPublishedContent content, string alias, IDictionary parameters) { if (content == null) { @@ -104,7 +104,7 @@ namespace Umbraco.Cms.Core.Templates x => x.Key.ToLowerInvariant(), i => (i.Value is string) ? WebUtility.HtmlDecode(i.Value.ToString()) : i.Value); - var html = _macroRenderer.Render(alias, content, macroProps).Text; + var html = (await _macroRenderer.RenderAsync(alias, content, macroProps)).Text; return new HtmlEncodedString(html); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs index dd5bb30722..d3ed87be24 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs @@ -60,11 +60,11 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters //callback for when text block is found textBlock => sb.Append(textBlock), //callback for when macro syntax is found - (macroAlias, macroAttributes) => sb.Append(_macroRenderer.Render( + (macroAlias, macroAttributes) => sb.Append(_macroRenderer.RenderAsync( macroAlias, umbracoContext.PublishedRequest?.PublishedContent, //needs to be explicitly casted to Dictionary - macroAttributes.ConvertTo(x => (string)x, x => x)).Text)); + macroAttributes.ConvertTo(x => (string)x, x => x)).GetAwaiter().GetResult().Text)); return sb.ToString(); } diff --git a/src/Umbraco.Tests.AcceptanceTest/cypress/integration/Settings/templates.ts b/src/Umbraco.Tests.AcceptanceTest/cypress/integration/Settings/templates.ts index e4bb989f75..f73174f531 100644 --- a/src/Umbraco.Tests.AcceptanceTest/cypress/integration/Settings/templates.ts +++ b/src/Umbraco.Tests.AcceptanceTest/cypress/integration/Settings/templates.ts @@ -139,7 +139,7 @@ context('Templates', () => { cy.get('.umb-card-grid-item').contains(name).click(); // Assert - cy.get('.ace_content').contains('@Umbraco.RenderMacro("' + name + '")').should('exist'); + cy.get('.ace_content').contains('@await Umbraco.RenderMacroAsync("' + name + '")').should('exist'); // Clean cy.umbracoEnsureTemplateNameNotExists(name); diff --git a/src/Umbraco.Web.BackOffice/Controllers/MacroRenderingController.cs b/src/Umbraco.Web.BackOffice/Controllers/MacroRenderingController.cs index 460bd4a8a8..2508e9f4dd 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/MacroRenderingController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/MacroRenderingController.cs @@ -4,7 +4,9 @@ using System.Globalization; using System.Linq; using System.Text; using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Mapping; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.ContentEditing; @@ -16,7 +18,6 @@ using Umbraco.Cms.Core.Templates; using Umbraco.Cms.Core.Web; using Umbraco.Cms.Web.Common.Attributes; using Umbraco.Extensions; -using Constants = Umbraco.Cms.Core.Constants; namespace Umbraco.Cms.Web.BackOffice.Controllers { @@ -86,9 +87,9 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers /// /// [HttpGet] - public IActionResult GetMacroResultAsHtmlForEditor(string macroAlias, int pageId, [FromQuery] IDictionary macroParams) + public async Task GetMacroResultAsHtmlForEditor(string macroAlias, int pageId, [FromQuery] IDictionary macroParams) { - return GetMacroResultAsHtml(macroAlias, pageId, macroParams); + return await GetMacroResultAsHtml(macroAlias, pageId, macroParams); } /// @@ -99,9 +100,9 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers /// /// [HttpPost] - public IActionResult GetMacroResultAsHtmlForEditor(MacroParameterModel model) + public async Task GetMacroResultAsHtmlForEditor(MacroParameterModel model) { - return GetMacroResultAsHtml(model.MacroAlias, model.PageId, model.MacroParams); + return await GetMacroResultAsHtml(model.MacroAlias, model.PageId, model.MacroParams); } public class MacroParameterModel @@ -111,7 +112,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers public IDictionary MacroParams { get; set; } } - private IActionResult GetMacroResultAsHtml(string macroAlias, int pageId, IDictionary macroParams) + private async Task GetMacroResultAsHtml(string macroAlias, int pageId, IDictionary macroParams) { var m = _macroService.GetByAlias(macroAlias); if (m == null) @@ -150,7 +151,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers { //need to create a specific content result formatted as HTML since this controller has been configured //with only json formatters. - return Content(_componentRenderer.RenderMacroForContent(publishedContent, m.Alias, macroParams).ToString(), "text/html", + return Content((await _componentRenderer.RenderMacroForContent(publishedContent, m.Alias, macroParams)).ToString(), "text/html", Encoding.UTF8); } } diff --git a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs index 5f2326fd5d..fc3c806b22 100644 --- a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.ApplicationModels; -using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -287,7 +286,6 @@ namespace Umbraco.Extensions builder.Services.AddUnique(); builder.Services.AddUnique(); - builder.Services.AddUnique(); // register the umbraco context factory diff --git a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs index 0b2b2e6625..9910065afd 100644 --- a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core; @@ -26,57 +28,51 @@ namespace Umbraco.Cms.Web.Common.Macros private readonly IProfilingLogger _profilingLogger; private readonly ILogger _logger; private readonly IUmbracoContextAccessor _umbracoContextAccessor; - private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; private readonly ContentSettings _contentSettings; private readonly ILocalizedTextService _textService; private readonly AppCaches _appCaches; private readonly IMacroService _macroService; private readonly IHostingEnvironment _hostingEnvironment; private readonly ICookieManager _cookieManager; - private readonly IMemberUserKeyProvider _memberUserKeyProvider; private readonly ISessionManager _sessionManager; private readonly IRequestAccessor _requestAccessor; - private readonly IHttpContextAccessor _httpContextAccessor; private readonly PartialViewMacroEngine _partialViewMacroEngine; + private readonly IHttpContextAccessor _httpContextAccessor; public MacroRenderer( IProfilingLogger profilingLogger, ILogger logger, IUmbracoContextAccessor umbracoContextAccessor, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, IOptions contentSettings, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, IHostingEnvironment hostingEnvironment, ICookieManager cookieManager, - IMemberUserKeyProvider memberUserKeyProvider, ISessionManager sessionManager, IRequestAccessor requestAccessor, - IHttpContextAccessor httpContextAccessor, - PartialViewMacroEngine partialViewMacroEngine) + PartialViewMacroEngine partialViewMacroEngine, + IHttpContextAccessor httpContextAccessor) { _profilingLogger = profilingLogger ?? throw new ArgumentNullException(nameof(profilingLogger)); _logger = logger; _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); - _backOfficeSecurityAccessor = backOfficeSecurityAccessor; _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); _textService = textService; _appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); _macroService = macroService ?? throw new ArgumentNullException(nameof(macroService)); _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); _cookieManager = cookieManager; - _memberUserKeyProvider = memberUserKeyProvider; _sessionManager = sessionManager; _requestAccessor = requestAccessor; - _httpContextAccessor = httpContextAccessor; _partialViewMacroEngine = partialViewMacroEngine; + _httpContextAccessor = httpContextAccessor; } #region MacroContent cache // gets this macro content cache identifier - private string GetContentCacheIdentifier(MacroModel model, int pageId, string cultureName) + private async Task GetContentCacheIdentifier(MacroModel model, int pageId, string cultureName) { var id = new StringBuilder(); @@ -96,9 +92,14 @@ namespace Umbraco.Cms.Web.Common.Macros { object key = 0; - if (_backOfficeSecurityAccessor.BackOfficeSecurity.IsAuthenticated()) + if (_httpContextAccessor.HttpContext?.User?.Identity?.IsAuthenticated ?? false) { - key = _memberUserKeyProvider.GetMemberProviderUserKey() ?? 0; + var memberManager = _httpContextAccessor.HttpContext.RequestServices.GetRequiredService(); + var member = await memberManager.GetCurrentMemberAsync(); + if (member is not null) + { + key = member.Key; + } } id.AppendFormat("m{0}-", key); @@ -148,7 +149,7 @@ namespace Umbraco.Cms.Web.Common.Macros } // stores macro content into the cache - private void AddMacroContentToCache(MacroModel model, MacroContent macroContent) + private async Task AddMacroContentToCacheAsync(MacroModel model, MacroContent macroContent) { // only if cache is enabled if (_umbracoContextAccessor.UmbracoContext.InPreviewMode || model.CacheDuration <= 0) @@ -161,9 +162,12 @@ namespace Umbraco.Cms.Web.Common.Macros // do not cache if it should cache by member and there's not member if (model.CacheByMember) { - var key = _memberUserKeyProvider.GetMemberProviderUserKey(); - if (key is null) + var memberManager = _httpContextAccessor.HttpContext.RequestServices.GetRequiredService(); + var member = await memberManager.GetCurrentMemberAsync(); + if (member is null) + { return; + } } // remember when we cache the content @@ -219,7 +223,7 @@ namespace Umbraco.Cms.Web.Common.Macros #region Render/Execute - public MacroContent Render(string macroAlias, IPublishedContent content, IDictionary macroParams) + public async Task RenderAsync(string macroAlias, IPublishedContent content, IDictionary macroParams) { var m = _appCaches.RuntimeCache.GetCacheItem(CacheKeys.MacroFromAliasCacheKey + macroAlias, () => _macroService.GetByAlias(macroAlias)); @@ -229,10 +233,10 @@ namespace Umbraco.Cms.Web.Common.Macros var macro = new MacroModel(m); UpdateMacroModelProperties(macro, macroParams); - return Render(macro, content); + return await RenderAsync(macro, content); } - private MacroContent Render(MacroModel macro, IPublishedContent content) + private async Task RenderAsync(MacroModel macro, IPublishedContent content) { if (content == null) throw new ArgumentNullException(nameof(content)); @@ -245,7 +249,7 @@ namespace Umbraco.Cms.Web.Common.Macros prop.Value = ParseAttribute(prop.Value); var cultureName = System.Threading.Thread.CurrentThread.CurrentUICulture.Name; - macro.CacheIdentifier = GetContentCacheIdentifier(macro, content.Id, cultureName); + macro.CacheIdentifier = await GetContentCacheIdentifier(macro, content.Id, cultureName); // get the macro from cache if it is there var macroContent = GetMacroContentFromCache(macro); @@ -272,7 +276,7 @@ namespace Umbraco.Cms.Web.Common.Macros if (attempt.Success) { // write to cache (if appropriate) - AddMacroContentToCache(macro, macroContent); + await AddMacroContentToCacheAsync(macro, macroContent); } return macroContent; diff --git a/src/Umbraco.Web.Common/Macros/MemberUserKeyProvider.cs b/src/Umbraco.Web.Common/Macros/MemberUserKeyProvider.cs deleted file mode 100644 index 0d9fce3fc7..0000000000 --- a/src/Umbraco.Web.Common/Macros/MemberUserKeyProvider.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Umbraco.Cms.Core.Security; - -namespace Umbraco.Cms.Web.Common.Macros -{ - internal class MemberUserKeyProvider : IMemberUserKeyProvider - { - public object GetMemberProviderUserKey() - { - // TODO Implement - - return string.Empty; - } - } -} diff --git a/src/Umbraco.Web.Common/UmbracoHelper.cs b/src/Umbraco.Web.Common/UmbracoHelper.cs index 266f719a8b..48de01b74c 100644 --- a/src/Umbraco.Web.Common/UmbracoHelper.cs +++ b/src/Umbraco.Web.Common/UmbracoHelper.cs @@ -107,9 +107,9 @@ namespace Umbraco.Cms.Web.Common /// /// The alias. /// - public IHtmlEncodedString RenderMacro(string alias) + public async Task RenderMacroAsync(string alias) { - return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, null); + return await _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, null); } /// @@ -118,9 +118,9 @@ namespace Umbraco.Cms.Web.Common /// The alias. /// The parameters. /// - public IHtmlEncodedString RenderMacro(string alias, object parameters) + public async Task RenderMacroAsync(string alias, object parameters) { - return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, parameters?.ToDictionary()); + return await _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, parameters?.ToDictionary()); } /// @@ -129,9 +129,9 @@ namespace Umbraco.Cms.Web.Common /// The alias. /// The parameters. /// - public IHtmlEncodedString RenderMacro(string alias, IDictionary parameters) + public async Task RenderMacroAsync(string alias, IDictionary parameters) { - return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, parameters); + return await _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, parameters); } #endregion diff --git a/src/Umbraco.Web.UI.Client/src/common/services/macro.service.js b/src/Umbraco.Web.UI.Client/src/common/services/macro.service.js index 5b79b9c327..139418f1c9 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/macro.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/macro.service.js @@ -2,17 +2,17 @@ * @ngdoc service * @name umbraco.services.macroService * - * + * * @description * A service to return macro information such as generating syntax to insert a macro into an editor */ function macroService() { return { - + /** parses the special macro syntax like and returns an object with the macro alias and it's parameters */ parseMacroSyntax: function (syntax) { - + //This regex will match an alias of anything except characters that are quotes or new lines (for legacy reasons, when new macros are created // their aliases are cleaned an invalid chars are stripped) var expression = /(<\?UMBRACO_MACRO (?:.+?)?macroAlias=["']([^\"\'\n\r]+?)["'][\s\S]+?)(\/>|>.*?<\/\?UMBRACO_MACRO>)/i; @@ -24,9 +24,9 @@ function macroService() { //this will leave us with just the parameters var paramsChunk = match[1].trim().replace(new RegExp("UMBRACO_MACRO macroAlias=[\"']" + alias + "[\"']"), "").trim(); - + var paramExpression = /(\w+?)=['\"]([\s\S]*?)['\"]/g; - + var paramMatch; var returnVal = { macroAlias: alias, @@ -42,11 +42,11 @@ function macroService() { * @ngdoc function * @name umbraco.services.macroService#generateMacroSyntax * @methodOf umbraco.services.macroService - * @function + * @function * * @description * generates the syntax for inserting a macro into a rich text editor - this is the very old umbraco style syntax - * + * * @param {object} args an object containing the macro alias and it's parameter values */ generateMacroSyntax: function (args) { @@ -72,7 +72,7 @@ function macroService() { var encoded = encodeURIComponent(json); keyVal = key + "=\"" + encoded + "\" "; } - + macroString += keyVal; }); @@ -82,38 +82,38 @@ function macroService() { return macroString; }, - + /** * @ngdoc function * @name umbraco.services.macroService#generateMvcSyntax * @methodOf umbraco.services.macroService - * @function + * @function * * @description * generates the syntax for inserting a macro into an mvc template - * + * * @param {object} args an object containing the macro alias and it's parameter values */ generateMvcSyntax: function (args) { - var macroString = "@Umbraco.RenderMacro(\"" + args.macroAlias + "\""; + var macroString = "@await Umbraco.RenderMacroAsync(\"" + args.macroAlias + "\""; var hasParams = false; var paramString; if (args.macroParamsDictionary) { - + paramString = ", new {"; _.each(args.macroParamsDictionary, function(val, key) { hasParams = true; - + var keyVal = key + "=\"" + (val ? val : "") + "\", "; paramString += keyVal; }); - - //remove the last , + + //remove the last , paramString = paramString.trimEnd(", "); paramString += "}"; diff --git a/src/Umbraco.Web.UI.Client/test/unit/common/services/macro-service.spec.js b/src/Umbraco.Web.UI.Client/test/unit/common/services/macro-service.spec.js index 3f92236169..c319c3b524 100644 --- a/src/Umbraco.Web.UI.Client/test/unit/common/services/macro-service.spec.js +++ b/src/Umbraco.Web.UI.Client/test/unit/common/services/macro-service.spec.js @@ -62,7 +62,7 @@ describe('macro service tests', function () { expect(result.macroParamsDictionary.test2).not.toBeUndefined(); expect(result.macroParamsDictionary.test2).toBe("hello"); }); - + it('can parse syntax for macros with body', function () { var result = macroService.parseMacroSyntax(""); @@ -108,7 +108,7 @@ describe('macro service tests', function () { toBe(""); }); - + it('can generate syntax for MVC', function () { var syntax = macroService.generateMvcSyntax({ @@ -121,11 +121,11 @@ describe('macro service tests', function () { }); expect(syntax). - toBe("@Umbraco.RenderMacro(\"myMacro\", new {param1=\"value1\", param2=\"value2\", param3=\"value3\"})"); + toBe("@await Umbraco.RenderMacroAsync(\"myMacro\", new {param1=\"value1\", param2=\"value2\", param3=\"value3\"})"); + - }); - + it('can generate syntax for MVC with no params', function () { var syntax = macroService.generateMvcSyntax({ @@ -134,7 +134,7 @@ describe('macro service tests', function () { }); expect(syntax). - toBe("@Umbraco.RenderMacro(\"myMacro\")"); + toBe("@await Umbraco.RenderMacroAsync(\"myMacro\")"); }); diff --git a/src/Umbraco.Web.UI.NetCore/Views/Partials/grid/editors/macro.cshtml b/src/Umbraco.Web.UI.NetCore/Views/Partials/grid/editors/macro.cshtml index 8543d00209..0e9661edd9 100644 --- a/src/Umbraco.Web.UI.NetCore/Views/Partials/grid/editors/macro.cshtml +++ b/src/Umbraco.Web.UI.NetCore/Views/Partials/grid/editors/macro.cshtml @@ -10,6 +10,6 @@ } - @Umbraco.RenderMacro(macroAlias, parameters) + @await Umbraco.RenderMacroAsync(macroAlias, parameters) } diff --git a/src/Umbraco.Web/Macros/MemberUserKeyProvider.cs b/src/Umbraco.Web/Macros/MemberUserKeyProvider.cs deleted file mode 100644 index c1fc422969..0000000000 --- a/src/Umbraco.Web/Macros/MemberUserKeyProvider.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Umbraco.Cms.Core.Security; -using Umbraco.Web.Security; - -namespace Umbraco.Web.Macros -{ - internal class MemberUserKeyProvider : IMemberUserKeyProvider - { - public object GetMemberProviderUserKey() - { - //ugh, membershipproviders :( - var provider = MembershipProviderExtensions.GetMembersMembershipProvider(); - var member = MembershipProviderExtensions.GetCurrentUser(provider); - - return member?.ProviderUserKey; - } - } -} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 60299a9b34..de98dfedb9 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -136,7 +136,6 @@ - diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index f7f6374ea4..849d378b4c 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -120,7 +120,7 @@ namespace Umbraco.Web /// public IHtmlEncodedString RenderMacro(string alias) { - return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, null); + return _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, null).GetAwaiter().GetResult(); } /// @@ -131,7 +131,7 @@ namespace Umbraco.Web /// public IHtmlEncodedString RenderMacro(string alias, object parameters) { - return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, parameters?.ToDictionary()); + return _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, parameters?.ToDictionary()).GetAwaiter().GetResult(); } /// @@ -142,7 +142,7 @@ namespace Umbraco.Web /// public IHtmlEncodedString RenderMacro(string alias, IDictionary parameters) { - return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, parameters); + return _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, parameters).GetAwaiter().GetResult(); } #endregion