Browse Source

feat: allow data coordinators to create, edit and view stock owners' schemes

pull/1958/head
natdeanlewissoftwire 3 years ago
parent
commit
92969d3e97
  1. 6
      app/controllers/schemes_controller.rb
  2. 2
      app/helpers/check_answers_helper.rb
  3. 14
      app/helpers/schemes_helper.rb
  4. 14
      app/policies/scheme_policy.rb
  5. 1
      app/views/schemes/check_answers.html.erb
  6. 4
      app/views/schemes/details.html.erb
  7. 4
      app/views/schemes/edit_name.html.erb
  8. 10
      app/views/schemes/new.html.erb
  9. 2
      app/views/schemes/show.html.erb

6
app/controllers/schemes_controller.rb

@ -273,7 +273,7 @@ private
required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive]
if current_user.data_coordinator?
if current_user.data_coordinator? && current_user.organisation.stock_owners.nil?
required_params[:owning_organisation_id] = current_user.organisation_id
end
required_params
@ -291,10 +291,6 @@ private
@scheme
end
def user_allowed_action?
current_user.support? || current_user.organisation == @scheme&.owning_organisation || current_user.organisation.parent_organisations.exists?(@scheme&.owning_organisation_id)
end
def redirect_if_scheme_confirmed
redirect_to @scheme if @scheme.confirmed?
end

2
app/helpers/check_answers_helper.rb

@ -14,7 +14,7 @@ module CheckAnswersHelper
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 = ["Name", "Confidential information", "Housing stock owned by"]
!scheme.confirmed? || editable_attributes.include?(attribute_name)
end

14
app/helpers/schemes_helper.rb

@ -1,6 +1,6 @@
module SchemesHelper
def display_scheme_attributes(scheme, user)
base_attributes = [
def display_scheme_attributes(scheme)
[
{ name: "Scheme code", value: scheme.id_to_display },
{ name: "Name", value: scheme.service_name, edit: true },
{ name: "Status", value: status_tag_from_resource(scheme) },
@ -16,16 +16,6 @@ module SchemesHelper
{ name: "Intended length of stay", value: scheme.intended_stay },
{ name: "Availability", value: scheme_availability(scheme) },
]
if user.data_coordinator?
base_attributes.delete_if { |item| item[:name] == "Housing stock owned by" }
end
if scheme.has_other_client_group == "Yes"
base_attributes.append
end
base_attributes
end
def scheme_availability(scheme)

14
app/policies/scheme_policy.rb

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

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

@ -9,7 +9,6 @@
<h2 class="govuk-visually-hidden">Scheme</h2>
<dl class="govuk-summary-list">
<% @scheme.check_details_attributes.each do |attr| %>
<% 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) } %>
<% end %>

4
app/views/schemes/details.html.erb

@ -50,7 +50,9 @@
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% if current_user.support? %>
<% if current_user.data_coordinator? && current_user.organisation.stock_owners.nil? %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% else %>
<%= f.govuk_collection_select :owning_organisation_id,
organisations,
:id,

4
app/views/schemes/edit_name.html.erb

@ -27,7 +27,9 @@
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% if current_user.support? %>
<% if current_user.data_coordinator? && current_user.organisation.stock_owners.nil? %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% else %>
<%= f.govuk_collection_select :owning_organisation_id,
organisations,
:id,

10
app/views/schemes/new.html.erb

@ -30,10 +30,6 @@
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% answer_options = null_option + organisations %>
<% if current_user.data_coordinator? %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% end %>
<% scheme_types_selection = Scheme.scheme_types.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %>
<%= f.govuk_collection_radio_buttons :scheme_type,
scheme_types_selection,
@ -52,8 +48,10 @@
:description,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %>
<% if current_user.support? %>
<%= f.govuk_collection_select :owning_organisation_id,
<% if current_user.data_coordinator? && current_user.organisation.stock_owners.nil? %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% else %>
<%= f.govuk_collection_select :owning_organisation_id,
answer_options,
:id,
:name,

2
app/views/schemes/show.html.erb

@ -16,7 +16,7 @@
<h2 class="govuk-visually-hidden">Scheme</h2>
<%= govuk_summary_list do |summary_list| %>
<% display_scheme_attributes(@scheme, current_user).each do |attr| %>
<% display_scheme_attributes(@scheme).each do |attr| %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name] } %>
<% row.value do %>

Loading…
Cancel
Save