Merge remote-tracking branch 'origin/netcore/dev' into netcore/dev
This commit is contained in:
@@ -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
|
||||
/// </summary>
|
||||
public interface IMacroRenderer
|
||||
{
|
||||
MacroContent Render(string macroAlias, IPublishedContent content, IDictionary<string, object> macroParams);
|
||||
Task<MacroContent> RenderAsync(string macroAlias, IPublishedContent content, IDictionary<string, object> macroParams);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Umbraco.Cms.Core.Security
|
||||
{
|
||||
public interface IMemberUserKeyProvider
|
||||
{
|
||||
object GetMemberProviderUserKey();
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace Umbraco.Cms.Core.Templates
|
||||
/// </summary>
|
||||
/// <param name="contentId">The content id</param>
|
||||
/// <param name="alias">The alias.</param>
|
||||
IHtmlEncodedString RenderMacro(int contentId, string alias);
|
||||
Task<IHtmlEncodedString> RenderMacroAsync(int contentId, string alias);
|
||||
|
||||
/// <summary>
|
||||
/// Renders the macro with the specified alias, passing in the specified parameters.
|
||||
@@ -30,7 +30,7 @@ namespace Umbraco.Cms.Core.Templates
|
||||
/// <param name="contentId">The content id</param>
|
||||
/// <param name="alias">The alias.</param>
|
||||
/// <param name="parameters">The parameters.</param>
|
||||
IHtmlEncodedString RenderMacro(int contentId, string alias, object parameters);
|
||||
Task<IHtmlEncodedString> RenderMacroAsync(int contentId, string alias, object parameters);
|
||||
|
||||
/// <summary>
|
||||
/// Renders the macro with the specified alias, passing in the specified parameters.
|
||||
@@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Templates
|
||||
/// <param name="contentId">The content id</param>
|
||||
/// <param name="alias">The alias.</param>
|
||||
/// <param name="parameters">The parameters.</param>
|
||||
IHtmlEncodedString RenderMacro(int contentId, string alias, IDictionary<string, object> parameters);
|
||||
Task<IHtmlEncodedString> RenderMacroAsync(int contentId, string alias, IDictionary<string, object> parameters);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </remarks>
|
||||
IHtmlEncodedString RenderMacroForContent(IPublishedContent content, string alias, IDictionary<string, object> parameters);
|
||||
Task<IHtmlEncodedString> RenderMacroForContent(IPublishedContent content, string alias, IDictionary<string, object> parameters);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,13 +54,13 @@ namespace Umbraco.Cms.Core.Templates
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IHtmlEncodedString RenderMacro(int contentId, string alias) => RenderMacro(contentId, alias, new { });
|
||||
public async Task<IHtmlEncodedString> RenderMacroAsync(int contentId, string alias) => await RenderMacroAsync(contentId, alias, new { });
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IHtmlEncodedString RenderMacro(int contentId, string alias, object parameters) => RenderMacro(contentId, alias, parameters?.ToDictionary<object>());
|
||||
public async Task<IHtmlEncodedString> RenderMacroAsync(int contentId, string alias, object parameters) => await RenderMacroAsync(contentId, alias, parameters?.ToDictionary<object>());
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IHtmlEncodedString RenderMacro(int contentId, string alias, IDictionary<string, object> parameters)
|
||||
public async Task<IHtmlEncodedString> RenderMacroAsync(int contentId, string alias, IDictionary<string, object> 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);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IHtmlEncodedString RenderMacroForContent(IPublishedContent content, string alias, IDictionary<string, object> parameters)
|
||||
public async Task<IHtmlEncodedString> RenderMacroForContent(IPublishedContent content, string alias, IDictionary<string, object> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the macro with the specified alias, passing in the specified parameters.
|
||||
/// </summary>
|
||||
private IHtmlEncodedString RenderMacro(IPublishedContent content, string alias, IDictionary<string, object> parameters)
|
||||
private async Task<IHtmlEncodedString> RenderMacroAsync(IPublishedContent content, string alias, IDictionary<string, object> 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);
|
||||
}
|
||||
|
||||
@@ -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<string, object>
|
||||
macroAttributes.ConvertTo(x => (string)x, x => x)).Text));
|
||||
macroAttributes.ConvertTo(x => (string)x, x => x)).GetAwaiter().GetResult().Text));
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult GetMacroResultAsHtmlForEditor(string macroAlias, int pageId, [FromQuery] IDictionary<string, object> macroParams)
|
||||
public async Task<IActionResult> GetMacroResultAsHtmlForEditor(string macroAlias, int pageId, [FromQuery] IDictionary<string, object> macroParams)
|
||||
{
|
||||
return GetMacroResultAsHtml(macroAlias, pageId, macroParams);
|
||||
return await GetMacroResultAsHtml(macroAlias, pageId, macroParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,9 +100,9 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetMacroResultAsHtmlForEditor(MacroParameterModel model)
|
||||
public async Task<IActionResult> 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<string, object> MacroParams { get; set; }
|
||||
}
|
||||
|
||||
private IActionResult GetMacroResultAsHtml(string macroAlias, int pageId, IDictionary<string, object> macroParams)
|
||||
private async Task<IActionResult> GetMacroResultAsHtml(string macroAlias, int pageId, IDictionary<string, object> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<IMacroRenderer, MacroRenderer>();
|
||||
builder.Services.AddUnique<PartialViewMacroEngine>();
|
||||
builder.Services.AddUnique<IMemberUserKeyProvider, MemberUserKeyProvider>();
|
||||
|
||||
// register the umbraco context factory
|
||||
|
||||
|
||||
@@ -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<MacroRenderer> _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<MacroRenderer> logger,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
|
||||
IOptions<ContentSettings> 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<string> 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<IMemberManager>();
|
||||
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<IMemberManager>();
|
||||
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<string, object> macroParams)
|
||||
public async Task<MacroContent> RenderAsync(string macroAlias, IPublishedContent content, IDictionary<string, object> 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<MacroContent> 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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,9 +107,9 @@ namespace Umbraco.Cms.Web.Common
|
||||
/// </summary>
|
||||
/// <param name="alias">The alias.</param>
|
||||
/// <returns></returns>
|
||||
public IHtmlEncodedString RenderMacro(string alias)
|
||||
public async Task<IHtmlEncodedString> RenderMacroAsync(string alias)
|
||||
{
|
||||
return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, null);
|
||||
return await _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,9 +118,9 @@ namespace Umbraco.Cms.Web.Common
|
||||
/// <param name="alias">The alias.</param>
|
||||
/// <param name="parameters">The parameters.</param>
|
||||
/// <returns></returns>
|
||||
public IHtmlEncodedString RenderMacro(string alias, object parameters)
|
||||
public async Task<IHtmlEncodedString> RenderMacroAsync(string alias, object parameters)
|
||||
{
|
||||
return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, parameters?.ToDictionary<object>());
|
||||
return await _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, parameters?.ToDictionary<object>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,9 +129,9 @@ namespace Umbraco.Cms.Web.Common
|
||||
/// <param name="alias">The alias.</param>
|
||||
/// <param name="parameters">The parameters.</param>
|
||||
/// <returns></returns>
|
||||
public IHtmlEncodedString RenderMacro(string alias, IDictionary<string, object> parameters)
|
||||
public async Task<IHtmlEncodedString> RenderMacroAsync(string alias, IDictionary<string, object> parameters)
|
||||
{
|
||||
return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, parameters);
|
||||
return await _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, parameters);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -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 <?UMBRACO_MACRO macroAlias="Map" /> 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 += "}";
|
||||
|
||||
@@ -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("<?UMBRACO_MACRO macroAlias='Map' test1=\"asdf\" test2='hello' ><img src='blah.jpg'/></?UMBRACO_MACRO>");
|
||||
@@ -108,7 +108,7 @@ describe('macro service tests', function () {
|
||||
toBe("<?UMBRACO_MACRO macroAlias=\"myMacro\" />");
|
||||
|
||||
});
|
||||
|
||||
|
||||
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\")");
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
}
|
||||
|
||||
<text>
|
||||
@Umbraco.RenderMacro(macroAlias, parameters)
|
||||
@await Umbraco.RenderMacroAsync(macroAlias, parameters)
|
||||
</text>
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,6 @@
|
||||
<Compile Include="AspNet\FrameworkMarchal.cs" />
|
||||
<Compile Include="AspNet\AspNetUmbracoApplicationLifetime.cs" />
|
||||
<Compile Include="HttpContextExtensions.cs" />
|
||||
<Compile Include="Macros\MemberUserKeyProvider.cs" />
|
||||
<Compile Include="Security\BackOfficeSecurity.cs" />
|
||||
<Compile Include="HttpContextAccessorExtensions.cs" />
|
||||
<Compile Include="Models\Membership\UmbracoMembershipMember.cs" />
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace Umbraco.Web
|
||||
/// <returns></returns>
|
||||
public IHtmlEncodedString RenderMacro(string alias)
|
||||
{
|
||||
return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, null);
|
||||
return _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, null).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -131,7 +131,7 @@ namespace Umbraco.Web
|
||||
/// <returns></returns>
|
||||
public IHtmlEncodedString RenderMacro(string alias, object parameters)
|
||||
{
|
||||
return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, parameters?.ToDictionary<object>());
|
||||
return _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, parameters?.ToDictionary<object>()).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -142,7 +142,7 @@ namespace Umbraco.Web
|
||||
/// <returns></returns>
|
||||
public IHtmlEncodedString RenderMacro(string alias, IDictionary<string, object> parameters)
|
||||
{
|
||||
return _componentRenderer.RenderMacro(AssignedContentItem?.Id ?? 0, alias, parameters);
|
||||
return _componentRenderer.RenderMacroAsync(AssignedContentItem?.Id ?? 0, alias, parameters).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user