From 18d98abd7c862ed37c10395cab5782e2822b850a Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 22 Nov 2023 14:50:51 +0000 Subject: [PATCH] Display managing organisation users in created_by --- app/models/form/sales/questions/created_by_id.rb | 12 ++++++------ .../form/sales/questions/created_by_id_spec.rb | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/models/form/sales/questions/created_by_id.rb b/app/models/form/sales/questions/created_by_id.rb index e48b4f9e5..4e0e73e27 100644 --- a/app/models/form/sales/questions/created_by_id.rb +++ b/app/models/form/sales/questions/created_by_id.rb @@ -4,7 +4,7 @@ class Form::Sales::Questions::CreatedById < ::Form::Question def initialize(id, hsh, page) super @id = "created_by_id" - @check_answer_label = "User" + @check_answer_label = "Log owner" @header = "Which user are you creating this log for?" @type = "select" end @@ -14,19 +14,19 @@ class Form::Sales::Questions::CreatedById < ::Form::Question end def displayed_answer_options(log, current_user = nil) - return ANSWER_OPTS unless log.owning_organisation + return ANSWER_OPTS unless log.managing_organisation return ANSWER_OPTS unless current_user users = [] users += if current_user.support? [ ( - if log.owning_organisation - log.owning_organisation.absorbing_organisation.present? ? log.owning_organisation&.absorbing_organisation&.users : log.owning_organisation&.users + if log.managing_organisation + log.managing_organisation.absorbing_organisation.present? ? log.managing_organisation&.absorbing_organisation&.users : log.managing_organisation.users end), ].flatten else - current_user.organisation.users + log.managing_organisation.users end.uniq.compact users.each_with_object(ANSWER_OPTS.dup) do |user, hsh| hsh[user.id] = present_user(user) @@ -58,6 +58,6 @@ private end def selected_answer_option_is_derived?(_log) - false + true end end diff --git a/spec/models/form/sales/questions/created_by_id_spec.rb b/spec/models/form/sales/questions/created_by_id_spec.rb index 29f5b38b8..ae52798b4 100644 --- a/spec/models/form/sales/questions/created_by_id_spec.rb +++ b/spec/models/form/sales/questions/created_by_id_spec.rb @@ -52,9 +52,9 @@ RSpec.describe Form::Sales::Questions::CreatedById, type: :model do describe "#displayed_answer_options" do let(:owning_org_user) { create(:user) } - let(:sales_log) { create(:sales_log, owning_organisation: owning_org_user.organisation) } + let(:sales_log) { create(:sales_log, owning_organisation: owning_org_user.organisation, managing_organisation: owning_org_user.organisation) } - it "only displays users that belong to the owning organisation" do + it "only displays users that belong to the managing organisation" do expect(question.displayed_answer_options(sales_log, support_user)).to eq(expected_option_for_users(owning_org_user.organisation.users)) end end @@ -69,14 +69,14 @@ RSpec.describe Form::Sales::Questions::CreatedById, type: :model do describe "#displayed_answer_options" do let(:owning_org_user) { create(:user) } - let(:sales_log) { create(:sales_log, owning_organisation: owning_org_user.organisation) } + let(:sales_log) { create(:sales_log, owning_organisation: owning_org_user.organisation, managing_organisation: owning_org_user.organisation) } before do create(:user, organisation: data_coordinator.organisation) end - it "only displays users that belong user's org" do - expect(question.displayed_answer_options(sales_log, data_coordinator)).to eq(expected_option_for_users(data_coordinator.organisation.users)) + it "only displays users that belong to managing organisation" do + expect(question.displayed_answer_options(sales_log, data_coordinator)).to eq(expected_option_for_users(owning_org_user.organisation.users)) end end end