Merge remote-tracking branch 'upstream/pull/1973'

This commit is contained in:
Tom Hughes 2018-09-05 19:01:24 +01:00
commit 70cca71f38
10 changed files with 52 additions and 60 deletions

View file

@ -4,11 +4,11 @@ class DiaryEntryController < ApplicationController
before_action :authorize_web
before_action :set_locale
before_action :require_user, :only => [:new, :edit, :comment, :hide, :hidecomment, :subscribe, :unsubscribe]
before_action :lookup_user, :only => [:view, :comments]
before_action :lookup_user, :only => [:show, :comments]
before_action :check_database_readable
before_action :check_database_writable, :only => [:new, :edit, :comment, :hide, :hidecomment, :subscribe, :unsubscribe]
before_action :require_administrator, :only => [:hide, :hidecomment]
before_action :allow_thirdparty_images, :only => [:new, :edit, :list, :view, :comments]
before_action :allow_thirdparty_images, :only => [:new, :edit, :list, :show, :comments]
def new
@title = t "diary_entry.new.title"
@ -47,9 +47,9 @@ class DiaryEntryController < ApplicationController
@diary_entry = DiaryEntry.find(params[:id])
if current_user != @diary_entry.user
redirect_to :action => "view", :id => params[:id]
redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
elsif params[:diary_entry] && @diary_entry.update(entry_params)
redirect_to :action => "view", :id => params[:id]
redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
end
set_map_location
@ -71,9 +71,9 @@ class DiaryEntryController < ApplicationController
# Add the commenter to the subscribers if necessary
@entry.subscriptions.create(:user => current_user) unless @entry.subscribers.exists?(current_user.id)
redirect_to :action => "view", :display_name => @entry.user.display_name, :id => @entry.id
redirect_to diary_entry_path(@entry.user, @entry)
else
render :action => "view"
render :action => "show"
end
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
@ -84,7 +84,7 @@ class DiaryEntryController < ApplicationController
diary_entry.subscriptions.create(:user => current_user) unless diary_entry.subscribers.exists?(current_user.id)
redirect_to :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
redirect_to diary_entry_path(diary_entry.user, diary_entry)
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
end
@ -94,7 +94,7 @@ class DiaryEntryController < ApplicationController
diary_entry.subscriptions.where(:user => current_user).delete_all if diary_entry.subscribers.exists?(current_user.id)
redirect_to :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
redirect_to diary_entry_path(diary_entry.user, diary_entry)
rescue ActiveRecord::RecordNotFound
render :action => "no_such_entry", :status => :not_found
end
@ -180,10 +180,10 @@ class DiaryEntryController < ApplicationController
@entries = @entries.visible.includes(:user).order("created_at DESC").limit(20)
end
def view
def show
@entry = @user.diary_entries.visible.where(:id => params[:id]).first
if @entry
@title = t "diary_entry.view.title", :user => params[:display_name], :title => @entry.title
@title = t "diary_entry.show.title", :user => params[:display_name], :title => @entry.title
else
@title = t "diary_entry.no_such_entry.title", :id => params[:id]
render :action => "no_such_entry", :status => :not_found
@ -199,7 +199,7 @@ class DiaryEntryController < ApplicationController
def hidecomment
comment = DiaryComment.find(params[:comment])
comment.update(:visible => false)
redirect_to :action => "view", :display_name => comment.diary_entry.user.display_name, :id => comment.diary_entry.id
redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
end
def comments
@ -235,7 +235,7 @@ class DiaryEntryController < ApplicationController
def require_administrator
unless current_user.administrator?
flash[:error] = t("user.filter.not_an_administrator")
redirect_to :action => "view"
redirect_to :action => "show"
end
end

View file

@ -2,11 +2,11 @@ module IssuesHelper
def reportable_url(reportable)
case reportable
when DiaryEntry
url_for(:controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.user.display_name, :id => reportable.id)
diary_entry_url(reportable.user, reportable)
when User
user_url(reportable)
when DiaryComment
url_for(:controller => reportable.diary_entry.class.name.underscore, :action => :view, :display_name => reportable.diary_entry.user.display_name, :id => reportable.diary_entry.id, :anchor => "comment#{reportable.id}")
diary_entry_url(reportable.diary_entry.user, reportable.diary_entry, :anchor => "comment#{reportable.id}")
when Note
url_for(:controller => :browse, :action => :note, :id => reportable.id)
end

