Fix AbpDashboardOptionsProvider

pull/17413/head
liangshiwei 1 year ago
parent 8e5113a7ce
commit 736b072d09

@ -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>();
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>();
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,

@ -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;
}
};
}
}

Loading…
Cancel
Save