From: Shaun McDonald Date: Fri, 12 Dec 2008 19:29:27 +0000 (+0000) Subject: resync from rails_port 11795:12304 X-Git-Tag: live~8686^2~97 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/721dd9c27d299455b9159457a095716f797389f1?hp=fac8b5d28aa81f2233c7233b6876ad31d86be28b resync from rails_port 11795:12304 --- diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 06ae5dc3b..022c304fb 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -2,6 +2,7 @@ class TraceController < ApplicationController layout 'site' before_filter :authorize_web + before_filter :require_user, :only => [:mine, :edit, :delete, :make_public] before_filter :authorize, :only => [:api_details, :api_data, :api_create] before_filter :check_database_availability, :except => [:api_details, :api_data, :api_create] before_filter :check_read_availability, :only => [:api_details, :api_data, :api_create] @@ -47,8 +48,9 @@ class TraceController < ApplicationController if params[:tag] @tag = params[:tag] - conditions[0] += " AND EXISTS (SELECT * FROM gpx_file_tags AS gft WHERE gft.gpx_id = gpx_files.id AND gft.tag = ?)" - conditions << @tag + + files = Tracetag.find_all_by_tag(params[:tag]).collect { |tt| tt.gpx_id } + conditions[0] += " AND gpx_files.id IN (#{files.join(',')})" end conditions[0] += " AND gpx_files.visible = ?" @@ -78,17 +80,7 @@ class TraceController < ApplicationController end def mine - if @user - @trace = Trace.new - unless @user.trace_public_default.nil? - @trace.public = true - else - @trace.public = false - end - list(@user, "mine") unless @user.nil? - else - redirect_to :controller => 'user', :action => 'login', :referer => request.request_uri - end + list(@user, "mine") end def view @@ -140,7 +132,7 @@ class TraceController < ApplicationController send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => 'attachment') end else - render :nothing, :status => :not_found + render :nothing => true, :status => :not_found end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found @@ -158,7 +150,7 @@ class TraceController < ApplicationController end end else - render :nothing, :status => :forbidden + render :nothing => true, :status => :forbidden end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found @@ -174,10 +166,10 @@ class TraceController < ApplicationController flash[:notice] = 'Track scheduled for deletion' redirect_to :controller => 'traces', :action => 'mine' else - render :nothing, :status => :bad_request + render :nothing => true, :status => :bad_request end else - render :nothing, :status => :forbidden + render :nothing => true, :status => :forbidden end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found @@ -193,10 +185,10 @@ class TraceController < ApplicationController flash[:notice] = 'Track made public' redirect_to :controller => 'trace', :action => 'view', :id => params[:id] else - render :nothing, :status => :bad_request + render :nothing => true, :status => :bad_request end else - render :nothing, :status => :forbidden + render :nothing => true, :status => :forbidden end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found @@ -234,7 +226,7 @@ class TraceController < ApplicationController if trace.public? or (@user and @user == trace.user) send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') else - render :nothing, :status => :forbidden + render :nothing => true, :status => :forbidden end else render :nothing => true, :status => :not_found @@ -250,7 +242,7 @@ class TraceController < ApplicationController if trace.public? or (@user and @user == trace.user) send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') else - render :nothing, :status => :forbidden + render :nothing => true, :status => :forbidden end else render :nothing => true, :status => :not_found diff --git a/app/models/user.rb b/app/models/user.rb index 0eddb259d..ce244fe02 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -110,4 +110,17 @@ class User < ActiveRecord::Base return self.preferences.find(:first, :conditions => {:k => "gps.trace.public", :v => "default"}) end + def delete + self.active = false + self.display_name = "user_#{self.id}" + self.description = nil + self.home_lat = nil + self.home_lon = nil + self.image = nil + self.email_valid = false + self.new_email = nil + self.visible = false + self.save + end + end diff --git a/db/migrate/017_add_gpx_indexes.rb b/db/migrate/017_add_gpx_indexes.rb new file mode 100644 index 000000000..1778dcc75 --- /dev/null +++ b/db/migrate/017_add_gpx_indexes.rb @@ -0,0 +1,11 @@ +class AddGpxIndexes < ActiveRecord::Migration + def self.up + add_index "gpx_files", ["user_id"], :name => "gpx_files_user_id_idx" + add_index "gpx_file_tags", ["tag"], :name => "gpx_file_tags_tag_idx" + end + + def self.down + remove_index "gpx_file_tags", :name => "gpx_file_tags_tag_idx" + remove_index "gpx_files", :name => "gpx_files_user_id_idx" + end +end diff --git a/db/migrate/017_add_timestamp_indexes.rb b/db/migrate/018_add_timestamp_indexes.rb similarity index 100% rename from db/migrate/017_add_timestamp_indexes.rb rename to db/migrate/018_add_timestamp_indexes.rb diff --git a/db/migrate/018_populate_node_tags_and_remove.rb b/db/migrate/019_populate_node_tags_and_remove.rb similarity index 94% rename from db/migrate/018_populate_node_tags_and_remove.rb rename to db/migrate/019_populate_node_tags_and_remove.rb index 2a3f3c988..860358646 100644 --- a/db/migrate/018_populate_node_tags_and_remove.rb +++ b/db/migrate/019_populate_node_tags_and_remove.rb @@ -3,9 +3,9 @@ class PopulateNodeTagsAndRemove < ActiveRecord::Migration have_nodes = select_value("SELECT count(*) FROM current_nodes").to_i != 0 if have_nodes - prefix = File.join Dir.tmpdir, "017_populate_node_tags_and_remove.#{$$}." + prefix = File.join Dir.tmpdir, "019_populate_node_tags_and_remove.#{$$}." - cmd = "db/migrate/018_populate_node_tags_and_remove_helper" + cmd = "db/migrate/019_populate_node_tags_and_remove_helper" src = "#{cmd}.c" if not File.exists? cmd or File.mtime(cmd) < File.mtime(src) then system 'cc -O3 -Wall `mysql_config --cflags --libs` ' + diff --git a/db/migrate/018_populate_node_tags_and_remove_helper.c b/db/migrate/019_populate_node_tags_and_remove_helper.c similarity index 96% rename from db/migrate/018_populate_node_tags_and_remove_helper.c rename to db/migrate/019_populate_node_tags_and_remove_helper.c index 83c1b1743..c41ea33da 100644 --- a/db/migrate/018_populate_node_tags_and_remove_helper.c +++ b/db/migrate/019_populate_node_tags_and_remove_helper.c @@ -7,9 +7,9 @@ static void exit_mysql_err(MYSQL *mysql) { const char *err = mysql_error(mysql); if (err) { - fprintf(stderr, "018_populate_node_tags_and_remove_helper: MySQL error: %s\n", err); + fprintf(stderr, "019_populate_node_tags_and_remove_helper: MySQL error: %s\n", err); } else { - fprintf(stderr, "018_populate_node_tags_and_remove_helper: MySQL error\n"); + fprintf(stderr, "019_populate_node_tags_and_remove_helper: MySQL error\n"); } abort(); exit(EXIT_FAILURE); @@ -192,7 +192,7 @@ int main(int argc, char **argv) { struct data data, *d = &data; if (argc != 8) { - printf("Usage: 018_populate_node_tags_and_remove_helper host user passwd database port socket prefix\n"); + printf("Usage: 019_populate_node_tags_and_remove_helper host user passwd database port socket prefix\n"); exit(EXIT_FAILURE); } diff --git a/db/migrate/019_move_to_innodb.rb b/db/migrate/020_move_to_innodb.rb similarity index 100% rename from db/migrate/019_move_to_innodb.rb rename to db/migrate/020_move_to_innodb.rb diff --git a/db/migrate/020_key_constraints.rb b/db/migrate/021_key_constraints.rb similarity index 100% rename from db/migrate/020_key_constraints.rb rename to db/migrate/021_key_constraints.rb diff --git a/db/migrate/021_add_changesets.rb b/db/migrate/022_add_changesets.rb similarity index 100% rename from db/migrate/021_add_changesets.rb rename to db/migrate/022_add_changesets.rb diff --git a/db/migrate/022_order_relation_members.rb b/db/migrate/023_order_relation_members.rb similarity index 100% rename from db/migrate/022_order_relation_members.rb rename to db/migrate/023_order_relation_members.rb diff --git a/db/migrate/023_add_end_time_to_changesets.rb b/db/migrate/024_add_end_time_to_changesets.rb similarity index 100% rename from db/migrate/023_add_end_time_to_changesets.rb rename to db/migrate/024_add_end_time_to_changesets.rb