Bugfix: Do not allow routing content that is unpublished (#17251)
* Ensure routing respect publish status * Check published status per culture * Added PublishStatusService to get publish status for a given documentkey and culture * Added tests and fixed bug with a static fields that should not have been static * Make sure the write and read cache key is always the same no matter where the request comes from There is an edge case where the incomming culure is fully capitalized while the read is camelcase * Fixed review comments --------- Co-authored-by: Sven Geusens <sge@umbraco.dk>
This commit is contained in:
@@ -22,6 +22,7 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
private readonly IDocumentNavigationQueryService _documentNavigationQueryService;
|
||||
private readonly IDocumentNavigationManagementService _documentNavigationManagementService;
|
||||
private readonly IContentService _contentService;
|
||||
private readonly IPublishStatusManagementService _publishStatusManagementService;
|
||||
private readonly IIdKeyMap _idKeyMap;
|
||||
|
||||
public ContentCacheRefresher(
|
||||
@@ -35,7 +36,8 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
IDomainCacheService domainCacheService,
|
||||
IDocumentNavigationQueryService documentNavigationQueryService,
|
||||
IDocumentNavigationManagementService documentNavigationManagementService,
|
||||
IContentService contentService)
|
||||
IContentService contentService,
|
||||
IPublishStatusManagementService publishStatusManagementService)
|
||||
: base(appCaches, serializer, eventAggregator, factory)
|
||||
{
|
||||
_idKeyMap = idKeyMap;
|
||||
@@ -45,6 +47,7 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
_documentNavigationQueryService = documentNavigationQueryService;
|
||||
_documentNavigationManagementService = documentNavigationManagementService;
|
||||
_contentService = contentService;
|
||||
_publishStatusManagementService = publishStatusManagementService;
|
||||
}
|
||||
|
||||
#region Indirect
|
||||
@@ -109,6 +112,7 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
HandleRouting(payload);
|
||||
|
||||
HandleNavigation(payload);
|
||||
HandlePublishedAsync(payload, CancellationToken.None).GetAwaiter().GetResult();
|
||||
_idKeyMap.ClearCache(payload.Id);
|
||||
if (payload.Key.HasValue)
|
||||
{
|
||||
@@ -143,6 +147,13 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
|
||||
private void HandleNavigation(JsonPayload payload)
|
||||
{
|
||||
|
||||
if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshAll))
|
||||
{
|
||||
_documentNavigationManagementService.RebuildAsync();
|
||||
_documentNavigationManagementService.RebuildBinAsync();
|
||||
}
|
||||
|
||||
if (payload.Key is null)
|
||||
{
|
||||
return;
|
||||
@@ -154,15 +165,9 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
_documentNavigationManagementService.RemoveFromBin(payload.Key.Value);
|
||||
}
|
||||
|
||||
if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshAll))
|
||||
{
|
||||
_documentNavigationManagementService.RebuildAsync();
|
||||
_documentNavigationManagementService.RebuildBinAsync();
|
||||
}
|
||||
|
||||
if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshNode))
|
||||
{
|
||||
IContent? content = _contentService.GetById(payload.Id);
|
||||
IContent? content = _contentService.GetById(payload.Key.Value);
|
||||
|
||||
if (content is null)
|
||||
{
|
||||
@@ -174,7 +179,7 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
|
||||
if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshBranch))
|
||||
{
|
||||
IContent? content = _contentService.GetById(payload.Id);
|
||||
IContent? content = _contentService.GetById(payload.Key.Value);
|
||||
|
||||
if (content is null)
|
||||
{
|
||||
@@ -237,6 +242,32 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase<ContentCac
|
||||
|
||||
private bool ExistsInNavigationBin(Guid contentKey) => _documentNavigationQueryService.TryGetParentKeyInBin(contentKey, out _);
|
||||
|
||||
private async Task HandlePublishedAsync(JsonPayload payload, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshAll))
|
||||
{
|
||||
await _publishStatusManagementService.InitializeAsync(cancellationToken);
|
||||
}
|
||||
|
||||
if (payload.Key.HasValue is false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (payload.ChangeTypes.HasType(TreeChangeTypes.Remove))
|
||||
{
|
||||
await _publishStatusManagementService.RemoveAsync(payload.Key.Value, cancellationToken);
|
||||
}
|
||||
else if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshNode))
|
||||
{
|
||||
await _publishStatusManagementService.AddOrUpdateStatusAsync(payload.Key.Value, cancellationToken);
|
||||
}
|
||||
else if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshBranch))
|
||||
{
|
||||
await _publishStatusManagementService.AddOrUpdateStatusWithDescendantsAsync(payload.Key.Value, cancellationToken);
|
||||
}
|
||||
}
|
||||
private void HandleRouting(JsonPayload payload)
|
||||
{
|
||||
if(payload.ChangeTypes.HasType(TreeChangeTypes.Remove))
|
||||
|
||||
Reference in New Issue
Block a user