Skip to content

Commit c309e18

Browse files
committed
Fixes: U4-459 Public Access permissions not set on distributed servers
1 parent cde3c42 commit c309e18

File tree

8 files changed

+461
-241
lines changed

8 files changed

+461
-241
lines changed

src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,19 @@ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplica
139139
//NOTE: we do not listen for the trashed event because there is no cache to update for content in that case since
140140
// the unpublishing event handles that, and for examine with unpublished content indexes, we want to keep that data
141141
// in the index, it's not until it's complete deleted that we want to remove it.
142+
143+
//public access events
144+
Access.AfterSave += Access_AfterSave;
142145
}
143146

144-
147+
#region Public access event handlers
148+
149+
static void Access_AfterSave(Access sender, SaveEventArgs e)
150+
{
151+
DistributedCache.Instance.RefreshPublicAccess();
152+
}
153+
154+
#endregion
145155

146156
#region Content service event handlers
147157

src/Umbraco.Web/Cache/DistributedCache.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public sealed class DistributedCache
5454
public const string StylesheetPropertyCacheRefresherId = "2BC7A3A4-6EB1-4FBC-BAA3-C9E7B6D36D38";
5555
public const string DataTypeCacheRefresherId = "35B16C25-A17E-45D7-BC8F-EDAB1DCC28D2";
5656
public const string DictionaryCacheRefresherId = "D1D7E227-F817-4816-BFE9-6C39B6152884";
57+
public const string PublicAccessCacheRefresherId = "1DB08769-B104-4F8B-850E-169CAC1DF2EC";
5758

5859
#endregion
5960

@@ -221,4 +222,4 @@ private static ICacheRefresher GetRefresherById(Guid uniqueIdentifier)
221222
}
222223

223224
}
224-
}
225+
}

src/Umbraco.Web/Cache/DistributedCacheExtensions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ namespace Umbraco.Web.Cache
1313
/// </summary>
1414
internal static class DistributedCacheExtensions
1515
{
16+
#region Public access
17+
18+
public static void RefreshPublicAccess(this DistributedCache dc)
19+
{
20+
dc.RefreshByJson(new Guid(DistributedCache.PublicAccessCacheRefresherId),
21+
PublicAccessCacheRefresher.SerializeToJsonPayload(
22+
Access.GetXmlDocumentCopy()));
23+
}
24+
25+
#endregion
26+
1627
#region Application tree cache
1728
public static void RefreshAllApplicationTreeCache(this DistributedCache dc)
1829
{

src/Umbraco.Web/Cache/MediaCacheRefresher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
using System.Web.Script.Serialization;
55
using Umbraco.Core;
66
using Umbraco.Core.Cache;
7+
using Umbraco.Core.IO;
78
using Umbraco.Core.Models;
89
using umbraco.interfaces;
910
using System.Linq;
1011

1112
namespace Umbraco.Web.Cache
1213
{
13-
1414
/// <summary>
1515
/// A cache refresher to ensure media cache is updated
1616
/// </summary>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Xml;
3+
using Newtonsoft.Json;
4+
using umbraco.cms.businesslogic.web;
5+
using Umbraco.Core;
6+
using Umbraco.Core.Cache;
7+
8+
namespace Umbraco.Web.Cache
9+
{
10+
public sealed class PublicAccessCacheRefresher : JsonCacheRefresherBase<PublicAccessCacheRefresher>
11+
{
12+
#region Static helpers
13+
14+
internal static JsonPayload DeserializeFromJsonPayload(string json)
15+
{
16+
return JsonConvert.DeserializeObject<JsonPayload>(json);
17+
}
18+
19+
internal static string SerializeToJsonPayload(XmlDocument doc)
20+
{
21+
return JsonConvert.SerializeObject(FromXml(doc));
22+
}
23+
24+
internal static JsonPayload FromXml(XmlDocument doc)
25+
{
26+
if (doc == null) return null;
27+
28+
var payload = new JsonPayload
29+
{
30+
XmlContent = doc.OuterXml
31+
};
32+
return payload;
33+
}
34+
35+
#endregion
36+
37+
#region Sub classes
38+
39+
internal class JsonPayload
40+
{
41+
public string XmlContent { get; set; }
42+
}
43+
44+
#endregion
45+
46+
protected override PublicAccessCacheRefresher Instance
47+
{
48+
get { return this; }
49+
}
50+
51+
public override Guid UniqueIdentifier
52+
{
53+
get { return new Guid(DistributedCache.PublicAccessCacheRefresherId); }
54+
}
55+
56+
public override string Name
57+
{
58+
get { return "Public access cache refresher"; }
59+
}
60+
61+
public override void Refresh(string jsonPayload)
62+
{
63+
if (jsonPayload.IsNullOrWhiteSpace()) return;
64+
var deserialized = DeserializeFromJsonPayload(jsonPayload);
65+
if (deserialized == null) return;
66+
var xDoc = new XmlDocument();
67+
xDoc.LoadXml(deserialized.XmlContent);
68+
ClearCache(xDoc);
69+
base.Refresh(jsonPayload);
70+
}
71+
72+
private void ClearCache(XmlDocument xDoc)
73+
{
74+
Access.UpdateInMemoryDocument(xDoc);
75+
}
76+
}
77+
}

src/Umbraco.Web/Umbraco.Web.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@
285285
<Compile Include="Cache\MemberCacheRefresher.cs" />
286286
<Compile Include="Cache\MemberGroupCacheRefresher.cs" />
287287
<Compile Include="Cache\PageCacheRefresher.cs" />
288+
<Compile Include="Cache\PublicAccessCacheRefresher.cs" />
288289
<Compile Include="Cache\StylesheetCacheRefresher.cs" />
289290
<Compile Include="Cache\StylesheetPropertyCacheRefresher.cs" />
290291
<Compile Include="Cache\TemplateCacheRefresher.cs" />

src/UmbracoExamine/DataServices/UmbracoContentService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public XDocument GetLatestContentByXPath(string xpath)
9696
[SecuritySafeCritical]
9797
private static XmlNode GetPage(int documentId)
9898
{
99-
var x = Access.AccessXml.SelectSingleNode("/access/page [@id=" + documentId.ToString() + "]");
99+
var xDoc = Access.GetXmlDocumentCopy();
100+
var x = xDoc.SelectSingleNode("/access/page [@id=" + documentId.ToString() + "]");
100101
return x;
101102
}
102103

0 commit comments

Comments
 (0)