From 827bf80d1d86bb7d60585f147442211451305009 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 14 Dec 2020 17:04:02 +1100 Subject: [PATCH] Removes EnterPreview, RefreshPreview, ExitPreview --- .../IPublishedSnapshotService.cs | 50 ------------------- .../PublishedSnapshotServiceBase.cs | 9 ---- .../PublishedSnapshotService.cs | 21 -------- .../XmlPublishedSnapshotService.cs | 26 ---------- .../Controllers/PreviewController.cs | 14 ++---- 5 files changed, 4 insertions(+), 116 deletions(-) diff --git a/src/Umbraco.Core/PublishedCache/IPublishedSnapshotService.cs b/src/Umbraco.Core/PublishedCache/IPublishedSnapshotService.cs index cc526ffe6e..a953c7677e 100644 --- a/src/Umbraco.Core/PublishedCache/IPublishedSnapshotService.cs +++ b/src/Umbraco.Core/PublishedCache/IPublishedSnapshotService.cs @@ -77,56 +77,6 @@ namespace Umbraco.Web.PublishedCache #endregion - #region Preview - - /* Later on we can imagine that EnterPreview would handle a "level" that would be either - * the content only, or the content's branch, or the whole tree + it could be possible - * to register filters against the factory to filter out which nodes should be preview - * vs non preview. - * - * EnterPreview() returns the previewToken. It is up to callers to store that token - * wherever they want, most probably in a cookie. - * - */ - - /// - /// Enters preview for specified user and content. - /// - /// The user. - /// The content identifier. - /// A preview token. - /// - /// Tells the caches that they should prepare any data that they would be keeping - /// in order to provide preview to a given user. In the Xml cache this means creating the Xml - /// file, though other caches may do things differently. - /// Does not handle the preview token storage (cookie, etc) that must be handled separately. - /// - string EnterPreview(IUser user, int contentId); // TODO: Remove this, it is not needed and is legacy from the XML cache - - /// - /// Refreshes preview for a specified content. - /// - /// The preview token. - /// The content identifier. - /// Tells the caches that they should update any data that they would be keeping - /// in order to provide preview to a given user. In the Xml cache this means updating the Xml - /// file, though other caches may do things differently. - void RefreshPreview(string previewToken, int contentId); // TODO: Remove this, it is not needed and is legacy from the XML cache - - /// - /// Exits preview for a specified preview token. - /// - /// The preview token. - /// - /// Tells the caches that they can dispose of any data that they would be keeping - /// in order to provide preview to a given user. In the Xml cache this means deleting the Xml file, - /// though other caches may do things differently. - /// Does not handle the preview token storage (cookie, etc) that must be handled separately. - /// - void ExitPreview(string previewToken); // TODO: Remove this, it is not needed and is legacy from the XML cache - - #endregion - #region Changes /* An IPublishedCachesService implementation can rely on transaction-level events to update diff --git a/src/Umbraco.Core/PublishedCache/PublishedSnapshotServiceBase.cs b/src/Umbraco.Core/PublishedCache/PublishedSnapshotServiceBase.cs index 6a8324cc27..d334e69775 100644 --- a/src/Umbraco.Core/PublishedCache/PublishedSnapshotServiceBase.cs +++ b/src/Umbraco.Core/PublishedCache/PublishedSnapshotServiceBase.cs @@ -36,15 +36,6 @@ namespace Umbraco.Web.PublishedCache /// public abstract bool EnsureEnvironment(out IEnumerable errors); - /// - public abstract string EnterPreview(IUser user, int contentId); - - /// - public abstract void RefreshPreview(string previewToken, int contentId); - - /// - public abstract void ExitPreview(string previewToken); - /// public abstract void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged); diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs index 3011e3d655..cb5fed176e 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs @@ -1131,27 +1131,6 @@ namespace Umbraco.Web.PublishedCache.NuCache #endregion - #region Preview - - // TODO: Delete this all - public override string EnterPreview(IUser user, int contentId) - { - return "preview"; // anything - } - - public override void RefreshPreview(string previewToken, int contentId) - { - // nothing - } - - public override void ExitPreview(string previewToken) - { - // nothing - } - - #endregion - - #region Rebuild Database PreCache public override void Rebuild( diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs index 9c9e2d1da2..134f3b1938 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlPublishedSnapshotService.cs @@ -169,32 +169,6 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache #endregion - #region Preview - - public override string EnterPreview(IUser user, int contentId) - { - var previewContent = new PreviewContent(_xmlStore, user.Id); - previewContent.CreatePreviewSet(contentId, true); // preview branch below that content - return previewContent.Token; - //previewContent.ActivatePreviewCookie(); - } - - public override void RefreshPreview(string previewToken, int contentId) - { - if (previewToken.IsNullOrWhiteSpace()) return; - var previewContent = new PreviewContent(_xmlStore, previewToken); - previewContent.CreatePreviewSet(contentId, true); // preview branch below that content - } - - public override void ExitPreview(string previewToken) - { - if (previewToken.IsNullOrWhiteSpace()) return; - var previewContent = new PreviewContent(_xmlStore, previewToken); - previewContent.ClearPreviewSet(); - } - - #endregion - #region Xml specific /// diff --git a/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs b/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs index 3dd4191c2e..0405012898 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ViewEngines; using Microsoft.Extensions.Options; @@ -108,7 +108,6 @@ namespace Umbraco.Web.BackOffice.Controllers /// /// The endpoint that is loaded within the preview iframe /// - /// [Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)] public ActionResult Frame(int id, string culture) { @@ -119,22 +118,17 @@ namespace Umbraco.Web.BackOffice.Controllers return RedirectPermanent($"../../{id}.aspx{query}"); } + public ActionResult EnterPreview(int id) { var user = _backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser; - - var previewToken = _publishedSnapshotService.EnterPreview(user, id); - - _cookieManager.SetCookieValue(Constants.Web.PreviewCookieName, previewToken); + _cookieManager.SetCookieValue(Constants.Web.PreviewCookieName, "preview"); return null; } + public ActionResult End(string redir = null) { - var previewToken = _cookieManager.GetPreviewCookieValue(); - - _publishedSnapshotService.ExitPreview(previewToken); - _cookieManager.ExpireCookie(Constants.Web.PreviewCookieName); // Expire Client-side cookie that determines whether the user has accepted to be in Preview Mode when visiting the website.