Skip to content

Commit

Permalink
Merge pull request from GHSA-74p6-39f2-23v3
Browse files Browse the repository at this point in the history
* Don't display exception if not in debug mode

* Only display not OK status code in production
  • Loading branch information
Zeegaan committed Feb 6, 2024
1 parent 802758e commit 6b80678
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Umbraco.Core/EmbeddedResources/Lang/da.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,8 @@
<key alias="createHeader">Opret header</key>
<key alias="deliveries">Leverancer</key>
<key alias="noHeaders">Der er ikke tilføjet nogen webhook headers</key>
<key alias="toggleDebug">Skift til debug mode for mere information.</key>
<key alias="statusNotOk">Ikke OK status kode.</key>
</area>
<area alias="language">
<key alias="cultureCode">Culture Code</key>
Expand Down
2 changes: 2 additions & 0 deletions src/Umbraco.Core/EmbeddedResources/Lang/en_us.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,8 @@ To manage your website, simply open the Umbraco backoffice and start adding cont
<key alias="types">Types</key>
<key alias="webhookKey">Webhook key</key>
<key alias="retryCount">Retry count</key>
<key alias="toggleDebug">Toggle debug mode for more information.</key>
<key alias="statusNotOk">Not OK status code</key>
</area>
<area alias="languages">
<key alias="addLanguage">Add language</key>
Expand Down
30 changes: 25 additions & 5 deletions src/Umbraco.Web.BackOffice/Mapping/WebhookMapDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Webhooks;
using Umbraco.Cms.Web.Common.Models;

namespace Umbraco.Cms.Web.BackOffice.Mapping;

public class WebhookMapDefinition : IMapDefinition
{
private readonly IHostingEnvironment _hostingEnvironment;
private readonly ILocalizedTextService _localizedTextService;

public WebhookMapDefinition(IHostingEnvironment hostingEnvironment, ILocalizedTextService localizedTextService)
{
_hostingEnvironment = hostingEnvironment;
_localizedTextService = localizedTextService;
}

public void DefineMaps(IUmbracoMapper mapper)
{
mapper.Define<WebhookViewModel, IWebhook>((_, _) => new Webhook(string.Empty), Map);
Expand Down Expand Up @@ -40,13 +51,22 @@ private void Map(WebhookLog source, WebhookLogViewModel target, MapperContext co
target.EventAlias = source.EventAlias;
target.Key = source.Key;
target.RequestBody = source.RequestBody ?? string.Empty;
target.ResponseBody = source.ResponseBody;
target.RetryCount = source.RetryCount;
target.StatusCode = source.StatusCode;
target.Url = source.Url;
target.RequestHeaders = source.RequestHeaders;
target.ResponseHeaders = source.ResponseHeaders;
target.WebhookKey = source.WebhookKey;
target.ExceptionOccured = source.ExceptionOccured;

if (_hostingEnvironment.IsDebugMode)
{
target.ExceptionOccured = source.ExceptionOccured;
target.ResponseBody = source.ResponseBody;
target.ResponseHeaders = source.ResponseHeaders;
target.StatusCode = source.StatusCode;
}
else
{
target.ResponseBody = _localizedTextService.Localize("webhooks", "toggleDebug", Thread.CurrentThread.CurrentUICulture);
target.StatusCode = source.StatusCode is "OK (200)" ? source.StatusCode : _localizedTextService.Localize("webhooks", "statusNotOk", Thread.CurrentThread.CurrentUICulture);
}
}
}

0 comments on commit 6b80678

Please sign in to comment.