From: Tom Hughes Date: Thu, 30 May 2019 08:20:37 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/2237' X-Git-Tag: live~2611 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/b92c699a66fcf6433915ca7771206c61de205a67?hp=3e414a50256761cc626f91d67834aa9687329f30 Merge remote-tracking branch 'upstream/pull/2237' --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f989d393d..d63584223 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -40,7 +40,7 @@ Metrics/AbcSize: # Configuration parameters: CountComments, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: - Max: 262 + Max: 263 # Offense count: 11 # Configuration parameters: CountBlocks. diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index d2864e452..1106d843e 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -36,7 +36,7 @@ class Ability if Settings.status != "database_offline" can [:index, :new, :create, :show, :edit, :update, :destroy], ClientApplication - can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry + can [:new, :create, :edit, :update, :comment, :subscribe, :unsubscribe], DiaryEntry can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message can [:close, :reopen], Note can [:new, :create], Report diff --git a/app/controllers/diary_entries_controller.rb b/app/controllers/diary_entries_controller.rb index fb1e7b702..1e113e09f 100644 --- a/app/controllers/diary_entries_controller.rb +++ b/app/controllers/diary_entries_controller.rb @@ -8,38 +8,40 @@ class DiaryEntriesController < ApplicationController authorize_resource before_action :lookup_user, :only => [:show, :comments] - before_action :check_database_writable, :only => [:new, :edit, :comment, :hide, :hidecomment, :subscribe, :unsubscribe] - before_action :allow_thirdparty_images, :only => [:new, :edit, :index, :show, :comments] + before_action :check_database_writable, :only => [:new, :create, :edit, :update, :comment, :hide, :hidecomment, :subscribe, :unsubscribe] + before_action :allow_thirdparty_images, :only => [:new, :create, :edit, :update, :index, :show, :comments] def new @title = t "diary_entries.new.title" - if request.post? - @diary_entry = DiaryEntry.new(entry_params) - @diary_entry.user = current_user + default_lang = current_user.preferences.where(:k => "diary.default_language").first + lang_code = default_lang ? default_lang.v : current_user.preferred_language + @diary_entry = DiaryEntry.new(entry_params.merge(:language_code => lang_code)) + set_map_location + render :action => "new" + end - if @diary_entry.save - default_lang = current_user.preferences.where(:k => "diary.default_language").first - if default_lang - default_lang.v = @diary_entry.language_code - default_lang.save! - else - current_user.preferences.create(:k => "diary.default_language", :v => @diary_entry.language_code) - end + def create + @title = t "diary_entries.new.title" - # Subscribe user to diary comments - @diary_entry.subscriptions.create(:user => current_user) + @diary_entry = DiaryEntry.new(entry_params) + @diary_entry.user = current_user - redirect_to :action => "index", :display_name => current_user.display_name + if @diary_entry.save + default_lang = current_user.preferences.where(:k => "diary.default_language").first + if default_lang + default_lang.v = @diary_entry.language_code + default_lang.save! else - render :action => "edit" + current_user.preferences.create(:k => "diary.default_language", :v => @diary_entry.language_code) end + + # Subscribe user to diary comments + @diary_entry.subscriptions.create(:user => current_user) + + redirect_to :action => "index", :display_name => current_user.display_name else - default_lang = current_user.preferences.where(:k => "diary.default_language").first - lang_code = default_lang ? default_lang.v : current_user.preferred_language - @diary_entry = DiaryEntry.new(entry_params.merge(:language_code => lang_code)) - set_map_location - render :action => "edit" + render :action => "new" end end @@ -47,13 +49,25 @@ class DiaryEntriesController < ApplicationController @title = t "diary_entries.edit.title" @diary_entry = DiaryEntry.find(params[:id]) + redirect_to diary_entry_path(@diary_entry.user, @diary_entry) if current_user != @diary_entry.user + + set_map_location + rescue ActiveRecord::RecordNotFound + render :action => "no_such_entry", :status => :not_found + end + + def update + @title = t "diary_entries.edit.title" + @diary_entry = DiaryEntry.find(params[:id]) + if current_user != @diary_entry.user redirect_to diary_entry_path(@diary_entry.user, @diary_entry) elsif params[:diary_entry] && @diary_entry.update(entry_params) redirect_to diary_entry_path(@diary_entry.user, @diary_entry) + else + set_map_location + render :action => "edit" end - - set_map_location rescue ActiveRecord::RecordNotFound render :action => "no_such_entry", :status => :not_found end @@ -166,6 +180,10 @@ class DiaryEntriesController < ApplicationController else @entries = DiaryEntry.joins(:user).where(:users => { :status => %w[active confirmed] }) + # Items can't be flagged as deleted in the RSS format. + # For the general feeds, allow a delay before publishing, to help spam fighting + @entries = @entries.where("created_at < :time", :time => Settings.diary_feed_delay.hours.ago) + if params[:language] @entries = @entries.where(:language_code => params[:language]) @title = t("diary_entries.feed.language.title", :language_name => Language.find(params[:language]).english_name) @@ -177,7 +195,6 @@ class DiaryEntriesController < ApplicationController @link = url_for :action => "index", :host => Settings.server_url, :protocol => Settings.server_protocol end end - @entries = @entries.visible.includes(:user).order("created_at DESC").limit(20) end diff --git a/app/models/acl.rb b/app/models/acl.rb index ea19c74b0..cf83e673c 100644 --- a/app/models/acl.rb +++ b/app/models/acl.rb @@ -2,7 +2,7 @@ # # Table name: acls # -# id :integer not null, primary key +# id :bigint(8) not null, primary key # address :inet # k :string not null # v :string diff --git a/app/models/changeset.rb b/app/models/changeset.rb index b98d213c7..d57086a8e 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -2,8 +2,8 @@ # # Table name: changesets # -# id :integer not null, primary key -# user_id :integer not null +# id :bigint(8) not null, primary key +# user_id :bigint(8) not null # created_at :datetime not null # min_lat :integer # max_lat :integer @@ -14,7 +14,7 @@ # # Indexes # -# changesets_bbox_idx (min_lat,max_lat,min_lon,max_lon) +# changesets_bbox_idx (min_lat,max_lat,min_lon,max_lon) USING gist # changesets_closed_at_idx (closed_at) # changesets_created_at_idx (created_at) # changesets_user_id_created_at_idx (user_id,created_at) diff --git a/app/models/changeset_comment.rb b/app/models/changeset_comment.rb index a0ad6f2ea..529641c7e 100644 --- a/app/models/changeset_comment.rb +++ b/app/models/changeset_comment.rb @@ -3,8 +3,8 @@ # Table name: changeset_comments # # id :integer not null, primary key -# changeset_id :integer not null -# author_id :integer not null +# changeset_id :bigint(8) not null +# author_id :bigint(8) not null # body :text not null # created_at :datetime not null # visible :boolean not null diff --git a/app/models/changeset_tag.rb b/app/models/changeset_tag.rb index 942fafb2a..751029e03 100644 --- a/app/models/changeset_tag.rb +++ b/app/models/changeset_tag.rb @@ -2,7 +2,7 @@ # # Table name: changeset_tags # -# changeset_id :integer not null, primary key +# changeset_id :bigint(8) not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null # diff --git a/app/models/diary_comment.rb b/app/models/diary_comment.rb index ade7a64ea..4ae21be88 100644 --- a/app/models/diary_comment.rb +++ b/app/models/diary_comment.rb @@ -2,9 +2,9 @@ # # Table name: diary_comments # -# id :integer not null, primary key -# diary_entry_id :integer not null -# user_id :integer not null +# id :bigint(8) not null, primary key +# diary_entry_id :bigint(8) not null +# user_id :bigint(8) not null # body :text not null # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/diary_entry.rb b/app/models/diary_entry.rb index d61241993..4affe8b59 100644 --- a/app/models/diary_entry.rb +++ b/app/models/diary_entry.rb @@ -2,8 +2,8 @@ # # Table name: diary_entries # -# id :integer not null, primary key -# user_id :integer not null +# id :bigint(8) not null, primary key +# user_id :bigint(8) not null # title :string not null # body :text not null # created_at :datetime not null diff --git a/app/models/diary_entry_subscription.rb b/app/models/diary_entry_subscription.rb index 6d24c4598..6e9a103ad 100644 --- a/app/models/diary_entry_subscription.rb +++ b/app/models/diary_entry_subscription.rb @@ -2,8 +2,8 @@ # # Table name: diary_entry_subscriptions # -# user_id :integer not null, primary key -# diary_entry_id :integer not null, primary key +# user_id :bigint(8) not null, primary key +# diary_entry_id :bigint(8) not null, primary key # # Indexes # diff --git a/app/models/friend.rb b/app/models/friend.rb index 86da87b93..615da1076 100644 --- a/app/models/friend.rb +++ b/app/models/friend.rb @@ -2,9 +2,9 @@ # # Table name: friends # -# id :integer not null, primary key -# user_id :integer not null -# friend_user_id :integer not null +# id :bigint(8) not null, primary key +# user_id :bigint(8) not null +# friend_user_id :bigint(8) not null # # Indexes # diff --git a/app/models/message.rb b/app/models/message.rb index e3a3ec921..4ab129e91 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -2,13 +2,13 @@ # # Table name: messages # -# id :integer not null, primary key -# from_user_id :integer not null +# id :bigint(8) not null, primary key +# from_user_id :bigint(8) not null # title :string not null # body :text not null # sent_on :datetime not null # message_read :boolean default(FALSE), not null -# to_user_id :integer not null +# to_user_id :bigint(8) not null # to_user_visible :boolean default(TRUE), not null # from_user_visible :boolean default(TRUE), not null # body_format :enum default("markdown"), not null diff --git a/app/models/node.rb b/app/models/node.rb index be561fb5d..91a1dbc41 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -2,14 +2,14 @@ # # Table name: current_nodes # -# id :integer not null, primary key +# id :bigint(8) not null, primary key # latitude :integer not null # longitude :integer not null -# changeset_id :integer not null +# changeset_id :bigint(8) not null # visible :boolean not null # timestamp :datetime not null -# tile :integer not null -# version :integer not null +# tile :bigint(8) not null +# version :bigint(8) not null # # Indexes # diff --git a/app/models/node_tag.rb b/app/models/node_tag.rb index 43915bc12..86404599b 100644 --- a/app/models/node_tag.rb +++ b/app/models/node_tag.rb @@ -2,7 +2,7 @@ # # Table name: current_node_tags # -# node_id :integer not null, primary key +# node_id :bigint(8) not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null # diff --git a/app/models/note.rb b/app/models/note.rb index d96addbe7..d4f9a801f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -2,10 +2,10 @@ # # Table name: notes # -# id :integer not null, primary key +# id :bigint(8) not null, primary key # latitude :integer not null # longitude :integer not null -# tile :integer not null +# tile :bigint(8) not null # updated_at :datetime not null # created_at :datetime not null # status :enum not null diff --git a/app/models/note_comment.rb b/app/models/note_comment.rb index f94032e1e..388f890a6 100644 --- a/app/models/note_comment.rb +++ b/app/models/note_comment.rb @@ -2,18 +2,18 @@ # # Table name: note_comments # -# id :integer not null, primary key -# note_id :integer not null +# id :bigint(8) not null, primary key +# note_id :bigint(8) not null # visible :boolean not null # created_at :datetime not null # author_ip :inet -# author_id :integer +# author_id :bigint(8) # body :text # event :enum # # Indexes # -# index_note_comments_on_body (to_tsvector('english'::regconfig, body)) +# index_note_comments_on_body (to_tsvector('english'::regconfig, body)) USING gin # index_note_comments_on_created_at (created_at) # note_comments_note_id_idx (note_id) # diff --git a/app/models/old_node.rb b/app/models/old_node.rb index 9690dc46c..cc2327d08 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -2,14 +2,14 @@ # # Table name: nodes # -# node_id :integer not null, primary key +# node_id :bigint(8) not null, primary key # latitude :integer not null # longitude :integer not null -# changeset_id :integer not null +# changeset_id :bigint(8) not null # visible :boolean not null # timestamp :datetime not null -# tile :integer not null -# version :integer not null, primary key +# tile :bigint(8) not null +# version :bigint(8) not null, primary key # redaction_id :integer # # Indexes diff --git a/app/models/old_node_tag.rb b/app/models/old_node_tag.rb index 77b78751b..a3e1c3aaf 100644 --- a/app/models/old_node_tag.rb +++ b/app/models/old_node_tag.rb @@ -2,8 +2,8 @@ # # Table name: node_tags # -# node_id :integer not null, primary key -# version :integer not null, primary key +# node_id :bigint(8) not null, primary key +# version :bigint(8) not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null # diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index 3470561ce..109f7d968 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -2,10 +2,10 @@ # # Table name: relations # -# relation_id :integer default(0), not null, primary key -# changeset_id :integer not null +# relation_id :bigint(8) default(0), not null, primary key +# changeset_id :bigint(8) not null # timestamp :datetime not null -# version :integer not null, primary key +# version :bigint(8) not null, primary key # visible :boolean default(TRUE), not null # redaction_id :integer # diff --git a/app/models/old_relation_member.rb b/app/models/old_relation_member.rb index a74637435..f8d4a359f 100644 --- a/app/models/old_relation_member.rb +++ b/app/models/old_relation_member.rb @@ -2,11 +2,11 @@ # # Table name: relation_members # -# relation_id :integer default(0), not null, primary key +# relation_id :bigint(8) default(0), not null, primary key # member_type :enum not null -# member_id :integer not null +# member_id :bigint(8) not null # member_role :string not null -# version :integer default(0), not null, primary key +# version :bigint(8) default(0), not null, primary key # sequence_id :integer default(0), not null, primary key # # Indexes diff --git a/app/models/old_relation_tag.rb b/app/models/old_relation_tag.rb index 4a247949c..c674f708b 100644 --- a/app/models/old_relation_tag.rb +++ b/app/models/old_relation_tag.rb @@ -2,10 +2,10 @@ # # Table name: relation_tags # -# relation_id :integer default(0), not null, primary key +# relation_id :bigint(8) default(0), not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null -# version :integer not null, primary key +# version :bigint(8) not null, primary key # # Foreign Keys # diff --git a/app/models/old_way.rb b/app/models/old_way.rb index baca05d33..31e230c38 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -2,10 +2,10 @@ # # Table name: ways # -# way_id :integer default(0), not null, primary key -# changeset_id :integer not null +# way_id :bigint(8) default(0), not null, primary key +# changeset_id :bigint(8) not null # timestamp :datetime not null -# version :integer not null, primary key +# version :bigint(8) not null, primary key # visible :boolean default(TRUE), not null # redaction_id :integer # diff --git a/app/models/old_way_node.rb b/app/models/old_way_node.rb index e1627d3fa..836e76e47 100644 --- a/app/models/old_way_node.rb +++ b/app/models/old_way_node.rb @@ -2,10 +2,10 @@ # # Table name: way_nodes # -# way_id :integer not null, primary key -# node_id :integer not null -# version :integer not null, primary key -# sequence_id :integer not null, primary key +# way_id :bigint(8) not null, primary key +# node_id :bigint(8) not null +# version :bigint(8) not null, primary key +# sequence_id :bigint(8) not null, primary key # # Indexes # diff --git a/app/models/old_way_tag.rb b/app/models/old_way_tag.rb index 5832f6d4f..ae4ad605e 100644 --- a/app/models/old_way_tag.rb +++ b/app/models/old_way_tag.rb @@ -2,10 +2,10 @@ # # Table name: way_tags # -# way_id :integer default(0), not null, primary key +# way_id :bigint(8) default(0), not null, primary key # k :string not null, primary key # v :string not null -# version :integer not null, primary key +# version :bigint(8) not null, primary key # # Foreign Keys # diff --git a/app/models/redaction.rb b/app/models/redaction.rb index e6d748706..d9b2a5579 100644 --- a/app/models/redaction.rb +++ b/app/models/redaction.rb @@ -7,7 +7,7 @@ # description :text # created_at :datetime # updated_at :datetime -# user_id :integer not null +# user_id :bigint(8) not null # description_format :enum default("markdown"), not null # # Foreign Keys diff --git a/app/models/relation.rb b/app/models/relation.rb index 884e96ed7..bcac9d04b 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -2,11 +2,11 @@ # # Table name: current_relations # -# id :integer not null, primary key -# changeset_id :integer not null +# id :bigint(8) not null, primary key +# changeset_id :bigint(8) not null # timestamp :datetime not null # visible :boolean not null -# version :integer not null +# version :bigint(8) not null # # Indexes # diff --git a/app/models/relation_member.rb b/app/models/relation_member.rb index 3e5cdfca2..7c399c3a8 100644 --- a/app/models/relation_member.rb +++ b/app/models/relation_member.rb @@ -2,9 +2,9 @@ # # Table name: current_relation_members # -# relation_id :integer not null, primary key +# relation_id :bigint(8) not null, primary key # member_type :enum not null -# member_id :integer not null +# member_id :bigint(8) not null # member_role :string not null # sequence_id :integer default(0), not null, primary key # diff --git a/app/models/relation_tag.rb b/app/models/relation_tag.rb index 151615f72..b186f505d 100644 --- a/app/models/relation_tag.rb +++ b/app/models/relation_tag.rb @@ -2,7 +2,7 @@ # # Table name: current_relation_tags # -# relation_id :integer not null, primary key +# relation_id :bigint(8) not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null # diff --git a/app/models/trace.rb b/app/models/trace.rb index 1a2dfc9e4..af2c0af3b 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -2,11 +2,11 @@ # # Table name: gpx_files # -# id :integer not null, primary key -# user_id :integer not null +# id :bigint(8) not null, primary key +# user_id :bigint(8) not null # visible :boolean default(TRUE), not null # name :string default(""), not null -# size :integer +# size :bigint(8) # latitude :float # longitude :float # timestamp :datetime not null diff --git a/app/models/tracepoint.rb b/app/models/tracepoint.rb index 445688c55..6473c9430 100644 --- a/app/models/tracepoint.rb +++ b/app/models/tracepoint.rb @@ -6,9 +6,9 @@ # trackid :integer not null # latitude :integer not null # longitude :integer not null -# gpx_id :integer not null +# gpx_id :bigint(8) not null # timestamp :datetime -# tile :integer +# tile :bigint(8) # # Indexes # diff --git a/app/models/tracetag.rb b/app/models/tracetag.rb index 84b6c6dfa..8d2f4fffa 100644 --- a/app/models/tracetag.rb +++ b/app/models/tracetag.rb @@ -2,9 +2,9 @@ # # Table name: gpx_file_tags # -# gpx_id :integer default(0), not null +# gpx_id :bigint(8) default(0), not null # tag :string not null -# id :integer not null, primary key +# id :bigint(8) not null, primary key # # Indexes # diff --git a/app/models/user.rb b/app/models/user.rb index dbe91ab0f..2979b13d7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,7 +3,7 @@ # Table name: users # # email :string not null -# id :integer not null, primary key +# id :bigint(8) not null, primary key # pass_crypt :string not null # creation_time :datetime not null # display_name :string default(""), not null @@ -33,7 +33,7 @@ # image_use_gravatar :boolean default(FALSE), not null # image_content_type :string # auth_provider :string -# home_tile :integer +# home_tile :bigint(8) # tou_agreed :datetime # # Indexes diff --git a/app/models/user_block.rb b/app/models/user_block.rb index 27bc40498..92cee16cd 100644 --- a/app/models/user_block.rb +++ b/app/models/user_block.rb @@ -3,12 +3,12 @@ # Table name: user_blocks # # id :integer not null, primary key -# user_id :integer not null -# creator_id :integer not null +# user_id :bigint(8) not null +# creator_id :bigint(8) not null # reason :text not null # ends_at :datetime not null # needs_view :boolean default(FALSE), not null -# revoker_id :integer +# revoker_id :bigint(8) # created_at :datetime # updated_at :datetime # reason_format :enum default("markdown"), not null diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 3963bd02a..583ced3c5 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -2,7 +2,7 @@ # # Table name: user_preferences # -# user_id :integer not null, primary key +# user_id :bigint(8) not null, primary key # k :string not null, primary key # v :string not null # diff --git a/app/models/user_role.rb b/app/models/user_role.rb index adf569a03..f3d48cade 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -3,11 +3,11 @@ # Table name: user_roles # # id :integer not null, primary key -# user_id :integer not null +# user_id :bigint(8) not null # role :enum not null # created_at :datetime # updated_at :datetime -# granter_id :integer not null +# granter_id :bigint(8) not null # # Indexes # diff --git a/app/models/user_token.rb b/app/models/user_token.rb index 0d1e16e8a..844357d8d 100644 --- a/app/models/user_token.rb +++ b/app/models/user_token.rb @@ -2,8 +2,8 @@ # # Table name: user_tokens # -# id :integer not null, primary key -# user_id :integer not null +# id :bigint(8) not null, primary key +# user_id :bigint(8) not null # token :string not null # expiry :datetime not null # referer :text diff --git a/app/models/way.rb b/app/models/way.rb index ddb82ed1e..6fcaf39cc 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -2,11 +2,11 @@ # # Table name: current_ways # -# id :integer not null, primary key -# changeset_id :integer not null +# id :bigint(8) not null, primary key +# changeset_id :bigint(8) not null # timestamp :datetime not null # visible :boolean not null -# version :integer not null +# version :bigint(8) not null # # Indexes # diff --git a/app/models/way_node.rb b/app/models/way_node.rb index 5c09cd740..0788a631c 100644 --- a/app/models/way_node.rb +++ b/app/models/way_node.rb @@ -2,9 +2,9 @@ # # Table name: current_way_nodes # -# way_id :integer not null, primary key -# node_id :integer not null -# sequence_id :integer not null, primary key +# way_id :bigint(8) not null, primary key +# node_id :bigint(8) not null +# sequence_id :bigint(8) not null, primary key # # Indexes # diff --git a/app/models/way_tag.rb b/app/models/way_tag.rb index c4df0abb5..6637c1585 100644 --- a/app/models/way_tag.rb +++ b/app/models/way_tag.rb @@ -2,7 +2,7 @@ # # Table name: current_way_tags # -# way_id :integer not null, primary key +# way_id :bigint(8) not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null # diff --git a/app/views/diary_entries/_form.html.erb b/app/views/diary_entries/_form.html.erb new file mode 100644 index 000000000..0d8f7ef5b --- /dev/null +++ b/app/views/diary_entries/_form.html.erb @@ -0,0 +1,35 @@ +
+
+
+ + <%= f.text_field :title, :class => "richtext_title" %> +
+
+ + <%= richtext_area :diary_entry, :body, :cols => 80, :rows => 20, :format => @diary_entry.body_format %> +
+
+ + <%= f.collection_select :language_code, Language.order(:english_name), :code, :name %> +
+
+
+ + <%= content_tag "div", "", :id => "map", :data => { :lat => @lat, :lon => @lon, :zoom => @zoom } %> +
+
+ + <%= f.text_field :latitude, :size => 20, :id => "latitude" %> +
+
+ + <%= f.text_field :longitude, :size => 20, :id => "longitude" %> +
+ +
+
+ + <%= f.submit %> +
diff --git a/app/views/diary_entries/edit.html.erb b/app/views/diary_entries/edit.html.erb index 62aed884c..5ea619328 100644 --- a/app/views/diary_entries/edit.html.erb +++ b/app/views/diary_entries/edit.html.erb @@ -8,44 +8,6 @@ <%= error_messages_for "diary_entry" %> -<%= form_for :diary_entry do |f| %> -
-
-
- - <%= f.text_field :title, :class => "richtext_title" %> -
-
- - <%= richtext_area :diary_entry, :body, :cols => 80, :rows => 20, :format => @diary_entry.body_format %> -
-
- - <%= f.collection_select :language_code, Language.order(:english_name), :code, :name %> -
-
-
- - <%= content_tag "div", "", :id => "map", :data => { :lat => @lat, :lon => @lon, :zoom => @zoom } %> -
-
- - <%= f.text_field :latitude, :size => 20, :id => "latitude" %> -
-
- - <%= f.text_field :longitude, :size => 20, :id => "longitude" %> -
- -
-
- - <% if action_name == 'new' %> - <%= submit_tag t("diary_entries.new.publish_button") %> - <% else %> - <%= submit_tag t(".save_button") %> - <% end %> -
+<%= form_for @diary_entry, :url => diary_entry_path(current_user, @diary_entry), :html => { :method => :put } do |f| %> + <%= render :partial => "form", :locals => { :f => f } %> <% end %> diff --git a/app/views/diary_entries/index.html.erb b/app/views/diary_entries/index.html.erb index 4e5dc994d..4610e5fd7 100644 --- a/app/views/diary_entries/index.html.erb +++ b/app/views/diary_entries/index.html.erb @@ -13,13 +13,13 @@ <% if @user %> <% if @user == current_user %>
-
  • <%= link_to image_tag("new.png", :class => "small_icon", :border => 0) + t(".new"), diary_new_path, :title => t(".new_title") %>
  • +
  • <%= link_to image_tag("new.png", :class => "small_icon", :border => 0) + t(".new"), new_diary_entry_path, :title => t(".new_title") %>
  • <% end %> <% else %> <% if current_user %>
    -
  • <%= link_to image_tag("new.png", :class => "small_icon", :border => 0) + t(".new"), diary_new_path, :title => t(".new_title") %>
  • +
  • <%= link_to image_tag("new.png", :class => "small_icon", :border => 0) + t(".new"), new_diary_entry_path, :title => t(".new_title") %>
  • <% end %> <% end %> diff --git a/app/views/diary_entries/new.html.erb b/app/views/diary_entries/new.html.erb new file mode 100644 index 000000000..dfe69f22a --- /dev/null +++ b/app/views/diary_entries/new.html.erb @@ -0,0 +1,13 @@ +<% content_for :head do %> + <%= javascript_include_tag "diary_entry" %> +<% end %> + +<% content_for :heading do %> +

    <%= @title %>

    +<% end %> + +<%= error_messages_for "diary_entry" %> + +<%= form_for @diary_entry do |f| %> + <%= render :partial => "form", :locals => { :f => f } %> +<% end %> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index a2a63b406..725000a13 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -49,7 +49,7 @@ <% end %>
  • <%= link_to t("layouts.gps_traces"), traces_path %>
  • -
  • <%= link_to t("layouts.user_diaries"), diary_path %>
  • +
  • <%= link_to t("layouts.user_diaries"), diary_entries_path %>
  • <%= link_to t("layouts.copyright"), copyright_path %>
  • <%= link_to t("layouts.help"), help_path %>
  • <%= link_to t("layouts.about"), about_path %>
  • @@ -65,7 +65,7 @@ <% end %>
  • <%= link_to t("layouts.gps_traces"), traces_path %>
  • -
  • <%= link_to t("layouts.user_diaries"), diary_path %>
  • +
  • <%= link_to t("layouts.user_diaries"), diary_entries_path %>
  • <%= link_to t("layouts.copyright"), copyright_path %>
  • <%= link_to t("layouts.help"), help_path %>
  • <%= link_to t("layouts.about"), about_path %>
  • diff --git a/app/views/site/about.html.erb b/app/views/site/about.html.erb index 219e0ab6b..886aaf006 100644 --- a/app/views/site/about.html.erb +++ b/app/views/site/about.html.erb @@ -17,7 +17,7 @@

    <%= t ".community_driven_title" %>

    -

    <%= t ".community_driven_html", :diary_path => diary_path %>

    +

    <%= t ".community_driven_html", :diary_path => diary_entries_path %>

    diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 5090cbee0..87eb9b45f 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -205,7 +205,7 @@ <% else %>
    <%= render :partial => "contact", :collection => friends, :locals => { :type => "friend" } %> @@ -221,7 +221,7 @@ <% else %>
    • <%= link_to t(".nearby_changesets"), nearby_changesets_path %>
    • -
    • <%= link_to t(".nearby_diaries"), nearby_diaries_path %>
    • +
    • <%= link_to t(".nearby_diaries"), nearby_diary_entries_path %>
    <%= render :partial => "contact", :collection => nearby, :locals => { :type => "nearby mapper" } %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 575c361bb..ec6591226 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5,6 +5,11 @@ en: formats: friendly: "%e %B %Y at %H:%M" blog: "%e %B %Y" + helpers: + submit: + diary_entry: + create: "Publish" + update: "Update" activerecord: errors: messages: @@ -282,7 +287,14 @@ en: diary_entries: new: title: New Diary Entry - publish_button: "Publish" + form: + subject: "Subject:" + body: "Body:" + language: "Language:" + location: "Location:" + latitude: "Latitude:" + longitude: "Longitude:" + use_map_link: "use map" index: title: "Users' diaries" title_friends: "Friends' diaries" @@ -296,15 +308,7 @@ en: older_entries: Older Entries newer_entries: Newer Entries edit: - title: "Edit diary entry" - subject: "Subject:" - body: "Body:" - language: "Language:" - location: "Location:" - latitude: "Latitude:" - longitude: "Longitude:" - use_map_link: "use map" - save_button: "Save" + title: Edit Diary Entry marker_text: Diary entry location show: title: "%{user}'s diary | %{title}" diff --git a/config/routes.rb b/config/routes.rb index 198932583..63ce06167 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -216,9 +216,12 @@ OpenStreetMap::Application.routes.draw do post "/trace/:id/delete" => "traces#delete", :id => /\d+/ # diary pages - match "/diary/new" => "diary_entries#new", :via => [:get, :post] - get "/diary/friends" => "diary_entries#index", :friends => true, :as => "friend_diaries" - get "/diary/nearby" => "diary_entries#index", :nearby => true, :as => "nearby_diaries" + resources :diary_entries, :path => "diary", :only => [:new, :create, :index] do + collection do + get "friends" => "diary_entries#index", :friends => true + get "nearby" => "diary_entries#index", :nearby => true + end + end get "/user/:display_name/diary/rss" => "diary_entries#rss", :defaults => { :format => :rss } get "/diary/:language/rss" => "diary_entries#rss", :defaults => { :format => :rss } get "/diary/rss" => "diary_entries#rss", :defaults => { :format => :rss } @@ -226,10 +229,10 @@ OpenStreetMap::Application.routes.draw do get "/user/:display_name/diary/comments/" => "diary_entries#comments" get "/user/:display_name/diary" => "diary_entries#index" get "/diary/:language" => "diary_entries#index" - get "/diary" => "diary_entries#index" - get "/user/:display_name/diary/:id" => "diary_entries#show", :id => /\d+/, :as => :diary_entry + scope "/user/:display_name" do + resources :diary_entries, :path => "diary", :only => [:edit, :update, :show] + end post "/user/:display_name/diary/:id/newcomment" => "diary_entries#comment", :id => /\d+/ - match "/user/:display_name/diary/:id/edit" => "diary_entries#edit", :via => [:get, :post], :id => /\d+/ post "/user/:display_name/diary/:id/hide" => "diary_entries#hide", :id => /\d+/, :as => :hide_diary_entry post "/user/:display_name/diary/:id/hidecomment/:comment" => "diary_entries#hidecomment", :id => /\d+/, :comment => /\d+/, :as => :hide_diary_comment post "/user/:display_name/diary/:id/subscribe" => "diary_entries#subscribe", :as => :diary_entry_subscribe, :id => /\d+/ diff --git a/config/settings.yml b/config/settings.yml index 6031f0654..51d3ed2c9 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -57,6 +57,8 @@ nearby_users: 30 nearby_radius: 50 # Spam threshold spam_threshold: 50 +# Delay diary entries from appearing in the feed for this many hours +diary_feed_delay: 0 # Default legale (jurisdiction location) for contributor terms default_legale: GB # Use the built-in jobs queue for importing traces diff --git a/config/settings/test.yml b/config/settings/test.yml index 022c93246..e9a506c41 100644 --- a/config/settings/test.yml +++ b/config/settings/test.yml @@ -1,6 +1,8 @@ # Trace directories for testing gpx_trace_dir: <%= Rails.root.join("test", "gpx", "traces") %> gpx_image_dir: <%= Rails.root.join("test", "gpx", "images") %> +# Ignore the diary feed delay unless we're specifically testing it +diary_feed_delay: 0 # Geonames credentials for testing geonames_username: "dummy" # External authentication credentials for testing diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index b1f2216c7..71684c65e 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -62,8 +62,8 @@ class DiaryEntriesControllerTest < ActionController::TestCase { :controller => "diary_entries", :action => "new" } ) assert_routing( - { :path => "/diary/new", :method => :post }, - { :controller => "diary_entries", :action => "new" } + { :path => "/diary", :method => :post }, + { :controller => "diary_entries", :action => "create" } ) assert_routing( { :path => "/user/username/diary/1", :method => :get }, @@ -74,8 +74,8 @@ class DiaryEntriesControllerTest < ActionController::TestCase { :controller => "diary_entries", :action => "edit", :display_name => "username", :id => "1" } ) assert_routing( - { :path => "/user/username/diary/1/edit", :method => :post }, - { :controller => "diary_entries", :action => "edit", :display_name => "username", :id => "1" } + { :path => "/user/username/diary/1", :method => :put }, + { :controller => "diary_entries", :action => "update", :display_name => "username", :id => "1" } ) assert_routing( { :path => "/user/username/diary/1/newcomment", :method => :post }, @@ -116,7 +116,7 @@ class DiaryEntriesControllerTest < ActionController::TestCase assert_select "h1", :text => /New Diary Entry/, :count => 1 end assert_select "div#content", :count => 1 do - assert_select "form[action='/diary/new'][method=post]", :count => 1 do + assert_select "form[action='/diary'][method=post]", :count => 1 do assert_select "input#diary_entry_title[name='diary_entry[title]']", :count => 1 assert_select "textarea#diary_entry_body[name='diary_entry[body]']", :text => "", :count => 1 assert_select "select#diary_entry_language_code", :count => 1 @@ -140,30 +140,30 @@ class DiaryEntriesControllerTest < ActionController::TestCase :session => { :user => create(:user).id } end assert_response :success - assert_template :edit + assert_template :new end - def test_new_no_body + def test_create_no_body # Now try creating a invalid diary entry with an empty body user = create(:user) assert_no_difference "DiaryEntry.count" do - post :new, + post :create, :params => { :commit => "save", :diary_entry => { :title => "New Title", :body => "", :latitude => "1.1", :longitude => "2.2", :language_code => "en" } }, :session => { :user => user.id } end assert_response :success - assert_template :edit + assert_template :new assert_nil UserPreference.where(:user_id => user.id, :k => "diary.default_language").first end - def test_new_post + def test_create # Now try creating a diary entry user = create(:user) assert_difference "DiaryEntry.count", 1 do - post :new, + post :create, :params => { :commit => "save", :diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1", :longitude => "2.2", :language_code => "en" } }, @@ -185,13 +185,13 @@ class DiaryEntriesControllerTest < ActionController::TestCase assert_equal "en", UserPreference.where(:user_id => user.id, :k => "diary.default_language").first.v end - def test_new_german + def test_create_german create(:language, :code => "de") user = create(:user) # Now try creating a diary entry in a different language assert_difference "DiaryEntry.count", 1 do - post :new, + post :create, :params => { :commit => "save", :diary_entry => { :title => "New Title", :body => "This is a new body for the diary entry", :latitude => "1.1", :longitude => "2.2", :language_code => "de" } }, @@ -221,7 +221,7 @@ class DiaryEntriesControllerTest < ActionController::TestCase # Try creating a spammy diary entry assert_difference "DiaryEntry.count", 1 do - post :new, + post :create, :params => { :commit => "save", :diary_entry => { :title => spammy_title, :body => spammy_body, :language_code => "en" } }, :session => { :user => user.id } @@ -279,21 +279,21 @@ class DiaryEntriesControllerTest < ActionController::TestCase :params => { :display_name => entry.user.display_name, :id => entry.id }, :session => { :user => entry.user } assert_response :success - assert_select "title", :text => /Edit diary entry/, :count => 1 + assert_select "title", :text => /Edit Diary Entry/, :count => 1 assert_select "div.content-heading", :count => 1 do - assert_select "h1", :text => /Edit diary entry/, :count => 1 + assert_select "h1", :text => /Edit Diary Entry/, :count => 1 end assert_select "div#content", :count => 1 do - assert_select "form[action='/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}/edit'][method=post]", :count => 1 do + assert_select "form[action='/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}'][method=post]", :count => 1 do assert_select "input#diary_entry_title[name='diary_entry[title]'][value='#{entry.title}']", :count => 1 assert_select "textarea#diary_entry_body[name='diary_entry[body]']", :text => entry.body, :count => 1 assert_select "select#diary_entry_language_code", :count => 1 assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1 assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1 - assert_select "input[name=commit][type=submit][value=Save]", :count => 1 + assert_select "input[name=commit][type=submit][value=Update]", :count => 1 assert_select "input[name=commit][type=submit][value=Edit]", :count => 1 assert_select "input[name=commit][type=submit][value=Preview]", :count => 1 - assert_select "input", :count => 7 + assert_select "input", :count => 8 end end @@ -303,11 +303,11 @@ class DiaryEntriesControllerTest < ActionController::TestCase new_latitude = "1.1" new_longitude = "2.2" new_language_code = "en" - post :edit, - :params => { :display_name => entry.user.display_name, :id => entry.id, :commit => "save", - :diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude, - :longitude => new_longitude, :language_code => new_language_code } }, - :session => { :user => entry.user.id } + put :update, + :params => { :display_name => entry.user.display_name, :id => entry.id, :commit => "save", + :diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude, + :longitude => new_longitude, :language_code => new_language_code } }, + :session => { :user => entry.user.id } assert_response :redirect assert_redirected_to :action => :show, :display_name => entry.user.display_name, :id => entry.id @@ -664,6 +664,18 @@ class DiaryEntriesControllerTest < ActionController::TestCase assert_match "<script>", response.body end + def test_feed_delay + create(:diary_entry, :created_at => 7.hours.ago) + create(:diary_entry, :created_at => 5.hours.ago) + get :rss, :params => { :format => :rss } + assert_select "rss>channel>item", :count => 2 + + with_diary_feed_delay(6) do + get :rss, :params => { :format => :rss } + assert_select "rss>channel>item", :count => 1 + end + end + def test_show user = create(:user) suspended_user = create(:user, :suspended) @@ -897,4 +909,13 @@ class DiaryEntriesControllerTest < ActionController::TestCase assert_select "a[href=?]", "/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}" end end + + def with_diary_feed_delay(value) + diary_feed_delay = Settings.diary_feed_delay + Settings.diary_feed_delay = value + + yield + + Settings.diary_feed_delay = diary_feed_delay + end end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index df2e7d8f5..5dbd866a9 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -445,34 +445,34 @@ class UsersControllerTest < ActionController::TestCase def test_confirm_success_no_token_with_referer user = create(:user, :pending) stub_gravatar_request(user.email) - confirm_string = user.tokens.create(:referer => diary_new_path).token + confirm_string = user.tokens.create(:referer => new_diary_entry_path).token @request.cookies["_osm_session"] = user.display_name post :confirm, :params => { :display_name => user.display_name, :confirm_string => confirm_string } - assert_redirected_to login_path(:referer => diary_new_path) + assert_redirected_to login_path(:referer => new_diary_entry_path) assert_match(/Confirmed your account/, flash[:notice]) end def test_confirm_success_good_token_with_referer user = create(:user, :pending) stub_gravatar_request(user.email) - confirm_string = user.tokens.create(:referer => diary_new_path).token + confirm_string = user.tokens.create(:referer => new_diary_entry_path).token token = user.tokens.create.token @request.cookies["_osm_session"] = user.display_name post :confirm, :params => { :display_name => user.display_name, :confirm_string => confirm_string }, :session => { :token => token } - assert_redirected_to diary_new_path + assert_redirected_to new_diary_entry_path end def test_confirm_success_bad_token_with_referer user = create(:user, :pending) stub_gravatar_request(user.email) - confirm_string = user.tokens.create(:referer => diary_new_path).token + confirm_string = user.tokens.create(:referer => new_diary_entry_path).token token = create(:user).tokens.create.token @request.cookies["_osm_session"] = user.display_name post :confirm, :params => { :display_name => user.display_name, :confirm_string => confirm_string }, :session => { :token => token } - assert_redirected_to login_path(:referer => diary_new_path) + assert_redirected_to login_path(:referer => new_diary_entry_path) assert_match(/Confirmed your account/, flash[:notice]) end @@ -488,7 +488,7 @@ class UsersControllerTest < ActionController::TestCase def test_confirm_already_confirmed user = create(:user) - confirm_string = user.tokens.create(:referer => diary_new_path).token + confirm_string = user.tokens.create(:referer => new_diary_entry_path).token @request.cookies["_osm_session"] = user.display_name post :confirm, :params => { :display_name => user.display_name, :confirm_string => confirm_string } diff --git a/test/integration/user_diaries_test.rb b/test/integration/user_diaries_test.rb index 026028d5f..e090342c1 100644 --- a/test/integration/user_diaries_test.rb +++ b/test/integration/user_diaries_test.rb @@ -29,7 +29,7 @@ class UserDiariesTest < ActionDispatch::IntegrationTest follow_redirect! assert_response :success - assert_template "diary_entries/edit" + assert_template "diary_entries/new" # print @response.body # print @html_document.to_yaml @@ -42,7 +42,7 @@ class UserDiariesTest < ActionDispatch::IntegrationTest assert_select "h1", "New Diary Entry" end assert_select "div#content" do - assert_select "form[action='/diary/new']" do + assert_select "form[action='/diary']" do assert_select "input[id=diary_entry_title]" end end diff --git a/test/system/diary_entry_test.rb b/test/system/diary_entry_test.rb index 39ccc04b2..6b6a51de5 100644 --- a/test/system/diary_entry_test.rb +++ b/test/system/diary_entry_test.rb @@ -8,7 +8,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase test "reply to diary entry should prefill the message subject" do sign_in_as(create(:user)) - visit diary_path + visit diary_entries_path click_on "Reply to this entry"