diff options
| author | cedricnjanga | 2017-08-04 02:00:44 +0200 |
|---|---|---|
| committer | cedricnjanga | 2017-08-04 02:00:44 +0200 |
| commit | 154760f497eceb8e93e4f63cf16346d99c17d2d2 (patch) | |
| tree | ef9ee1094c3888ae9bbbde96a4971a822ce070a2 | |
| parent | 09b0d438c50c7cd9ec9c18d1d90c16877b07d9a9 (diff) | |
| download | chouette-core-154760f497eceb8e93e4f63cf16346d99c17d2d2.tar.bz2 | |
Refs #4227 Add timetable_combination policies
| -rw-r--r-- | app/controllers/time_table_combinations_controller.rb | 4 | ||||
| -rw-r--r-- | app/decorators/time_table_decorator.rb | 14 |
2 files changed, 12 insertions, 6 deletions
diff --git a/app/controllers/time_table_combinations_controller.rb b/app/controllers/time_table_combinations_controller.rb index 32f1818b0..ba61a2ea4 100644 --- a/app/controllers/time_table_combinations_controller.rb +++ b/app/controllers/time_table_combinations_controller.rb @@ -3,13 +3,17 @@ class TimeTableCombinationsController < ChouetteController belongs_to :time_table, :parent_class => Chouette::TimeTable end + # include PolicyChecker + def new @combination = TimeTableCombination.new(source_id: parent.id) + authorize @combination @combination.combined_type = 'time_table' end def create @combination = TimeTableCombination.new(params[:time_table_combination].merge(source_id: parent.id)) + authorize @combination @combination.valid? ? perform_combination : render(:new) end diff --git a/app/decorators/time_table_decorator.rb b/app/decorators/time_table_decorator.rb index 526537310..c6eeac176 100644 --- a/app/decorators/time_table_decorator.rb +++ b/app/decorators/time_table_decorator.rb @@ -21,13 +21,15 @@ class TimeTableDecorator < Draper::Decorator ) end - links << Link.new( - content: h.t('actions.combine'), - href: h.new_referential_time_table_time_table_combination_path( - context[:referential], - object + if h.policy(object).edit? + links << Link.new( + content: h.t('actions.combine'), + href: h.new_referential_time_table_time_table_combination_path( + context[:referential], + object + ) ) - ) + end if h.policy(object).duplicate? links << Link.new( |
