|
|
|
@ -3,6 +3,7 @@ class LocationsController < ApplicationController
|
|
|
|
|
before_action :authenticate_scope! |
|
|
|
|
before_action :find_location, except: %i[new create] |
|
|
|
|
before_action :find_scheme |
|
|
|
|
before_action :authenticate_action! |
|
|
|
|
|
|
|
|
|
def new |
|
|
|
|
@location = Location.new |
|
|
|
@ -42,6 +43,12 @@ private
|
|
|
|
|
head :unauthorized and return unless current_user.data_coordinator? || current_user.support? |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def authenticate_action! |
|
|
|
|
if %w[new create details update].include?(action_name) && !((current_user.organisation == @scheme.organisation) || current_user.support?) |
|
|
|
|
render_not_found and return |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def location_params |
|
|
|
|
required_params = params.require(:location).permit(:postcode, :name, :total_units, :type_of_unit, :wheelchair_adaptation, :add_another_location).merge(scheme_id: @scheme.id) |
|
|
|
|
required_params[:postcode] = required_params[:postcode].gsub(" ", "").encode("ASCII", "UTF-8", invalid: :replace, undef: :replace, replace: "") if required_params[:postcode] |
|
|
|
|