Search code examples
ruby-on-railsauthenticationdelayed-jobpundit

How to use Pundit to authorize admin users to see delayed job web?


I am very new to Rails and Ruby but I am involved on a project as a trainee, which uses Pundit for authorization of users.

Our project uses delayed_job_active_record gem and I wanted to add delayed_job_web for a quick and easy view of jobs.

I can see that documentation for the latter gem uses basic rack authorisation or devise gem when matching or mounting the route to DelayedJobWeb.

I looked and googled but I couldn't find any suggestions on how to use Pundit instead (so that when you type the link yourself it doesn't allow you to see it unless you are an admin).

Any ideas of how this can be done please?


Solution

  • in your routes you could do something like this:

    authenticate :user, lambda { |u| u.admin? } do          
      mount DelayedJobWeb => '/delayedjobweb'
    end