Browse Source

Pass current_user to questions

pull/968/head
Jack S 4 years ago
parent
commit
5f11da4baa
  1. 2
      app/models/form/common/questions/created_by_id.rb
  2. 2
      app/models/form/common/questions/owning_organisation_id.rb
  3. 2
      app/models/form/lettings/questions/scheme_id.rb
  4. 2
      app/models/form/question.rb
  5. 2
      app/views/form/_radio_question.html.erb
  6. 2
      app/views/form/_select_question.html.erb

2
app/models/form/common/questions/created_by_id.rb

@ -19,7 +19,7 @@ class Form::Common::Questions::CreatedById < ::Form::Question
end
end
def displayed_answer_options(log)
def displayed_answer_options(log, _user = nil)
return answer_options unless log.owning_organisation
user_ids = log.owning_organisation.users.pluck(:id) + [""]

2
app/models/form/common/questions/owning_organisation_id.rb

@ -19,7 +19,7 @@ class Form::Common::Questions::OwningOrganisationId < ::Form::Question
end
end
def displayed_answer_options(_log)
def displayed_answer_options(_log, _user = nil)
answer_options
end

2
app/models/form/lettings/questions/scheme_id.rb

@ -20,7 +20,7 @@ class Form::Lettings::Questions::SchemeId < ::Form::Question
end
end
def displayed_answer_options(lettings_log)
def displayed_answer_options(lettings_log, _user = nil)
organisation = lettings_log.owning_organisation || lettings_log.created_by&.organisation
schemes = organisation ? Scheme.select(:id).where(owning_organisation_id: organisation.id, confirmed: true) : Scheme.select(:id).where(confirmed: true)
filtered_scheme_ids = schemes.joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL", Time.zone.today)).map(&:id)

2
app/models/form/question.rb

@ -107,7 +107,7 @@ class Form::Question
false
end
def displayed_answer_options(log)
def displayed_answer_options(log, _current_user = nil)
answer_options.select do |_key, val|
!val.is_a?(Hash) || !val["depends_on"] || form.depends_on_met(val["depends_on"], log)
end

2
app/views/form/_radio_question.html.erb

@ -5,7 +5,7 @@
legend: legend(question, page_header, conditional),
hint: { text: question.hint_text&.html_safe } do %>
<% question.displayed_answer_options(@log).map do |key, options| %>
<% question.displayed_answer_options(@log, current_user).map do |key, options| %>
<% if key.starts_with?("divider") %>
<%= f.govuk_radio_divider %>
<% else %>

2
app/views/form/_select_question.html.erb

@ -1,7 +1,7 @@
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %>
<% selected = @log.public_send(question.id) || "" %>
<% answers = question.displayed_answer_options(@log).map { |key, value| OpenStruct.new(id: key, name: value.respond_to?(:service_name) ? value.service_name : nil, resource: value) } %>
<% answers = question.displayed_answer_options(@log, current_user).map { |key, value| OpenStruct.new(id: key, name: value.respond_to?(:service_name) ? value.service_name : nil, resource: value) } %>
<%= f.govuk_select(question.id.to_sym,
label: legend(question, page_header, conditional),
"data-controller": "accessible-autocomplete",

Loading…
Cancel
Save