-
Notifications
You must be signed in to change notification settings - Fork 1.4k
#8862: Preventing the SQL Server Service Broker feature from being enabled for tenants that are not using Microsoft SQL Server as their database provider (Lombiq Technologies: ORCH-309) #8875
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
Merged
+97
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/Orchard.Web/Modules/Orchard.MessageBus/Services/SqlServerServiceBrokerFeatureGuard.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| using System; | ||
| using System.Web.Mvc; | ||
| using Orchard.Environment; | ||
| using Orchard.Environment.Configuration; | ||
| using Orchard.Environment.Extensions.Models; | ||
| using Orchard.Environment.Features; | ||
| using Orchard.Localization; | ||
| using Orchard.Mvc; | ||
| using Orchard.Mvc.Filters; | ||
| using Orchard.UI.Notify; | ||
|
|
||
| namespace Orchard.MessageBus.Services | ||
| { | ||
| /// <summary> | ||
| /// Prevents the SQL Server Service Broker feature from being enabled for tenants that are not using Microsoft SQL | ||
| /// Server as their database provider. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The implementation is hackish but there seems to be no other way: if it would use <see cref="INotifier"/> it | ||
| /// wouldn't work since <see cref="NotifyFilter"/> that writes out notifications to TempData runs before feature | ||
| /// events are raised. Thus we have to manually add the messages to TempData, just as the filter would do. | ||
| /// </remarks> | ||
| public class SqlServerServiceBrokerFeatureGuard : FilterProvider, IFeatureEventHandler, IActionFilter | ||
| { | ||
| private const string FeatureId = "Orchard.MessageBus.SqlServerServiceBroker"; | ||
| private const string TempDataKey = FeatureId + ".TempData"; | ||
|
|
||
| private readonly ShellSettings _shellSettings; | ||
| private readonly IFeatureManager _featureManager; | ||
| private readonly IHttpContextAccessor _hca; | ||
|
|
||
| public Localizer T { get; set; } | ||
|
|
||
| public SqlServerServiceBrokerFeatureGuard( | ||
| ShellSettings shellSettings, | ||
| IFeatureManager featureManager, | ||
| IHttpContextAccessor hca) | ||
| { | ||
| _shellSettings = shellSettings; | ||
| _featureManager = featureManager; | ||
| _hca = hca; | ||
|
|
||
| T = NullLocalizer.Instance; | ||
| } | ||
|
|
||
| void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) { } | ||
|
|
||
| void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext) | ||
| { | ||
| var httpContext = _hca.Current(); | ||
|
|
||
| if (httpContext == null) return; | ||
|
|
||
| httpContext.Items[TempDataKey] = filterContext.Controller.TempData; | ||
| } | ||
|
|
||
| public void Installing(Feature feature) { } | ||
|
|
||
| public void Installed(Feature feature) { } | ||
|
|
||
| public void Enabling(Feature feature) { } | ||
|
|
||
| public void Enabled(Feature feature) | ||
| { | ||
| if (feature.Descriptor.Id != FeatureId) | ||
| return; | ||
|
|
||
| if (!_shellSettings.DataProvider.Equals("SqlServer", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| _featureManager.DisableFeatures(new[] { FeatureId }, force: true); | ||
|
|
||
| AddNotification( | ||
| T("The SQL Server Service Broker cannot be enabled because it requires Microsoft SQL Server."), | ||
| NotifyType.Error); | ||
BenedekFarkas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| public void Disabling(Feature feature) { } | ||
|
|
||
| public void Disabled(Feature feature) { } | ||
|
|
||
| public void Uninstalling(Feature feature) { } | ||
|
|
||
| public void Uninstalled(Feature feature) { } | ||
|
|
||
| private void AddNotification(LocalizedString message, NotifyType notifyType = NotifyType.Warning) | ||
| { | ||
| var tempDataDictionary = _hca.Current()?.Items[TempDataKey]; | ||
|
|
||
| if (tempDataDictionary == null) return; | ||
|
|
||
| ((TempDataDictionary)tempDataDictionary)["messages"] += | ||
| $"{notifyType}:{message.Text}{System.Environment.NewLine}-{System.Environment.NewLine}"; | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.