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

link generating fixed #31

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Kentico.Xperience.Admin" Version="29.3.0" />
<PackageVersion Include="Kentico.Xperience.WebApp" Version="29.3.0" />
<PackageVersion Include="kentico.xperience.azurestorage" Version="29.3.0" />
<PackageVersion Include="kentico.xperience.imageprocessing" Version="29.3.0" />
<PackageVersion Include="Kentico.Xperience.Admin" Version="29.5.0" />
<PackageVersion Include="Kentico.Xperience.WebApp" Version="29.5.0" />
<PackageVersion Include="kentico.xperience.azurestorage" Version="29.5.0" />
<PackageVersion Include="kentico.xperience.imageprocessing" Version="29.5.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.6.0.74858" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
Expand Down
335 changes: 167 additions & 168 deletions examples/DancingGoat/packages.lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ internal class ZapierApiKeyListingPage : ListingPage
private readonly IInfoProvider<ApiKeyInfo> apiKeyInfoProvider;
private readonly IAuthenticatedUserAccessor userAccessor;
private readonly IUserInfoProvider userProvider;
private readonly IPageUrlGenerator pageUrlGenerator;
private readonly IPageLinkGenerator pageLinkGenerator;


public ZapierApiKeyListingPage(IInfoProvider<ApiKeyInfo> apiKeyInfoProvider, IAuthenticatedUserAccessor userAccessor, IUserInfoProvider userProvider, IPageUrlGenerator pageUrlGenerator)
public ZapierApiKeyListingPage(IInfoProvider<ApiKeyInfo> apiKeyInfoProvider, IAuthenticatedUserAccessor userAccessor, IUserInfoProvider userProvider, IPageLinkGenerator pageLinkGenerator)
{
this.apiKeyInfoProvider = apiKeyInfoProvider;
this.userAccessor = userAccessor;
this.userProvider = userProvider;
this.pageUrlGenerator = pageUrlGenerator;
this.pageLinkGenerator = pageLinkGenerator;
}


Expand Down Expand Up @@ -91,6 +91,9 @@ public async Task<INavigateResponse> Generate(CancellationToken _)
apiKeyInfoProvider.Set(apiKeyInfo);

