From 65663905bced3cc28ade2f696272fbdf156bf181 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 20 Oct 2023 15:08:49 +0100 Subject: [PATCH] feat: update helper logic --- app/helpers/filters_helper.rb | 14 +++++++++----- app/views/logs/_log_filters.html.erb | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index 61afb573b..fa2665177 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -116,16 +116,20 @@ module FiltersHelper user.support? || org.stock_owners.count > 1 || (org.holds_own_stock? && org.stock_owners.count.positive?) end - def has_logs_for_both_needstypes? + def logs_for_both_needstypes_present? [1, 2].all? { |needstype| current_user.lettings_logs.where(needstype:).count.positive? } end - def multiple_owning_orgs? - current_user.support? || current_user.organisation.stock_owners.count > 1 + def non_support_with_multiple_owning_orgs? + current_user.organisation.stock_owners.count > 1 && user_lettings_path? end - def multiple_managing_orgs? - current_user.support? || current_user.organisation.managing_agents.count > 1 + def non_support_with_multiple_managing_orgs? + current_user.organisation.managing_agents.count > 1 && user_lettings_path? + end + + def user_lettings_path? + request.path == "/lettings-logs" end def user_or_org_lettings_path? diff --git a/app/views/logs/_log_filters.html.erb b/app/views/logs/_log_filters.html.erb index d8cb1d7d7..ffa05c2d8 100644 --- a/app/views/logs/_log_filters.html.erb +++ b/app/views/logs/_log_filters.html.erb @@ -42,7 +42,7 @@ category: "status", } %> - <% if has_logs_for_both_needstypes? && user_or_org_lettings_path? %> + <% if logs_for_both_needstypes_present? && user_or_org_lettings_path? %> <%= render partial: "filters/checkbox_filter", locals: { f:, @@ -73,7 +73,7 @@ category: "assigned_to", } %> - <% if multiple_owning_orgs? && user_or_org_lettings_path? %> + <% if current_user.support? || non_support_with_multiple_owning_orgs? %> <%= render partial: "filters/radio_filter", locals: { f:, options: { @@ -93,7 +93,7 @@ } %> <% end %> - <% if multiple_managing_orgs? && user_or_org_lettings_path? %> + <% if current_user.support? || non_support_with_multiple_managing_orgs? %> <%= render partial: "filters/radio_filter", locals: { f:, options: {