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

OSOE-818: Upgrade to Orchard Core 2.0 #73

Merged
merged 70 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
9b0f74f
Update NuGet versions to pre-release.
sarahelsaig Feb 22, 2024
b0900f9
Merge remote-tracking branch 'origin/dev' into issue/OSOE-795
sarahelsaig Feb 22, 2024
590d604
Update OC to latest (because of bug fix for WorkflowTypeStep)
sarahelsaig Mar 3, 2024
4332395
Update OC preview version.
sarahelsaig Mar 7, 2024
21dcb67
Update OC package
sarahelsaig Mar 13, 2024
bbb5ac3
Better error diagnoses.
sarahelsaig Mar 17, 2024
a466db7
Actually working error reporting.
sarahelsaig Mar 17, 2024
0aef4ce
Remove unnecessary parentheses.
sarahelsaig Mar 17, 2024
1a717d5
Misc code cleanup.
sarahelsaig Mar 17, 2024
7b8ca2b
Update OC preview version.
sarahelsaig Apr 23, 2024
e72f5d7
Update OC package version.
sarahelsaig Apr 27, 2024
714e6cc
Update OC versions
sarahelsaig May 4, 2024
d1e8916
Update OC to the latest preview.
sarahelsaig May 7, 2024
ddfe7d9
Merge pull request #63 from Lombiq/issue/OSOE-795
dministro May 15, 2024
4cfbb26
Merge remote-tracking branch 'origin/dev' into task/system-text-json-…
sarahelsaig May 16, 2024
c6fd8f4
Merge remote-tracking branch 'origin/dev' into task/system-text-json-…
sarahelsaig May 28, 2024
51ca667
Update OC preview version.
sarahelsaig May 28, 2024
a0e7f91
Update OC preview version.
sarahelsaig May 30, 2024
605c107
Fix new "Obsolete" warnings.
sarahelsaig May 30, 2024
a01290c
Unusing.
sarahelsaig May 30, 2024
e401d2c
Update OC preview version.
sarahelsaig Jun 5, 2024
0c4388c
Merge remote-tracking branch 'origin/dev' into task/system-text-json-…
sarahelsaig Jun 14, 2024
3bc7399
Merge branch 'task/system-text-json-migration' into issue/OCC-245
sarahelsaig Jun 14, 2024
d289fd9
Fix warnings.
sarahelsaig Jun 17, 2024
f7cc9bb
Update OC version.
sarahelsaig Jun 18, 2024
c00df41
Update OC version.
sarahelsaig Jun 19, 2024
53ebd47
Update OC preview version.
sarahelsaig Jun 21, 2024
39d2027
Update OC preview version.
sarahelsaig Jul 11, 2024
0bd8558
Merge remote-tracking branch 'origin/dev' into issue/OCC-245
sarahelsaig Jul 11, 2024
0b4fe01
Fix package consolidation.
sarahelsaig Jul 11, 2024
a546727
Merge remote-tracking branch 'origin/dev' into task/system-text-json-…
sarahelsaig Jul 13, 2024
133527e
Merge branch 'task/system-text-json-migration' into issue/OCC-245
sarahelsaig Jul 13, 2024
4b50dd0
Update HL version.
sarahelsaig Jul 13, 2024
160cd3e
Update UITT version.
sarahelsaig Jul 13, 2024
14ef59c
Update HL nuget version.
sarahelsaig Jul 16, 2024
47ef9db
Update all UITT Nuget versions.
sarahelsaig Jul 16, 2024
17c9f61
Update package version.
sarahelsaig Jul 16, 2024
1b1ea9b
Update OC preview versions.
sarahelsaig Jul 24, 2024
f569020
Update HL preview version.
sarahelsaig Jul 26, 2024
b6f89db
Update UITT preview version.
sarahelsaig Jul 26, 2024
2a6c750
Update HL preview.
sarahelsaig Jul 27, 2024
eeb5e75
Update UITT version.
sarahelsaig Jul 27, 2024
ab46984
Update UITT preview version.
sarahelsaig Jul 27, 2024
26d6264
NuGet.config
sarahelsaig Jul 27, 2024
d3768b9
Update HL nuget version.
sarahelsaig Jul 27, 2024
eff4332
Update HL.
sarahelsaig Jul 27, 2024
3b77f4e
Merge pull request #68 from Lombiq/issue/OCC-245
Piedone Jul 28, 2024
4f409f9
Update OC preview version.
sarahelsaig Jul 29, 2024
449242c
Update OC preview versions.
sarahelsaig Jul 30, 2024
0595fed
Update OC preview version.
sarahelsaig Aug 6, 2024
9849532
Use CreateModelAsync where applicable.
sarahelsaig Aug 7, 2024
40a3b37
Update HL alpha version.
sarahelsaig Aug 7, 2024
a47b2fb
Update UITT alpha version.
sarahelsaig Aug 7, 2024
be7d30f
Update OC preview version.
sarahelsaig Aug 7, 2024
6052c90
Update OC preview.
sarahelsaig Aug 8, 2024
b1b4224
Update new breaking changes.
sarahelsaig Aug 8, 2024
938c10b
Merge pull request #72 from Lombiq/issue/OSOE-893
sarahelsaig Aug 9, 2024
2b87e6d
Update HL alpha version.
sarahelsaig Aug 9, 2024
f9f04b8
Update UITT alpha version.
sarahelsaig Aug 9, 2024
19c67f4
Update OC preview version.
sarahelsaig Aug 20, 2024
8865915
Update OC
sarahelsaig Aug 21, 2024
af41a73
Update OC preview version.
sarahelsaig Aug 23, 2024
a7591f3
Use OC release version.
sarahelsaig Sep 22, 2024
a98365f
Update HL preview.
sarahelsaig Sep 23, 2024
f65ec16
Update HL.
sarahelsaig Sep 23, 2024
6acdb14
Use AddNavigationProvider everywhere.
sarahelsaig Sep 24, 2024
cde92c4
Make migrations and background tasks sealed.
sarahelsaig Sep 24, 2024
681ff44
Seal INavigationProvider, IAsyncResultFilter, IPermissionProvider, St…
sarahelsaig Sep 24, 2024
503b759
Update HL NuGet version.
sarahelsaig Sep 25, 2024
09099d3
Update UITT version.
sarahelsaig Sep 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
using Lombiq.ContentEditors.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OrchardCore.Contents;
using OrchardCore.Modules;
using System.Threading.Tasks;
using static OrchardCore.Contents.CommonPermissions;