View file

@ -87,16 +87,8 @@ class Notifier < ActionMailer::Base
@from_user = comment.user.display_name
@text = comment.body
@title = comment.diary_entry.title
@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(:controller => "diary_entry",
:action => "view",
:display_name => comment.diary_entry.user.display_name,
:id => comment.diary_entry.id,
:anchor => "newcomment")
@readurl = diary_entry_url(comment.diary_entry.user, comment.diary_entry, :anchor => "comment#{comment.id}")
@commenturl = diary_entry_url(comment.diary_entry.user, comment.diary_entry, :anchor => "newcomment")
@replyurl = new_message_url(comment.user, :message => { :title => "Re: #{comment.diary_entry.title}" })
@author = @from_user

View file

@ -4,7 +4,7 @@
<%= user_thumbnail diary_entry.user %>
<% end %>
<h2><%= link_to h(diary_entry.title), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id %></h2>
<h2><%= link_to h(diary_entry.title), diary_entry_path(diary_entry.user, diary_entry) %></h2>
<small class='deemphasize'>
<%= raw(t '.posted_by', :link_user => (link_to h(diary_entry.user.display_name), user_path(diary_entry.user)), :created => l(diary_entry.created_at, :format => :blog), :language_link => (link_to h(diary_entry.language.name), :controller => 'diary_entry', :action => 'list', :display_name => nil, :language => diary_entry.language_code)) %>
@ -22,9 +22,9 @@
<ul class='secondary-actions clearfix'>
<% if params[:action] == 'list' %>
<li><%= link_to t('.comment_link'), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'newcomment' %></li>
<li><%= link_to t('.comment_link'), diary_entry_path(diary_entry.user, diary_entry, :anchor => 'newcomment') %></li>
<li><%= link_to t('.reply_link'), new_message_path(diary_entry.user, :message => { :title => "Re: #{diary_entry.title}" }) %></li>
<li><%= link_to t('.comment_count', :count => diary_entry.visible_comments.count), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'comments' %></li>
<li><%= link_to t('.comment_count', :count => diary_entry.visible_comments.count), diary_entry_path(diary_entry.user, diary_entry, :anchor => 'comments') %></li>
<% end %>
<% if current_user && current_user == diary_entry.user %>

View file

@ -11,7 +11,7 @@
<% @comments.each do |comment| -%>
<% cl = cycle('table0', 'table1') %>
<tr class="<%= cl %>">
<td width="25%"><%= link_to comment.diary_entry.title, :action => :view, :display_name => comment.diary_entry.user.display_name, :id => comment.diary_entry.id %></td>
<td width="25%"><%= link_to comment.diary_entry.title, diary_entry_path(comment.diary_entry.user, comment.diary_entry) %></td>
<td width="25%"><span title="<%= l comment.created_at, :format => :friendly %>"><%= t '.ago', :ago => time_ago_in_words(comment.created_at) %></span></td>
<td width="50%" class="richtext"><%= comment.body.to_html %></td>
</tr>

View file

