Removed WriterName and CreatorName from IPublished content and replaced functionality with an extension methods requiring an instance of IUserService.
This commit is contained in:
@@ -60,11 +60,6 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
/// </summary>
|
||||
int CreatorId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the user who created the content item.
|
||||
/// </summary>
|
||||
string CreatorName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date the content item was created.
|
||||
/// </summary>
|
||||
@@ -75,11 +70,6 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
/// </summary>
|
||||
int WriterId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the user who last updated the content item.
|
||||
/// </summary>
|
||||
string WriterName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date the content item was last updated.
|
||||
/// </summary>
|
||||
|
||||
@@ -60,18 +60,12 @@ namespace Umbraco.Web.Models
|
||||
/// <inheritdoc />
|
||||
public abstract int CreatorId { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract string CreatorName { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract DateTime CreateDate { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract int WriterId { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract string WriterName { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract DateTime UpdateDate { get; }
|
||||
|
||||
|
||||
@@ -78,18 +78,12 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
/// <inheritdoc />
|
||||
public virtual int CreatorId => _content.CreatorId;
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual string CreatorName => _content.CreatorName;
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual DateTime CreateDate => _content.CreateDate;
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual int WriterId => _content.WriterId;
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual string WriterName => _content.WriterName;
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual DateTime UpdateDate => _content.UpdateDate;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
@@ -135,5 +136,17 @@ namespace Umbraco.Core
|
||||
? children
|
||||
: children.Where(x => x.IsInvariantOrHasCulture(culture));
|
||||
}
|
||||
|
||||
public static string GetCreatorName(this IPublishedContent content, IUserService userService)
|
||||
{
|
||||
var user = userService.GetProfileById(content.CreatorId);
|
||||
return user?.Name;
|
||||
}
|
||||
|
||||
public static string GetWriterName(this IPublishedContent content, IUserService userService)
|
||||
{
|
||||
var user = userService.GetProfileById(content.WriterId);
|
||||
return user?.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,18 +147,12 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
/// <inheritdoc />
|
||||
public override int CreatorId => _contentNode.CreatorId;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CreatorName => string.Empty; // TODO: remove (as want to avoid injecting user service to get these names)
|
||||
|
||||
/// <inheritdoc />
|
||||
public override DateTime CreateDate => _contentNode.CreateDate;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int WriterId => ContentData.WriterId;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string WriterName => string.Empty; // TODO: remove (as want to avoid injecting user service to get these names)
|
||||
|
||||
/// <inheritdoc />
|
||||
public override DateTime UpdateDate => ContentData.VersionDate;
|
||||
|
||||
|
||||
@@ -141,10 +141,6 @@ namespace Umbraco.Web.PublishedCache
|
||||
|
||||
public override string UrlSegment => throw new NotSupportedException();
|
||||
|
||||
public override string WriterName => _member.GetCreatorProfile(_userService).Name;
|
||||
|
||||
public override string CreatorName => _member.GetCreatorProfile(_userService).Name;
|
||||
|
||||
public override int WriterId => _member.CreatorId;
|
||||
|
||||
public override int CreatorId => _member.CreatorId;
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
public class PublishMediaCacheTests : BaseWebTest
|
||||
{
|
||||
private Dictionary<string, PublishedContentType> _mediaTypes;
|
||||
private int _testWriterAndCreatorId;
|
||||
|
||||
private IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
protected override void Compose()
|
||||
@@ -51,6 +52,8 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
{ testMediaType.Alias, testMediaType }
|
||||
};
|
||||
ContentTypesCache.GetPublishedContentTypeByAlias = alias => _mediaTypes[alias];
|
||||
|
||||
_testWriterAndCreatorId = ServiceContext.UserService.CreateUserWithIdentity("Shannon", "test").Id;
|
||||
}
|
||||
|
||||
private IMediaType MakeNewMediaType(IUser user, string text, int parentId = -1)
|
||||
@@ -201,7 +204,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
{"path", "-1,1234"},
|
||||
{"updateDate", DateTime.Parse("2012-07-16T10:34:09").Ticks.ToString()},
|
||||
{"createDate", DateTime.Parse("2012-07-17T10:34:09").Ticks.ToString()},
|
||||
{"creatorID", "0"},
|
||||
{"creatorID", _testWriterAndCreatorId.ToString()},
|
||||
{"creatorName", "Shannon"}
|
||||
};
|
||||
|
||||
@@ -210,7 +213,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
var store = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null, HostingEnvironment), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>(), VariationContextAccessor);
|
||||
var doc = store.CreateFromCacheValues(store.ConvertFromSearchResult(result));
|
||||
|
||||
DoAssert(doc, 1234, key, null, 0, "/media/test.jpg", "Image", 23, "Shannon", "Shannon", 0, 0, "-1,1234", DateTime.Parse("2012-07-17T10:34:09"), DateTime.Parse("2012-07-16T10:34:09"), 2);
|
||||
DoAssert(doc, 1234, key, null, 0, "/media/test.jpg", "Image", 23, "Shannon", "Shannon", "-1,1234", DateTime.Parse("2012-07-17T10:34:09"), DateTime.Parse("2012-07-16T10:34:09"), 2);
|
||||
Assert.AreEqual(null, doc.Parent);
|
||||
}
|
||||
|
||||
@@ -226,7 +229,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null, HostingEnvironment), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>(),VariationContextAccessor);
|
||||
var doc = cache.CreateFromCacheValues(cache.ConvertFromXPathNavigator(navigator, true));
|
||||
|
||||
DoAssert(doc, 2000, key, null, 2, "image1", "Image", 23, "Shannon", "Shannon", 33, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1);
|
||||
DoAssert(doc, 2000, key, null, 2, "image1", "Image", 23, "Shannon", "Shannon", "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1);
|
||||
Assert.AreEqual(null, doc.Parent);
|
||||
Assert.AreEqual(2, doc.Children.Count());
|
||||
Assert.AreEqual(2001, doc.Children.ElementAt(0).Id);
|
||||
@@ -243,16 +246,18 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
<!ATTLIST CustomDocument id ID #REQUIRED>
|
||||
]>
|
||||
<root id=""-1"">
|
||||
<Image id=""2000"" parentID=""-1"" level=""1"" writerID=""33"" creatorID=""33"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" writerName=""Shannon"" creatorName=""Shannon"" path=""-1,2000"" isDoc="""">
|
||||
<Image id=""2000"" parentID=""-1"" level=""1"" writerID=""[WriterId]"" creatorID=""[CreatorId]"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" path=""-1,2000"" isDoc="""">
|
||||
<file><![CDATA[/media/1234/image1.png]]></file>
|
||||
<Image id=""2001"" parentID=""2000"" level=""2"" writerID=""33"" creatorID=""33"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" writerName=""Shannon"" creatorName=""Shannon"" path=""-1,2000,2001"" isDoc="""">
|
||||
<Image id=""2001"" parentID=""2000"" level=""2"" writerID=""[WriterId]"" creatorID=""[CreatorId]"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" path=""-1,2000,2001"" isDoc="""">
|
||||
<file><![CDATA[/media/1234/image1.png]]></file>
|
||||
</Image>
|
||||
<Image id=""2002"" parentID=""2000"" level=""2"" writerID=""33"" creatorID=""33"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" writerName=""Shannon"" creatorName=""Shannon"" path=""-1,2000,2002"" isDoc="""">
|
||||
<Image id=""2002"" parentID=""2000"" level=""2"" writerID=""[WriterId]"" creatorID=""[CreatorId]"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" path=""-1,2000,2002"" isDoc="""">
|
||||
<file><![CDATA[/media/1234/image1.png]]></file>
|
||||
</Image>
|
||||
</Image>
|
||||
</root>";
|
||||
xml = xml.Replace("[WriterId]", _testWriterAndCreatorId.ToString());
|
||||
xml = xml.Replace("[CreatorId]", _testWriterAndCreatorId.ToString());
|
||||
|
||||
var xmlDoc = new XmlDocument();
|
||||
xmlDoc.LoadXml(xml);
|
||||
@@ -279,10 +284,8 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
{"urlName", "testing"},
|
||||
{nodeTypeAliasKey, "myType"},
|
||||
{"nodeType", "22"},
|
||||
{"writerName", "Shannon"},
|
||||
{"creatorName", "Shannon"},
|
||||
{"writerID", "33"},
|
||||
{"creatorID", "33"},
|
||||
{"writerID", _testWriterAndCreatorId.ToString()},
|
||||
{"creatorID", _testWriterAndCreatorId.ToString()},
|
||||
{pathKey, "1,2,3,4,5"},
|
||||
{"createDate", "2012-01-02"},
|
||||
{"updateDate", "2012-01-02"},
|
||||
@@ -349,8 +352,6 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
int nodeTypeIdVal = 22,
|
||||
string writerNameVal = "Shannon",
|
||||
string creatorNameVal = "Shannon",
|
||||
int writerIdVal = 33,
|
||||
int creatorIdVal = 33,
|
||||
string pathVal = "1,2,3,4,5",
|
||||
DateTime? createDateVal = null,
|
||||
DateTime? updateDateVal = null,
|
||||
@@ -363,7 +364,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
updateDateVal = DateTime.Parse("2012-01-02");
|
||||
|
||||
DoAssert((IPublishedContent)dicDoc, idVal, keyVal, templateIdVal, sortOrderVal, urlNameVal, nodeTypeAliasVal, nodeTypeIdVal, writerNameVal,
|
||||
creatorNameVal, writerIdVal, creatorIdVal, pathVal, createDateVal, updateDateVal, levelVal);
|
||||
creatorNameVal, pathVal, createDateVal, updateDateVal, levelVal);
|
||||
|
||||
//now validate the parentId that has been parsed, this doesn't exist on the IPublishedContent
|
||||
Assert.AreEqual(parentIdVal, dicDoc.ParentId);
|
||||
@@ -380,8 +381,6 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
int nodeTypeIdVal = 22,
|
||||
string writerNameVal = "Shannon",
|
||||
string creatorNameVal = "Shannon",
|
||||
int writerIdVal = 33,
|
||||
int creatorIdVal = 33,
|
||||
string pathVal = "1,2,3,4,5",
|
||||
DateTime? createDateVal = null,
|
||||
DateTime? updateDateVal = null,
|
||||
@@ -399,10 +398,10 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
Assert.AreEqual(urlNameVal, doc.UrlSegment);
|
||||
Assert.AreEqual(nodeTypeAliasVal, doc.ContentType.Alias);
|
||||
Assert.AreEqual(nodeTypeIdVal, doc.ContentType.Id);
|
||||
Assert.AreEqual(writerNameVal, doc.WriterName);
|
||||
Assert.AreEqual(creatorNameVal, doc.CreatorName);
|
||||
Assert.AreEqual(writerIdVal, doc.WriterId);
|
||||
Assert.AreEqual(creatorIdVal, doc.CreatorId);
|
||||
Assert.AreEqual(writerNameVal, doc.GetWriterName(ServiceContext.UserService));
|
||||
Assert.AreEqual(creatorNameVal, doc.GetCreatorName(ServiceContext.UserService));
|
||||
Assert.AreEqual(_testWriterAndCreatorId, doc.WriterId);
|
||||
Assert.AreEqual(_testWriterAndCreatorId, doc.CreatorId);
|
||||
Assert.AreEqual(pathVal, doc.Path);
|
||||
Assert.AreEqual(createDateVal.Value, doc.CreateDate);
|
||||
Assert.AreEqual(updateDateVal.Value, doc.UpdateDate);
|
||||
|
||||
@@ -61,8 +61,6 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
ValidateAndSetProperty(valueDictionary, val => _urlName = val, "urlName");
|
||||
ValidateAndSetProperty(valueDictionary, val => _documentTypeAlias = val, "nodeTypeAlias", LuceneIndex.ItemTypeFieldName);
|
||||
ValidateAndSetProperty(valueDictionary, val => _documentTypeId = Int32.Parse(val), "nodeType");
|
||||
//ValidateAndSetProperty(valueDictionary, val => _writerName = val, "writerName");
|
||||
ValidateAndSetProperty(valueDictionary, val => _creatorName = val, "creatorName", "writerName"); //this is a bit of a hack fix for: U4-1132
|
||||
//ValidateAndSetProperty(valueDictionary, val => _writerId = int.Parse(val), "writerID");
|
||||
ValidateAndSetProperty(valueDictionary, val => _creatorId = Int32.Parse(val), "creatorID", "writerID"); //this is a bit of a hack fix for: U4-1132
|
||||
ValidateAndSetProperty(valueDictionary, val => _path = val, "path", "__Path");
|
||||
@@ -161,10 +159,6 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
|
||||
public override string UrlSegment => _urlName;
|
||||
|
||||
public override string WriterName => _creatorName;
|
||||
|
||||
public override string CreatorName => _creatorName;
|
||||
|
||||
public override int WriterId => _creatorId;
|
||||
|
||||
public override int CreatorId => _creatorId;
|
||||
@@ -203,8 +197,6 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
private string _urlName;
|
||||
private string _documentTypeAlias;
|
||||
private int _documentTypeId;
|
||||
//private string _writerName;
|
||||
private string _creatorName;
|
||||
//private int _writerId;
|
||||
private int _creatorId;
|
||||
private string _path;
|
||||
|
||||
@@ -61,8 +61,6 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
private string _name;
|
||||
private string _docTypeAlias;
|
||||
private int _docTypeId;
|
||||
private string _writerName;
|
||||
private string _creatorName;
|
||||
private int _writerId;
|
||||
private int _creatorId;
|
||||
private string _urlName;
|
||||
@@ -158,24 +156,6 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
|
||||
public override IReadOnlyDictionary<string, PublishedCultureInfo> Cultures => _cultures ?? (_cultures = GetCultures());
|
||||
|
||||
public override string WriterName
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureNodeInitialized();
|
||||
return _writerName;
|
||||
}
|
||||
}
|
||||
|
||||
public override string CreatorName
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureNodeInitialized();
|
||||
return _creatorName;
|
||||
}
|
||||
}
|
||||
|
||||
public override int WriterId
|
||||
{
|
||||
get
|
||||
@@ -301,8 +281,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
private void InitializeNode()
|
||||
{
|
||||
InitializeNode(this, _xmlNode, _isPreviewing,
|
||||
out _id, out _key, out _template, out _sortOrder, out _name, out _writerName,
|
||||
out _urlName, out _creatorName, out _creatorId, out _writerId, out _docTypeAlias, out _docTypeId, out _path,
|
||||
out _id, out _key, out _template, out _sortOrder, out _name,
|
||||
out _urlName, out _creatorId, out _writerId, out _docTypeAlias, out _docTypeId, out _path,
|
||||
out _createDate, out _updateDate, out _level, out _isDraft, out _contentType, out _properties,
|
||||
_contentTypeCache.Get);
|
||||
|
||||
@@ -311,18 +291,17 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
|
||||
// internal for some benchmarks
|
||||
internal static void InitializeNode(XmlPublishedContent node, XmlNode xmlNode, bool isPreviewing,
|
||||
out int id, out Guid key, out int template, out int sortOrder, out string name, out string writerName, out string urlName,
|
||||
out string creatorName, out int creatorId, out int writerId, out string docTypeAlias, out int docTypeId, out string path,
|
||||
out int id, out Guid key, out int template, out int sortOrder, out string name, out string urlName,
|
||||
out int creatorId, out int writerId, out string docTypeAlias, out int docTypeId, out string path,
|
||||
out DateTime createDate, out DateTime updateDate, out int level, out bool isDraft,
|
||||
out IPublishedContentType contentType, out Dictionary<string, IPublishedProperty> properties,
|
||||
Func<PublishedItemType, string, IPublishedContentType> getPublishedContentType)
|
||||
{
|
||||
//initialize the out params with defaults:
|
||||
writerName = null;
|
||||
docTypeAlias = null;
|
||||
id = template = sortOrder = template = creatorId = writerId = docTypeId = level = default(int);
|
||||
key = default(Guid);
|
||||
name = writerName = urlName = creatorName = docTypeAlias = path = null;
|
||||
name = docTypeAlias = urlName = path = null;
|
||||
createDate = updateDate = default(DateTime);
|
||||
isDraft = false;
|
||||
contentType = null;
|
||||
@@ -341,12 +320,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
sortOrder = int.Parse(xmlNode.Attributes.GetNamedItem("sortOrder").Value);
|
||||
if (xmlNode.Attributes.GetNamedItem("nodeName") != null)
|
||||
name = xmlNode.Attributes.GetNamedItem("nodeName").Value;
|
||||
if (xmlNode.Attributes.GetNamedItem("writerName") != null)
|
||||
writerName = xmlNode.Attributes.GetNamedItem("writerName").Value;
|
||||
if (xmlNode.Attributes.GetNamedItem("urlName") != null)
|
||||
urlName = xmlNode.Attributes.GetNamedItem("urlName").Value;
|
||||
if (xmlNode.Attributes.GetNamedItem("creatorName") != null)
|
||||
creatorName = xmlNode.Attributes.GetNamedItem("creatorName").Value;
|
||||
|
||||
//Added the actual userID, as a user cannot be looked up via full name only...
|
||||
if (xmlNode.Attributes.GetNamedItem("creatorID") != null)
|
||||
|
||||
@@ -52,8 +52,8 @@ namespace Umbraco.Tests.PublishedContent
|
||||
{"NodeTypeAlias", "NodeTypeAlias"},
|
||||
{"CreateDate", "CreateDate"},
|
||||
{"UpdateDate", "UpdateDate"},
|
||||
{"CreatorName", "CreatorName"},
|
||||
{"WriterName", "WriterName"},
|
||||
{"CreatorId", "CreatorId"},
|
||||
{"WriterId", "WriterId"},
|
||||
{"Url", "Url"}
|
||||
};
|
||||
foreach (var f in userFields.Where(f => !allFields.ContainsKey(f.Key)))
|
||||
@@ -135,7 +135,6 @@ namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
CreateDate = DateTime.Now,
|
||||
CreatorId = 1,
|
||||
CreatorName = "Shannon",
|
||||
Id = 3,
|
||||
SortOrder = 4,
|
||||
TemplateId = 5,
|
||||
@@ -145,7 +144,6 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Name = "Page" + Guid.NewGuid(),
|
||||
Version = Guid.NewGuid(),
|
||||
WriterId = 1,
|
||||
WriterName = "Shannon",
|
||||
Parent = null,
|
||||
Level = 1,
|
||||
Children = new List<IPublishedContent>()
|
||||
|
||||
@@ -59,8 +59,6 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var pc = new Mock<IPublishedContent>();
|
||||
pc.Setup(content => content.Id).Returns(1);
|
||||
pc.Setup(content => content.Name).Returns("test");
|
||||
pc.Setup(content => content.WriterName).Returns("admin");
|
||||
pc.Setup(content => content.CreatorName).Returns("admin");
|
||||
pc.Setup(content => content.CreateDate).Returns(DateTime.Now);
|
||||
pc.Setup(content => content.UpdateDate).Returns(DateTime.Now);
|
||||
pc.Setup(content => content.Path).Returns("-1,1");
|
||||
|
||||
@@ -167,7 +167,6 @@ namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
// initialize boring stuff
|
||||
TemplateId = 0;
|
||||
WriterName = CreatorName = string.Empty;
|
||||
WriterId = CreatorId = 0;
|
||||
CreateDate = UpdateDate = DateTime.Now;
|
||||
Version = Guid.Empty;
|
||||
@@ -193,8 +192,6 @@ namespace Umbraco.Tests.PublishedContent
|
||||
public string Name { get; set; }
|
||||
public IReadOnlyDictionary<string, PublishedCultureInfo> Cultures => _cultures ?? (_cultures = GetCultures());
|
||||
public string UrlSegment { get; set; }
|
||||
public string WriterName { get; set; }
|
||||
public string CreatorName { get; set; }
|
||||
public int WriterId { get; set; }
|
||||
public int CreatorId { get; set; }
|
||||
public string Path { get; set; }
|
||||
|
||||
@@ -101,7 +101,8 @@ namespace Umbraco.Tests.TestHelpers
|
||||
new TestVariationContextAccessor(),
|
||||
container?.TryGetInstance<ServiceContext>() ?? ServiceContext.CreatePartial(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()),
|
||||
container?.TryGetInstance<IUmbracoSettingsSection>() ?? Current.Factory.GetInstance<IUmbracoSettingsSection>());
|
||||
container?.TryGetInstance<IUmbracoSettingsSection>() ?? Current.Factory.GetInstance<IUmbracoSettingsSection>(),
|
||||
Mock.Of<IUserService>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,9 @@ namespace Umbraco.Web.Macros
|
||||
private readonly ILocalizedTextService _textService;
|
||||
private readonly AppCaches _appCaches;
|
||||
private readonly IMacroService _macroService;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public MacroRenderer(IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, IContentSection contentSection, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService)
|
||||
public MacroRenderer(IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, IContentSection contentSection, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, IUserService userService)
|
||||
{
|
||||
_plogger = plogger ?? throw new ArgumentNullException(nameof(plogger));
|
||||
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
|
||||
@@ -35,6 +36,7 @@ namespace Umbraco.Web.Macros
|
||||
_textService = textService;
|
||||
_appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches));
|
||||
_macroService = macroService ?? throw new ArgumentNullException(nameof(macroService));
|
||||
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
|
||||
}
|
||||
|
||||
#region MacroContent cache
|
||||
@@ -201,7 +203,7 @@ namespace Umbraco.Web.Macros
|
||||
if (m == null)
|
||||
throw new InvalidOperationException("No macro found by alias " + macroAlias);
|
||||
|
||||
var page = new PublishedContentHashtableConverter(content);
|
||||
var page = new PublishedContentHashtableConverter(content, _userService);
|
||||
|
||||
var macro = new MacroModel(m);
|
||||
|
||||
|
||||
@@ -25,19 +25,20 @@ namespace Umbraco.Web.Macros
|
||||
/// Initializes a new instance of the <see cref="PublishedContentHashtableConverter"/> class for a published document request.
|
||||
/// </summary>
|
||||
/// <param name="frequest">The <see cref="PublishedRequest"/> pointing to the document.</param>
|
||||
/// <param name="userService">The <see cref="IUserService"/>.</param>
|
||||
/// <remarks>
|
||||
/// The difference between creating the page with PublishedRequest vs an IPublishedContent item is
|
||||
/// that the PublishedRequest takes into account how a template is assigned during the routing process whereas
|
||||
/// with an IPublishedContent item, the template id is assigned purely based on the default.
|
||||
/// </remarks>
|
||||
internal PublishedContentHashtableConverter(PublishedRequest frequest)
|
||||
internal PublishedContentHashtableConverter(PublishedRequest frequest, IUserService userService)
|
||||
{
|
||||
if (!frequest.HasPublishedContent)
|
||||
throw new ArgumentException("Document request has no node.", nameof(frequest));
|
||||
|
||||
PopulatePageData(frequest.PublishedContent.Id,
|
||||
frequest.PublishedContent.Name, frequest.PublishedContent.ContentType.Id, frequest.PublishedContent.ContentType.Alias,
|
||||
frequest.PublishedContent.WriterName, frequest.PublishedContent.CreatorName, frequest.PublishedContent.CreateDate, frequest.PublishedContent.UpdateDate,
|
||||
frequest.PublishedContent.GetWriterName(userService), frequest.PublishedContent.GetCreatorName(userService), frequest.PublishedContent.CreateDate, frequest.PublishedContent.UpdateDate,
|
||||
frequest.PublishedContent.Path, frequest.PublishedContent.Parent?.Id ?? -1);
|
||||
|
||||
if (frequest.HasTemplate)
|
||||
@@ -53,13 +54,13 @@ namespace Umbraco.Web.Macros
|
||||
/// Initializes a new instance of the page for a published document
|
||||
/// </summary>
|
||||
/// <param name="doc"></param>
|
||||
internal PublishedContentHashtableConverter(IPublishedContent doc)
|
||||
internal PublishedContentHashtableConverter(IPublishedContent doc, IUserService userService)
|
||||
{
|
||||
if (doc == null) throw new ArgumentNullException(nameof(doc));
|
||||
|
||||
PopulatePageData(doc.Id,
|
||||
doc.Name, doc.ContentType.Id, doc.ContentType.Alias,
|
||||
doc.WriterName, doc.CreatorName, doc.CreateDate, doc.UpdateDate,
|
||||
doc.GetWriterName(userService), doc.GetCreatorName(userService), doc.CreateDate, doc.UpdateDate,
|
||||
doc.Path, doc.Parent?.Id ?? -1);
|
||||
|
||||
if (doc.TemplateId.HasValue)
|
||||
@@ -78,7 +79,7 @@ namespace Umbraco.Web.Macros
|
||||
/// <param name="variationContextAccessor"></param>
|
||||
/// <remarks>This is for <see cref="MacroRenderingController"/> usage only.</remarks>
|
||||
internal PublishedContentHashtableConverter(IContent content, IVariationContextAccessor variationContextAccessor, IUserService userService, IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IPublishedContentTypeFactory publishedContentTypeFactory, UrlSegmentProviderCollection urlSegmentProviders)
|
||||
: this(new PagePublishedContent(content, variationContextAccessor, userService, shortStringHelper, contentTypeBaseServiceProvider, publishedContentTypeFactory, urlSegmentProviders))
|
||||
: this(new PagePublishedContent(content, variationContextAccessor, userService, shortStringHelper, contentTypeBaseServiceProvider, publishedContentTypeFactory, urlSegmentProviders), userService)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1000,15 +1000,15 @@ namespace Umbraco.Web
|
||||
|
||||
var standardVals = new Dictionary<string, object>
|
||||
{
|
||||
{ "Id", n.Id },
|
||||
{ "NodeName", n.Name(VariationContextAccessor) },
|
||||
{ "NodeTypeAlias", n.ContentType.Alias },
|
||||
{ "CreateDate", n.CreateDate },
|
||||
{ "UpdateDate", n.UpdateDate },
|
||||
{ "CreatorName", n.CreatorName },
|
||||
{ "WriterName", n.WriterName },
|
||||
{ "Url", n.Url() }
|
||||
};
|
||||
{ "Id", n.Id },
|
||||
{ "NodeName", n.Name(VariationContextAccessor) },
|
||||
{ "NodeTypeAlias", n.ContentType.Alias },
|
||||
{ "CreateDate", n.CreateDate },
|
||||
{ "UpdateDate", n.UpdateDate },
|
||||
{ "CreatorId", n.CreatorId},
|
||||
{ "WriterId", n.WriterId },
|
||||
{ "Url", n.Url() }
|
||||
};
|
||||
|
||||
var userVals = new Dictionary<string, object>();
|
||||
foreach (var p in from IPublishedProperty p in n.Properties where p.GetSourceValue() != null select p)
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace Umbraco.Web.Routing
|
||||
private readonly IVariationContextAccessor _variationContextAccessor;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PublishedRouter"/> class.
|
||||
@@ -39,7 +40,8 @@ namespace Umbraco.Web.Routing
|
||||
IVariationContextAccessor variationContextAccessor,
|
||||
ServiceContext services,
|
||||
IProfilingLogger proflog,
|
||||
IUmbracoSettingsSection umbracoSettingsSection)
|
||||
IUmbracoSettingsSection umbracoSettingsSection,
|
||||
IUserService userService)
|
||||
{
|
||||
_webRoutingSection = webRoutingSection ?? throw new ArgumentNullException(nameof(webRoutingSection));
|
||||
_contentFinders = contentFinders ?? throw new ArgumentNullException(nameof(contentFinders));
|
||||
@@ -49,6 +51,7 @@ namespace Umbraco.Web.Routing
|
||||
_variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
|
||||
_logger = proflog;
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -194,7 +197,7 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
// assign the legacy page back to the request
|
||||
// handlers like default.aspx will want it and most macros currently need it
|
||||
frequest.LegacyContentHashTable = new PublishedContentHashtableConverter(frequest);
|
||||
frequest.LegacyContentHashTable = new PublishedContentHashtableConverter(frequest, _userService);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -234,8 +237,7 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
// assign the legacy page back to the docrequest
|
||||
// handlers like default.aspx will want it and most macros currently need it
|
||||
request.LegacyContentHashTable = new PublishedContentHashtableConverter(request);
|
||||
|
||||
request.LegacyContentHashTable = new PublishedContentHashtableConverter(request, _userService);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user