Rename traces#view to traces#show

This commit is contained in:
Andy Allan 2018-08-29 17:43:34 +08:00
parent b745126b6e
commit 16fef14b61
7 changed files with 29 additions and 29 deletions

View file

@ -67,7 +67,7 @@ class ApiController < ApplicationController
if gpx_file.identifiable?
track << (XML::Node.new("name") << gpx_file.name)
track << (XML::Node.new("desc") << gpx_file.description)
track << (XML::Node.new("url") << url_for(:controller => "traces", :action => "view", :display_name => gpx_file.user.display_name, :id => gpx_file.id))
track << (XML::Node.new("url") << url_for(:controller => "traces", :action => "show", :display_name => gpx_file.user.display_name, :id => gpx_file.id))
end
else
# use the anonymous track segment if the user hasn't allowed

View file

@ -12,7 +12,7 @@ class TracesController < ApplicationController
before_action :check_api_writable, :only => [:api_create, :api_update, :api_delete]
before_action :require_allow_read_gpx, :only => [:api_read, :api_data]
before_action :require_allow_write_gpx, :only => [:api_create, :api_update, :api_delete]
before_action :offline_warning, :only => [:mine, :view]
before_action :offline_warning, :only => [:mine, :show]
before_action :offline_redirect, :only => [:new, :create, :edit, :delete, :data, :api_create, :api_delete, :api_data]
around_action :api_call_handle_error, :only => [:api_create, :api_read, :api_update, :api_delete, :api_data]
@ -89,7 +89,7 @@ class TracesController < ApplicationController
redirect_to :action => :list, :display_name => current_user.display_name
end
def view
def show
@trace = Trace.find(params[:id])
if @trace && @trace.visible? &&
@ -189,7 +189,7 @@ class TracesController < ApplicationController
head :forbidden
elsif @trace.update(trace_params)
flash[:notice] = t ".updated"
redirect_to :action => "view", :display_name => current_user.display_name
redirect_to :action => "show", :display_name => current_user.display_name
else
@title = t ".title", :name => @trace.name
render :action => "edit"

View file

