Skip to content

Latest commit

 

History

History
91 lines (73 loc) · 3.6 KB

File metadata and controls

91 lines (73 loc) · 3.6 KB

Lombiq Hosting - Tenants Features Guard for Orchard Core

Lombiq.Hosting.Tenants.FeaturesGuard NuGet

About

A module that makes it possible to conditionally enable and conditionally keep enabled, or entirely prevent enabling, configurable sets of features on tenants.

Documentation

Conditionally enabling features

  • To use this feature, enable it on both the Default and the user tenant.
  • Features that should be conditionally enabled, as well as the features whose status acts as the condition, can be specified either in appsettings.json using ConditionallyEnabledFeaturesOptions or in Program via the ConfigureFeaturesGuard() or ConfigureFeaturesGuardWithoutOverriding() extension method. Conditionally enabled features need to be provided with a singular or multiple condition features, where the status of the condition features determines whether the corresponding conditional feature is enabled or disabled. Example configuration:

Program config example:

builder.Services
    .AddOrchardCms(orchardCoreBuilder =>
        orchardCoreBuilder.ConfigureFeaturesGuard(
            new Dictionary<string, IEnumerable<string>>
            {
                // "Enable this feature and keep it enabled": "If any of these features are enabled",
                ["OrchardCore.Media.Azure.Storage"] = new[] { "OrchardCore.Media" },
                ["OrchardCore.Twitter"] = new[] { "Lombiq.UIKit", "Lombiq.ChartJs" },
            }));
  • ConfigureFeaturesGuardForAzureStorage() is available to add Azure Storage as a conditional feature and Media as its condition feature.
  • ConfigureFeaturesGuardForElasticsearch() is available to add Elasticsearch as a conditional feature and Indexing or Search as its condition feature.

appsettings.json config example:

{
  "OrchardCore": {
    "Lombiq_Hosting_Tenants_FeaturesGuard": {
      "ConditionallyEnabledFeaturesOptions": {
        "ConditionallyEnabledFeatures": {
          "EnableFeatureIfOtherFeatureIsEnabled": {
            // "Enable this feature and keep it enabled": "If any of these features are enabled",
            "OrchardCore.Media.Azure.Storage": "OrchardCore.Media",
            "OrchardCore.Twitter": "OrchardCore.Media, OrchardCore.Workflows"
          }
        }
      }
    },
}

Example case 1:

  • Enables Azure Storage when Media is enabled. Keeps Azure Storage enabled as long as Media is enabled.

Example case 2:

  • Enables Twitter when Media or Workflows is enabled. Keeps Twitter enabled as long as either Media or Workflows remains enabled.

Preventing enabling features

  • Preventing enabling certain features on user tenants is possible via recipes in a FeatureProfiles step. For more on the Feature Profiles feature, see the official documentation. Example configuration:
{
  "name": "FeatureProfiles",
  "FeatureProfiles": {
    "Features Guard": {
      "FeatureRules": [
        {
            "Rule": "Exclude",
            "Expression": "OrchardCore.Workflows.Session"
        },
        {
            "Rule": "Exclude",
            "Expression": "OrchardCore.Search.Lucene"
        },
        {
            "Rule": "Exclude",
            "Expression": "OrchardCore.MiniProfiler"
        },
        {
            "Rule": "Exclude",
            "Expression": "Lombiq.Tests.UI.Shortcuts"
        }
      ]
    }
  }
}