Open Closed

How to hide Settings->Account tab for Tenants and users (not Host) #3423


User avatar
0
Sturla created

I´m trying to remove (just) the Account part from my Settings in Blazor for newly created tenant/users

If I filter it out by "AbpAccount.SettingManagement" and try to remove it with the PermissionDataSeeder the whole Settings menu gets removed. For ordinary user removing Settings could be fine but I have more stuff than just Account for my tenants.

I tried these two https://support.abp.io/QA/Questions/1690/HOW-TO-remove--Two-factor-item and https://support.abp.io/QA/Questions/2926/Remove-two-auth-and-Profile-picture-tab-from-manage-profile-page but I just get this error if I try to remove an individual component "Volo-Abp-Account-TwoFactor"

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

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

    hi

    This error seems not related to ABP.

    Can you share full error stack and you PageContributor code?

  • User Avatar
    0
    Sturla created

    This error seems not related to ABP. Are you sure? How I read it is that "Volo-Abp-Account-TwoFactor" just isn´t in the Groups?

    And I wan´t to hide the whole Account menu item and not individual parts of it. And just for Tenants and users but not Host.

    Here is the code

    using Microsoft.Extensions.DependencyInjection;
    using System.Threading.Tasks;
    using Volo.Abp.Account.Public.Web.ProfileManagement;
    using Volo.Abp.Identity;
    using Volo.Abp.Users;
    
    namespace BSR.Beinni.ProfileManagement;
    
    public class AccountProfileManagementPageContributor : IProfileManagementPageContributor
    {
        public async Task ConfigureAsync(ProfileManagementPageCreationContext context)
        {
            context.Groups.ForEach(Console.WriteLine);
            
            // Here I was just trying to take out TwoFactor BUT I wan´t to remove the whole Account  
            context.Groups.Remove(context.Groups.First(x => x.Id == "Volo-Abp-Account-TwoFactor"));
            await Task.CompletedTask;
        }
    
        protected virtual async Task<bool> IsPasswordChangeEnabled(ProfileManagementPageCreationContext context)
        {
            var userManager = context.ServiceProvider.GetRequiredService<IdentityUserManager>();
            var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>();
    
            var user = await userManager.GetByIdAsync(currentUser.GetId());
    
            return !user.IsExternal;
        }
    }
    

    and then inI have

    Configure<ProfileManagementPageOptions>(options =>
    {
        options.Contributors.Add(new ProfileManagement.AccountProfileManagementPageContributor());
    });
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Using FirstOrDefault.

     var item = context.Groups.FirstOrDefault(x => x.Id == "Volo-Abp-Account-TwoFactor")
     if(item != null)
     {
         context.Groups.Remove(item );
     }
    
  • User Avatar
    0
    Sturla created

    I know how to guard against null exceptions 😉 its just that Groups never contains Volo-Abp-Account-TwoFactor, that is that error..

    BUT the thing is that I want to remove the whole Account tab and not just from within it!

    If I filter it out by "AbpAccount.SettingManagement" and try to remove it with the PermissionDataSeeder the whole Settings menu gets removed.

    I have (as stated above) tried using PermissionDataSeedContributor to remove access to the menu item like this (my code is longer and little different of course)

    .Select(p => p.Name)
                .WhereIf(x=>tenantId.HasValue && providerKey == RoleConstants.Tenantuser,
                                x => !x.Contains("AbpAccount.SettingManagement")
                .ToArray();   
    

    and then using PermissionGrantRepository.InsertAsync() to give the user permissions (but not that one) BUT then the WHOLE Settings menu goes away

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can consider to custom the Manage(account\src\Volo.Abp.Account.Pro.Public.Web\Pages\Account\Manage.cshtml.cs) page.

  • User Avatar
    0
    Sturla created

    Ok that solved it for my users (I could hide the two-factor part at least) in the MVC part of my app.

    I then figured out I had to do the same for Blazor and overrode ISettingComponentContributor

    and added this code to hide it

    //Hide the account menu item (Self registration/Two-factor/captcha/google-fb-etc
    var accountMenuToRemove = context.Groups.Find(x => x.Id == "Volo.Abp.Account");
    context.Groups.Remove(accountMenuToRemove);
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15