From: Tom Hughes Date: Wed, 18 Apr 2018 19:21:52 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/1827' X-Git-Tag: live~4445 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/9ced230fe1cdd18190c4a296d0cc2293bfb1980a?hp=736ff9b1a0fd251778c06e785a78ceebac960190 Merge remote-tracking branch 'upstream/pull/1827' --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2c8d29eb8..cdac8fd67 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -35,7 +35,7 @@ Lint/AssignmentInCondition: - 'app/controllers/notes_controller.rb' - 'app/controllers/trace_controller.rb' - 'app/controllers/user_controller.rb' - - 'app/controllers/user_preference_controller.rb' + - 'app/controllers/user_preferences_controller.rb' - 'app/helpers/application_helper.rb' - 'app/helpers/browse_helper.rb' - 'app/models/client_application.rb' diff --git a/app/controllers/user_preference_controller.rb b/app/controllers/user_preferences_controller.rb similarity index 97% rename from app/controllers/user_preference_controller.rb rename to app/controllers/user_preferences_controller.rb index 16165513a..0aa2e8d52 100644 --- a/app/controllers/user_preference_controller.rb +++ b/app/controllers/user_preferences_controller.rb @@ -1,5 +1,5 @@ # Update and read user preferences, which are arbitrayr key/val pairs -class UserPreferenceController < ApplicationController +class UserPreferencesController < ApplicationController skip_before_action :verify_authenticity_token before_action :authorize before_action :require_allow_read_prefs, :only => [:read_one, :read] diff --git a/app/models/notifier.rb b/app/models/notifier.rb index 36564f614..4b61b202c 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -8,9 +8,7 @@ class Notifier < ActionMailer::Base def signup_confirm(user, token) with_recipient_locale user do - @url = url_for(:host => SERVER_URL, - :protocol => SERVER_PROTOCOL, - :controller => "user", :action => "confirm", + @url = url_for(:controller => "user", :action => "confirm", :display_name => user.display_name, :confirm_string => token.token) @@ -22,9 +20,7 @@ class Notifier < ActionMailer::Base def email_confirm(user, token) with_recipient_locale user do @address = user.new_email - @url = url_for(:host => SERVER_URL, - :protocol => SERVER_PROTOCOL, - :controller => "user", :action => "confirm_email", + @url = url_for(:controller => "user", :action => "confirm_email", :confirm_string => token.token) mail :to => user.new_email, @@ -34,9 +30,7 @@ class Notifier < ActionMailer::Base def lost_password(user, token) with_recipient_locale user do - @url = url_for(:host => SERVER_URL, - :protocol => SERVER_PROTOCOL, - :controller => "user", :action => "reset_password", + @url = url_for(:controller => "user", :action => "reset_password", :token => token.token) mail :to => user.email, @@ -75,13 +69,9 @@ class Notifier < ActionMailer::Base @from_user = message.sender.display_name @text = message.body @title = message.title - @readurl = url_for(:host => SERVER_URL, - :protocol => SERVER_PROTOCOL, - :controller => "message", :action => "read", + @readurl = url_for(:controller => "message", :action => "read", :message_id => message.id) - @replyurl = url_for(:host => SERVER_URL, - :protocol => SERVER_PROTOCOL, - :controller => "message", :action => "reply", + @replyurl = url_for(:controller => "message", :action => "reply", :message_id => message.id) @author = @from_user @@ -99,26 +89,21 @@ class Notifier < ActionMailer::Base @from_user = comment.user.display_name @text = comment.body @title = comment.diary_entry.title - @readurl = url_for(:host => SERVER_URL, - :protocol => SERVER_PROTOCOL, - :controller => "diary_entry", + @readurl = url_for(:controller => "diary_entry", :action => "view", :display_name => comment.diary_entry.user.display_name, :id => comment.diary_entry.id, :anchor => "comment#{comment.id}") - @commenturl = url_for(:host => SERVER_URL, - :protocol => SERVER_PROTOCOL, - :controller => "diary_entry", + @commenturl = url_for(:controller => "diary_entry", :action => "view", :display_name => comment.diary_entry.user.display_name, :id => comment.diary_entry.id, :anchor => "newcomment") - @replyurl = url_for(:host => SERVER_URL, - :protocol => SERVER_PROTOCOL, - :controller => "message", + @replyurl = url_for(:controller => "message", :action => "new", :display_name => comment.user.display_name, :title => "Re: #{comment.diary_entry.title}") + @author = @from_user attach_user_avatar(comment.user) @@ -132,13 +117,9 @@ class Notifier < ActionMailer::Base def friend_notification(friend) with_recipient_locale friend.befriendee do @friend = friend - @viewurl = url_for(:host => SERVER_URL, - :protocol => SERVER_PROTOCOL, - :controller => "user", :action => "view", + @viewurl = url_for(:controller => "user", :action => "view", :display_name => @friend.befriender.display_name) - @friendurl = url_for(:host => SERVER_URL, - :protocol => SERVER_PROTOCOL, - :controller => "user", :action => "make_friend", + @friendurl = url_for(:controller => "user", :action => "make_friend", :display_name => @friend.befriender.display_name) @author = @friend.befriender.display_name @@ -150,7 +131,7 @@ class Notifier < ActionMailer::Base def note_comment_notification(comment, recipient) with_recipient_locale recipient do - @noteurl = browse_note_url(comment.note, :host => SERVER_URL) + @noteurl = browse_note_url(comment.note) @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, I18n.locale) @comment = comment.body @owner = recipient == comment.note.author @@ -178,7 +159,7 @@ class Notifier < ActionMailer::Base def changeset_comment_notification(comment, recipient) with_recipient_locale recipient do @to_user = recipient.display_name - @changeset_url = changeset_url(comment.changeset, :host => SERVER_URL) + @changeset_url = changeset_url(comment.changeset) @comment = comment.body @owner = recipient == comment.changeset.user @commenter = comment.author.display_name @@ -202,7 +183,7 @@ class Notifier < ActionMailer::Base private def set_shared_template_vars - @root_url = root_url(:host => SERVER_URL) + @root_url = root_url end def attach_project_logo diff --git a/app/views/notifier/_message_body.html.erb b/app/views/notifier/_message_body.html.erb index b71c5f994..38f491799 100644 --- a/app/views/notifier/_message_body.html.erb +++ b/app/views/notifier/_message_body.html.erb @@ -10,7 +10,7 @@ height: 50, border: 0 ), - user_url(@author, :host => SERVER_URL), + user_url(@author), :target => "_blank" ) %> diff --git a/config/initializers/action_mailer.rb b/config/initializers/action_mailer.rb index 6b27bb686..54da28139 100644 --- a/config/initializers/action_mailer.rb +++ b/config/initializers/action_mailer.rb @@ -5,3 +5,9 @@ ActionMailer::Base.smtp_settings = { :domain => "localhost", :enable_starttls_auto => false } + +# Set the host and protocol for all ActionMailer URLs +ActionMailer::Base.default_url_options = { + :host => SERVER_URL, + :protocol => SERVER_PROTOCOL +} diff --git a/config/routes.rb b/config/routes.rb index ca0c4ecf0..67deae7ed 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,11 +68,11 @@ OpenStreetMap::Application.routes.draw do get "user/details" => "user#api_details" get "user/gpx_files" => "user#api_gpx_files" - get "user/preferences" => "user_preference#read" - get "user/preferences/:preference_key" => "user_preference#read_one" - put "user/preferences" => "user_preference#update" - put "user/preferences/:preference_key" => "user_preference#update_one" - delete "user/preferences/:preference_key" => "user_preference#delete_one" + get "user/preferences" => "user_preferences#read" + get "user/preferences/:preference_key" => "user_preferences#read_one" + put "user/preferences" => "user_preferences#update" + put "user/preferences/:preference_key" => "user_preferences#update_one" + delete "user/preferences/:preference_key" => "user_preferences#delete_one" post "gpx/create" => "trace#api_create" get "gpx/:id" => "trace#api_read", :id => /\d+/ diff --git a/test/controllers/user_preference_controller_test.rb b/test/controllers/user_preferences_controller_test.rb similarity index 93% rename from test/controllers/user_preference_controller_test.rb rename to test/controllers/user_preferences_controller_test.rb index 7f614587d..3e5cbb369 100644 --- a/test/controllers/user_preference_controller_test.rb +++ b/test/controllers/user_preferences_controller_test.rb @@ -1,28 +1,28 @@ require "test_helper" -class UserPreferenceControllerTest < ActionController::TestCase +class UserPreferencesControllerTest < ActionController::TestCase ## # test all routes which lead to this controller def test_routes assert_routing( { :path => "/api/0.6/user/preferences", :method => :get }, - { :controller => "user_preference", :action => "read" } + { :controller => "user_preferences", :action => "read" } ) assert_routing( { :path => "/api/0.6/user/preferences", :method => :put }, - { :controller => "user_preference", :action => "update" } + { :controller => "user_preferences", :action => "update" } ) assert_routing( { :path => "/api/0.6/user/preferences/key", :method => :get }, - { :controller => "user_preference", :action => "read_one", :preference_key => "key" } + { :controller => "user_preferences", :action => "read_one", :preference_key => "key" } ) assert_routing( { :path => "/api/0.6/user/preferences/key", :method => :put }, - { :controller => "user_preference", :action => "update_one", :preference_key => "key" } + { :controller => "user_preferences", :action => "update_one", :preference_key => "key" } ) assert_routing( { :path => "/api/0.6/user/preferences/key", :method => :delete }, - { :controller => "user_preference", :action => "delete_one", :preference_key => "key" } + { :controller => "user_preferences", :action => "delete_one", :preference_key => "key" } ) end