diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 507e3d7ce..453c0934f 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -7,35 +7,7 @@ class LocationsController < ApplicationController before_action :find_scheme before_action :scheme_and_location_present, except: %i[create index] - before_action :authorize_read, - only: %i[ - show - postcode - local_authority - name - units - type_of_unit - mobility_standards - availability - check_answers - confirm - ] - - before_action :authorize_write, - only: %i[ - update_postcode - update_local_authority - update_name - update_units - update_type_of_unit - update_mobility_standards - update_availability - new_deactivation - deactivate_confirm - deactivate - new_reactivation - reactivate - ] + before_action :authorize_user, except: %i[index create] def index authorize @scheme @@ -240,12 +212,8 @@ class LocationsController < ApplicationController private - def authorize_read - authorize @location - end - - def authorize_write - authorize @location + def authorize_user + authorize(@location || Location) end def scheme_and_location_present diff --git a/app/policies/location_policy.rb b/app/policies/location_policy.rb index dac54e235..81ba4dedc 100644 --- a/app/policies/location_policy.rb +++ b/app/policies/location_policy.rb @@ -13,7 +13,11 @@ class LocationPolicy def create? return true if user.support? - user.data_coordinator? && user.organisation == scheme&.owning_organisation + if location == Location + user.data_coordinator? + else + user.data_coordinator? && user.organisation == scheme&.owning_organisation + end end def update? diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb index 0be68ffe5..d949a8c63 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/locations/show.html.erb @@ -26,7 +26,7 @@ <% if FeatureToggle.location_toggle_enabled? %> - <% if LocationPolicy.new(current_user, Location).deactivate? %> + <% if LocationPolicy.new(current_user, @location).deactivate? %> <%= toggle_location_link(@location) %> <% end %> <% end %>