-
Notifications
You must be signed in to change notification settings - Fork 9
Pages MetaData Editing Mode Support #29
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
bb946a5
MetaData Config & Render calls configured
robearlam 3c023f6
Configured metadata render method to correctly render page using new …
robearlam 5a1d70d
Moved GQL logic out of LC.CLient and back into Pages logic. Introduce…
robearlam 1c8752e
Wired up Placeholder and Rendering chromes
robearlam bd0dcde
Metadata editing now working
robearlam 2b99fc6
Wired up EditingDictionaryQuery requests
robearlam 5f34722
Fixed failing unit tests
robearlam 5494e8e
Added UnitTests for EditingScriptsTagHelper
robearlam d007e5b
Added UnitTests for Pages GQL Factory, and RenderingEngine TagHelpers
robearlam b92f31d
ComponentName is now persisted in rendering collection, to be returne…
robearlam 01a9228
Added UnitTests for Pages Config Middleware
robearlam 5be1780
Added Unit Tests for Pages Setup Render Middleware call
robearlam 4ea37ae
Added UniTests for GraphQLEditingServiceHandler
robearlam ddb0716
Added UniTests for EditingChromes being added to response for Pages r…
robearlam 328561f
Restructured test for Pages config middleware
robearlam c2851cb
Fixed bug with ImageTagHelper and ViewCompponent
robearlam 4d1c1dd
Moved PagesSetupMiddleware in a Controller, other small fixes
robearlam 9e5608e
Moved log messages into Resources RESX
robearlam fb2f772
Added Resources RESX to Pages project
robearlam d0938ba
Refactored PlaceHolder processing to use Stack approach instead of re…
robearlam d380f8e
Improved logic controlling when Pages middleware executes
robearlam 4570f44
Moved Dictionary functionality out of PagesGQLHandler into dedicated …
robearlam fa5202e
Removed GraphQlClient used for EditingHandler, added GraphQLClient wi…
robearlam f8eee28
Changed to no longer persist component names for predicate registrati…
robearlam ac8a933
Code TidyUp, fixed all warnings
robearlam 1af1068
Removed ID property from EdtiableField as didnt need to be added
robearlam af13261
Created Integration tests for PagesSetupController
robearlam 8109f8b
Added Integration test for succesful call to get editing layout with …
robearlam 0a08769
Added csproj missing from previous commit
robearlam 17e0b09
Improved logic for when to enable editing of Fields in MetaData editi…
robearlam 21f0e77
Added handling for /config route OPTIONS request
robearlam 4371c24
Fixed correct component naming for ViewComponents and PartialViews
robearlam 17e6f29
Aligned empty placeholder classname with jss
robearlam 8fd259f
Fixed issue with rendering of empty nested placeholders due to incorr…
robearlam 0bc23b7
Style refactor
IvanLieckens 64cb3d7
Fixed incorrect error being thrown from Config call
robearlam 8cfecbf
Changes from PR Review
robearlam 7e2b893
Moved MetaData Queries back from constants to improve readability
robearlam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/Sitecore.AspNetCore.SDK.LayoutService.Client/Response/Model/DataSource.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using System.Runtime.Serialization; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model; | ||
|
|
||
| /// <summary> | ||
| /// Class used to define an items datasource information. | ||
| /// </summary> | ||
| public class DataSource | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the Id. | ||
| /// </summary> | ||
| public string Id { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the Language. | ||
| /// </summary> | ||
| public string Language { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the Revision. | ||
| /// </summary> | ||
| public string Revision { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the Version. | ||
| /// </summary> | ||
| public int Version { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Sitecore.AspNetCore.SDK.LayoutService.Client/Response/Model/MetaData.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| namespace Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model; | ||
|
|
||
| /// <summary> | ||
| /// Class used to define an items metadata information. | ||
| /// </summary> | ||
| public class MetaData | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the title. | ||
| /// </summary> | ||
| public string Title { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the FieldId. | ||
| /// </summary> | ||
| public string FieldId { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the FieldType. | ||
| /// </summary> | ||
| public string FieldType { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the RawValue. | ||
| /// </summary> | ||
| public string RawValue { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the DataSource. | ||
| /// </summary> | ||
| public DataSource? DataSource { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/Sitecore.AspNetCore.SDK.Pages/Configuration/PagesMarkerService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace Sitecore.AspNetCore.SDK.Pages.Configuration; | ||
|
|
||
| /// <summary> | ||
| /// Marker service used to identify when Pages services have been registered. | ||
| /// </summary> | ||
| internal class PagesMarkerService; |
37 changes: 37 additions & 0 deletions
37
src/Sitecore.AspNetCore.SDK.Pages/Configuration/PagesOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| namespace Sitecore.AspNetCore.SDK.Pages.Configuration; | ||
|
|
||
| /// <summary> | ||
| /// The options to configure the Pages middleware. | ||
| /// </summary> | ||
| public class PagesOptions | ||
| { | ||
| /// <summary> | ||
| /// Key used to define the settings section in config. | ||
| /// </summary> | ||
| public static readonly string Key = "SitecoreXmcPages"; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the config endpoint for Pages MetaData mode. | ||
| /// </summary> | ||
| public string? ConfigEndpoint { get; set; } = "/api/editing/config"; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the render endpoint for Pages MetaData mode. | ||
| /// </summary> | ||
| public string? RenderEndpoint { get; set; } = "/api/editing/render"; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the valid editing origin for all editing requests. | ||
| /// </summary> | ||
| public string? ValidEditingOrigin { get; set; } = "https://pages.sitecorecloud.io"; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the valid origins for the head to run under. | ||
| /// </summary> | ||
| public string? ValidOrigins { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the Editing Secret. | ||
| /// </summary> | ||
| public string? EditingSecret { get; set; } = string.Empty; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| namespace Sitecore.AspNetCore.SDK.Pages | ||
| { | ||
| /// <summary> | ||
| /// Class used to stored constants referenced throughout the Pages project. | ||
| /// </summary> | ||
| public static class Constants | ||
| { | ||
| /// <summary> | ||
| /// Class used to hold the names of different Layout Clients used by the Pages project. | ||
| /// </summary> | ||
| public static class LayoutClients | ||
| { | ||
| /// <summary> | ||
| /// Name of the Pages Editing Layout Client. | ||
| /// </summary> | ||
| public const string Pages = "pages"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Class used to hold the names of the different tag helpers defined in the Pages project. | ||
| /// </summary> | ||
| public static class SitecoreTagHelpers | ||
| { | ||
| /// <summary> | ||
| /// The HTML tag used to render the Editing Scripts tag helper. | ||
| /// </summary> | ||
| public const string EditScriptsHtmlTag = "sc-editingscripts"; | ||
| } | ||
| } | ||
| } |
149 changes: 149 additions & 0 deletions
149
src/Sitecore.AspNetCore.SDK.Pages/Controllers/PagesSetupController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.Options; | ||
| using Microsoft.Extensions.Primitives; | ||
| using Sitecore.AspNetCore.SDK.Pages.Configuration; | ||
| using Sitecore.AspNetCore.SDK.Pages.Middleware; | ||
| using Sitecore.AspNetCore.SDK.Pages.Models; | ||
| using Sitecore.AspNetCore.SDK.RenderingEngine.Configuration; | ||
|
|
||
| namespace Sitecore.AspNetCore.SDK.Pages.Controllers | ||
| { | ||
| /// <summary> | ||
| /// Pages Setup Controller, used to handle the configuration requests that MetaData editing mode uses to validate the editing host can connect successfully. | ||
| /// </summary> | ||
| /// <param name="options">The Sitecore Pages configuration options.</param> | ||
| /// <param name="logger">The <see cref="ILogger"/> to use for logging.</param> | ||
| /// <param name="renderingEngineOptions">The RenderingEngineOptions, used to retriece a list of all registered renderings for the applications.</param> | ||
| public class PagesSetupController(IOptions<PagesOptions> options, ILogger<PagesSetupController> logger, IOptions<RenderingEngineOptions> renderingEngineOptions) : ControllerBase | ||
| { | ||
| private readonly PagesOptions options = options != null ? options.Value : throw new ArgumentNullException(nameof(options)); | ||
| private readonly ILogger<PagesSetupController> logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
| private readonly RenderingEngineOptions renderingEngineOptions = renderingEngineOptions != null ? renderingEngineOptions.Value : throw new ArgumentNullException(nameof(renderingEngineOptions)); | ||
|
|
||
| /// <summary> | ||
| /// The Config endpoint used to inform Pages how this editing host is configured and which components are implemented. | ||
| /// </summary> | ||
| /// <returns>PagesConfigResponse object.</returns> | ||
| [HttpGet] | ||
| public ActionResult<PagesConfigResponse> Config() | ||
| { | ||
| if (IsValidPagesConfigRequest(Request)) | ||
| { | ||
| logger.LogDebug("Processing valid Pages Config request"); | ||
| SetConfigResponseHeaders(Response); | ||
| return Ok(BuildConfigResponseBody()); | ||
| } | ||
|
|
||
| return BadRequest(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The render endpoint used to redirect the Pages application to the correct page. | ||
| /// </summary> | ||
| /// <returns>Redirect response.</returns> | ||
| [HttpGet] | ||
| public IActionResult Render() | ||
| { | ||
| if (IsValidPagesRenderRequest(Request)) | ||
| { | ||
| logger.LogDebug("Processing valid Pages Render request"); | ||
| PagesRenderArgs args = ParseQueryStringArgs(Request); | ||
| return Redirect($"{args.Route}?mode={args.Mode}&sc_itemid={args.ItemId}&sc_version={args.Version}&sc_lang={args.Language}&sc_site={args.Site}&sc_layoutKind={args.LayoutKind}&secret={args.EditingSecret}&tenant_id={args.TenantId}&route={args.Route}"); | ||
| } | ||
|
|
||
| return BadRequest(); | ||
| } | ||
|
|
||
| private PagesRenderArgs ParseQueryStringArgs(HttpRequest request) | ||
| { | ||
| return new PagesRenderArgs | ||
| { | ||
| ItemId = Guid.TryParse(request.Query["sc_itemid"].FirstOrDefault(), out Guid itemId) ? itemId : Guid.Empty, | ||
|
robearlam marked this conversation as resolved.
Outdated
|
||
| EditingSecret = request.Query["secret"].FirstOrDefault() ?? string.Empty, | ||
| Language = request.Query["sc_lang"].FirstOrDefault() ?? string.Empty, | ||
| LayoutKind = request.Query["sc_layoutKind"].FirstOrDefault() ?? string.Empty, | ||
| Mode = request.Query["mode"].FirstOrDefault() ?? string.Empty, | ||
| Route = request.Query["route"].FirstOrDefault() ?? string.Empty, | ||
| Site = request.Query["sc_site"].FirstOrDefault() ?? string.Empty, | ||
| Version = int.TryParse(request.Query["sc_version"].FirstOrDefault(), out int version) ? version : 0, | ||
| TenantId = request.Query["tenant_id"].FirstOrDefault() ?? string.Empty, | ||
| }; | ||
| } | ||
|
|
||
| private bool IsValidPagesRenderRequest(HttpRequest httpRequest) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(httpRequest); | ||
|
|
||
| if (!IsValidEditingSecret(httpRequest)) | ||
| { | ||
| logger.LogError("Invalid Pages Editing Secret Value"); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| private PagesConfigResponse BuildConfigResponseBody() | ||
| { | ||
| return new PagesConfigResponse | ||
| { | ||
| EditMode = "metadata", | ||
| Components = renderingEngineOptions.RendererRegistry.Select(x => x.Value.ComponentName).ToList() | ||
| }; | ||
| } | ||
|
|
||
| private void SetConfigResponseHeaders(HttpResponse httpResponse) | ||
| { | ||
| httpResponse.Headers.ContentSecurityPolicy = $"frame-ancestors 'self' {options.ValidOrigins} {options.ValidEditingOrigin}"; | ||
|
robearlam marked this conversation as resolved.
Outdated
|
||
| httpResponse.Headers.AccessControlAllowOrigin = options.ValidEditingOrigin; | ||
| httpResponse.Headers.AccessControlAllowMethods = "GET, POST, OPTIONS, PUT, PATCH, DELETE"; | ||
| httpResponse.StatusCode = StatusCodes.Status200OK; | ||
| httpResponse.ContentType = "application/json"; | ||
| } | ||
|
|
||
| private bool IsValidPagesConfigRequest(HttpRequest httpRequest) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(httpRequest); | ||
|
|
||
| if (!IsValidEditingSecret(httpRequest)) | ||
| { | ||
| logger.LogError("Invalid Pages Editing Secret Value"); | ||
| return false; | ||
| } | ||
|
|
||
| if (!RequestHasValidEditingOrigin(httpRequest)) | ||
| { | ||
| logger.LogError("Invalid Pages Editing Origin"); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| private bool IsValidEditingSecret(HttpRequest httpRequest) | ||
| { | ||
| if (httpRequest.Query.TryGetValue("secret", out StringValues editingSecretValues)) | ||
| { | ||
| string editingSecret = editingSecretValues.FirstOrDefault() ?? string.Empty; | ||
| if (editingSecret == options.EditingSecret) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private bool RequestHasValidEditingOrigin(HttpRequest httpRequest) | ||
| { | ||
| if (httpRequest.Headers.Origin == options.ValidEditingOrigin) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.