]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/trace_controller.rb
Sort out storage and use of user preferred languages.
[rails.git] / app / controllers / trace_controller.rb
index dc7456c45099ec923731ccd43944be57001bd459..1787bb196a162e225631e67d0e22c1db5e648de4 100644 (file)
@@ -2,6 +2,7 @@ class TraceController < ApplicationController
   layout 'site'
 
   before_filter :authorize_web
+  before_filter :set_locale
   before_filter :require_user, :only => [:mine, :create, :edit, :delete, :make_public]
   before_filter :authorize, :only => [:api_details, :api_data, :api_create]
   before_filter :check_database_readable, :except => [:api_details, :api_data, :api_create]
@@ -57,7 +58,12 @@ class TraceController < ApplicationController
       @tag = params[:tag]
 
       files = Tracetag.find_all_by_tag(params[:tag]).collect { |tt| tt.gpx_id }
-      conditions[0] += " AND gpx_files.id IN (#{files.join(',')})"
+
+      if files.length > 0
+        conditions[0] += " AND gpx_files.id IN (#{files.join(',')})"
+      else
+        conditions[0] += " AND 0 = 1"
+      end
     end
     
     conditions[0] += " AND gpx_files.visible = ?"
@@ -87,6 +93,13 @@ class TraceController < ApplicationController
   end
 
   def mine
+    # Load the preference of whether the user set the trace public the last time
+    @trace = Trace.new
+    if @user.preferences.find(:first, :conditions => {:k => "gps.trace.public", :v => "default"}).nil?
+      @trace.public = false
+    else 
+      @trace.public = true
+    end
     list(@user, "mine")
   end
 
@@ -233,6 +246,7 @@ class TraceController < ApplicationController
 
     if trace.inserted?
       if trace.public? or (@user and @user == trace.user)
+        expires_in 7.days, :private => !trace.public, :public => trace.public
         send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline')
       else
         render :nothing => true, :status => :forbidden
@@ -249,6 +263,7 @@ class TraceController < ApplicationController
 
     if trace.inserted?
       if trace.public? or (@user and @user == trace.user)
+        expires_in 7.days, :private => !trace.public, :public => trace.public
         send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline')
       else
         render :nothing => true, :status => :forbidden