Browse Source

fix rebase issues

pull/1642/head
Phil Lee 3 years ago
parent
commit
654368964f
  1. 3
      app/helpers/check_answers_helper.rb
  2. 2
      app/policies/location_policy.rb
  3. 8
      app/policies/scheme_policy.rb
  4. 2
      app/views/locations/index.html.erb
  5. 7
      app/views/schemes/_scheme_summary_list_row.html.erb
  6. 9
      app/views/schemes/check_answers.html.erb
  7. 2
      spec/requests/locations_controller_spec.rb
  8. 58
      spec/views/schemes/check_answers.html.erb_spec.rb

3
app/helpers/check_answers_helper.rb

@ -12,7 +12,10 @@ module CheckAnswersHelper
end end
def can_change_scheme_answer?(attribute_name, scheme) def can_change_scheme_answer?(attribute_name, scheme)
return false unless current_user.support? || current_user.data_coordinator?
editable_attributes = current_user.support? ? ["Name", "Confidential information", "Housing stock owned by"] : ["Name", "Confidential information"] editable_attributes = current_user.support? ? ["Name", "Confidential information", "Housing stock owned by"] : ["Name", "Confidential information"]
!scheme.confirmed? || editable_attributes.include?(attribute_name) !scheme.confirmed? || editable_attributes.include?(attribute_name)
end end

2
app/policies/location_policy.rb

@ -62,7 +62,7 @@ class LocationPolicy
define_method method_name do define_method method_name do
return true if user.support? return true if user.support?
scheme&.owning_organisation == user.organisation user.organisation.parent_organisations.exists?(scheme&.owning_organisation_id) || scheme&.owning_organisation == user.organisation
end end
end end

8
app/policies/scheme_policy.rb

@ -12,7 +12,7 @@ class SchemePolicy
if scheme == Scheme if scheme == Scheme
true true
else else
scheme&.owning_organisation == user.organisation user.organisation.parent_organisations.exists?(scheme&.owning_organisation_id) || scheme&.owning_organisation == user.organisation
end end
end end
@ -25,7 +25,9 @@ class SchemePolicy
end end
def update? def update?
user.data_coordinator? || user.support? return true if user.support?
user.data_coordinator? && (scheme&.owning_organisation == user.organisation)
end end
%w[ %w[
@ -35,7 +37,7 @@ class SchemePolicy
define_method method_name do define_method method_name do
return true if user.support? return true if user.support?
scheme&.owning_organisation == user.organisation user.organisation.parent_organisations.exists?(scheme&.owning_organisation_id) || scheme&.owning_organisation == user.organisation
end end
end end

2
app/views/locations/index.html.erb

@ -65,7 +65,7 @@
<% end %> <% end %>
<% end %> <% end %>
<% if LocationPolicy.new(current_user, Location).create? %> <% if LocationPolicy.new(current_user, @scheme.locations.new).create? %>
<%= govuk_button_to "Add a location", scheme_locations_path(@scheme), method: "post", secondary: true %> <%= govuk_button_to "Add a location", scheme_locations_path(@scheme), method: "post", secondary: true %>
<% end %> <% end %>
</div> </div>

7
app/views/schemes/_scheme_summary_list_row.html.erb

@ -14,9 +14,10 @@
<%= details_html(attribute) %> <%= details_html(attribute) %>
</dd> </dd>
<% end %> <% end %>
<% if can_change_scheme_answer?(attribute[:name], scheme) %> <% if can_change_scheme_answer?(attribute[:name], scheme) %>
<dd class="govuk-summary-list__actions"> <dd class="govuk-summary-list__actions">
<a class="govuk-link" href="<%= change_link %>">Change</a> <a class="govuk-link" href="<%= change_link %>">Change</a>
</dd> </dd>
<% end %> <% end %>
</div> </div>

9
app/views/schemes/check_answers.html.erb

@ -12,17 +12,21 @@
<% next if current_user.data_coordinator? && attr[:name] == ("owned by") %> <% next if current_user.data_coordinator? && attr[:name] == ("owned by") %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: @scheme.confirmed? ? scheme_edit_name_path(@scheme) : scheme_details_path(@scheme, check_answers: true) } %> <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: @scheme.confirmed? ? scheme_edit_name_path(@scheme) : scheme_details_path(@scheme, check_answers: true) } %>
<% end %> <% end %>
<% @scheme.check_primary_client_attributes.each do |attr| %> <% @scheme.check_primary_client_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_primary_client_group_path(@scheme, check_answers: true) } %> <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_primary_client_group_path(@scheme, check_answers: true) } %>
<% end %> <% end %>
<% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %> <% @scheme.check_secondary_client_confirmation_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_confirm_secondary_client_group_path(@scheme, check_answers: true) } %> <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_confirm_secondary_client_group_path(@scheme, check_answers: true) } %>
<% end %> <% end %>
<% if @scheme.has_other_client_group == "Yes" %> <% if @scheme.has_other_client_group == "Yes" %>
<% @scheme.check_secondary_client_attributes.each do |attr| %> <% @scheme.check_secondary_client_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_secondary_client_group_path(@scheme, check_answers: true) } %> <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_secondary_client_group_path(@scheme, check_answers: true) } %>
<% end %> <% end %>
<% end %> <% end %>
<% @scheme.check_support_attributes.each do |attr| %> <% @scheme.check_support_attributes.each do |attr| %>
<%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_support_path(@scheme, check_answers: true) } %> <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_support_path(@scheme, check_answers: true) } %>
<% end %> <% end %>
@ -32,5 +36,8 @@
<%= f.hidden_field :page, value: "check-answers" %> <%= f.hidden_field :page, value: "check-answers" %>
<%= f.hidden_field :confirmed, value: "true" %> <%= f.hidden_field :confirmed, value: "true" %>
<% button_label = @scheme.confirmed? ? "Save" : "Create scheme" %> <% button_label = @scheme.confirmed? ? "Save" : "Create scheme" %>
<%= f.govuk_submit button_label %>
<% if SchemePolicy.new(current_user, @scheme).create? %>
<%= f.govuk_submit button_label %>
<% end %>
<% end %> <% end %>

