From 736b072d09749aa9e3c9f35414ea33a58e14be17 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Sun, 20 Aug 2023 22:05:52 +0800 Subject: [PATCH] Fix AbpDashboardOptionsProvider --- docs/en/Background-Jobs-Hangfire.md | 14 ++++++-------- .../Hangfire/AbpDashboardOptionsProvider.cs | 13 +++++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/en/Background-Jobs-Hangfire.md b/docs/en/Background-Jobs-Hangfire.md index 77f2da8bd0..6f13d32e05 100644 --- a/docs/en/Background-Jobs-Hangfire.md +++ b/docs/en/Background-Jobs-Hangfire.md @@ -128,10 +128,9 @@ You can integrate the Hangfire dashboard to [ABP authorization system](Authoriza class. This class is defined in the `Volo.Abp.Hangfire` package. The following example, checks if the current user is logged in to the application: ```csharp -app.UseHangfireDashboard("/hangfire", new DashboardOptions -{ - AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter() } -}); +var dashboardOptions = app.ApplicationServices.GetRequiredService(); +dashboardOptions.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter() }; +app.UseHangfireDashboard("/hangfire", dashboardOptions); ``` * `AbpHangfireAuthorizationFilter` is an implementation of an authorization filter. @@ -146,10 +145,9 @@ app.UseHangfireDashboard("/hangfire", new DashboardOptions If you want to require an additional permission, you can pass it into the constructor as below: ```csharp -app.UseHangfireDashboard("/hangfire", new DashboardOptions -{ - AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter(requiredPermissionName: "MyHangFireDashboardPermissionName") } -}); +var dashboardOptions = app.ApplicationServices.GetRequiredService(); +dashboardOptions.AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter(requiredPermissionName: "MyHangFireDashboardPermissionName") }; +app.UseHangfireDashboard("/hangfire", dashboardOptions); ``` **Important**: `UseHangfireDashboard` should be called after the authentication and authorization middlewares in your `Startup` class (probably at the last line). Otherwise, diff --git a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs index bc41b21ce8..e68489290a 100644 --- a/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs +++ b/framework/src/Volo.Abp.BackgroundJobs.HangFire/Volo/Abp/BackgroundJobs/Hangfire/AbpDashboardOptionsProvider.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading; using Hangfire; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; @@ -18,8 +19,16 @@ public class AbpDashboardOptionsProvider : ITransientDependency { return new DashboardOptions { - DisplayNameFunc = (dashboardContext, job) => - AbpBackgroundJobOptions.GetJob(job.Args.First().GetType()).JobName + DisplayNameFunc = (_, job) => + { + var jobName = job.ToString(); + if (job.Args.Count == 3 && job.Args.Last() is CancellationToken) + { + jobName = AbpBackgroundJobOptions.GetJob(job.Args[1].GetType()).JobName; + } + + return jobName; + } }; } }