Open Closed

Hide or show Main Menú Items from Abp Modules based on roles permissions #2643


User avatar
0
jhsanc created
  • ABP Framework version: v5.1.3
  • UI type: Blazor WebAssembly
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes / no

I need hide or show Main Menú Items from Abp Modules.

For example I need hide FileManagement from main menu based on roles or permissions, don't matter if I added permissions inside application I need always hide menu based in other permission. This not found:

        var fileMenu = context.Menu.FindMenuItem(FileManagementMenuNames.GroupName);
        fileMenu.RequirePermissions("MyProject.Crm.Shared");

Thank you.


12 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Are you enable the FileManagementFeatures.Enable?

    await featureChecker.IsEnabledAsync(FileManagementFeatures.Enable)

  • User Avatar
    0
    jhsanc created

    Thank you maliming, sorry but I don't know where can I put this sentence, is in menu class?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Manage the host or tenant features.

  • User Avatar
    0
    jhsanc created

    Hi maliming, yes this is enabled:

    But I can't hide this menu item.

    Thank you,

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you create a template project to reproduce and share it with me? liming.ma@volosoft.com

  • User Avatar
    0
    jhsanc created

    Sure I send you a email.

    Thank you,

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Please share via attached, Thanks.

  • User Avatar
    0
    jhsanc created

    Hello maliming,

    I granted you more access to project please try again.

    Thank you,

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Please just send a template project, Thanks.

    abp new DemoApp -u blazor

  • User Avatar
    0
    jhsanc created

    Hello,

    I already send you the project through email.

    Thank you,

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can add these code to the SportsMenuContributor I will fix the menu problem in next version.

    var lf = context.GetLocalizer<FileManagementResource>();
    
    context.Menu.GetAdministration().TryRemoveMenuItem(FileManagementMenuNames.GroupName);
    
    context.Menu
        .GetAdministration()
        .AddItem(
            new ApplicationMenuItem(FileManagementMenuNames.GroupName, lf["Menu:FileManagement"], "~/file-management", icon: "fa fa-folder-open")
                .RequireFeatures(FileManagementFeatures.Enable)
                .RequirePermissions(FileManagementPermissions.DirectoryDescriptor.Default)
                .RequirePermissions("Innovain.Sports.Shared")
        );
    
  • User Avatar
    0
    jhsanc created

    Hi,

    With little changes, this found.

    Thank you maliming.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38