From: Tom Hughes Date: Fri, 9 May 2008 23:22:26 +0000 (+0000) Subject: Merge 7452:7744 from trunk. X-Git-Tag: live~7827^2~11 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/5620d7263a36fe842f4d97bc21dda5edd0651b37?hp=ca0989f90fcc14832a54fe129dfdedd907850304 Merge 7452:7744 from trunk. --- diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 4afba1484..421444869 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -594,8 +594,8 @@ class AmfController < ApplicationController # the delete_with_relations_and_nodes_and_history method should do this, # but at present it just throws a 'precondition failed' way=way.to_i - db_now='@now'+(rand*100).to_i.to_s+uid.to_s+id.to_i.abs.to_s+Time.new.to_i.to_s - db_uqn='unin'+(rand*100).to_i.to_s+uid.to_s+way.to_i.abs.to_s+Time.new.to_i.to_s + db_now='@now'+(rand*100).to_i.to_s+uid.to_s+way.abs.to_s+Time.new.to_i.to_s + db_uqn='unin'+(rand*100).to_i.to_s+uid.to_s+way.abs.to_s+Time.new.to_i.to_s ActiveRecord::Base.connection.execute("SET #{db_now}=NOW()") createuniquenodes(way,db_uqn,[]) deleteuniquenoderelations(db_uqn,uid,db_now) diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index 643728dc4..a3b37b931 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -30,11 +30,16 @@ class DiaryEntryController < ApplicationController def list if params[:display_name] @this_user = User.find_by_display_name(params[:display_name]) - @title = @this_user.display_name + "'s diary" - @entry_pages, @entries = paginate(:diary_entries, - :conditions => ['user_id = ?', @this_user.id], - :order => 'created_at DESC', - :per_page => 20) + if @this_user + @title = @this_user.display_name + "'s diary" + @entry_pages, @entries = paginate(:diary_entries, + :conditions => ['user_id = ?', @this_user.id], + :order => 'created_at DESC', + :per_page => 20) + else + @not_found_user = params[:display_name] + render :action => 'no_such_user', :status => :not_found + end else @title = "Users' diaries" @entry_pages, @entries = paginate(:diary_entries, diff --git a/app/controllers/message_controller.rb b/app/controllers/message_controller.rb index 9dc1d6922..85c0ac328 100644 --- a/app/controllers/message_controller.rb +++ b/app/controllers/message_controller.rb @@ -17,13 +17,17 @@ class MessageController < ApplicationController Notifier::deliver_message_notification(@message) redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name end + else + @title = params[:title] end end def reply message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ]) - title = message.title.sub(/^Re:\s*/, "Re: ") - redirect_to :action => 'new', :user_id => message.from_user_id, :title => title + @body = "On #{message.sent_on} #{message.sender.display_name} wrote:\n\n#{message.body.gsub(/^/, '> ')}" + @title = "Re: #{message.title.sub(/^Re:\s*/, '')}" + @user_id = message.from_user_id + render :action => 'new' rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found end diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 4db6e8e15..cf35d0046 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -83,14 +83,17 @@ class TraceController < ApplicationController def view @trace = Trace.find(params[:id]) - @title = "Viewing trace #{@trace.name}" - if !@trace.visible? - render :nothing => true, :status => :not_found - elsif !@trace.public? and @trace.user.id != @user.id - render :nothing => true, :status => :forbidden + + if @trace and @trace.visible? and + (@trace.public? or @trace.user.id == @user.id) + @title = "Viewing trace #{@trace.name}" + else + flash[:notice] = "Trace not found!" + redirect_to :controller => 'trace', :action => 'list' end rescue ActiveRecord::RecordNotFound - render :nothing => true, :status => :not_found + flash[:notice] = "Trace not found!" + redirect_to :controller => 'trace', :action => 'list' end def create @@ -196,7 +199,7 @@ class TraceController < ApplicationController conditions[0] += " AND users.display_name = ?" conditions << params[:display_name] end - + if params[:tag] conditions[0] += " AND EXISTS (SELECT * FROM gpx_file_tags AS gft WHERE gft.gpx_id = gpx_files.id AND gft.tag = ?)" conditions << params[:tag] diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index bd0c143c0..e998e83c6 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -11,6 +11,8 @@ class UserController < ApplicationController @title = 'create account' @user = User.new(params[:user]) + @user.data_public = true + if @user.save token = @user.tokens.create flash[:notice] = "User was successfully created. Check your email for a confirmation note, and you\'ll be mapping in no time :-)
Please note that you won't be able to login until you've received and confirmed your email address." @@ -179,7 +181,8 @@ class UserController < ApplicationController if @this_user @title = @this_user.display_name else - render :nothing => true, :status => :not_found + @not_found_user = params[:display_name] + render :action => 'no_such_user', :status => :not_found end end diff --git a/app/controllers/user_preference_controller.rb b/app/controllers/user_preference_controller.rb index b22c52240..559479929 100644 --- a/app/controllers/user_preference_controller.rb +++ b/app/controllers/user_preference_controller.rb @@ -1,8 +1,41 @@ +# Update and read user preferences, which are arbitrayr key/val pairs class UserPreferenceController < ApplicationController before_filter :authorize - def read + def read_one + pref = UserPreference.find(@user.id, params[:preference_key]) + + if pref + render :text => pref.v.to_s + else + render :text => 'OH NOES! PREF NOT FOUND!', :status => 404 + end + end + + def update_one + begin + pref = UserPreference.find(@user.id, params[:preference_key]) + pref.v = request.raw_post.chomp + pref.save + rescue ActiveRecord::RecordNotFound + pref = UserPreference.new + pref.user = @user + pref.k = params[:preference_key] + pref.v = request.raw_post.chomp + pref.save + end + + render :nothing => true + end + def delete_one + UserPreference.delete(@user.id, params[:preference_key]) + + render :nothing => true + end + + # print out all the preferences as a big xml block + def read doc = OSM::API.new.get_xml_doc prefs = @user.preferences @@ -15,9 +48,9 @@ class UserPreferenceController < ApplicationController doc.root << el1 render :text => doc.to_s, :content_type => "text/xml" - end + # update the entire set of preferences def update begin p = XML::Parser.new @@ -30,12 +63,12 @@ class UserPreferenceController < ApplicationController doc.find('//preferences/preference').each do |pt| pref = UserPreference.new - + unless keyhash[pt['k']].nil? # already have that key render :text => 'OH NOES! CAN HAS UNIQUE KEYS?', :status => :not_acceptable return end - + keyhash[pt['k']] = 1 pref.k = pt['k'] @@ -64,5 +97,4 @@ class UserPreferenceController < ApplicationController render :nothing => true end - end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9c2b5fd3f..3119c8435 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,4 +2,8 @@ module ApplicationHelper def htmlize(text) return sanitize(auto_link(simple_format(text), :urls)) end + + def rss_link_to(*args) + return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" }); + end end diff --git a/app/models/notifier.rb b/app/models/notifier.rb index b9b81a889..84d097341 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -35,6 +35,8 @@ class Notifier < ActionMailer::Base headers "Auto-Submitted" => "auto-generated" body :trace_name => trace.name, :trace_points => trace.size, + :trace_description => trace.description, + :trace_tags => trace.tags, :possible_points => possible_points end @@ -44,6 +46,8 @@ class Notifier < ActionMailer::Base subject "[OpenStreetMap] GPX Import failure" headers "Auto-Submitted" => "auto-generated" body :trace_name => trace.name, + :trace_description => trace.description, + :trace_tags => trace.tags, :error => error end diff --git a/app/models/trace.rb b/app/models/trace.rb index ab99dc290..0e9e7bcc1 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -191,6 +191,7 @@ class Trace < ActiveRecord::Base if first f_lat = point['latitude'] f_lon = point['longitude'] + first = false end tp = Tracepoint.new diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 2a73f2233..3985a527e 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -1,4 +1,5 @@ class UserPreference < ActiveRecord::Base + set_primary_keys :user_id, :k belongs_to :user # Turn this Node in to an XML Node without the wrapper. diff --git a/app/views/diary_entry/list.rhtml b/app/views/diary_entry/list.rhtml index dd90de169..e648e46f2 100644 --- a/app/views/diary_entry/list.rhtml +++ b/app/views/diary_entry/list.rhtml @@ -28,5 +28,5 @@
-<%= link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), :action => 'rss') %> -<%= auto_discovery_link_tag(:atom, :action => 'rss') %> +<%= rss_link_to :action => 'rss' %> +<%= auto_discovery_link_tag :atom, :action => 'rss' %> diff --git a/app/views/diary_entry/new.rhtml b/app/views/diary_entry/new.rhtml index b46bb4d9f..0a5203a66 100644 --- a/app/views/diary_entry/new.rhtml +++ b/app/views/diary_entry/new.rhtml @@ -11,10 +11,13 @@ <%= f.text_area :body, :cols => 80 %> - Location - - Latitude: <%= f.text_field :latitude, :size => 20, :id => "latitude" %> Longitude: <%= f.text_field :longitude, :size => 20, :id => "longitude" %> use map - + Location + + + Latitude: <%= f.text_field :latitude, :size => 20, :id => "latitude" %> Longitude: <%= f.text_field :longitude, :size => 20, :id => "longitude" %> + use map + + <%= submit_tag 'Save' %> @@ -40,7 +43,7 @@