Base solution for your next web application
Open Closed

Show/Hide Navigation Items by both Feature Dependency & Permission Dependency #6837


User avatar
0
davidharrison created

Hi all,

I'm setting up editions in my application at the moment and I want my application areas to be controlled by both features and permissions, and as an extension of that, I want to show and hide menu items, first by feature dependency and then by permission dependency. I have implemented this in the way that I understand it needs to be done, but menu items still show up when the logged in users edition doesn't allow for that feature to be seen.


.AddItem(new MenuItemDefinition(
                            FalconPageNames.Common.OrganizationUnits,
                            L("Teams"),
                            url: "Falcon/OrganizationUnits",
                            icon: "fa fa-sitemap",
                            featureDependency: new SimpleFeatureDependency(true, AppFeatures.TeamsManagement),
                            permissionDependency: new SimplePermissionDependency(AppPermissions.Pages_Administration_OrganizationUnits)
                        )

What have I done to make this not work, or what haven't I done? Any help or pointers appreciated.


10 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team
    • What is your product version?
    • What is your product type (Angular or MVC)?
    • What is product framework type (.net framework or .net core)?
  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, you will need to implement it on the client side as well.

    See https://github.com/aspnetzero/aspnet-zero-core/issues/1632#issuecomment-428900148

  • User Avatar
    0
    davidharrison created

    Sorry guys, I should've led with the product details. We're using .Net Core MVC v6.9.1.

    @Ryancyq - if I'm not mistaken, the above link is for an Angular solution - is there a similar method that needs to be implemented for the MVC product?

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, @davidharrison the equivalent code for jquery project should be at https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Mvc/Areas/AppAreaName/Views/Shared/Components/AppAreaNameMenu/AppAreaNameMenuViewComponent.cs

    can you check if _userNavigationManager.GetMenuAsync(menuName) return the menu item associated with the feature?

  • User Avatar
    0
    davidharrison created

    Hi @Ryancyq - the GetMenuAsync method seems to be returning all of the menu items relevant to a tenant (i.e. it doesn't contain the host dashboard), but this also means its returning the items that should be hidden. The tenant user is an admin, and from a permissions viewpoint, has permission to view those menu items, but the items should be hidden due to the tenant features.

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, @davidharrison the feature dependency is actually being checked after permission dependency, see https://github.com/aspnetboilerplate/aspnetboilerplate/blob/59cd65143f59238664e0dd98826510eb38ea23ba/src/Abp/Application/Navigation/UserNavigationManager.cs#L93

    so in your case, the logged in user is a tenant admin and it has all permissions but not the specified tenant feature right?

    can you inject feature checker and check for if the feature is enabled for the logged in user? e.g. _featureChecker.IsEnabled(featureName) or _featureChecker.GetValue(featureName)

  • User Avatar
    0
    davidharrison created

    Hi @Ryancyq, Yes that's correct - it's a tenant admin with all permissions but the tenant lacks the feature, and thus, the admin user not should be able to see or interact with it.

    I tried swapping the order of the permissionDependancy and the featureDependancy, just incase their defined order in the Navigation provider affected the outcome of the FillUserMenuItems method, but to no avail.

    I also implemented the feature checker, which does return false on the tenant admin having the feature, but the menu item still displays.

  • User Avatar
    0
    maliming created
    Support Team

    @davidharrison

    I can't reproduce your problem. I saw that it was checked correctly.

    Do you think you can use the Zero Demo project to reproduce it?

  • User Avatar
    0
    davidharrison created

    Hi @Maliming

    I donwloaded a fresh demo project and the menu items show and hide as expected, with their display being governed by both feature dependancy and permission dependancy.

    Clearly there is an issue with my project. Would you have any suggestions/ideas as to where or what the issue might be, as to why my menu items are not showing/hiding correctly?

    I've defined the features in AppFeatureProvider.cs and defined the constants in AppFeatures.cs. I've then assigned features to editions and places the featureDependancy checks on the menu items. Have I missed a step?

  • User Avatar
    0
    maliming created
    Support Team

    You can test your project with a new database. If I still can't find the reason, I can take a look at it remotely.