Open Closed

Linked accounts in header bar #3741


User avatar
0
david.bandinelli.unoinformatica created

Hello,

I need to apply a user permission on the linked accounts button. Is it possible to apply a permission on it? Should I replace with a new link? If yes, how and where to put the code? Is it possible to do this instead of overwrite the entire header bar? Is it possible to hide a single link of the menu in the previous image?

Thank you in advance


5 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Of course, you can apply a permission on it.

    But I don't what UI are you using, here I assume UI is MVC.

    Open your <YourProjectName>MenuContributor class:

    public class MyProjectNameMenuContributor : IMenuContributor
    {
        public async Task ConfigureMenuAsync(MenuConfigurationContext context)
        {
            //......
            if (context.Menu.Name == StandardMenus.User)
            {
                var linkedAccount = context.Menu.GetMenuItemOrNull("Account.LinkedAccounts");
                linkedAccount?.RequirePermissions("<Your permission name>");
            }
        }
    }
    
  • User Avatar
    0

    I tried to toggle a comment on the code, where the item is setted This is the AbpAccountUserMenuContributor's snippet. But it didn't change anything. If I want to delete the link what should I do? In which project should I create the MenuContributor class?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    When you create a new project, you can see the MenuContributor class.

    Define permission:

    Update MenuContributor

  • User Avatar
    0

    Hello, i created in my project (see the picture below) menus folder with the menucontributor and i followed your instructions, only permission work but it didn't appear any button or link in the menu. So if I want to apply permission on a button or link that already exists, what's the best way to do this? E.g. I want to apply a permission on the "My account" button (see the picture below) you see in user menu (see your last answer), how can I apply a permission on it and hide for some users??? Is it possible to do or should i replace the entire header bar like the documentation says??

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    menus folder with the menucontributor and i followed your instructions, only permission work but it didn't appear any button or link in the menu. So if I want to apply permission on a button or link that already exists, what's the best way to do this? E.g. I want to apply a permission on the "My account" button (see the picture below)

    Here I have explained how to hide link account, to hide my account we just have to do something like this: https://support.abp.io/QA/Questions/3741#answer-d4e39d0b-e9fe-2225-d96c-3a067a5828eb

    public class MyProjectNameMenuContributor : IMenuContributor
    {
        public async Task ConfigureMenuAsync(MenuConfigurationContext context)
        {
            //......
            if (context.Menu.Name == StandardMenus.User)
            {
                var linkedAccount = context.Menu.GetMenuItemOrNull("Account.Manage");
                linkedAccount?.RequirePermissions("<Your permission name>");
            }
        }
    }
    

    It still does not work for you, you can share the project with me via email, I will check it, shiwei.liang@volosoft.com

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