From: Andy Allan Date: Wed, 25 Jan 2023 19:22:10 +0000 (+0000) Subject: Move browse#new_note to notes#new X-Git-Tag: live~1365^2~4 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/b5046fdcd02b7ae9c10f22fa0b483e6eb2e06fa3 Move browse#new_note to notes#new This allows a more resourceful routing approach. --- diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index fd548c5f3..aee44e6e5 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -5,7 +5,8 @@ class Ability def initialize(user) can [:relation, :relation_history, :way, :way_history, :node, :node_history, - :changeset, :note, :new_note, :query], :browse + :changeset, :note, :query], :browse + can [:new], Note can :search, :direction can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site can [:finish, :embed], :export diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 7d6163f48..4c1bac193 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -1,8 +1,9 @@ class NotesController < ApplicationController - layout "site" + layout :map_layout before_action :check_api_readable before_action :authorize_web + before_action :require_oauth authorize_resource @@ -21,12 +22,16 @@ class NotesController < ApplicationController @notes = @user.notes @notes = @notes.visible unless current_user&.moderator? @notes = @notes.order("updated_at DESC, id").distinct.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author) + + render :layout => "site" else @title = t "users.no_such_user.title" @not_found_user = params[:display_name] - render :template => "users/no_such_user", :status => :not_found + render :template => "users/no_such_user", :status => :not_found, :layout => "site" end end end + + def new; end end diff --git a/app/views/browse/new_note.html.erb b/app/views/notes/new.html.erb similarity index 100% rename from app/views/browse/new_note.html.erb rename to app/views/notes/new.html.erb diff --git a/config/routes.rb b/config/routes.rb index b0b2219c3..d60202670 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -114,7 +114,8 @@ OpenStreetMap::Application.routes.draw do get "/changeset/:id" => "browse#changeset", :as => :changeset, :id => /\d+/ get "/changeset/:id/comments/feed" => "changeset_comments#index", :as => :changeset_comments_feed, :id => /\d*/, :defaults => { :format => "rss" } get "/note/:id" => "browse#note", :id => /\d+/, :as => "browse_note" - get "/note/new" => "browse#new_note" + resources :notes, :path => "note", :only => [:new] + get "/user/:display_name/history" => "changesets#index" get "/user/:display_name/history/feed" => "changesets#feed", :defaults => { :format => :atom } get "/user/:display_name/notes" => "notes#index", :as => :user_notes diff --git a/test/controllers/browse_controller_test.rb b/test/controllers/browse_controller_test.rb index cde9403d0..82068629d 100644 --- a/test/controllers/browse_controller_test.rb +++ b/test/controllers/browse_controller_test.rb @@ -36,10 +36,6 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest { :path => "/note/1", :method => :get }, { :controller => "browse", :action => "note", :id => "1" } ) - assert_routing( - { :path => "/note/new", :method => :get }, - { :controller => "browse", :action => "new_note" } - ) assert_routing( { :path => "/query", :method => :get }, { :controller => "browse", :action => "query" } @@ -256,12 +252,6 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest assert_select ".browse-section.browse-relation", 2 end - def test_new_note - get note_new_path - assert_response :success - assert_template "browse/new_note" - end - def test_query get query_path assert_response :success diff --git a/test/controllers/notes_controller_test.rb b/test/controllers/notes_controller_test.rb index 50e7ae833..4032b538d 100644 --- a/test/controllers/notes_controller_test.rb +++ b/test/controllers/notes_controller_test.rb @@ -15,6 +15,11 @@ class NotesControllerTest < ActionDispatch::IntegrationTest { :path => "/user/username/notes", :method => :get }, { :controller => "notes", :action => "index", :display_name => "username" } ) + + assert_routing( + { :path => "/note/new", :method => :get }, + { :controller => "notes", :action => "new" } + ) end def test_index_success @@ -80,4 +85,10 @@ class NotesControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_select "h4", :html => "No notes" end + + def test_new_note + get new_note_path + assert_response :success + assert_template "notes/new" + end end