From: Tom Hughes Date: Wed, 22 Aug 2007 18:01:23 +0000 (+0000) Subject: Put the option to delete GPS traces back. Fixes #405. X-Git-Tag: live~8196 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/d274c0e3d8176f2e4da7ecc24c6247253c9f07f1 Put the option to delete GPS traces back. Fixes #405. --- diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index d84059874..3b3097755 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -48,6 +48,8 @@ class TraceController < ApplicationController conditions << @tag end + conditions[0] += " AND gpx_files.visible = 1" + @trace_pages, @traces = paginate(:traces, :include => [:user, :tags], :conditions => conditions, @@ -82,10 +84,10 @@ class TraceController < ApplicationController def view @trace = Trace.find(params[:id]) @title = "Viewing trace #{@trace.name}" - unless @trace.public - if @user - render :nothing, :status => :forbidden if @trace.user.id != @user.id - end + if !@trace.visible? + render :nothing => true, :status => :not_found + elsif !@trace.public? and @trace.user.id != @user.id + render :nothing => true, :status => :forbidden end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found @@ -109,7 +111,7 @@ class TraceController < ApplicationController def data trace = Trace.find(params[:id]) - if trace.public? or (@user and @user == trace.user) + if trace.visible? and (trace.public? or (@user and @user == trace.user)) send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => 'attachment') else render :nothing, :status => :not_found @@ -118,14 +120,42 @@ class TraceController < ApplicationController render :nothing => true, :status => :not_found end + def delete + trace = Trace.find(params[:id]) + + if @user and trace.user == @user + if request.post? and trace.visible? + trace.visible = false + trace.save + flash[:notice] = 'Track scheduled for deletion' + redirect_to :controller => 'traces', :action => 'mine' + else + render :nothing, :status => :bad_request + end + else + render :nothing, :status => :forbidden + end + rescue ActiveRecord::RecordNotFound + render :nothing => true, :status => :not_found + end + def make_public trace = Trace.find(params[:id]) - if @user and trace.user == @user and !trace.public - trace.public = true - trace.save - flash[:notice] = 'Track made public' - redirect_to :controller => 'trace', :action => 'view', :id => params[:id] + + if @user and trace.user == @user + if request.post? and !trace.public? + trace.public = true + trace.save + flash[:notice] = 'Track made public' + redirect_to :controller => 'trace', :action => 'view', :id => params[:id] + else + render :nothing, :status => :bad_request + end + else + render :nothing, :status => :forbidden end + rescue ActiveRecord::RecordNotFound + render :nothing => true, :status => :not_found end def georss diff --git a/app/views/trace/view.rhtml b/app/views/trace/view.rhtml index d907d7c88..fd3986a44 100644 --- a/app/views/trace/view.rhtml +++ b/app/views/trace/view.rhtml @@ -3,26 +3,54 @@ - - + + + + + + + + <% if @trace.inserted? %> - - + + + + + + + <% end %> - - - + + + + + + + + + + + +
filename:<%= @trace.name %> (<%= link_to 'download', :controller => 'trace', :action => 'data', :id => @trace.id %>)
uploaded at:<%= @trace.timestamp %>
Filename:<%= @trace.name %> (<%= link_to 'download', :controller => 'trace', :action => 'data', :id => @trace.id %>)
Uploaded at:<%= @trace.timestamp %>
points:<%= @trace.size.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') %>
start coordinate:<%= @trace.latitude %>, <%= @trace.longitude %> (<%=link_to 'map', :controller => 'site', :action => 'index', :lat => @trace.latitude, :lon => @trace.longitude, :zoom => 14 %> / <%=link_to 'edit', :controller => 'site', :action => 'edit', :lat => @trace.latitude, :lon => @trace.longitude, :zoom => 14 %>)
Points:<%= @trace.size.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') %>
Start coordinate:<%= @trace.latitude %>, <%= @trace.longitude %> (<%=link_to 'map', :controller => 'site', :action => 'index', :lat => @trace.latitude, :lon => @trace.longitude, :zoom => 14 %> / <%=link_to 'edit', :controller => 'site', :action => 'edit', :lat => @trace.latitude, :lon => @trace.longitude, :zoom => 14 %>)
owner:<%= link_to @trace.user.display_name, {:controller => 'trace', :action => 'view', :display_name => @trace.user.display_name, :id => nil} %>
description:<%= @trace.description %>
tags: +
Owner:<%= link_to @trace.user.display_name, {:controller => 'trace', :action => 'view', :display_name => @trace.user.display_name} %>
Description:<%= @trace.description %>
Tags: <% if @trace.tags %> <% @trace.tags.each do |tag| %> <%= link_to tag.tag, { :controller => 'trace', :action => 'list', :tag => tag.tag, :id => nil } %> <% end %> + <% else %> + None <% end %> -
-<% unless @trace.public? %> -

- <%= start_form_tag :controller => 'trace', :action => 'make_public', :id => @trace.id%> - <%= submit_tag 'Make this track public permanently' %> - <%= end_form_tag %> -<% end %> +

+ + + + <% unless @trace.public? %> + + <% end %> + <% if @trace.user.id == @user.id %> + + <% end %> + +
<%= button_to 'Make this track public permanently', :controller => 'trace', :action => 'make_public', :id => @trace.id %><%= button_to 'Delete this track', :controller => 'trace', :action => 'delete', :id => @trace.id %>
diff --git a/config/routes.rb b/config/routes.rb index 97d450068..45a4d6048 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -75,6 +75,8 @@ ActionController::Routing::Routes.draw do |map| map.connect '/traces/mine/tag/:tag', :controller => 'trace', :action => 'mine' map.connect '/traces/mine/tag/:tag/page/:page', :controller => 'trace', :action => 'mine' map.connect '/trace/create', :controller => 'trace', :action => 'create' + map.connect '/trace/:id/delete', :controller => 'trace', :action => 'delete' + map.connect '/trace/:id/make_public', :controller => 'trace', :action => 'make_public' map.connect '/user/:display_name/traces', :controller => 'trace', :action => 'list' map.connect '/user/:display_name/traces/page/:page', :controller => 'trace', :action => 'list' map.connect '/user/:display_name/traces/rss', :controller => 'trace', :action => 'georss' diff --git a/lib/daemons/gpx_import.rb b/lib/daemons/gpx_import.rb index ba76d60f0..e80a51944 100755 --- a/lib/daemons/gpx_import.rb +++ b/lib/daemons/gpx_import.rb @@ -12,7 +12,7 @@ logger = ActiveRecord::Base.logger while(true) do ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.") - Trace.find(:all, :conditions => ['inserted = ?', false]).each do |trace| + Trace.find(:all, :conditions => 'inserted = 0').each do |trace| Signal.trap("TERM") do terminated = true end @@ -38,5 +38,22 @@ while(true) do exit if terminated end + Trace.find(:all, :conditions => 'visible = 0').each do |trace| + Signal.trap("TERM") do + terminated = true + end + + begin + trace.destroy + rescue Exception => ex + logger.info ex.to_s + ex.backtrace.each {|l| logger.info l } + end + + Signal.trap("TERM", "DEFAULT") + + exit if terminated + end + sleep 5.minutes end