Browse Source

Display managing organisation users in created_by

pull/2077/head
Kat 3 years ago
parent
commit
18d98abd7c
  1. 12
      app/models/form/sales/questions/created_by_id.rb
  2. 10
      spec/models/form/sales/questions/created_by_id_spec.rb

12
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) def initialize(id, hsh, page)
super super
@id = "created_by_id" @id = "created_by_id"
@check_answer_label = "User" @check_answer_label = "Log owner"
@header = "Which user are you creating this log for?" @header = "Which user are you creating this log for?"
@type = "select" @type = "select"
end end
@ -14,19 +14,19 @@ class Form::Sales::Questions::CreatedById < ::Form::Question
end end
def displayed_answer_options(log, current_user = nil) 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 return ANSWER_OPTS unless current_user
users = [] users = []
users += if current_user.support? users += if current_user.support?
[ [
( (
if log.owning_organisation if log.managing_organisation
log.owning_organisation.absorbing_organisation.present? ? log.owning_organisation&.absorbing_organisation&.users : log.owning_organisation&.users log.managing_organisation.absorbing_organisation.present? ? log.managing_organisation&.absorbing_organisation&.users : log.managing_organisation.users
end), end),
].flatten ].flatten
else else
current_user.organisation.users log.managing_organisation.users
end.uniq.compact end.uniq.compact
users.each_with_object(ANSWER_OPTS.dup) do |user, hsh| users.each_with_object(ANSWER_OPTS.dup) do |user, hsh|
hsh[user.id] = present_user(user) hsh[user.id] = present_user(user)
@ -58,6 +58,6 @@ private
end end
def selected_answer_option_is_derived?(_log) def selected_answer_option_is_derived?(_log)
false true
end end
end end

10
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 describe "#displayed_answer_options" do
let(:owning_org_user) { create(:user) } 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)) expect(question.displayed_answer_options(sales_log, support_user)).to eq(expected_option_for_users(owning_org_user.organisation.users))
end end
end end
@ -69,14 +69,14 @@ RSpec.describe Form::Sales::Questions::CreatedById, type: :model do
describe "#displayed_answer_options" do describe "#displayed_answer_options" do
let(:owning_org_user) { create(:user) } 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 before do
create(:user, organisation: data_coordinator.organisation) create(:user, organisation: data_coordinator.organisation)
end end
it "only displays users that belong user's org" do 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(data_coordinator.organisation.users)) expect(question.displayed_answer_options(sales_log, data_coordinator)).to eq(expected_option_for_users(owning_org_user.organisation.users))
end end
end end
end end

Loading…
Cancel
Save