diff options
| author | cedricnjanga | 2017-07-06 17:38:47 +0200 |
|---|---|---|
| committer | cedricnjanga | 2017-07-06 17:38:47 +0200 |
| commit | 4bddbdb6a1eb52260b1fdaa78ebd9415582daafd (patch) | |
| tree | d85f906433876b05a35edfe093e3aa6b5b40956e /app/controllers | |
| parent | bf63449de6ac9624352af4c0319758da3c8d827e (diff) | |
| parent | 1ed7b4a1398fcc39c539de5e0b045e098e02e50f (diff) | |
| download | chouette-core-4bddbdb6a1eb52260b1fdaa78ebd9415582daafd.tar.bz2 | |
Merge branch 'master' of github.com:af83/stif-boiv
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/application_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/concerns/policy_checker.rb | 9 | ||||
| -rw-r--r-- | app/controllers/journey_patterns_collections_controller.rb | 9 | ||||
| -rw-r--r-- | app/controllers/line_footnotes_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/referentials_controller.rb | 1 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 1 | ||||
| -rw-r--r-- | app/controllers/vehicle_journeys_controller.rb | 9 |
7 files changed, 17 insertions, 16 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 42b7c2a25..8fcaa3b1b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,7 +19,7 @@ class ApplicationController < ActionController::Base end def pundit_user - UserContext.new(current_user, referential: self.try(:current_referential)) + UserContext.new(current_user, referential: @referential) end protected diff --git a/app/controllers/concerns/policy_checker.rb b/app/controllers/concerns/policy_checker.rb index 72c18c64f..c8a821cf7 100644 --- a/app/controllers/concerns/policy_checker.rb +++ b/app/controllers/concerns/policy_checker.rb @@ -2,11 +2,16 @@ module PolicyChecker extend ActiveSupport::Concern included do - before_action :check_policy, only: [:edit, :update, :destroy] + before_action :authorize_resource, except: [:create, :index, :new] + before_action :authorize_resource_class, only: [:create, :index, :new] end protected - def check_policy + def authorize_resource authorize resource end + + def authorize_resource_class + authorize resource_class + end end diff --git a/app/controllers/journey_patterns_collections_controller.rb b/app/controllers/journey_patterns_collections_controller.rb index 7b97e1408..837ac65e7 100644 --- a/app/controllers/journey_patterns_collections_controller.rb +++ b/app/controllers/journey_patterns_collections_controller.rb @@ -49,11 +49,10 @@ class JourneyPatternsCollectionsController < ChouetteController end def user_permissions - @perms = {}.tap do |perm| - ['journey_patterns.create', 'journey_patterns.edit', 'journey_patterns.destroy'].each do |name| - perm[name] = policy(:journey_pattern).send("#{name.split('.').last}?") - end - end.to_json + @perms = + %w{create destroy edit}.inject({}) do | permissions, action | + permissions.merge( "journey_patterns.#{action}" => policy.authorizes_action?(action) ) + end.to_json end def update diff --git a/app/controllers/line_footnotes_controller.rb b/app/controllers/line_footnotes_controller.rb index c42aa785b..6a9048392 100644 --- a/app/controllers/line_footnotes_controller.rb +++ b/app/controllers/line_footnotes_controller.rb @@ -34,7 +34,7 @@ class LineFootnotesController < BreadcrumbController private def resource @referential = Referential.find params[:referential_id] - @line = @referential.lines.find params[:line_id] + @line = @referential.lines.find params[:line_id] end def line_params diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index 1239d512f..31b953ace 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -1,7 +1,6 @@ class ReferentialsController < BreadcrumbController defaults :resource_class => Referential include PolicyChecker - before_action :check_policy, :only => [:edit, :update, :destroy, :archive, :unarchive] # overrides default respond_to :html respond_to :json, :only => :show diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 6d2639981..0e0cade56 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -17,7 +17,6 @@ class TimeTablesController < ChouetteController @time_table = @time_table.decorate(context: { referential: @referential }) - build_breadcrumb :show end end diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb index fe2e2137f..f7e2fcdc1 100644 --- a/app/controllers/vehicle_journeys_controller.rb +++ b/app/controllers/vehicle_journeys_controller.rb @@ -159,11 +159,10 @@ class VehicleJourneysController < ChouetteController end def user_permissions - @perms = {}.tap do |perm| - ['vehicle_journeys.create', 'vehicle_journeys.edit', 'vehicle_journeys.destroy'].each do |name| - perm[name] = policy(:vehicle_journey).send("#{name.split('.').last}?") - end - end.to_json + @perms = + %w{create destroy update}.inject({}) do | permissions, action | + permissions.merge( "vehicle_journeys.#{action}" => policy.authorizes_action?(action) ) + end.to_json end private |
