Open Closed

MVC - Customizing the Settings page #478


User avatar
0
XavierRM created
  • ABP Framework version: v3.0.5
  • UI type: MVC
  • Tiered (MVC) or Identity Server Seperated (Angular): no

Hello,

I want to allow a website's administrator user to edit the SMTP settings, including MailKit's SecureSocketOption since it is required to connect to some email providers. While there is some documentation about customizing the Angular settings page, I can't find anything about doing the same using the MVC UI, and it's impossible to know how to do it without the source code.

Is there a way to automatically add an Email tab with the email related settings ? What about the SecureSocketOption option ? If I have to do it manyally, what are the extension moints and their documentation ?

Thank you


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

    See https://support.abp.io/QA/Questions/95/Setting-Definitions-UI-in-MVC-Razor-page

  • User Avatar
    0
    XavierRM created

    Thanks, that's a good start. I can get the custom page settings to show, but I can't get it to show only to users having the right permission.

    Here is what I have in my settings page contributor :

    public class EmailSettingsPageContributor : ISettingPageContributor
    {
        public async Task<bool> CheckPermissionsAsync(SettingPageCreationContext context)
        {
            Check.NotNull(context, nameof(context));
            var permissionChecker = context.ServiceProvider.GetRequiredService<IPermissionChecker>();
    
            var result = await permissionChecker.IsGrantedAsync(MyAppPermissions.EmailSettings.Edit);
            return result;
        }
    
        public Task ConfigureAsync(SettingPageCreationContext context)
        {
            Check.NotNull(context, nameof(context));
            var localizer = context.ServiceProvider.GetRequiredService<IStringLocalizer<MyAppResource>>();
    
            context.Groups.Add(new SettingPageGroup("emailsPageGroup", localizer["Settings:Email"], typeof(EmailSettingsViewComponent)));
            return Task.CompletedTask;
        }
    }
    

    It seems CheckPermissionsAsync is never called, and my settings pages is always displayed.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi Try :

    public class EmailSettingsPageContributor : ISettingPageContributor
    {
        public async Task<bool> CheckPermissionsAsync(SettingPageCreationContext context)
        {
            Check.NotNull(context, nameof(context));
            var permissionChecker = context.ServiceProvider.GetRequiredService<IPermissionChecker>();
    
            var result = await permissionChecker.IsGrantedAsync(MyAppPermissions.EmailSettings.Edit);
            return result;
        }
    
        public async Task ConfigureAsync(SettingPageCreationContext context)
        {
            if (!await CheckPermissionsAsync(context))
            {
                return;
            }
                
            Check.NotNull(context, nameof(context));
            var localizer = context.ServiceProvider.GetRequiredService<IStringLocalizer<MyAppResource>>();
    
            context.Groups.Add(new SettingPageGroup("emailsPageGroup", localizer["Settings:Email"], typeof(EmailSettingsViewComponent)));
        }
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38