namespace Lombiq.ContentEditors.Samples.Controllers;

// In case you want to create an async editor UI on a page other than the admin UI, you can create a similar controller
// to this one.
[Feature(FeatureIds.Samples)]
[Route(Routes.FrontEndContentItemAsyncEditor)]
public class FrontEndDemoContentItemAsyncEditorController : Controller
public sealed class FrontEndDemoContentItemAsyncEditorController : Controller
{
private readonly IAuthorizationService _authorizationService;

Expand All @@ -25,7 +25,7 @@ public async Task<IActionResult> Index(string contentItemId)
{
if (!ModelState.IsValid) return BadRequest(ModelState);

if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContent)) return this.ChallengeOrForbid();
if (!await _authorizationService.AuthorizeAsync(User, EditContent)) return this.ChallengeOrForbid();

// You can use the existing ContentItemAsyncEditorViewModel to pass the required data.
return View(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
using Lombiq.ContentEditors.Samples.ViewModels;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Display.Models;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using System.Threading.Tasks;

namespace Lombiq.ContentEditors.Samples.Drivers;

// This is the driver for the SupportTicketPart. It'll generate and place editor shapes for the respective editor
// groups.
public class SupportTicketPartDisplayDriver : ContentPartDisplayDriver<SupportTicketPart>
public sealed class SupportTicketPartDisplayDriver : ContentPartDisplayDriver<SupportTicketPart>
{
// The editor shapes are generated here. The shape is placed from here instead of using the placement.json file.
public override IDisplayResult Edit(SupportTicketPart part, BuildPartEditorContext context) =>
Expand All @@ -27,23 +27,21 @@ public override IDisplayResult Edit(SupportTicketPart part, BuildPartEditorConte
viewModel.Description = part.Description;
}).OnGroup(EditorGroups.SupportTicket.Details).Location("Content"));

