pundit: convert delayed jobs to pundit.
This commit is contained in:
@@ -1,14 +1,13 @@
|
|||||||
class DelayedJobsController < ApplicationController
|
class DelayedJobsController < ApplicationController
|
||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
before_action :admin_only, except: [:index]
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@delayed_jobs = Delayed::Job.order("run_at asc").extending(PaginationExtension).paginate(params[:page], :limit => params[:limit])
|
@delayed_jobs = authorize Delayed::Job.order("run_at asc").extending(PaginationExtension).paginate(params[:page], :limit => params[:limit]), policy_class: DelayedJobPolicy
|
||||||
respond_with(@delayed_jobs)
|
respond_with(@delayed_jobs)
|
||||||
end
|
end
|
||||||
|
|
||||||
def cancel
|
def cancel
|
||||||
@job = Delayed::Job.find(params[:id])
|
@job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy
|
||||||
if !@job.locked_at?
|
if !@job.locked_at?
|
||||||
@job.fail!
|
@job.fail!
|
||||||
end
|
end
|
||||||
@@ -16,7 +15,7 @@ class DelayedJobsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def retry
|
def retry
|
||||||
@job = Delayed::Job.find(params[:id])
|
@job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy
|
||||||
if !@job.locked_at?
|
if !@job.locked_at?
|
||||||
@job.update(failed_at: nil, attempts: 0)
|
@job.update(failed_at: nil, attempts: 0)
|
||||||
end
|
end
|
||||||
@@ -24,7 +23,7 @@ class DelayedJobsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
@job = Delayed::Job.find(params[:id])
|
@job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy
|
||||||
if !@job.locked_at?
|
if !@job.locked_at?
|
||||||
@job.update(run_at: Time.now)
|
@job.update(run_at: Time.now)
|
||||||
end
|
end
|
||||||
@@ -32,7 +31,7 @@ class DelayedJobsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@job = Delayed::Job.find(params[:id])
|
@job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy
|
||||||
if !@job.locked_at?
|
if !@job.locked_at?
|
||||||
@job.destroy
|
@job.destroy
|
||||||
end
|
end
|
||||||
|
|||||||
10
app/policies/delayed_job_policy.rb
Normal file
10
app/policies/delayed_job_policy.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class DelayedJobPolicy < ApplicationPolicy
|
||||||
|
def update?
|
||||||
|
user.is_admin?
|
||||||
|
end
|
||||||
|
|
||||||
|
alias_method :cancel?, :update?
|
||||||
|
alias_method :destroy?, :update?
|
||||||
|
alias_method :retry?, :update?
|
||||||
|
alias_method :run?, :update?
|
||||||
|
end
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<%= time_ago_in_words_tagged(job.run_at) %>
|
<%= time_ago_in_words_tagged(job.run_at) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% t.column column: "control" do |job| %>
|
<% t.column column: "control" do |job| %>
|
||||||
<% if CurrentUser.is_admin? %>
|
<% if policy(job).update? %>
|
||||||
<% if job.locked_at? %>
|
<% if job.locked_at? %>
|
||||||
Running
|
Running
|
||||||
<% elsif job.failed? %>
|
<% elsif job.failed? %>
|
||||||
|
|||||||
Reference in New Issue
Block a user