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

Add a way to queue releasing shell context from setting display drivers #15875

Merged
merged 26 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d2d2668
Add a way to queue releasing shell cotext from dite drivers
MikeAlhayek Apr 25, 2024
49b1ad4
cleanup
MikeAlhayek Apr 25, 2024
11f7cf2
Merge branch 'main' into ma/queue-release-settings
MikeAlhayek Apr 25, 2024
6a99ac9
remove a change
MikeAlhayek Apr 25, 2024
57eb99c
Merge branch 'ma/queue-release-settings' of https://github.com/Orchar…
MikeAlhayek Apr 25, 2024
42250f3
made ShellSettingsReleaseRequest more global
MikeAlhayek Apr 26, 2024
3b155b3
undo some changes
MikeAlhayek Apr 26, 2024
6c3b896
Update src/docs/releases/1.9.0.md
MikeAlhayek Apr 26, 2024
f4fe7ee
update docs
MikeAlhayek Apr 26, 2024
5d77f76
fix conflict
MikeAlhayek Apr 26, 2024
1c947ac
cleanup
MikeAlhayek Apr 26, 2024
c3b5e5e
use IShellContextReleaseService instead of HttpContext
MikeAlhayek Apr 28, 2024
43a7049
Fix service registration
MikeAlhayek Apr 28, 2024
75fcd45
Update src/docs/releases/1.9.0.md
MikeAlhayek Apr 28, 2024
ad8c41b
Merge branch 'main' into ma/queue-release-settings
MikeAlhayek Apr 29, 2024
6ed9918
cleanup
MikeAlhayek Apr 29, 2024
a183650
Merge branch 'main' into ma/queue-release-settings
MikeAlhayek Apr 29, 2024
78b0a0f
Update src/OrchardCore/OrchardCore/Shell/ShellContextReleaseService.cs
MikeAlhayek Apr 29, 2024
32ed4d9
Update src/OrchardCore/OrchardCore/ShellSettingsReleaseFilter.cs
MikeAlhayek Apr 29, 2024
31a509d
Drop the filter and rename IDeferredShellContextReleaseService
MikeAlhayek Apr 29, 2024
c61ea3d
update docs
MikeAlhayek Apr 29, 2024
19fca82
Merge branch 'main' into ma/queue-release-settings
MikeAlhayek Apr 29, 2024
fed8a44
call AddDeferredTask from the service
MikeAlhayek Apr 30, 2024
8790360
update docs
MikeAlhayek Apr 30, 2024
04087a0
Rename IDeferredShellContextReleaseService to IShellReleaseManager
MikeAlhayek Apr 30, 2024
a2b75a5
Merge branch 'main' into ma/queue-release-settings
MikeAlhayek Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,26 @@ namespace OrchardCore.Azure.Email.Drivers;