public override async Task<IDisplayResult> UpdateAsync(SupportTicketPart part, IUpdateModel updater, UpdatePartEditorContext context)
public override async Task<IDisplayResult> UpdateAsync(SupportTicketPart part, UpdatePartEditorContext context)
{
// It's a good idea to check what editor group is being updated. This way you can have different update logic
// for different editor groups and you won't update properties that aren't on the current editor group.
// for different editor groups, and you won't update properties that aren't on the current editor group.
switch (context.GroupId)
{
case EditorGroups.SupportTicket.Reporter:
var reporterViewModel = new EditSupportTicketReporterViewModel();
await updater.TryUpdateModelAsync(reporterViewModel, Prefix);
var reporterViewModel = await context.CreateModelAsync<EditSupportTicketReporterViewModel>(Prefix);

part.Name = reporterViewModel.Name;
part.Email = reporterViewModel.Email;

break;
case EditorGroups.SupportTicket.Details:
var detailsViewModel = new EditSupportTicketDetailsViewModel();
await updater.TryUpdateModelAsync(detailsViewModel, Prefix);
var detailsViewModel = await context.CreateModelAsync<EditSupportTicketDetailsViewModel>(Prefix);

part.Url = detailsViewModel.Url;
part.Description = detailsViewModel.Description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.0" />
<PackageReference Include="OrchardCore.Contents" Version="1.8.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0" />
<PackageReference Include="OrchardCore.Contents" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Lombiq.ContentEditors.Samples.Migrations;

// This is the migration class for the Employee content type. Nothing specific to async editors here.
public class EmployeeMigrations : DataMigration
public sealed class EmployeeMigrations : DataMigration
{
private readonly IContentDefinitionManager _contentDefinitionManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Lombiq.ContentEditors.Samples.Migrations;

// This is the migration class for the Support Ticket content type. Nothing specific to async editors here.
public class SupportTicketMigrations : DataMigration
public sealed class SupportTicketMigrations : DataMigration
{
private readonly IContentDefinitionManager _contentDefinitionManager;

Expand Down
4 changes: 2 additions & 2 deletions Lombiq.ContentEditors.Samples/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace Lombiq.ContentEditors.Samples;

[Feature(FeatureIds.Samples)]
public class Startup : StartupBase
public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
Expand All @@ -33,6 +33,6 @@ public override void ConfigureServices(IServiceCollection services)

services.AddTransient<IConfigureOptions<ResourceManagementOptions>, ResourceManagementOptionsConfiguration>();

services.AddScoped<INavigationProvider, ContentEditorsSamplesNavigationProvider>();
services.AddNavigationProvider<ContentEditorsSamplesNavigationProvider>();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Atata;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Services;
using OpenQA.Selenium;
using Shouldly;
using System.Threading.Tasks;

namespace Lombiq.ContentEditors.Tests.UI.Extensions;
Expand All @@ -12,7 +14,7 @@ public static Task EnableContentEditorsSamplesFeatureAsync(this UITestContext co

public static async Task<UITestContext> TestDemoContentItemAsyncEditorAsync(this UITestContext context)
{
await context.GoToRelativeUrlAsync("/Admin/ContentItemAsyncEditor/EmployeeAsyncEditorProvider/Employee");
await context.GoToAdminRelativeUrlAsync("/ContentItemAsyncEditor/EmployeeAsyncEditorProvider/Employee");

context.Exists(By.XPath("//label[. = 'Name']"));
context.Exists(By.XPath("//*[contains(@class, 'asyncEditor__groupLink') and contains(., 'Personal Details')]"));
Expand All @@ -24,9 +26,11 @@ public static async Task<UITestContext> TestDemoContentItemAsyncEditorAsync(this
await context.FillInWithRetriesAsync(By.Id("AsyncEditorEmployeePart_Position_Text"), "CEO");
await context.FillInWithRetriesAsync(By.Id("AsyncEditorEmployeePart_Office_Text"), "Budapest");
await context.ClickReliablyOnAsync(By.ClassName("asyncEditor__submitAction"));
context.Exists(
By.XPath(
"//*[contains(@class, 'asyncEditor__message') and contains(., 'Editor has been successfully submitted.')]"));

context.Exists(By.ClassName("asyncEditor__messages"));
var errorMessage = context.Get(By.ClassName("asyncEditor__error").Safely());
errorMessage?.Text?.ShouldBeNullOrWhiteSpace(errorMessage.GetAttribute("data-error-json"));
context.Get(By.ClassName("asyncEditor__message")).Text.Trim().ShouldBe("Editor has been successfully submitted.");

return context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.Tests.UI" Version="10.0.1" />
<PackageReference Include="Lombiq.Tests.UI" Version="10.0.2-alpha.5.osoe-818" />
</ItemGroup>

<ItemGroup>
Expand Down
46 changes: 29 additions & 17 deletions Lombiq.ContentEditors/Assets/Scripts/async-editor/async-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,42 @@ class AsyncEditorApiClient {
this.contentType = parameters.contentType;
}

async fetchEditor(callback, contentId, editorGroup, nextEditorGroup, requestOptions, raiseEvent) {
try {
const response = await fetch(this.createUrl(contentId, editorGroup, nextEditorGroup), requestOptions);
const data = await response.json();
const success = data.type !== 'Error';

callback(success, data);
if (!success) return;

if (raiseEvent) {
const submittedEditorEvent = new CustomEvent('asyncEditorSubmittedEditor', {
bubbles: true,
cancelable: true,
detail: { asyncEditor: window.asyncEditor },
});
document.dispatchEvent(submittedEditorEvent);
}
}
catch (error) {
callback(false, error);
}
}

loadEditor(contentId, editorGroup, callback) {
return fetch(this.createUrl(contentId, editorGroup))
.then((response) => response.json())
.then((data) => callback(true, data))
.catch((error) => callback(false, error));
return this.fetchEditor(callback, contentId, editorGroup);
}

submitEditor(contentId, editorGroup, nextEditorGroup, formData, callback) {
return fetch(this.createUrl(contentId, editorGroup, nextEditorGroup), {
const requestOptions = {
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
body: new URLSearchParams(formData),
})
.then((response) => response.json())
.then((data) => callback(true, data))
.then(() => {
const submittedEditorEvent = new CustomEvent('asyncEditorSubmittedEditor', {
bubbles: true,
cancelable: true,
detail: { asyncEditor: window.asyncEditor },
});
document.dispatchEvent(submittedEditorEvent);
})
.catch((error) => callback(false, error));
};
return this.fetchEditor(callback, contentId, editorGroup, nextEditorGroup, requestOptions, true);
}

createUrl(contentId, editorGroup, nextEditorGroup) {
Expand Down Expand Up @@ -67,6 +77,7 @@ window.asyncEditor.editor = {
api: null,
message: '',
errorText: '',
errorJson: '',
contentId: '',
editorHtml: '',
validationSummaryHtml: '',
Expand Down Expand Up @@ -166,6 +177,7 @@ window.asyncEditor.editor = {
if (shouldUpdateQuery) self.updateQuery();
}
else {
self.errorJson = JSON.stringify({ error: data, string: data.toString() });
self.errorText = self.defaultErrorText;
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Lombiq.ContentEditors.Constants;
using Lombiq.ContentEditors.Models;
using Lombiq.ContentEditors.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OrchardCore.ContentManagement;
using OrchardCore.Modules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -12,7 +14,7 @@ namespace Lombiq.ContentEditors.Controllers;

[Feature(FeatureIds.AsyncEditor)]
[Route(Routes.ContentItemAsyncEditorApi)]
public class ContentItemAsyncEditorApiController : Controller
public sealed class ContentItemAsyncEditorApiController : Controller
{
private readonly IEnumerable<IAsyncEditorProvider<ContentItem>> _providers;
private readonly IContentManager _contentManager;
Expand Down Expand Up @@ -46,32 +48,42 @@ public async Task<ActionResult<RenderedAsyncEditorGroupRequest>> Get([FromQuery]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Post([FromQuery] SubmitAsyncEditorRequest request)
{
var provider = GetProvider(request.ProviderName);
if (provider == null) return NotFound();
try
{
var provider = GetProvider(request.ProviderName);
if (provider == null) return Fail($"Couldn't get the provider \"{request.ProviderName}\".");

var item = await _contentManager.GetOrCreateAsync(request.ContentId, request.ContentType, VersionOptions.Latest);
if (item == null) return NotFound();
var item = await _contentManager.GetOrCreateAsync(request.ContentId, request.ContentType, VersionOptions.Latest);
if (item == null) return Fail($"Couldn't find the content item \"{request.ContentId}\".");

var context = PopulateContext(request, item);
if (!await provider.CanRenderEditorGroupAsync(context)) return NotFound();
var context = PopulateContext(request, item);
if (!await provider.CanRenderEditorGroupAsync(context))
{
return Fail($"The editor group of provider \"{request.ProviderName}\" can't be rendered.");
}

var result = await provider.UpdateEditorAsync(context);
if (!result.ModelState.IsValid ||
string.IsNullOrEmpty(request.NextEditorGroup) ||
request.NextEditorGroup == request.EditorGroup)
{
var result = await provider.UpdateEditorAsync(context);
if (!result.ModelState.IsValid ||
string.IsNullOrEmpty(request.NextEditorGroup) ||
request.NextEditorGroup == request.EditorGroup)
{
return await AsyncEditorResultAsync(
context,
provider,
renderedEditor: await result.RenderedEditorShapeFactory(),
message: result.Message);
}

var nextEditorContext = PopulateContext(request, item, request.NextEditorGroup);
return await AsyncEditorResultAsync(
context,
!await provider.CanRenderEditorGroupAsync(nextEditorContext) ? context : nextEditorContext,
provider,
renderedEditor: await result.RenderedEditorShapeFactory(),
message: result.Message);
}

var nextEditorContext = PopulateContext(request, item, request.NextEditorGroup);
return await AsyncEditorResultAsync(
!await provider.CanRenderEditorGroupAsync(nextEditorContext) ? context : nextEditorContext,
provider,
message: result.Message);
catch (Exception exception)
{
return Fail(exception);
}
}

private IAsyncEditorProvider<ContentItem> GetProvider(string name) =>
Expand Down Expand Up @@ -116,4 +128,14 @@ private async Task<ViewResult> AsyncEditorResultAsync(
Message = message,
});
}

/// <summary>
/// Provides serialized JSON information during local development, but ony a generic error message in production.
/// It's useful to always return JSON, regardless whether the request succeeded or failed.
/// </summary>
private JsonResult Fail(object data) => Json(new
{
Type = "Error",
Content = HttpContext.IsDevelopmentAndLocalhost() ? data : "Something went wrong.",
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Lombiq.ContentEditors.Controllers;
[Feature(FeatureIds.AsyncEditor)]
[Admin]
[Route(Routes.ContentItemAsyncEditor)]
public class ContentItemAsyncEditorController : Controller
public sealed class ContentItemAsyncEditorController : Controller
{
[HttpGet("{providerName}/{contentType}/{contentItemId?}")]
public ActionResult Index(string providerName, string contentType, string contentItemId)
Expand Down
16 changes: 8 additions & 8 deletions Lombiq.ContentEditors/Lombiq.ContentEditors.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.0" />
<PackageReference Include="OrchardCore.ContentFields" Version="1.8.0" />
<PackageReference Include="OrchardCore.ContentManagement" Version="1.8.0" />
<PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="1.8.0" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.8.0" />
<PackageReference Include="OrchardCore.Media" Version="1.8.0" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.8.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0" />
<PackageReference Include="OrchardCore.ContentFields" Version="2.0.0" />
<PackageReference Include="OrchardCore.ContentManagement" Version="2.0.0" />
<PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="2.0.0" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="2.0.0" />
<PackageReference Include="OrchardCore.Media" Version="2.0.0" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -47,7 +47,7 @@
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="10.0.0" />
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="10.0.1-alpha.8.osoe-818" />
<PackageReference Include="Lombiq.NodeJs.Extensions" Version="2.1.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Lombiq.ContentEditors/Migrations/AsyncEditorMigrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Lombiq.ContentEditors.Migrations;

public class AsyncEditorMigrations : DataMigration
public sealed class AsyncEditorMigrations : DataMigration
{
public async Task<int> CreateAsync()
{
Expand Down
Loading