transaction.Commit();
return NavigateTo(pageUrlGenerator.GenerateUrl<ZapierNewApiKeyPage>(apiKeyInfo.ApiKeyID.ToString()));
return NavigateTo(pageLinkGenerator.GetPath<ZapierNewApiKeyPage>(new PageParameterValues
{
{ typeof(ZapierApiKeyEditSection), apiKeyInfo.ApiKeyID }
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Kentico.Xperience.Zapier.Admin.UIPages;
internal class ZapierNewApiKeyPage : InfoEditPage<ApiKeyInfo>
{
private readonly IInfoProvider<ApiKeyInfo> apiKeyInfoProvider;
private readonly IPageUrlGenerator pageUrlGenerator;
private readonly IPageLinkGenerator pageLinkGenerator;
private readonly IZapierTokenManager tokenManager;


Expand All @@ -34,11 +34,11 @@ internal class ZapierNewApiKeyPage : InfoEditPage<ApiKeyInfo>
protected override bool RefetchAll => true;


public ZapierNewApiKeyPage(IFormComponentMapper formComponentMapper, IFormDataBinder formDataBinder, IInfoProvider<ApiKeyInfo> apiKeyInfoProvider, IPageUrlGenerator pageUrlGenerator, IZapierTokenManager tokenManager)
public ZapierNewApiKeyPage(IFormComponentMapper formComponentMapper, IFormDataBinder formDataBinder, IInfoProvider<ApiKeyInfo> apiKeyInfoProvider, IPageLinkGenerator pageLinkGenerator, IZapierTokenManager tokenManager)
: base(formComponentMapper, formDataBinder)
{
this.apiKeyInfoProvider = apiKeyInfoProvider;
this.pageUrlGenerator = pageUrlGenerator;
this.pageLinkGenerator = pageLinkGenerator;
this.tokenManager = tokenManager;
}

Expand Down Expand Up @@ -67,7 +67,7 @@ public override async Task ConfigurePage()

protected override async Task<ICommandResponse> SubmitInternal(FormSubmissionCommandArguments args, ICollection<IFormItem> items, IFormFieldValueProvider formFieldValueProvider)
{
string navigationUrl = pageUrlGenerator.GenerateUrl<ZapierApiKeyListingPage>();
string navigationUrl = pageLinkGenerator.GetPath<ZapierApiKeyListingPage>();
return await Task.FromResult(NavigateTo(navigationUrl, RefetchAll));
}

Expand Down
29 changes: 29 additions & 0 deletions src/Kentico.Xperience.Zapier/Helpers/AdminUrlHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Kentico.Xperience.Admin.Base;
using Kentico.Xperience.Admin.Base.UIPages;
using Kentico.Xperience.Admin.Headless.UIPages;
using Kentico.Xperience.Admin.Websites.UIPages;

namespace Kentico.Xperience.Zapier.Helpers;

internal static class AdminUrlHelper
{
internal static PageParameterValues GetWebPageParams(int webPageItemId, int websiteChannelId, string lang) => new()
{
{ typeof(WebPageLayout), $"{lang}_{webPageItemId}" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use new WebPageUrlIdentifier(lang, webPageItemId).ToString() to generate parameter for WebPageLayout.

{ typeof(WebPagesApplication), $"webpages-{websiteChannelId}" },
};

internal static PageParameterValues GetHeadlessParams(int headlessItemId, int headlessChannelId, string lang) => new()
{
{ typeof(HeadlessEditLayout), headlessItemId },
{ typeof(HeadlessChannelContentLanguage), lang },
{ typeof(HeadlessChannelApplication), $"headless-{headlessChannelId}"},
};

internal static PageParameterValues GetReusableParams(int contentItemId, int contentItemContentFolderId, string lang) => new()
{
{ typeof(ContentItemEditSection), contentItemId},
{ typeof(ContentHubFolder), contentItemContentFolderId },
{ typeof(ContentHubContentLanguage), lang },
};
}
25 changes: 25 additions & 0 deletions src/Kentico.Xperience.Zapier/Triggers/AdminLinkService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Kentico.Xperience.Admin.Base;

namespace Kentico.Xperience.Zapier.Triggers;


internal interface IAdminLinkService
{
string GenerateAdminLink<T>(PageParameterValues parameters, Uri baseUri);
}


internal class AdminLinkService : IAdminLinkService
{
private readonly IPageLinkGenerator pageLinkGenerator;

public AdminLinkService(IPageLinkGenerator pageLinkGenerator) => this.pageLinkGenerator = pageLinkGenerator;

public string GenerateAdminLink<T>(PageParameterValues parameters, Uri baseUri)
{
string relativePath = pageLinkGenerator.GetPath<T>(parameters);
var adminUrl = new Uri(baseUri, $"/admin{relativePath}");

return adminUrl.ToString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ namespace Kentico.Xperience.Zapier.Triggers.Handlers.Abstractions;
internal abstract class ZapierWorkflowHandler : ZapierTriggerHandler
{
private readonly IHttpContextAccessor httpContextAccessor;
protected readonly IAdminLinkService AdminLinkService;


protected ZapierWorkflowHandler(
ZapierTriggerInfo zapierTrigger,
IEventLogService? eventLogService,
HttpClient client,
IHttpContextAccessor httpContextAccessor)
IHttpContextAccessor httpContextAccessor,
IAdminLinkService adminLinkService)
: base(zapierTrigger, eventLogService, client)
=> this.httpContextAccessor = httpContextAccessor;
{
this.httpContextAccessor = httpContextAccessor;
AdminLinkService = adminLinkService;
}


protected Uri GetHostDomain() => new($"https://{httpContextAccessor.HttpContext?.Request.Host.Value ?? string.Empty}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using CMS.Core;

using Kentico.Integration.Zapier;
using Kentico.Xperience.Admin.Headless.UIPages;
using Kentico.Xperience.Zapier.Helpers;
using Kentico.Xperience.Zapier.Triggers.Handlers.Abstractions;

using Microsoft.AspNetCore.Http;
Expand All @@ -10,7 +12,9 @@ namespace Kentico.Xperience.Zapier.Triggers.Handlers;

internal class WorkflowHeadlessHandler : ZapierWorkflowHandler
{
public WorkflowHeadlessHandler(ZapierTriggerInfo zapierTrigger, IEventLogService? eventLogService, HttpClient client, IHttpContextAccessor httpContextAccessor) : base(zapierTrigger, eventLogService, client, httpContextAccessor)
public WorkflowHeadlessHandler(ZapierTriggerInfo zapierTrigger, IEventLogService? eventLogService,
HttpClient client, IHttpContextAccessor httpContextAccessor, IAdminLinkService adminLinkService) : base(
zapierTrigger, eventLogService, client, httpContextAccessor, adminLinkService)
{
}

Expand Down Expand Up @@ -44,9 +48,11 @@ private void Handler(object? sender, HeadlessItemWorkflowMoveToStepArguments e)
}

var data = e.GetZapierWorkflowPostObject();
var websiteUri = GetHostDomain();
var adminUrl = new Uri(websiteUri, $"/admin/headless-{e.HeadlessChannelID}/{e.ContentLanguageName}/list/{e.ID}");
data.TryAdd("AdminLink", adminUrl);

var pageParams = AdminUrlHelper.GetHeadlessParams(e.ID, e.HeadlessChannelID, e.ContentLanguageName);
string adminLink = AdminLinkService.GenerateAdminLink<HeadlessContentTab>(pageParams, GetHostDomain());

data.TryAdd("AdminLink", adminLink);

if (ZapierTrigger != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using CMS.ContentWorkflowEngine;
using CMS.Core;

using Kentico.Integration.Zapier;
using Kentico.Xperience.Admin.Websites.UIPages;
using Kentico.Xperience.Zapier.Helpers;
using Kentico.Xperience.Zapier.Triggers.Handlers.Abstractions;

using Microsoft.AspNetCore.Http;
Expand All @@ -10,8 +11,15 @@ namespace Kentico.Xperience.Zapier.Triggers.Handlers;

internal class WorkflowPagesHandler : ZapierWorkflowHandler
{
public WorkflowPagesHandler(ZapierTriggerInfo zapierTrigger, IEventLogService? eventLogService, HttpClient client, IHttpContextAccessor httpContextAccessor) : base(zapierTrigger, eventLogService, client, httpContextAccessor)
public WorkflowPagesHandler(
ZapierTriggerInfo zapierTrigger,
IEventLogService? eventLogService,
HttpClient client,
IHttpContextAccessor httpContextAccessor,
IAdminLinkService adminLinkService)
: base(zapierTrigger, eventLogService, client, httpContextAccessor, adminLinkService)
{

}


Expand Down Expand Up @@ -45,10 +53,11 @@ private void Handler(object? sender, WebPageWorkflowMoveToStepArguments e)


var data = e.GetZapierWorkflowPostObject();
var websiteUri = GetHostDomain();
var adminUrl = new Uri(websiteUri, $"/admin/webpages-{e.WebsiteChannelID}/{e.ContentLanguageName}_{e.ID}");

data.TryAdd("AdminLink", adminUrl);
var pageParams = AdminUrlHelper.GetWebPageParams(e.ID, e.WebsiteChannelID, e.ContentLanguageName);
string adminLink = AdminLinkService.GenerateAdminLink<ContentTab>(pageParams, GetHostDomain());

data.TryAdd("AdminLink", adminLink);


if (ZapierTrigger != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using CMS.ContentEngine;
using CMS.ContentEngine.Internal;
using CMS.ContentWorkflowEngine;
using CMS.Core;
using CMS.DataEngine;

using Kentico.Integration.Zapier;
using Kentico.Xperience.Admin.Base.UIPages;
using Kentico.Xperience.Zapier.Helpers;
using Kentico.Xperience.Zapier.Triggers.Handlers.Abstractions;

using Microsoft.AspNetCore.Http;
Expand All @@ -13,13 +16,20 @@ namespace Kentico.Xperience.Zapier.Triggers.Handlers;
internal class WorkflowReusableHandler : ZapierWorkflowHandler
{
private readonly IInfoProvider<ContentLanguageInfo> contentLanguageProvider;
private readonly IInfoProvider<ContentItemInfo> contentInfoProvider;

public WorkflowReusableHandler(ZapierTriggerInfo zapierTrigger,
IEventLogService? eventLogService,
HttpClient client,
IHttpContextAccessor httpContextAccessor,
IInfoProvider<ContentLanguageInfo> contentLanguageProvider)
: base(zapierTrigger, eventLogService, client, httpContextAccessor) =>
IInfoProvider<ContentLanguageInfo> contentLanguageProvider,
IInfoProvider<ContentItemInfo> contentInfoProvider,
IAdminLinkService adminLinkService)
: base(zapierTrigger, eventLogService, client, httpContextAccessor, adminLinkService)
{
this.contentLanguageProvider = contentLanguageProvider;
this.contentInfoProvider = contentInfoProvider;
}


public override bool RegistrationProcessor(bool register = true)
Expand Down Expand Up @@ -52,12 +62,15 @@ private void Handler(object? sender, ContentItemWorkflowMoveToStepArguments e)

var data = e.GetZapierWorkflowPostObject();

var contentItemInfo = contentInfoProvider.Get(e.ID);
var info = contentLanguageProvider.Get(e.ContentLanguageID);

var websiteUri = GetHostDomain();
var adminUrl = new Uri(websiteUri, $"/admin/content-hub/{info.ContentLanguageName}/list/{e.ID}");
var pageParams = AdminUrlHelper.GetReusableParams(e.ID, contentItemInfo.ContentItemContentFolderID,
info.ContentLanguageName);

string adminLink = AdminLinkService.GenerateAdminLink<ContentItemEdit>(pageParams, GetHostDomain());

data.TryAdd("AdminLink", adminUrl);
data.TryAdd("AdminLink", adminLink);


if (ZapierTrigger != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CMS.ContentEngine;
using CMS.ContentEngine.Internal;
using CMS.Core;
using CMS.DataEngine;
using CMS.EventLog;
Expand All @@ -23,10 +24,13 @@ internal class ZapierTriggerHandlerFactory : IZapierTriggerHandlerFactory
private readonly HttpClient client;
private readonly IWorkflowScopeService workflowScopeService;
private readonly IInfoProvider<ContentLanguageInfo> contentLanguageProvider;
private readonly IInfoProvider<ContentItemInfo> contentInfoProvider;

private readonly IHttpContextAccessor httpContextAccessor;
private readonly IInfoProvider<ZapierTriggerEventLogTypeInfo> triggerEventLogTypeInfoProvider;
private readonly IProgressiveCache progressiveCache;
private readonly IEventLogService logService;
private readonly IAdminLinkService adminLinkService;


public ZapierTriggerHandlerFactory(HttpClient client,
Expand All @@ -35,7 +39,9 @@ public ZapierTriggerHandlerFactory(HttpClient client,
IHttpContextAccessor httpContextAccessor,
IInfoProvider<ZapierTriggerEventLogTypeInfo> triggerEventLogTypeInfoProvider,
IProgressiveCache progressiveCache,
IEventLogService logService)
IEventLogService logService,
IAdminLinkService adminLinkService,
IInfoProvider<ContentItemInfo> contentInfoProvider)
{
this.client = client;
this.workflowScopeService = workflowScopeService;
Expand All @@ -44,6 +50,8 @@ public ZapierTriggerHandlerFactory(HttpClient client,
this.triggerEventLogTypeInfoProvider = triggerEventLogTypeInfoProvider;
this.progressiveCache = progressiveCache;
this.logService = logService;
this.adminLinkService = adminLinkService;
this.contentInfoProvider = contentInfoProvider;
}


Expand Down Expand Up @@ -73,9 +81,9 @@ public ZapierTriggerHandlerFactory(HttpClient client,

ZapierWorkflowHandler workflowHandler = classType switch
{
ZapierTriggerObjectClassType.Website => new WorkflowPagesHandler(trigger, logService, client, httpContextAccessor),
ZapierTriggerObjectClassType.Reusable => new WorkflowReusableHandler(trigger, logService, client, httpContextAccessor, contentLanguageProvider),
ZapierTriggerObjectClassType.Headless => new WorkflowHeadlessHandler(trigger, logService, client, httpContextAccessor),
ZapierTriggerObjectClassType.Website => new WorkflowPagesHandler(trigger, logService, client, httpContextAccessor, adminLinkService),
ZapierTriggerObjectClassType.Reusable => new WorkflowReusableHandler(trigger, logService, client, httpContextAccessor, contentLanguageProvider, contentInfoProvider, adminLinkService),
ZapierTriggerObjectClassType.Headless => new WorkflowHeadlessHandler(trigger, logService, client, httpContextAccessor, adminLinkService),
ZapierTriggerObjectClassType.Form => throw new NotImplementedException(),
ZapierTriggerObjectClassType.Other => throw new NotImplementedException(),
ZapierTriggerObjectClassType.System => throw new NotImplementedException(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static IServiceCollection AddKenticoZapier(this IServiceCollection servic
services.AddSingleton<IZapierTriggerService, ZapierTriggerService>();
services.AddSingleton<IZapierTokenManager, ZapierTokenManager>();
services.AddSingleton<IZapierTriggerHandlerFactory, ZapierTriggerHandlerFactory>();

services.AddSingleton<IAdminLinkService, AdminLinkService>();
services.AddSingleton<IWorkflowScopeService, WorkflowScopeService>();

services.AddAuthentication()
Expand Down
Loading
Loading