Open Closed

Permission check issue adding a custom SettingComponentContributor #7732


User avatar
0
balessi75 created

ABP Commercial 7.4.2 / Blazor Server / EF / Non tiered / Separate Host and Tenant DBs / Lepton Theme

Hi,

Our custom SettingComponentContributor is defined as below. What we are finding is that the ConfigureAsync method executes, but the CheckPermissionsAsync method never executes. The group shows in the UI without the permission check. Is there something we are misunderstanding when it comes to only showing a settings group if the current user has a certain permission?

Thanks in advance.

namespace FM.nVision.Blazor.Settings
{
    public class NotificationSettingComponentContributor : ISettingComponentContributor
    {
        public Task ConfigureAsync(SettingComponentCreationContext context)
        {
            context.Groups.Add(
                new SettingComponentGroup(
                    "FM.nVision.Settings",
                    "Email Notifications",
                    typeof(NotificationSettingGroupComponent), order: 8888
                )
            );

            return Task.CompletedTask;
        }

        public async Task<bool> CheckPermissionsAsync(SettingComponentCreationContext context)
        {
            // check the permissions here
            var authService = context.ServiceProvider.GetRequiredService<IAuthorizationService>();

            if (await authService.IsGrantedAsync(nVisionPermissions.Notifications.Settings))
            {

                return true;

            }
            return false;

        }
    }

}

ConfigureServices

        Configure<SettingManagementComponentOptions>(options =>
        {

            options.Contributors.Add(new NotificationSettingComponentContributor());
            options.Contributors.Add(new AboutSettingComponentContributor());
        });

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

    Hi,

    you need to call CheckPermissionsAsync method yourself.

  • User Avatar
    0
    balessi75 created

    That makes sense. Thanks @liangshiwei !!

Made with ❤️ on ABP v9.0.0-preview Updated on September 19, 2024, 10:13