Skip to content

Commit

Permalink
Allow policies to overwrite admin task views
Browse files Browse the repository at this point in the history
Allow a policy to define it's own view for a specific task.
If a policy defines a template `admin/tasks/<policy name>/tasks/<task
name>` we'll use that when rendering the task view. If there isn't a
policy specific view we'll fall back to the task view in
`admin/tasks/<taske name>`.
  • Loading branch information
rjlynch committed Oct 31, 2024
1 parent 099ab4c commit 347232d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/controllers/admin/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def show
@notes = @claim.notes.automated.by_label(params[:name])
@task_pagination = Admin::TaskPagination.new(claim: @claim, current_task_name:)

render @task.name
render task_view(@task)
end

def create
Expand Down Expand Up @@ -78,4 +78,16 @@ def load_matching_claims
def current_task_name
@task.name
end

def task_view(task)
policy = task.claim.policy
policy_path = policy.to_s.underscore
policy_scoped_task_name = "#{policy_path}/#{task.name}"

if lookup_context.template_exists?(policy_scoped_task_name, [params[:controller]], false)
"admin/tasks/#{policy_scoped_task_name}"
else
task.name
end
end
end

0 comments on commit 347232d

Please sign in to comment.