public class AzureEmailSettingsDisplayDriver : SectionDisplayDriver<ISite, AzureEmailSettings>
{
private readonly IShellReleaseManager _shellReleaseManager;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IAuthorizationService _authorizationService;
private readonly IDataProtectionProvider _dataProtectionProvider;
private readonly IShellHost _shellHost;
private readonly ShellSettings _shellSettings;
private readonly IEmailAddressValidator _emailValidator;

protected IStringLocalizer S;

public AzureEmailSettingsDisplayDriver(
IShellReleaseManager shellReleaseManager,
IHttpContextAccessor httpContextAccessor,
IAuthorizationService authorizationService,
IDataProtectionProvider dataProtectionProvider,
IShellHost shellHost,
ShellSettings shellSettings,
IEmailAddressValidator emailValidator,
IStringLocalizer<AzureEmailSettingsDisplayDriver> stringLocalizer)
{
_shellReleaseManager = shellReleaseManager;
_httpContextAccessor = httpContextAccessor;
_authorizationService = authorizationService;
_dataProtectionProvider = dataProtectionProvider;
_shellHost = shellHost;
_shellSettings = shellSettings;
_emailValidator = emailValidator;
S = stringLocalizer;
}
Expand Down Expand Up @@ -150,8 +147,7 @@ public override async Task<IDisplayResult> UpdateAsync(ISite site, AzureEmailSet

if (hasChanges)
{
// Release the tenant to apply the settings when something changed.
await _shellHost.ReleaseShellContextAsync(_shellSettings);
_shellReleaseManager.RequestRelease();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class SmtpSettingsDisplayDriver : SectionDisplayDriver<ISite, SmtpSetting
[Obsolete("This property should no longer be used. Instead use EmailSettings.GroupId")]
public const string GroupId = EmailSettings.GroupId;

private readonly IShellReleaseManager _shellReleaseManager;
private readonly IDataProtectionProvider _dataProtectionProvider;
private readonly IShellHost _shellHost;
private readonly ShellSettings _shellSettings;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly SmtpOptions _smtpOptions;
private readonly IAuthorizationService _authorizationService;
Expand All @@ -36,18 +35,16 @@ public class SmtpSettingsDisplayDriver : SectionDisplayDriver<ISite, SmtpSetting
protected readonly IStringLocalizer S;

public SmtpSettingsDisplayDriver(
IShellReleaseManager shellReleaseManager,
IDataProtectionProvider dataProtectionProvider,
IShellHost shellHost,
ShellSettings shellSettings,
IHttpContextAccessor httpContextAccessor,
IOptions<SmtpOptions> options,
IAuthorizationService authorizationService,
IEmailAddressValidator emailAddressValidator,
IStringLocalizer<SmtpSettingsDisplayDriver> stringLocalizer)
{
_shellReleaseManager = shellReleaseManager;
_dataProtectionProvider = dataProtectionProvider;
_shellHost = shellHost;
_shellSettings = shellSettings;
_httpContextAccessor = httpContextAccessor;
_smtpOptions = options.Value;
_authorizationService = authorizationService;
Expand Down Expand Up @@ -200,8 +197,7 @@ public override async Task<IDisplayResult> UpdateAsync(ISite site, SmtpSettings

if (hasChanges)
{
// Release the tenant to apply the settings when something changed.
await _shellHost.ReleaseShellContextAsync(_shellSettings);
_shellReleaseManager.RequestRelease();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,28 @@ public class EmailSettingsDisplayDriver : SectionDisplayDriver<ISite, EmailSetti
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IAuthorizationService _authorizationService;
private readonly IShellHost _shellHost;
private readonly EmailOptions _emailOptions;
private readonly IEmailProviderResolver _emailProviderResolver;
private readonly ShellSettings _shellSettings;
private readonly IShellReleaseManager _shellReleaseManager;
private readonly EmailProviderOptions _emailProviders;

protected readonly IStringLocalizer S;

public EmailSettingsDisplayDriver(
IHttpContextAccessor httpContextAccessor,
IAuthorizationService authorizationService,
IShellHost shellHost,
IOptions<EmailProviderOptions> emailProviders,
IOptions<EmailOptions> emailOptions,
IEmailProviderResolver emailProviderResolver,
ShellSettings shellSettings,
IShellReleaseManager shellReleaseManager,
IStringLocalizer<EmailSettingsDisplayDriver> stringLocalizer)
{
_httpContextAccessor = httpContextAccessor;
_authorizationService = authorizationService;
_shellHost = shellHost;
_emailOptions = emailOptions.Value;
_emailProviderResolver = emailProviderResolver;
_emailProviders = emailProviders.Value;
_shellSettings = shellSettings;
_shellReleaseManager = shellReleaseManager;
S = stringLocalizer;
}
public override async Task<IDisplayResult> EditAsync(EmailSettings settings, BuildEditorContext context)
Expand Down Expand Up @@ -91,7 +88,7 @@ public override async Task<IDisplayResult> UpdateAsync(EmailSettings settings, U
{
settings.DefaultProviderName = model.DefaultProvider;

await _shellHost.ReleaseShellContextAsync(_shellSettings);
_shellReleaseManager.RequestRelease();
}

return await EditAsync(settings, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,24 @@ namespace OrchardCore.Facebook.Drivers
{
public class FacebookSettingsDisplayDriver : SectionDisplayDriver<ISite, FacebookSettings>
{
private readonly IShellReleaseManager _shellReleaseManager;
private readonly IAuthorizationService _authorizationService;
private readonly IDataProtectionProvider _dataProtectionProvider;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IShellHost _shellHost;
private readonly ShellSettings _shellSettings;
private readonly ILogger _logger;

public FacebookSettingsDisplayDriver(
IShellReleaseManager shellReleaseManager,
IAuthorizationService authorizationService,
IDataProtectionProvider dataProtectionProvider,
IHttpContextAccessor httpContextAccessor,
IShellHost shellHost,
ShellSettings shellSettings,
ILogger<FacebookSettingsDisplayDriver> logger
)
{
_shellReleaseManager = shellReleaseManager;
_authorizationService = authorizationService;
_dataProtectionProvider = dataProtectionProvider;
_httpContextAccessor = httpContextAccessor;
_shellHost = shellHost;
_shellSettings = shellSettings;
_logger = logger;
}

Expand Down Expand Up @@ -87,19 +84,23 @@ public override async Task<IDisplayResult> UpdateAsync(FacebookSettings settings
var model = new FacebookSettingsViewModel();
await context.Updater.TryUpdateModelAsync(model, Prefix);

settings.AppId = model.AppId;
settings.FBInit = model.FBInit;
settings.SdkJs = model.SdkJs;
settings.Version = model.Version;

if (!string.IsNullOrWhiteSpace(model.FBInitParams))
{
settings.FBInitParams = model.FBInitParams;
}

Piedone marked this conversation as resolved.
Show resolved Hide resolved
if (context.Updater.ModelState.IsValid)
{
var protector = _dataProtectionProvider.CreateProtector(FacebookConstants.Features.Core);
settings.AppId = model.AppId;
settings.AppSecret = protector.Protect(model.AppSecret);
settings.FBInit = model.FBInit;
settings.SdkJs = model.SdkJs;
if (!string.IsNullOrWhiteSpace(model.FBInitParams))
settings.FBInitParams = model.FBInitParams;
settings.Version = model.Version;

await _shellHost.ReleaseShellContextAsync(_shellSettings);
}

_shellReleaseManager.RequestRelease();
}

return await EditAsync(settings, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@ namespace OrchardCore.Facebook.Login.Drivers
{
public class FacebookLoginSettingsDisplayDriver : SectionDisplayDriver<ISite, FacebookLoginSettings>
{
private readonly IShellReleaseManager _shellReleaseManager;
private readonly IAuthorizationService _authorizationService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IShellHost _shellHost;
private readonly ShellSettings _shellSettings;

public FacebookLoginSettingsDisplayDriver(
IShellReleaseManager shellReleaseManager,
IAuthorizationService authorizationService,
IHttpContextAccessor httpContextAccessor,
IShellHost shellHost,
ShellSettings shellSettings)
IHttpContextAccessor httpContextAccessor)
{
_shellReleaseManager = shellReleaseManager;
_authorizationService = authorizationService;
_httpContextAccessor = httpContextAccessor;
_shellHost = shellHost;
_shellSettings = shellSettings;
}

public override async Task<IDisplayResult> EditAsync(FacebookLoginSettings settings, BuildEditorContext context)
Expand Down Expand Up @@ -56,15 +53,15 @@ public override async Task<IDisplayResult> UpdateAsync(FacebookLoginSettings set
}

var model = new FacebookLoginSettingsViewModel();

await context.Updater.TryUpdateModelAsync(model, Prefix);

if (context.Updater.ModelState.IsValid)
{
settings.CallbackPath = model.CallbackPath;
settings.SaveTokens = model.SaveTokens;
await _shellHost.ReleaseShellContextAsync(_shellSettings);
}
settings.CallbackPath = model.CallbackPath;
settings.SaveTokens = model.SaveTokens;

_shellReleaseManager.RequestRelease();
}

return await EditAsync(settings, context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,23 @@ namespace OrchardCore.GitHub.Drivers
{
public class GitHubAuthenticationSettingsDisplayDriver : SectionDisplayDriver<ISite, GitHubAuthenticationSettings>
{
private readonly IShellReleaseManager _shellReleaseManager;
private readonly IAuthorizationService _authorizationService;
private readonly IDataProtectionProvider _dataProtectionProvider;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IShellHost _shellHost;
private readonly ShellSettings _shellSettings;
private readonly ILogger _logger;

public GitHubAuthenticationSettingsDisplayDriver(
IShellReleaseManager shellReleaseManager,
IAuthorizationService authorizationService,
IDataProtectionProvider dataProtectionProvider,
IHttpContextAccessor httpContextAccessor,
IShellHost shellHost,
ShellSettings shellSettings,
ILogger<GitHubAuthenticationSettingsDisplayDriver> logger)
{
_shellReleaseManager = shellReleaseManager;
_authorizationService = authorizationService;
_dataProtectionProvider = dataProtectionProvider;
_httpContextAccessor = httpContextAccessor;
_shellHost = shellHost;
_shellSettings = shellSettings;
_logger = logger;
}

Expand Down Expand Up @@ -97,9 +94,11 @@ public override async Task<IDisplayResult> UpdateAsync(GitHubAuthenticationSetti
settings.ClientSecret = protector.Protect(model.ClientSecret);
settings.CallbackPath = model.CallbackUrl;
settings.SaveTokens = model.SaveTokens;
await _shellHost.ReleaseShellContextAsync(_shellSettings);

_shellReleaseManager.RequestRelease();
}
}

return await EditAsync(settings, context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,23 @@ namespace OrchardCore.Google.Authentication.Drivers
{
public class GoogleAuthenticationSettingsDisplayDriver : SectionDisplayDriver<ISite, GoogleAuthenticationSettings>
{
private readonly IShellReleaseManager _shellReleaseManager;
private readonly IAuthorizationService _authorizationService;
private readonly IDataProtectionProvider _dataProtectionProvider;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IShellHost _shellHost;
private readonly ShellSettings _shellSettings;
private readonly ILogger _logger;

public GoogleAuthenticationSettingsDisplayDriver(
IShellReleaseManager shellReleaseManager,
IAuthorizationService authorizationService,
IDataProtectionProvider dataProtectionProvider,
IHttpContextAccessor httpContextAccessor,
IShellHost shellHost,
ShellSettings shellSettings,
ILogger<GoogleAuthenticationSettingsDisplayDriver> logger)
{
_shellReleaseManager = shellReleaseManager;
_authorizationService = authorizationService;
_dataProtectionProvider = dataProtectionProvider;
_httpContextAccessor = httpContextAccessor;
_shellHost = shellHost;
_shellSettings = shellSettings;
_logger = logger;
}

Expand Down Expand Up @@ -89,17 +86,20 @@ public override async Task<IDisplayResult> UpdateAsync(GoogleAuthenticationSetti
var model = new GoogleAuthenticationSettingsViewModel();
await context.Updater.TryUpdateModelAsync(model, Prefix);

settings.ClientID = model.ClientID;
settings.CallbackPath = model.CallbackPath;
settings.SaveTokens = model.SaveTokens;

if (context.Updater.ModelState.IsValid)
{
var protector = _dataProtectionProvider.CreateProtector(GoogleConstants.Features.GoogleAuthentication);

settings.ClientID = model.ClientID;
settings.ClientSecret = protector.Protect(model.ClientSecret);
settings.CallbackPath = model.CallbackPath;
settings.SaveTokens = model.SaveTokens;
await _shellHost.ReleaseShellContextAsync(_shellSettings);
}

_shellReleaseManager.RequestRelease();
}

return await EditAsync(settings, context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,24 @@ public class HttpsSettingsDisplayDriver : SectionDisplayDriver<ISite, HttpsSetti
{
public const string GroupId = "Https";

private readonly IShellReleaseManager _shellReleaseManager;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IAuthorizationService _authorizationService;
private readonly INotifier _notifier;
private readonly IShellHost _shellHost;
private readonly ShellSettings _shellSettings;

protected readonly IHtmlLocalizer H;

public HttpsSettingsDisplayDriver(IHttpContextAccessor httpContextAccessor,
public HttpsSettingsDisplayDriver(
IShellReleaseManager shellReleaseManager,
IHttpContextAccessor httpContextAccessor,
IAuthorizationService authorizationService,
INotifier notifier,
IShellHost shellHost,
ShellSettings shellSettings,
IHtmlLocalizer<HttpsSettingsDisplayDriver> htmlLocalizer)
{
_shellReleaseManager = shellReleaseManager;
_httpContextAccessor = httpContextAccessor;
_authorizationService = authorizationService;
_notifier = notifier;
_shellHost = shellHost;
_shellSettings = shellSettings;
H = htmlLocalizer;
}

Expand Down Expand Up @@ -94,11 +93,7 @@ public override async Task<IDisplayResult> UpdateAsync(HttpsSettings settings, U
settings.RequireHttpsPermanent = model.RequireHttpsPermanent;
settings.SslPort = model.SslPort;

// If the settings are valid, release the current tenant.
if (context.Updater.ModelState.IsValid)
{
await _shellHost.ReleaseShellContextAsync(_shellSettings);
}
_shellReleaseManager.RequestRelease();
}

return await EditAsync(settings, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ namespace OrchardCore.Layers.Drivers
public class LayerSiteSettingsDisplayDriver : SectionDisplayDriver<ISite, LayerSettings>
{
public const string GroupId = "zones";
private static readonly char[] _separator = [' ', ','];

private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IAuthorizationService _authorizationService;
private static readonly char[] _separator = [' ', ','];

public LayerSiteSettingsDisplayDriver(
IHttpContextAccessor httpContextAccessor,
Expand Down