Open Closed

Navigation Authorization not Working #1685


0
kacey created

I am still trying to get a hang on the ABP Application framework and it's been good so far, even though it is a bit slow. However, my application is on the based on the SPA Angular with Module-Zero template for which I have trouble in using the Navigation Provider properly.

I created a page (cshtml and angular controller) which I tested and it's working fine. But after setting the permission to only be viewed by an application tenant and not a host, it appears in both sessions. Below is what I did to have it viewed only by a tenant;

public class iTrackPupilNavigationProvider : NavigationProvider
    {
        public override void SetNavigation(INavigationProviderContext context)
        {
            context.Manager.MainMenu
                .AddItem(
                    new MenuItemDefinition(
                        "Home",
                        new LocalizableString("HomePage", iTrackPupilConsts.LocalizationSourceName),
                        url: "#/",
                        icon: "fa fa-home"
                        )
                ).AddItem(
                    new MenuItemDefinition(
                        "Tenants",
                        L("Tenants"),
                        url: "#tenants",
                        icon: "fa fa-globe",
                        requiredPermissionName: PermissionNames.Pages_Tenants
                        )
                ).AddItem(
                    new MenuItemDefinition(
                        "Users",
                        L("Users"),
                        url: "#users",
                        icon: "fa fa-users",
                        requiredPermissionName: PermissionNames.Pages_Users
                        )
                ).AddItem(
                    new MenuItemDefinition(
                        "Subjects",
                        L("Subjects"),
                        url: "#subjects",
                        icon: "fa fa-info",
                        requiredPermissionName: PermissionNames.Pages_Users
                        )
                ).AddItem(
                    new MenuItemDefinition(
                        "About",
                        new LocalizableString("About", iTrackPupilConsts.LocalizationSourceName),
                        url: "#/about",
                        icon: "fa fa-info"
                        )
                );
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, iTrackPupilConsts.LocalizationSourceName);
        }

With the above code, I expected that a host user shouldn't see the "Subjects" MenuItem but the host can also see it. Please Can you point me in the right direction? I have been struggling with it for days. Thanks.


5 Answer(s)
  • 0
    ismcagdas created
    Support Team

    Hi,

    Can you share your permission definition in your AuthorizationProvider ? it should have "multiTenancySides: MultiTenancySides.Tenant".

  • 0
    kacey created

    Thanks for your response. I included this: "multiTenancySides: MultiTenancySides.Tenant" and the navigation view worked as I expected it to work. But I noticed it also affected other pages I needed the Host to see so I decided to create another permission name and tie it to the subject page. Below was what I did;

    <ins>in PermissionNames Class;</ins>

    public const string Pages_Schools_Users = "Pages.Schools.Users";
    

    <ins>AuthorizationProvider Class;</ins>

    var schoolUsers = pages.CreateChildPermission(PermissionNames.Pages_Schools_Users, L("SchoolUsers"), multiTenancySides: MultiTenancySides.Tenant);
    

    <ins>NavigationProvider Class;</ins>

    new MenuItemDefinition(
                            "Subjects",
                            L("Subjects"),
                            url: "#subjects",
                            icon: "fa fa-info",
                            requiredPermissionName: PermissionNames.Pages_Schools_Users
    

    After doing the above, the menuItem for subjects didn't appear both for host and tenant user. Please what did I miss?

  • 0
    kacey created

    Okay I finally figured it out. I discovered I needed to set the permission appropriately in the database and configure the angular route properly for it to work. However, I don't seem to get why the application redirects to another page instead of the homepage when I login successfully.

    If I login as a host, it redirects to Users page, if login as a tenant, it goes to another page. I want it to redirect to homepage. How do I do that?

  • 0
    ismcagdas created
    Support Team

    Hi,

    You can do it in app.js when defining your routes.

    $urlRouterProvider.otherwise("/users");
    

    this line defines the default route. You can override it calling this with a different route. for example

    $urlRouterProvider.otherwise("/welcome");
    

    Please take a look at app.js in module zero template <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero-template/blob/master/src/AbpCompanyName.AbpProjectName.WebSpaAngular/App/Main/app.js#L28">https://github.com/aspnetboilerplate/mo ... app.js#L28</a>

  • 0
    kacey created

    Awesome. Everything is fine now. Thank you so much. I'll continue to explore tbe framework while building my application.