From e50bd7502ce96cec5de715a69d6fd876352277cb Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Tue, 5 Dec 2023 12:15:37 +0000 Subject: [PATCH] feat: add user param to log breadcrumbs --- app/helpers/tasklist_helper.rb | 18 +++++++++++++----- app/views/logs/edit.html.erb | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index c9b0f5549..1d7e4d7ef 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -2,14 +2,18 @@ module TasklistHelper include GovukLinkHelper include CollectionTimeHelper - def breadcrumb_logs_title(log) + def breadcrumb_logs_title(log, current_user) log_type = log.lettings? ? "Lettings" : "Sales" - current_user.support? ? "#{log_type} logs (#{log.owning_organisation.name})" : "#{log_type} logs" + if current_user.support? && breadcrumb_organisation(log).present? + "#{log_type} logs (#{breadcrumb_organisation(log).name})" + else + "#{log_type} logs" + end end - def breadcrumb_logs_link(log) - if current_user.support? - log.lettings? ? lettings_logs_organisation_path(@log.owning_organisation) : sales_logs_organisation_path(@log.owning_organisation) + def breadcrumb_logs_link(log, current_user) + if current_user.support? && breadcrumb_organisation(log).present? + log.lettings? ? lettings_logs_organisation_path(breadcrumb_organisation(log)) : sales_logs_organisation_path(breadcrumb_organisation(log)) else log.lettings? ? lettings_logs_path : sales_logs_path end @@ -56,6 +60,10 @@ module TasklistHelper private + def breadcrumb_organisation(log) + log.owning_organisation || (log.managing_organisation if log.respond_to?(:managing_organisation)) + end + def next_page_or_check_answers(subsection, log, current_user) path = if subsection.is_started?(log) "#{log.class.name.underscore}_#{subsection.id}_check_answers_path" diff --git a/app/views/logs/edit.html.erb b/app/views/logs/edit.html.erb index 3cfed5bc8..b4769698b 100644 --- a/app/views/logs/edit.html.erb +++ b/app/views/logs/edit.html.erb @@ -1,6 +1,6 @@ <% content_for :title, "Log #{@log.id}" %> <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { - breadcrumb_logs_title(@log) => breadcrumb_logs_link(@log), + breadcrumb_logs_title(@log, current_user) => breadcrumb_logs_link(@log, current_user), content_for(:title) => "", }) %>