From b6e024b3729d4688c950a350fc95eba056db7495 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 8 Oct 2025 15:52:11 +0100 Subject: [PATCH] Rename export controller actions Refs #5539 --- .rubocop.yml | 1 - app/abilities/ability.rb | 2 +- app/controllers/export_controller.rb | 12 ++++----- .../export/{embed.html.erb => show.html.erb} | 0 app/views/site/export.html.erb | 2 +- config/routes.rb | 4 +-- test/controllers/export_controller_test.rb | 26 +++++++++---------- 7 files changed, 23 insertions(+), 24 deletions(-) rename app/views/export/{embed.html.erb => show.html.erb} (100%) diff --git a/.rubocop.yml b/.rubocop.yml index 2319b5f3a..83e2dc35a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -139,7 +139,6 @@ Rails/SpecificActionNames: - 'app/controllers/diary_comments_controller.rb' - 'app/controllers/diary_entries_controller.rb' - 'app/controllers/errors_controller.rb' - - 'app/controllers/export_controller.rb' - 'app/controllers/issues_controller.rb' - 'app/controllers/site_controller.rb' - 'app/controllers/traces_controller.rb' diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 471452986..412a18171 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -10,7 +10,7 @@ class Ability can [:show, :create], Note can :read, :directions can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :id], :site - can [:finish, :embed], :export + can [:create, :show], :export can [:create, :read], :search if Settings.status != "database_offline" diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 19d8294c6..c1bf73d6b 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -3,17 +3,19 @@ class ExportController < ApplicationController before_action :authorize_web before_action :set_locale - before_action :update_totp, :only => [:finish] + before_action :update_totp, :only => [:create] authorize_resource :class => false - content_security_policy(:only => :embed) do |policy| + content_security_policy(:only => :show) do |policy| policy.frame_ancestors("*") end - caches_page :embed + caches_page :show + + def show; end # When the user clicks 'Export' we redirect to a URL which generates the export download - def finish + def create bbox = BoundingBox.from_lon_lat_params(params) style = params[:format] format = params[:mapnik_format] @@ -39,6 +41,4 @@ class ExportController < ApplicationController redirect_to "https://tile.thunderforest.com/static/#{style[..-4]}/#{lon},#{lat},#{zoom}/#{width}x#{height}.#{format}?apikey=#{Settings.thunderforest_key}", :allow_other_host => true end end - - def embed; end end diff --git a/app/views/export/embed.html.erb b/app/views/export/show.html.erb similarity index 100% rename from app/views/export/embed.html.erb rename to app/views/export/show.html.erb diff --git a/app/views/site/export.html.erb b/app/views/site/export.html.erb index 8dc3bffdb..6dbdfcb7b 100644 --- a/app/views/site/export.html.erb +++ b/app/views/site/export.html.erb @@ -2,7 +2,7 @@ <%= render "sidebar_header", :title => t(".title") %> -<%= form_tag({ :controller => "export", :action => "finish" }, :class => "export_form", :data => { "turbo" => true }) do %> +<%= form_tag({ :controller => "export", :action => "create" }, :class => "export_form", :data => { "turbo" => true }) do %> <%= hidden_field_tag "format", "osm", :autocomplete => "off" %>
diff --git a/config/routes.rb b/config/routes.rb index 8b8e296ea..ead0044c0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -368,8 +368,8 @@ OpenStreetMap::Application.routes.draw do resource :directions, :only => :show # export - post "/export/finish" => "export#finish" - get "/export/embed" => "export#embed" + post "/export/finish" => "export#create" + get "/export/embed" => "export#show" # messages resources :messages, :path_names => { :new => "new/:display_name" }, :id => /\d+/, :only => [:new, :create, :show, :destroy] do diff --git a/test/controllers/export_controller_test.rb b/test/controllers/export_controller_test.rb index 467ecb4a0..371bb8ba1 100644 --- a/test/controllers/export_controller_test.rb +++ b/test/controllers/export_controller_test.rb @@ -8,47 +8,47 @@ class ExportControllerTest < ActionDispatch::IntegrationTest def test_routes assert_routing( { :path => "/export/finish", :method => :post }, - { :controller => "export", :action => "finish" } + { :controller => "export", :action => "create" } ) assert_routing( { :path => "/export/embed", :method => :get }, - { :controller => "export", :action => "embed" } + { :controller => "export", :action => "show" } ) end ### - # test the finish action for raw OSM data - def test_finish_osm + # test the create action for raw OSM data + def test_create_osm post export_finish_path(:minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "osm") assert_redirected_to api_map_path(:bbox => "0.0,50.0,1.0,51.0") end ### - # test the finish action for mapnik images - def test_finish_mapnik + # test the create action for mapnik images + def test_create_mapnik post export_finish_path(:minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "mapnik", :mapnik_format => "test", :mapnik_scale => "12") assert_redirected_to "https://render.openstreetmap.org/cgi-bin/export?bbox=0.0,50.0,1.0,51.0&scale=12&format=test&token=" end ### - # test the finish action for cyclemap images - def test_finish_cyclemap + # test the create action for cyclemap images + def test_create_cyclemap post export_finish_path(:minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "cyclemap", :mapnik_scale => 12, :mapnik_format => "png", :zoom => 17, :lat => 1, :lon => 2, :width => 400, :height => 300) assert_redirected_to "https://tile.thunderforest.com/static/cycle/2,1,17/400x300.png?apikey=#{Settings.thunderforest_key}" end ### - # test the finish action for transport images - def test_finish_transport + # test the create action for transport images + def test_create_transport post export_finish_path(:minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "transportmap", :mapnik_scale => 12, :mapnik_format => "png", :zoom => 17, :lat => 1, :lon => 2, :width => 400, :height => 300) assert_redirected_to "https://tile.thunderforest.com/static/transport/2,1,17/400x300.png?apikey=#{Settings.thunderforest_key}" end ## - # test the embed action - def test_embed + # test the show action + def test_show get export_embed_path assert_response :success - assert_template "export/embed" + assert_template "export/show" end end -- 2.39.5