diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 44341b48f..53055cf82 100644 --- a/app/controllers/schemes_controller.rb +++ b/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 diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index ed07f3b56..80f4326f7 100644 --- a/app/helpers/check_answers_helper.rb +++ b/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 diff --git a/app/helpers/schemes_helper.rb b/app/helpers/schemes_helper.rb index f7da6d3f7..ab6f4b6f2 100644 --- a/app/helpers/schemes_helper.rb +++ b/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) diff --git a/app/policies/scheme_policy.rb b/app/policies/scheme_policy.rb index 39842a160..30aa1543c 100644 --- a/app/policies/scheme_policy.rb +++ b/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 diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index 7924768f0..dccefc565 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -9,7 +9,6 @@