Open Closed

Disable CMS module for some Tenants #3518


User avatar
1
huseyinalan created

Hi, I wanna disable CMS feature in runtime. I couldn't see the under the Saas > Editions > Features menu

Thanks

  • ABP Framework version: v5.2.1
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes

1 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Hi @huseyininalan

    Currently, CmsKit doesn't have Features.

    I've created an issue (#13579) for that implementation to the next release.


    But I'll share some ways to achieve that on your version.

    Let's say we'll add a feature for Pages feature.

    1. Define a FeatureDefinitionProvider

      public class CmsKitFeatureDefinitionProvider : FeatureDefinitionProvider
      {
          public override void Define(IFeatureDefinitionContext context)
          {
              var cmsKit = context.AddGroup(CmsKitFeatures.GroupName);
      
              cmsKit.AddFeature(CmsKitFeatures.Pages, "true", L("Pages"), L("Toggle pages feature"), new ToggleStringValueType());
          }
      
          private static LocalizableString L(string name)
          {
              return LocalizableString.Create<MyProjectNameResource>(name);
          }
      }
      
      public static class CmsKitFeatures
      {
          public const string GroupName = "CmsKit";
      
          public const string Pages = GroupName + ".Pages";
      }
      
    2. Override both Admin & Public PagesAppService and add [RequiresFeature] attribute on them

      using Volo.Abp.DependencyInjection;
      using Volo.Abp.Features;
      using Volo.CmsKit.Admin.Pages;
      using Volo.CmsKit.Contents;
      using Volo.CmsKit.Domain.Shared.Volo.CmsKit;
      using Volo.CmsKit.Pages;
      using Volo.CmsKit.Public.Pages;
      
      namespace MyCompanyName.MyProjectName;
      
      [Dependency(ReplaceServices = true)]
      [ExposeServices(typeof(PageAdminAppService))]
      [RequiresFeature(CmsKitFeatures.Pages)]
      public class MyCmsKitPageAdminAppService : PageAdminAppService
      {
          public MyCmsKitPageAdminAppService(IPageRepository pageRepository, PageManager pageManager) : base(pageRepository, pageManager)
          {
          }
      }
      
      
      [Dependency(ReplaceServices = true)]
      [ExposeServices(typeof(PagePublicAppService))]
      [RequiresFeature(CmsKitFeatures.Pages)]
      public class MyCmsKitPagePublicAppService : PagePublicAppService
      {
          public MyCmsKitPagePublicAppService(IPageRepository pageRepository, ContentParser contentParser) : base(pageRepository, contentParser)
          {
          }
      }
      
    3. Hide it from Admin menu if disabled a. Add a custom menu contributor

      public class MyMenuContributor : IMenuContributor
      {
          public async Task ConfigureMenuAsync(MenuConfigurationContext context)
          {
              var cmsMenu = context.Menu.FindMenuItem(CmsKitAdminMenus.GroupName);
      
              if (cmsMenu is not null)
              {
                  var featureChecker = context.ServiceProvider.GetRequiredService<IFeatureChecker>();
      
                  if (!await featureChecker.IsEnabledAsync(CmsKitFeatures.Pages))
                  {
                      cmsMenu.TryRemoveMenuItem(CmsKitAdminMenus.Pages.PagesMenu);
                  }
              }
      
              return;
          }
      }
      

      b. Configure it to the module file

       ```csharp
       Configure<AbpNavigationOptions>(options =>
       {
           options.MenuContributors.Add(new MyMenuContributor());
       });
       ```
      
    4. That's it. You'll see it in the features modal and you'll be able to manage it to the your tenants.

    You can apply those methods for each of the CmsKit features.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11