Skip to content

Commit

Permalink
fix enabling Amazon S3 storage provider without configuration causes …
Browse files Browse the repository at this point in the history
…exception (OrchardCMS#15293)
  • Loading branch information
neglectedvalue authored and urbanit committed Mar 18, 2024
1 parent 29038f4 commit 20b2d84
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ private void ParseBucketName(AwsStorageOptions options, TemplateContext template
catch (Exception e)
{
_logger.LogCritical(e, "Unable to parse Amazon S3 Media Storage bucket name.");
throw;
}
}

Expand All @@ -76,7 +75,6 @@ private void ParseBasePath(AwsStorageOptions options, TemplateContext templateCo
catch (Exception e)
{
_logger.LogCritical(e, "Unable to parse Amazon S3 Media Storage base path.");
throw;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.DisplayManagement.Notify;
using OrchardCore.FileStorage.AmazonS3;
using OrchardCore.Media.AmazonS3.ViewModels;

Expand All @@ -11,12 +16,18 @@ public class AdminController : Controller
{
private readonly IAuthorizationService _authorizationService;
private readonly AwsStorageOptions _options;
private readonly INotifier _notifier;
protected readonly IHtmlLocalizer H;

public AdminController(
IAuthorizationService authorizationService,
IOptions<AwsStorageOptions> options)
IOptions<AwsStorageOptions> options,
INotifier notifier,
IHtmlLocalizer<AdminController> htmlLocalizer)
{
_authorizationService = authorizationService;
_notifier = notifier;
H = htmlLocalizer;
_options = options.Value;
}

Expand All @@ -26,6 +37,11 @@ public async Task<IActionResult> Options()
{
return Forbid();
}

if (_options.Validate().Any())
{
await _notifier.ErrorAsync(H["The Amazon S3 Media feature is enabled, but it was not configured with appsettings.json."]);
}

var model = new OptionsViewModel
{
Expand Down
Loading

0 comments on commit 20b2d84

Please sign in to comment.