diff options
| author | Robert | 2017-09-11 09:41:03 +0200 |
|---|---|---|
| committer | Robert | 2017-09-11 17:15:49 +0200 |
| commit | f7bc874de79ff9a68aa03523cf653407663e7c55 (patch) | |
| tree | 1716586822ad9b9912e44f658193e5c1aea04e88 /app | |
| parent | 003c4689248673fbc8922a107475caa9e059bcab (diff) | |
| download | chouette-core-f7bc874de79ff9a68aa03523cf653407663e7c55.tar.bz2 | |
Fixes #4189@4h Route Duplication
* Duplication of Route is triggered by link and UI forwarded to edit of duplicatee
- Changing route, only POST duplicate_referential_line_route --> RoutesController#duplicate
- Removing route GET duplicate_referential_line_route --> RoutesController#duplicate
- Removing controller action RoutesController#post_duplicate
* Link in Route Decorator depends on new policy RoutePolicy#decorate?
* Adapting specs
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/routes_controller.rb | 9 | ||||
| -rw-r--r-- | app/decorators/route_decorator.rb | 12 | ||||
| -rw-r--r-- | app/models/chouette/route.rb | 7 | ||||
| -rw-r--r-- | app/policies/route_policy.rb | 4 | ||||
| -rw-r--r-- | app/views/routes/duplicate.html.slim | 8 |
5 files changed, 21 insertions, 19 deletions
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index e20ae9d14..04f63c112 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -70,13 +70,8 @@ class RoutesController < ChouetteController end def duplicate - @route = Chouette::Route.find(params[:id]) - @line = @route.line - build_breadcrumb(:edit) - end - - def post_duplicate - @route = Chouette::Route.find(params[:id]) + route = Chouette::Route.find(params[:id]).duplicate + redirect_to edit_referential_line_route_path(@referential, route.line, route) end protected diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb index 484c3db04..46cb6cd5f 100644 --- a/app/decorators/route_decorator.rb +++ b/app/decorators/route_decorator.rb @@ -58,6 +58,18 @@ class RouteDecorator < Draper::Decorator ) end + if h.policy(object).duplicate? + links << Link.new( + content: h.t('routes.duplicate.title'), + href: h.duplicate_referential_line_route_path( + context[:referential], + context[:line], + object + ), + method: :post + ) + end + links end end diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 049ee2881..cab877dc7 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -76,11 +76,10 @@ class Chouette::Route < Chouette::TridentActiveRecord after_commit :journey_patterns_control_route_sections - def duplicate name: nil, published_name: nil + def duplicate overrides = { - 'name' => name || self.name, - 'published_name' => published_name || self.published_name, - 'object_version' => object_version - 1 + 'object_version' => object_version - 1, + 'opposite_route_id' => nil } keys_for_create = attributes.keys - %w{id objectid created_at updated_at} atts_for_create = attributes diff --git a/app/policies/route_policy.rb b/app/policies/route_policy.rb index 786b0acf4..7e9fe251a 100644 --- a/app/policies/route_policy.rb +++ b/app/policies/route_policy.rb @@ -16,4 +16,8 @@ class RoutePolicy < ApplicationPolicy def update? !archived? && organisation_match? && user.has_permission?('routes.update') end + + def duplicate? + create? + end end diff --git a/app/views/routes/duplicate.html.slim b/app/views/routes/duplicate.html.slim deleted file mode 100644 index 2c894cc47..000000000 --- a/app/views/routes/duplicate.html.slim +++ /dev/null @@ -1,8 +0,0 @@ -= pageheader 'map-marker', - t('routes.duplicate.title', route: @route.name) - -.page_content - .container-fluid - .row - .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 - == render 'form' |
