Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V14: Backend changes to facilitate Preview mode in Bellissima #16279

Merged
merged 16 commits into from
May 16, 2024

Conversation

elit0451
Copy link
Member

@elit0451 elit0451 commented May 13, 2024

Details

  • Updating SignalR Preview Hub to send Guid instead of int id;
  • Make UMB_PREVIEW cookie HttpOnly so that we are able to make a request to the server from a client on a different host;
  • Enable routing for the preview feature based on a Guid since we no longer expose integer ids by creating a new ContentFinderByKeyPath.
    • Creating a base class for common logic between ContentFinderByIdPath and ContentFinderByKeyPath;
    • Refactoring content finder tests.

Test

  • Make sure tests pass ✅ ;
  • Enable preview mode and verify that UMB_PREVIEW cookie is HttpOnly (see appendix*)
  • Create a simple content node with a template saying "Hello, World!";
    • Find its int id and guid key.
  • Verify that visiting https://localhost:44339/<nodeKey> and https://localhost:44339/<nodeId>:
    • Resolves to the same content node when using a valid key and a valid id of the same content node;
    • Resolves to 404 when using a random guid or -1 as int id;
    • Resolves to 404 when using valid int id or Guid key and setting Umbraco::CMS::WebRouting::DisableFindContentByIdPath to true (and you don't have the UMB_PREVIEW cookie).

Appendix

* Use the following endpoint in Swagger to enable preview mode and delete the cookie to disable it:

using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.Controllers;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Web.UI;

[Route("api/v{version:apiVersion}/myApi")]
[ApiVersion("1.0")]
[ApiExplorerSettings(GroupName = "A new API")]
public class MyApiController : ManagementApiControllerBase
{
    private readonly IPreviewService _previewService;

    public MyApiController(IPreviewService previewService)
    {
        _previewService = previewService;
    }

    [HttpGet]
    [Route("preview")]
    public IActionResult EnterPreview()
    {
        _previewService.EnterPreview();
        return Ok("In preview mode");
    }
}

@leekelleher leekelleher mentioned this pull request May 16, 2024
3 tasks
@bergmania bergmania merged commit 295f6f8 into v14/dev May 16, 2024
14 checks passed
@bergmania bergmania deleted the v14/bugfix/fix-preview branch May 16, 2024 13:53
@iOvergaard iOvergaard changed the title V14: Backend changes to facilitate Preview mode in Bellissimma V14: Backend changes to facilitate Preview mode in Bellissima May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants