Browse Source

slim down before filters

pull/1642/head
Phil Lee 3 years ago
parent
commit
e4a1c492c1
  1. 38
      app/controllers/locations_controller.rb
  2. 4
      app/policies/location_policy.rb
  3. 2
      app/views/locations/show.html.erb

38
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

4
app/policies/location_policy.rb

@ -13,8 +13,12 @@ class LocationPolicy
def create?
return true if user.support?
if location == Location
user.data_coordinator?
else
user.data_coordinator? && user.organisation == scheme&.owning_organisation
end
end
def update?
return true if user.support?

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

@ -26,7 +26,7 @@
</div>
<% 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 %>

Loading…
Cancel
Save