@ -3,13 +3,13 @@
<td class="<%= cl %>">
<% if STATUS != :gpx_offline %>
<% if trace.inserted %>
<a href="<%= url_for :controller => 'traces', :action => 'view', :id => trace.id, :display_name => trace.user.display_name %>"><img src="<%= url_for :controller => 'traces', :action => 'icon', :id => trace.id, :display_name => trace.user.display_name %>" border="0" alt="" /></a>
<a href="<%= url_for :controller => 'traces', :action => 'show', :id => trace.id, :display_name => trace.user.display_name %>"><img src="<%= url_for :controller => 'traces', :action => 'icon', :id => trace.id, :display_name => trace.user.display_name %>" border="0" alt="" /></a>
<% else %>
<span class="trace_pending"><%= t '.pending' %></span>
<% end %>
<% end %>
</td>
<td class="<%= cl %>"><%= link_to trace.name, { :controller => 'traces', :action => 'view', :display_name => trace.user.display_name, :id => trace.id } %>
<td class="<%= cl %>"><%= link_to trace.name, { :controller => 'traces', :action => 'show', :display_name => trace.user.display_name, :id => trace.id } %>
<span class="trace_summary" title="<%= trace.timestamp %>"> ...
<% if trace.inserted %>
(<%= t '.count_points', :count => trace.size.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') %>)

View file

@ -1726,7 +1726,7 @@ en:
updated: Trace updated
trace_optionals:
tags: "Tags"
view:
show:
title: "Viewing trace %{name}"
heading: "Viewing trace %{name}"
pending: "PENDING"

View file

@ -195,7 +195,7 @@ OpenStreetMap::Application.routes.draw do
get "/user/:display_name/traces" => "traces#list"
get "/user/:display_name/traces/tag/:tag/rss" => "traces#georss", :defaults => { :format => :rss }
get "/user/:display_name/traces/rss" => "traces#georss", :defaults => { :format => :rss }
get "/user/:display_name/traces/:id" => "traces#view"
get "/user/:display_name/traces/:id" => "traces#show"
get "/user/:display_name/traces/:id/picture" => "traces#picture"
get "/user/:display_name/traces/:id/icon" => "traces#icon"
get "/traces/tag/:tag/page/:page" => "traces#list", :page => /[1-9][0-9]*/

View file

@ -123,7 +123,7 @@ class TracesControllerTest < ActionController::TestCase
assert_routing(
{ :path => "/user/username/traces/1", :method => :get },
{ :controller => "traces", :action => "view", :display_name => "username", :id => "1" }
{ :controller => "traces", :action => "show", :display_name => "username", :id => "1" }
)
assert_routing(
{ :path => "/user/username/traces/1/picture", :method => :get },
@ -299,53 +299,53 @@ class TracesControllerTest < ActionController::TestCase
check_trace_feed user.traces.tagged("Birmingham").visible_to_all
end
# Test viewing a trace
def test_view
# Test showing a trace
def test_show
public_trace_file = create(:trace, :visibility => "public")
# First with no auth, which should work since the trace is public
get :view, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }
check_trace_view public_trace_file
get :show, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }
check_trace_show public_trace_file
# Now with some other user, which should work since the trace is public
get :view, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => create(:user) }
check_trace_view public_trace_file
get :show, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => create(:user) }
check_trace_show public_trace_file
# And finally we should be able to do it with the owner of the trace
get :view, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => public_trace_file.user }
check_trace_view public_trace_file
get :show, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id }, :session => { :user => public_trace_file.user }
check_trace_show public_trace_file
end
# Check an anonymous trace can't be viewed by another user
def test_view_anon
def test_show_anon
anon_trace_file = create(:trace, :visibility => "private")
# First with no auth
get :view, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }
get :show, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }
assert_response :redirect
assert_redirected_to :action => :list
# Now with some other user, which should not work since the trace is anon
get :view, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => create(:user) }
get :show, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => create(:user) }
assert_response :redirect
assert_redirected_to :action => :list
# And finally we should be able to do it with the owner of the trace
get :view, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => anon_trace_file.user }
check_trace_view anon_trace_file
get :show, :params => { :display_name => anon_trace_file.user.display_name, :id => anon_trace_file.id }, :session => { :user => anon_trace_file.user }
check_trace_show anon_trace_file
end
# Test viewing a trace that doesn't exist
def test_view_not_found
# Test showing a trace that doesn't exist
def test_show_not_found
deleted_trace_file = create(:trace, :deleted)
# First with a trace that has never existed
get :view, :params => { :display_name => create(:user).display_name, :id => 0 }
get :show, :params => { :display_name => create(:user).display_name, :id => 0 }
assert_response :redirect
assert_redirected_to :action => :list
# Now with a trace that has been deleted
get :view, :params => { :display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file.id }, :session => { :user => deleted_trace_file.user }
get :show, :params => { :display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file.id }, :session => { :user => deleted_trace_file.user }
assert_response :redirect
assert_redirected_to :action => :list
end
@ -640,7 +640,7 @@ class TracesControllerTest < ActionController::TestCase
# Finally with a trace that we are allowed to edit
put :update, :params => { :display_name => public_trace_file.user.display_name, :id => public_trace_file.id, :trace => new_details }, :session => { :user => public_trace_file.user }
assert_response :redirect
assert_redirected_to :action => :view, :display_name => public_trace_file.user.display_name
assert_redirected_to :action => :show, :display_name => public_trace_file.user.display_name
trace = Trace.find(public_trace_file.id)
assert_equal new_details[:description], trace.description
assert_equal new_details[:tagstring], trace.tagstring
@ -1029,9 +1029,9 @@ class TracesControllerTest < ActionController::TestCase
end
end
def check_trace_view(trace)
def check_trace_show(trace)
assert_response :success
assert_template "view"
assert_template "show"
assert_select "table", :count => 1 do
assert_select "td", /^#{Regexp.quote(trace.name)} /