@ -19,12 +19,12 @@ xml.rss("version" => "2.0",
@entries.each do |entry|
xml.item do
xml.title entry.title
xml.link url_for(:action => "view", :id => entry.id, :display_name => entry.user.display_name, :only_path => false)
xml.guid url_for(:action => "view", :id => entry.id, :display_name => entry.user.display_name, :only_path => false)
xml.link diary_entry_url(entry.user, entry, :only_path => false)
xml.guid diary_entry_url(entry.user, entry, :only_path => false)
xml.description entry.body.to_html
xml.dc :creator, entry.user.display_name
xml.pubDate entry.created_at.to_s(:rfc822)
xml.comments url_for(:action => "view", :id => entry.id, :display_name => entry.user.display_name, :anchor => "comments", :only_path => false)
xml.comments diary_entry_url(entry.user, entry, :anchor => "comments", :only_path => false)
if entry.latitude && entry.longitude
xml.geo :lat, entry.latitude.to_s

View file

@ -276,7 +276,7 @@ en:
use_map_link: "use map"
save_button: "Save"
marker_text: Diary entry location
view:
show:
title: "%{user}'s diary | %{title}"
user_title: "%{user}'s diary"
leave_a_comment: "Leave a comment"

View file

@ -225,7 +225,7 @@ OpenStreetMap::Application.routes.draw do
get "/user/:display_name/diary" => "diary_entry#list"
get "/diary/:language" => "diary_entry#list"
get "/diary" => "diary_entry#list"
get "/user/:display_name/diary/:id" => "diary_entry#view", :id => /\d+/, :as => :diary_entry
get "/user/:display_name/diary/:id" => "diary_entry#show", :id => /\d+/, :as => :diary_entry
post "/user/:display_name/diary/:id/newcomment" => "diary_entry#comment", :id => /\d+/
match "/user/:display_name/diary/:id/edit" => "diary_entry#edit", :via => [:get, :post], :id => /\d+/
post "/user/:display_name/diary/:id/hide" => "diary_entry#hide", :id => /\d+/, :as => :hide_diary_entry

View file

@ -67,7 +67,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
)
assert_routing(
{ :path => "/user/username/diary/1", :method => :get },
{ :controller => "diary_entry", :action => "view", :display_name => "username", :id => "1" }
{ :controller => "diary_entry", :action => "show", :display_name => "username", :id => "1" }
)
assert_routing(
{ :path => "/user/username/diary/1/edit", :method => :get },
@ -265,13 +265,13 @@ class DiaryEntryControllerTest < ActionController::TestCase
assert_select "h2", :text => "No entry with the id: 9999", :count => 1
end
# Verify that you get redirected to view if you are not the user
# Verify that you get redirected to show if you are not the user
# that created the entry
get :edit,
:params => { :display_name => entry.user.display_name, :id => entry.id },
:session => { :user => other_user }
assert_response :redirect
assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
# Now pass the id, and check that you can edit it, when using the same
# user as the person who created the entry
@ -309,14 +309,14 @@ class DiaryEntryControllerTest < ActionController::TestCase
:longitude => new_longitude, :language_code => new_language_code } },
:session => { :user => entry.user.id }
assert_response :redirect
assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
# Now check that the new data is rendered, when logged in
get :view,
get :show,
:params => { :display_name => entry.user.display_name, :id => entry.id },
:session => { :user => entry.user }
assert_response :success
assert_template "diary_entry/view"
assert_template "diary_entry/show"
assert_select "title", :text => /Users' diaries | /, :count => 1
assert_select "div.content-heading", :count => 1 do
assert_select "h2", :text => /#{entry.user.display_name}'s diary/, :count => 1
@ -333,11 +333,11 @@ class DiaryEntryControllerTest < ActionController::TestCase
end
# and when not logged in as the user who wrote the entry
get :view,
get :show,
:params => { :display_name => entry.user.display_name, :id => entry.id },
:session => { :user => create(:user) }
assert_response :success
assert_template "diary_entry/view"
assert_template "diary_entry/show"
assert_select "title", :text => /Users' diaries | /, :count => 1
assert_select "div.content-heading", :count => 1 do
assert_select "h2", :text => /#{entry.user.display_name}'s diary/, :count => 1
@ -397,7 +397,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
end
end
assert_response :success
assert_template :view
assert_template :show
# Now try again with the right id
assert_difference "ActionMailer::Base.deliveries.size", entry.subscribers.count do
@ -410,7 +410,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
end
end
assert_response :redirect
assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
email = ActionMailer::Base.deliveries.first
assert_equal [user.email], email.to
assert_equal "[OpenStreetMap] #{other_user.display_name} commented on a diary entry", email.subject
@ -422,8 +422,8 @@ class DiaryEntryControllerTest < ActionController::TestCase
assert_equal other_user.id, comment.user_id
assert_equal "New comment", comment.body
# Now view the diary entry, and check the new comment is present
get :view,
# Now show the diary entry, and check the new comment is present
get :show,
:params => { :display_name => entry.user.display_name, :id => entry.id }
assert_response :success
assert_select ".diary-comment", :count => 1 do
@ -456,7 +456,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
end
end
assert_response :redirect
assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id
email = ActionMailer::Base.deliveries.first
assert_equal [user.email], email.to
assert_equal "[OpenStreetMap] #{other_user.display_name} commented on a diary entry", email.subject
@ -476,8 +476,8 @@ class DiaryEntryControllerTest < ActionController::TestCase
assert_response :redirect
assert_redirected_to :controller => :user, :action => :suspended
# Now view the diary entry, and check the new comment is not present
get :view,
# Now show the diary entry, and check the new comment is not present
get :show,
:params => { :display_name => entry.user.display_name, :id => entry.id }
assert_response :success
assert_select ".diary-comment", :count => 0
@ -658,34 +658,34 @@ class DiaryEntryControllerTest < ActionController::TestCase
assert_match "<title>&lt;script&gt;</title>", response.body
end
def test_view
def test_show
user = create(:user)
suspended_user = create(:user, :suspended)
deleted_user = create(:user, :deleted)
# Try a normal entry that should work
diary_entry = create(:diary_entry, :user => user)
get :view, :params => { :display_name => user.display_name, :id => diary_entry.id }
get :show, :params => { :display_name => user.display_name, :id => diary_entry.id }
assert_response :success
assert_template :view
assert_template :show
# Try a deleted entry
diary_entry_deleted = create(:diary_entry, :user => user, :visible => false)
get :view, :params => { :display_name => user.display_name, :id => diary_entry_deleted.id }
get :show, :params => { :display_name => user.display_name, :id => diary_entry_deleted.id }
assert_response :not_found
# Try an entry by a suspended user
diary_entry_suspended = create(:diary_entry, :user => suspended_user)
get :view, :params => { :display_name => suspended_user.display_name, :id => diary_entry_suspended.id }
get :show, :params => { :display_name => suspended_user.display_name, :id => diary_entry_suspended.id }
assert_response :not_found
# Try an entry by a deleted user
diary_entry_deleted = create(:diary_entry, :user => deleted_user)
get :view, :params => { :display_name => deleted_user.display_name, :id => diary_entry_deleted.id }
get :show, :params => { :display_name => deleted_user.display_name, :id => diary_entry_deleted.id }
assert_response :not_found
end
def test_view_hidden_comments
def test_show_hidden_comments
# Get a diary entry that has hidden comments
user = create(:user)
diary_entry = create(:diary_entry, :user => user)
@ -694,9 +694,9 @@ class DiaryEntryControllerTest < ActionController::TestCase
deleted_user_comment = create(:diary_comment, :diary_entry => diary_entry, :user => create(:user, :deleted))
hidden_comment = create(:diary_comment, :diary_entry => diary_entry, :visible => false)
get :view, :params => { :display_name => user.display_name, :id => diary_entry.id }
get :show, :params => { :display_name => user.display_name, :id => diary_entry.id }
assert_response :success
assert_template :view
assert_template :show
assert_select "div.comments" do
assert_select "p#comment#{visible_comment.id}", :count => 1
assert_select "p#comment#{suspended_user_comment.id}", :count => 0
@ -720,7 +720,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
:params => { :display_name => user.display_name, :id => diary_entry.id },
:session => { :user => user }
assert_response :redirect
assert_redirected_to :action => :view, :display_name => user.display_name, :id => diary_entry.id
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_equal true, DiaryEntry.find(diary_entry.id).visible
# Finally try as an administrator
@ -748,7 +748,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
:params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
:session => { :user => user }
assert_response :redirect
assert_redirected_to :action => :view, :display_name => user.display_name, :id => diary_entry.id
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_equal true, DiaryComment.find(diary_comment.id).visible
# Finally try as an administrator
@ -756,7 +756,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
:params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
:session => { :user => administrator_user }
assert_response :redirect
assert_redirected_to :action => :view, :display_name => user.display_name, :id => diary_entry.id
assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
assert_equal false, DiaryComment.find(diary_comment.id).visible
end