From 45a9b946b1481ce8e481c4a7a9744c095d9a457a Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 11 Jul 2017 17:39:25 +0200 Subject: hotfix to open all non standard actions on ApplicationController --- app/controllers/concerns/policy_checker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/concerns/policy_checker.rb b/app/controllers/concerns/policy_checker.rb index c8a821cf7..9721dc63c 100644 --- a/app/controllers/concerns/policy_checker.rb +++ b/app/controllers/concerns/policy_checker.rb @@ -2,7 +2,7 @@ module PolicyChecker extend ActiveSupport::Concern included do - before_action :authorize_resource, except: [:create, :index, :new] + before_action :authorize_resource, only: [:destroy, :show, :update] before_action :authorize_resource_class, only: [:create, :index, :new] end -- cgit v1.2.3 From 4797bfbfec8f97ef09f62d6b170b8f749be4a0bf Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 7 Jul 2017 16:52:47 +0200 Subject: Companies#index: Use new table builder helper Refs #3479 --- app/controllers/companies_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb index 9d33c6cb8..1596975b8 100644 --- a/app/controllers/companies_controller.rb +++ b/app/controllers/companies_controller.rb @@ -15,6 +15,14 @@ class CompaniesController < BreadcrumbController if collection.out_of_bounds? redirect_to params.merge(:page => 1) end + + @companies = ModelDecorator.decorate( + @companies, + with: CompanyDecorator, + context: { + line_referential: line_referential + } + ) } build_breadcrumb :index end -- cgit v1.2.3 From 288c5980dc7cd9f143b88d5a8492c006c5f46bb7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 7 Jul 2017 17:08:00 +0200 Subject: ReferentialCompanies#index: Use new table builder helper TODO: Rename `line_referential` context parameter in `CompanyDecorator` to `referential` since the name needs to make sense both for `Referential` and for `LineReferential`. Refs #3479 --- app/controllers/referential_companies_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/referential_companies_controller.rb b/app/controllers/referential_companies_controller.rb index e8b104d14..09167009a 100644 --- a/app/controllers/referential_companies_controller.rb +++ b/app/controllers/referential_companies_controller.rb @@ -13,6 +13,14 @@ class ReferentialCompaniesController < ChouetteController if collection.out_of_bounds? redirect_to params.merge(:page => 1) end + + @companies = ModelDecorator.decorate( + @companies, + with: CompanyDecorator, + context: { + line_referential: referential + } + ) } build_breadcrumb :index end -- cgit v1.2.3 From a6a3122bf1d2c2f6fc6b0f27b25b14da16a9b976 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 7 Jul 2017 17:14:14 +0200 Subject: CompanyDecorator#action_links: Rename `line_referential` context param Rename this to `referential` to be more generic. This is because we could be passing both `Referential`s and `LineReferential`s into this parameter. In `CompaniesController`, we use a `LineReferential` while in `ReferentialCompaniesController` we use `Referential`. Refs #3479 --- app/controllers/companies_controller.rb | 2 +- app/controllers/referential_companies_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb index 1596975b8..07a732fc9 100644 --- a/app/controllers/companies_controller.rb +++ b/app/controllers/companies_controller.rb @@ -20,7 +20,7 @@ class CompaniesController < BreadcrumbController @companies, with: CompanyDecorator, context: { - line_referential: line_referential + referential: line_referential } ) } diff --git a/app/controllers/referential_companies_controller.rb b/app/controllers/referential_companies_controller.rb index 09167009a..53dde93bb 100644 --- a/app/controllers/referential_companies_controller.rb +++ b/app/controllers/referential_companies_controller.rb @@ -18,7 +18,7 @@ class ReferentialCompaniesController < ChouetteController @companies, with: CompanyDecorator, context: { - line_referential: referential + referential: referential } ) } -- cgit v1.2.3 From c7ceb38801b853154cdae31672ff2c105c8b191f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 7 Jul 2017 18:25:48 +0200 Subject: Remove ReferentialLines#index Delete this route and associated template files. Wasn't sure if using `exclude:` in the routes file was the best way to do this, as I'm not sure if there are other routes we want to exclude from here also. I visited the page because I'm migrating templates to the new table builder helper and this one uses table builder. Upon visiting the page, it looked pretty wonky, and after consulting with Jean-Paul and Luc, it turns out this page isn't used any more because the table of `Chouette::Line`s rendered there is now instead displayed on the Referentials#show page, obviating the need for this page. Refs #3479 --- app/controllers/referential_lines_controller.rb | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb index 4b4a822b4..fe81bee12 100644 --- a/app/controllers/referential_lines_controller.rb +++ b/app/controllers/referential_lines_controller.rb @@ -10,18 +10,6 @@ class ReferentialLinesController < ChouetteController belongs_to :referential - def index - @hide_group_of_line = referential.group_of_lines.empty? - index! do |format| - format.html { - if collection.out_of_bounds? - redirect_to params.merge(:page => 1) - end - build_breadcrumb :index - } - end - end - def show @routes = resource.routes -- cgit v1.2.3 From 74da5aa9fdfa792cfbef2fcfc23c35d9a0b19408 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 12 Jul 2017 10:01:47 +0200 Subject: #4015 adjust Tag filter to be strict --- app/controllers/time_tables_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index f23e4c201..0b3d704ee 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -117,7 +117,7 @@ class TimeTablesController < ChouetteController end def tags - @tags = ActsAsTaggableOn::Tag.where("tags.name LIKE ?", "%#{params[:tag]}%") + @tags = ActsAsTaggableOn::Tag.where("tags.name = ?", "%#{params[:tag]}%") respond_to do |format| format.json { render :json => @tags.map{|t| {:id => t.id, :name => t.name }} } end -- cgit v1.2.3 From df184535c36359921fd5aabfb4c5c3e98c91017d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 10 Jul 2017 11:48:23 +0200 Subject: Referentials#show: Use new table builder helper Needed to add a new decorator to provide links to this table's gear menu. The links correspond to those in the header on the "referential_lines/show.html.slim" page. Call `#human_attribute_name` on the model directly instead of the collection because the decorated collection doesn't expose that method. Refs #3479 --- app/controllers/referentials_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index 9505a47f3..838c46168 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -27,6 +27,14 @@ class ReferentialsController < BreadcrumbController show! do |format| @referential = @referential.decorate @reflines = lines_collection.paginate(page: params[:page], per_page: 10) + @reflines = ModelDecorator.decorate( + @reflines, + with: ReferentialLineDecorator, + context: { + referential: referential, + current_organisation: current_organisation + } + ) format.json { render :json => { :lines_count => resource.lines.count, -- cgit v1.2.3 From 6920db47172cb5b55f6bdeccb575821cbf3a9f10 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 10 Jul 2017 11:59:55 +0200 Subject: ReferentialLines#show: Render links from ReferentialLineDecorator Leverage our newly created `ReferentialLineDecorator` to render the header links, allowing us to use them both here and in the table of lines on the Referentials#show page. Used the extended decoration syntax to allow us to specify the `ReferentialLineDecorator`, otherwise Draper will infer `LineDecorator`, which is not what we want in this case. Refs #3479 --- app/controllers/referential_lines_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb index fe81bee12..1da64991d 100644 --- a/app/controllers/referential_lines_controller.rb +++ b/app/controllers/referential_lines_controller.rb @@ -37,6 +37,14 @@ class ReferentialLinesController < ChouetteController ) show! do + @line = ReferentialLineDecorator.decorate( + @line, + context: { + referential: referential, + current_organisation: current_organisation + } + ) + build_breadcrumb :show end end -- cgit v1.2.3 From 2215e9696dc435940a8a40ffb45c1a11d95e3ee9 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 10 Jul 2017 12:23:28 +0200 Subject: RoutingConstraintZones#show: Fix breadcrumb I had broken the breadcrumb by overriding `#show` here. Add in the `build_breadcrumb` call to make it appear again. Refs #3479 --- app/controllers/routing_constraint_zones_controller.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb index c526e6348..f019b5ea9 100644 --- a/app/controllers/routing_constraint_zones_controller.rb +++ b/app/controllers/routing_constraint_zones_controller.rb @@ -16,6 +16,8 @@ class RoutingConstraintZonesController < ChouetteController referential: current_referential, line: parent.id }) + + build_breadcrumb :show end end -- cgit v1.2.3 From 09aef0d99cd86a75afe6aa81297cc7d3e7d8cae4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 10 Jul 2017 12:33:15 +0200 Subject: RoutingConstraintZones#index: Use new table builder helper Render table of `RoutingConstraintZones` using the new table builder. Refs #3479 --- app/controllers/routing_constraint_zones_controller.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb index f019b5ea9..3d0ee19ed 100644 --- a/app/controllers/routing_constraint_zones_controller.rb +++ b/app/controllers/routing_constraint_zones_controller.rb @@ -10,6 +10,21 @@ class RoutingConstraintZonesController < ChouetteController belongs_to :line, parent_class: Chouette::Line end + def index + index! do |format| + @routing_constraint_zones = ModelDecorator.decorate( + @routing_constraint_zones, + with: RoutingConstraintZoneDecorator, + context: { + referential: referential, + line: parent + } + ) + + build_breadcrumb :index + end + end + def show show! do |format| @routing_constraint_zone = @routing_constraint_zone.decorate(context: { -- cgit v1.2.3 From d6185a881dc0428950629acfd16c632f413ac728 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 10 Jul 2017 12:34:47 +0200 Subject: RoutingConstraintZones#show: Match decorator context from #index Just wrote the `#index` method and saw that the `#show` method's `context` hash contents are a bit verbose. Shorten them to match the `#index` method. These mean the same thing but are a bit cleaner. Refs #3479 --- app/controllers/routing_constraint_zones_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb index 3d0ee19ed..6c3cb8a29 100644 --- a/app/controllers/routing_constraint_zones_controller.rb +++ b/app/controllers/routing_constraint_zones_controller.rb @@ -28,8 +28,8 @@ class RoutingConstraintZonesController < ChouetteController def show show! do |format| @routing_constraint_zone = @routing_constraint_zone.decorate(context: { - referential: current_referential, - line: parent.id + referential: referential, + line: parent }) build_breadcrumb :show -- cgit v1.2.3 From ccbd1cfa43662933991dd85bef072e5ca0ae77c7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 11 Jul 2017 17:05:59 +0200 Subject: Networks#show: Move header links into a decorator In order to allow us to use these links in tables of networks via the new table builder, move the link definitions into decorator `#action_links`. This changes both of these types of pages: * http://stif-boiv.dev:3000/referentials/4/networks/118 * http://stif-boiv.dev:3000/line_referentials/1/networks/118 Refs #3479 --- app/controllers/networks_controller.rb | 5 +++++ app/controllers/referential_networks_controller.rb | 8 ++++++++ 2 files changed, 13 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/networks_controller.rb b/app/controllers/networks_controller.rb index ea8410c5b..2e2f3f0d1 100644 --- a/app/controllers/networks_controller.rb +++ b/app/controllers/networks_controller.rb @@ -12,7 +12,12 @@ class NetworksController < BreadcrumbController def show @map = NetworkMap.new(resource).with_helpers(self) + show! do + @network = @network.decorate(context: { + line_referential: line_referential + }) + build_breadcrumb :show end end diff --git a/app/controllers/referential_networks_controller.rb b/app/controllers/referential_networks_controller.rb index 30c7dd244..8426c6ba3 100644 --- a/app/controllers/referential_networks_controller.rb +++ b/app/controllers/referential_networks_controller.rb @@ -10,7 +10,15 @@ class ReferentialNetworksController < ChouetteController def show @map = NetworkMap.new(resource).with_helpers(self) + show! do + @network = ReferentialNetworkDecorator.decorate( + @network, + context: { + referential: referential + } + ) + build_breadcrumb :show end end -- cgit v1.2.3 From dc155d36bdf0dc1c056888794586fca10c1f11b0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 11 Jul 2017 17:28:19 +0200 Subject: Networks#index: Use new table builder helper on both networks tables Refs #3479 --- app/controllers/networks_controller.rb | 8 ++++++++ app/controllers/referential_networks_controller.rb | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/networks_controller.rb b/app/controllers/networks_controller.rb index 2e2f3f0d1..d1f83340e 100644 --- a/app/controllers/networks_controller.rb +++ b/app/controllers/networks_controller.rb @@ -36,6 +36,14 @@ class NetworksController < BreadcrumbController if collection.out_of_bounds? redirect_to params.merge(:page => 1) end + + @networks = ModelDecorator.decorate( + @networks, + with: NetworkDecorator, + context: { + line_referential: line_referential + } + ) } build_breadcrumb :index end diff --git a/app/controllers/referential_networks_controller.rb b/app/controllers/referential_networks_controller.rb index 8426c6ba3..e0ce71ce4 100644 --- a/app/controllers/referential_networks_controller.rb +++ b/app/controllers/referential_networks_controller.rb @@ -29,6 +29,14 @@ class ReferentialNetworksController < ChouetteController if collection.out_of_bounds? redirect_to params.merge(:page => 1) end + + @networks = ModelDecorator.decorate( + @networks, + with: ReferentialNetworkDecorator, + context: { + referential: referential + } + ) } build_breadcrumb :index end -- cgit v1.2.3 From ef937098ef2c5e7ad8a05c5d84b8a201cb6358e8 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 11 Jul 2017 18:48:42 +0200 Subject: StopAreaReferentials#show: Move header links to decorator On the http://stif-boiv.dev:3000/stop_area_referentials/1/stop_areas/139416 page, move the header links into a decorator to allow us to use them in the table of stop areas on StopAreaReferentials#index. Refs #3479 --- app/controllers/stop_areas_controller.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index ae3edbd3e..e97aad8d3 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -90,6 +90,9 @@ class StopAreasController < BreadcrumbController } end + + @stop_area = @stop_area.decorate + build_breadcrumb :show end end -- cgit v1.2.3 From 0970ba4be6b152e1f3aea0f10e8471e68dc60c4b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 11 Jul 2017 18:59:27 +0200 Subject: StopAreaReferentials#index: Use new table builder helper Change "_filters.html.slim" to call `#human_attribute_name` on the model instead of the collection, because the collection decorator doesn't delegate that method, and it's better to call it on the class. Refs #3479 --- app/controllers/stop_areas_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index e97aad8d3..cdb7c59ab 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -53,11 +53,18 @@ class StopAreasController < BreadcrumbController def index request.format.kml? ? @per_page = nil : @per_page = 12 @zip_codes = stop_area_referential.stop_areas.where("zip_code is NOT null").distinct.pluck(:zip_code) + index! do |format| format.html { if collection.out_of_bounds? redirect_to params.merge(:page => 1) end + + @stop_areas = ModelDecorator.decorate( + @stop_areas, + with: StopAreaDecorator + ) + build_breadcrumb :index } end -- cgit v1.2.3 From 9fed0c184323de9e5e0bcfe83465cb4e2b153590 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 11 Jul 2017 19:21:10 +0200 Subject: ReferentialStopAreas#show: Render header buttons from decorator Since we already have the decorator available, get the links from there for better code reuse. Refs #3479 --- app/controllers/referential_stop_areas_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/referential_stop_areas_controller.rb b/app/controllers/referential_stop_areas_controller.rb index 4d33ebb2e..7519418e7 100644 --- a/app/controllers/referential_stop_areas_controller.rb +++ b/app/controllers/referential_stop_areas_controller.rb @@ -72,13 +72,16 @@ class ReferentialStopAreasController < ChouetteController def show map.editable = false @access_points = @stop_area.access_points + show! do |format| unless stop_area.position or params[:default] or params[:routing] format.kml { render :nothing => true, :status => :not_found } - end + + @stop_area = @stop_area.decorate + build_breadcrumb :show end end -- cgit v1.2.3 From a021c872a51271ac43a253cffdd55761200bbee6 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 11 Jul 2017 19:33:30 +0200 Subject: Routes#show: Use new table builder helper Update the table builder helper for the table of `Chouette::StopPoints` on this page. Created a new `StopPointDecorator` which unfortunately has the same code as `StopAreaDecorator`, the only difference being that instead of using `object`, it uses `object.stop_area`. Need to work out how to eliminate that code duplication. Refs #3479 --- app/controllers/routes_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 4781d0d16..7ba2c1a58 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -47,6 +47,11 @@ class RoutesController < ChouetteController line: @line }) + @route_sp = ModelDecorator.decorate( + @route_sp, + with: StopPointDecorator + ) + build_breadcrumb :show end end -- cgit v1.2.3 From bc33eba0f1129a491a56bc9b616f388477489b0b Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 12 Jul 2017 16:48:27 +0200 Subject: Remove wild option in timetable tag filter --- app/controllers/time_tables_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 0b3d704ee..20d500ea9 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -130,7 +130,7 @@ class TimeTablesController < ChouetteController if params[:q] && params[:q]["tag_search"] tags = params[:q]["tag_search"].reject {|c| c.empty?} params[:q].delete("tag_search") - scope = select_time_tables.tagged_with(tags, :wild => true, :any => true) if tags.any? + scope = select_time_tables.tagged_with(tags, :any => true) if tags.any? end scope = ransack_periode(scope) @q = scope.search(params[:q]) -- cgit v1.2.3 From 8d342e0402d0f4b858c77469ca01f428a45503f0 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Thu, 13 Jul 2017 15:34:41 +0200 Subject: Fix footnotes policy Refs #4094 @2 --- app/controllers/line_footnotes_controller.rb | 29 +++++++++++----------------- 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/line_footnotes_controller.rb b/app/controllers/line_footnotes_controller.rb index 6a9048392..f24d624d4 100644 --- a/app/controllers/line_footnotes_controller.rb +++ b/app/controllers/line_footnotes_controller.rb @@ -1,16 +1,7 @@ -class LineFootnotesController < BreadcrumbController - defaults :resource_class => Chouette::Line - include PolicyChecker - respond_to :json, :only => :show +class LineFootnotesController < ChouetteController + defaults resource_class: Chouette::Line, collection_name: 'lines', instance_name: 'line' belongs_to :referential - def show - show! do - build_breadcrumb :show - end - @footnotes = @line.footnotes - end - def edit edit! do build_breadcrumb :edit @@ -18,25 +9,27 @@ class LineFootnotesController < BreadcrumbController end def update - if @line.update(line_params) - redirect_to referential_line_footnotes_path(@referential, @line) , notice: t('notice.footnotes.updated') - else - render :edit + update! do |success, failure| + success.html { redirect_to referential_line_footnotes_path(@referential, @line) , notice: t('notice.footnotes.updated') } + failure.html { render :edit } end end protected + + alias_method :line, :resource + # overrides default def check_policy authorize resource, "#{action_name}_footnote?".to_sym end - private def resource - @referential = Referential.find params[:referential_id] - @line = @referential.lines.find params[:line_id] + @line ||= current_referential.lines.find params[:line_id] end + private + def line_params params.require(:line).permit( { footnotes_attributes: [ :code, :label, :_destroy, :id ] } ) -- cgit v1.2.3 From 383ccd7d1337276c5d086e3dc077c7235fe0541d Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Thu, 13 Jul 2017 16:44:46 +0200 Subject: Update policies to make a custom behaviour on footnotes Refs #4094 @1 --- app/controllers/concerns/policy_checker.rb | 2 +- app/controllers/line_footnotes_controller.rb | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/concerns/policy_checker.rb b/app/controllers/concerns/policy_checker.rb index 9721dc63c..65a4428e2 100644 --- a/app/controllers/concerns/policy_checker.rb +++ b/app/controllers/concerns/policy_checker.rb @@ -2,7 +2,7 @@ module PolicyChecker extend ActiveSupport::Concern included do - before_action :authorize_resource, only: [:destroy, :show, :update] + before_action :authorize_resource, only: [:destroy, :edit, :show, :update] before_action :authorize_resource_class, only: [:create, :index, :new] end diff --git a/app/controllers/line_footnotes_controller.rb b/app/controllers/line_footnotes_controller.rb index f24d624d4..581c921e8 100644 --- a/app/controllers/line_footnotes_controller.rb +++ b/app/controllers/line_footnotes_controller.rb @@ -2,6 +2,9 @@ class LineFootnotesController < ChouetteController defaults resource_class: Chouette::Line, collection_name: 'lines', instance_name: 'line' belongs_to :referential + before_action :authorize_resource, only: [:destroy_footnote, :edit_footnote, :show_footnote, :update_footnote] + before_action :authorize_resource_class, only: [:create_footnote, :index_footnote, :new_footnote] + def edit edit! do build_breadcrumb :edit @@ -17,13 +20,17 @@ class LineFootnotesController < ChouetteController protected - alias_method :line, :resource - - # overrides default - def check_policy + protected + def authorize_resource authorize resource, "#{action_name}_footnote?".to_sym end + def authorize_resource_class + authorize resource_class, "#{action_name}_footnote?".to_sym + end + + alias_method :line, :resource + def resource @line ||= current_referential.lines.find params[:line_id] end -- cgit v1.2.3