Skip to content

Commit

Permalink
Merge pull request #10 from Kentico/feat/1PhaseCRfixes
Browse files Browse the repository at this point in the history
1st phase CR fixes
  • Loading branch information
ondrejhenek authored Mar 12, 2024
2 parents 513dc51 + d4c1d39 commit 439ab45
Show file tree
Hide file tree
Showing 19 changed files with 533 additions and 503 deletions.
5 changes: 1 addition & 4 deletions src/Kentico.Xperience.Zapier/Admin/ApiKeyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ internal static string GetToken(string input)
internal static bool VerifyToken(string input, string hash)
{
string hashOfInput = GetToken(input);

var comparer = StringComparer.OrdinalIgnoreCase;

return comparer.Compare(hashOfInput, hash) == 0;
return hashOfInput == hash;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override Task ConfigurePage()
{
PageConfiguration.Callouts = [new()
{
Content = "Generate button will create a new API Key.If API Key already exists, this will override the existing one. Generating new key, can broke other connected zapier webhooks. Keep that in mind!",
Content = LocalizationService.GetString("apikey.callout"),
Type = CalloutType.FriendlyWarning,
ContentAsHtml = true
}];
Expand Down Expand Up @@ -88,7 +88,7 @@ public async Task<ICommandResponse<RowActionResult>> Generate(CancellationToken

transaction.Commit();

return ResponseFrom(rowAction).UseCommand("LoadData").AddWarningMessage($"Save your API Key (It will not be visible again): {apiKey}"); //Nice to have - Can be redirected to a separate page to display ApiKey
return ResponseFrom(rowAction).UseCommand("LoadData").AddWarningMessage(string.Format(LocalizationService.GetString("apikey.savemessage"), apiKey)); //Nice to have - Can be redirected to a separate page to display ApiKey
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel;
using CMS.DataEngine;
using CMS.DataEngine;
using CMS.Helpers;
using Kentico.Integration.Zapier;
using Kentico.Xperience.Admin.Base.FormAnnotations;
Expand All @@ -11,22 +10,22 @@ namespace Kentico.Xperience.Zapier.Admin.UIPages;
internal class ZapierTriggerEditModel
{
[RequiredValidationRule]
[TextInputComponent(Label = "Name", Order = 0, Disabled = true)]
[TextInputComponent(Label = "Name", Order = 0)]
public string? Name { get; set; }

[CheckBoxComponent(Label = "Enabled", Order = 1, Disabled = true)]
[CheckBoxComponent(Label = "Enabled", Order = 1)]
public bool Enabled { get; set; }

[RequiredValidationRule]
[ObjectSelectorComponent("cms.class", Label = "Object type", Disabled = true, MaximumItems = 1, Placeholder = "Choose an option", Order = 2, WhereConditionProviderType = typeof(ZapierTriggerObjectTypesWhereConditionProvider))]
[ObjectSelectorComponent("cms.class", Label = "Object type", MaximumItems = 1, Placeholder = "Choose an option", Order = 2, WhereConditionProviderType = typeof(ZapierTriggerObjectTypesWhereConditionProvider))]
public IEnumerable<ObjectRelatedItem>? ObjectType { get; set; }

[RequiredValidationRule]
[DropDownComponent(Label = "Event", Order = 3, Disabled = true, DataProviderType = typeof(ZapierTriggerEventTypesDropdownOptionsProvider))]
[DropDownComponent(Label = "Event", Order = 3, DataProviderType = typeof(ZapierTriggerEventTypesDropdownOptionsProvider))]
public string? EventType { get; set; }


[TextInputComponent(Label = "Zapier Url", Order = 4, Disabled = true)]
[TextInputComponent(Label = "Zapier Url", Order = 4)]
public string? ZapierURL { get; set; }


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ protected override async Task<ICommandResponse> ProcessFormData(ZapierTriggerEdi

public override Task ConfigurePage()
{
PageConfiguration.Disabled = true;
PageConfiguration.SubmitConfiguration.Visible = false;

return base.ConfigurePage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,16 @@ public override async Task ConfigurePage()
{
PageConfiguration.AddEditRowAction<ZapierTriggerEditPage>();

// Creating and editting is primarly managed directly from Zapier
//PageConfiguration.HeaderActions.AddLink<ZapierTriggerCreatePage>("Create");

PageConfiguration.TableActions.AddDeleteAction(nameof(Delete), "Delete");


var modelRetriever = new Func<object, IDataContainer, object>(StatusColumnModelRetriever);

PageConfiguration.ColumnConfigurations
.AddColumn(nameof(ZapierTriggerInfo.ZapierTriggerID), "ID", defaultSortDirection: SortTypeEnum.Asc, maxWidth: 20, sortable: true)
.AddColumn(nameof(ZapierTriggerInfo.ZapierTriggerDisplayName), "Name", sortable: true, searchable: true)
.AddColumn(nameof(ZapierTriggerInfo.ZapierTriggerEventType), "Event type", searchable: true, sortable: true)
.AddColumn(nameof(ZapierTriggerInfo.ZapierTriggerObjectType), "Object type", searchable: true, sortable: true)
.AddColumn(nameof(ZapierTriggerInfo.ZapierTriggerZapierURL), "Url", searchable: true, sortable: true)
.AddComponentColumn(nameof(ZapierTriggerInfo.ZapierTriggerEnabled), NamedComponentCellComponentNames.SIMPLE_STATUS_COMPONENT, "Status", maxWidth: 30, searchable: true, modelRetriever: modelRetriever);
.AddComponentColumn(nameof(ZapierTriggerInfo.ZapierTriggerEnabled), NamedComponentCellComponentNames.SIMPLE_STATUS_COMPONENT, "Status", maxWidth: 30, searchable: true, modelRetriever: StatusColumnModelRetriever);

await base.ConfigurePage();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Kentico.Xperience.Zapier/Admin/ZapierConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ internal static class Permissions
{
public const string GENERATE = "Generate";
}

internal static class AuthenticationScheme
{
public const string XbyKZapierApiKeyScheme = "XbyKZapierApiKey";
}
}
13 changes: 8 additions & 5 deletions src/Kentico.Xperience.Zapier/Admin/ZapierModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal class ZapierModule : Module
{
private IZapierModuleInstaller? installer;

private IZapierRegistrationService? zapierRegistrationService;

public ZapierModule() : base(nameof(ZapierModule)) { }


Expand All @@ -25,6 +27,7 @@ protected override void OnInit(ModuleInitParameters parameters)
var services = parameters.Services;

installer = services.GetRequiredService<IZapierModuleInstaller>();
zapierRegistrationService = services.GetRequiredService<IZapierRegistrationService>();

ApplicationEvents.Initialized.Execute += InitializeModule;
ApplicationEvents.Initialized.Execute += InitZapierRegistrations;
Expand All @@ -39,7 +42,7 @@ private void InitZapierRegistrations(object? sender, EventArgs e)

foreach (var zapInfo in zapsToRegister)
{
ZapierHelper.RegisterWebhook(zapInfo);
zapierRegistrationService?.RegisterWebhook(zapInfo);
}
}

Expand All @@ -49,11 +52,11 @@ private void UpdateIfEnabled(ObjectEventArgs e)
{
if (webhook.ZapierTriggerEnabled)
{
ZapierHelper.RegisterWebhook(webhook);
zapierRegistrationService?.RegisterWebhook(webhook);
}
else
{
ZapierHelper.UnregisterWebhook(webhook);
zapierRegistrationService?.UnregisterWebhook(webhook);
}
}
}
Expand All @@ -63,15 +66,15 @@ private void RemoveZapWebhook(ObjectEventArgs e)
{
if (e.Object is ZapierTriggerInfo webhook)
{
ZapierHelper.UnregisterWebhook(webhook);
zapierRegistrationService?.UnregisterWebhook(webhook);
}
}

private void AddNewZapWebhook(ObjectEventArgs e)
{
if (e.Object is ZapierTriggerInfo webhook)
{
ZapierHelper.RegisterWebhook(webhook);
zapierRegistrationService?.RegisterWebhook(webhook);
}
}

Expand Down
38 changes: 38 additions & 0 deletions src/Kentico.Xperience.Zapier/ApiKeyCachedService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using CMS.Helpers;
using Kentico.Integration.Zapier;

namespace Kentico.Xperience.Zapier;


public interface IApiKeyCachedService
{
string? GetApiKeyToken();
}

public class ApiKeyCachedService : IApiKeyCachedService
{
private readonly IProgressiveCache progressiveCache;
private readonly IApiKeyInfoProvider apiKeyInfoProvider;

public ApiKeyCachedService(IProgressiveCache progressiveCache, IApiKeyInfoProvider apiKeyInfoProvider)
{
this.progressiveCache = progressiveCache;
this.apiKeyInfoProvider = apiKeyInfoProvider;
}

public string? GetApiKeyToken()
{
var data = progressiveCache.Load(cacheSettings =>
{
var result = apiKeyInfoProvider.Get().FirstOrDefault();
cacheSettings.CacheDependency = CacheHelper.GetCacheDependency($"{ApiKeyInfo.OBJECT_TYPE}|all");
return result;
}, new CacheSettings(TimeSpan.FromHours(1).TotalMinutes, $"{ApiKeyInfo.OBJECT_TYPE}-resultstring"));

return data?.ApiKeyToken;
}

}

15 changes: 15 additions & 0 deletions src/Kentico.Xperience.Zapier/Kentico.Xperience.Zapier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,19 @@
<AssemblyAttribute Include="CMS.AssemblyDiscoverableAttribute"></AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\Localization.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Localization.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Compile Update="Resources\Localization.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Localization.resx</DependentUpon>
</Compile>
</ItemGroup>

</Project>
90 changes: 90 additions & 0 deletions src/Kentico.Xperience.Zapier/Resources/Localization.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 439ab45

Please sign in to comment.