2
spec/requests/locations_controller_spec.rb

@ -1723,6 +1723,8 @@ RSpec.describe LocationsController, type: :request do
end end
it "shows the location" do it "shows the location" do
get "/schemes/#{scheme.id}/locations/#{location.id}"
expect(page).to have_content("Location name") expect(page).to have_content("Location name")
expect(page).to have_content(location.name) expect(page).to have_content(location.name)
end end

58
spec/views/schemes/check_answers.html.erb_spec.rb

@ -0,0 +1,58 @@
require "rails_helper"
RSpec.describe "schemes/check_answers.html.erb" do
let(:user) { build(:user) }
let(:scheme) do
instance_double(
Scheme,
owning_organisation: user.organisation,
id: 1,
service_name: "some name",
id_to_display: "S1",
sensitive: false,
scheme_type: "some type",
registered_under_care_act: false,
arrangement_type: "some other type",
primary_client_group: false,
has_other_client_group: false,
secondary_client_group: false,
support_type: "some support type",
intended_stay: "some intended stay",
available_from: 1.week.ago,
scheme_deactivation_periods: [],
status: :active,
to_model: Scheme.new,
check_details_attributes: [],
check_primary_client_attributes: [
{ name: "Primary client group", value: "foo", id: "primary_client_group" },
],
check_secondary_client_confirmation_attributes: [],
check_support_attributes: [],
confirmed?: false,
errors: ActiveModel::Errors.new(Scheme.new),
)
end
context "when a data provider" do
it "does not render change links" do
assign(:scheme, scheme)
allow(view).to receive(:current_user).and_return(user)
render
expect(rendered).not_to have_content("Change")
end
it "does not render submit button" do
assign(:scheme, scheme)
allow(view).to receive(:current_user).and_return(user)
render
expect(rendered).not_to have_content("Create scheme")
end
end
end
Loading…
Cancel
Save