From: Tom Hughes Date: Tue, 5 Feb 2013 19:03:28 +0000 (+0000) Subject: Merge branch 'master' into notes X-Git-Tag: live~5677^2~20 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/8090e086daad67eac711ad6fd6a5eba6f28d44fd?hp=a5ca0f48c1fd2d5693ce8c3435de97facb130cf5 Merge branch 'master' into notes --- diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index f218ea6bb..12f3fdcc8 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -70,6 +70,8 @@ class DiaryEntryController < ApplicationController else render :action => 'view' end + rescue ActiveRecord::RecordNotFound + render :action => "no_such_entry", :status => :not_found end def list diff --git a/app/controllers/message_controller.rb b/app/controllers/message_controller.rb index c6a269a06..8d03811a9 100644 --- a/app/controllers/message_controller.rb +++ b/app/controllers/message_controller.rb @@ -100,11 +100,9 @@ class MessageController < ApplicationController notice = t 'message.mark.as_read' end @message.message_read = message_read - if @message.save - if not request.xhr? - flash[:notice] = notice - redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name - end + if @message.save and not request.xhr? + flash[:notice] = notice + redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name end rescue ActiveRecord::RecordNotFound @title = t'message.no_such_message.title' @@ -113,10 +111,10 @@ class MessageController < ApplicationController # Delete the message. def delete - message = Message.where("to_user_id = ? OR from_user_id = ?", @user.id, @user.id).find(params[:message_id]) - message.from_user_visible = false if message.sender == @user - message.to_user_visible = false if message.recipient == @user - if message.save + @message = Message.where("to_user_id = ? OR from_user_id = ?", @user.id, @user.id).find(params[:message_id]) + @message.from_user_visible = false if @message.sender == @user + @message.to_user_visible = false if @message.recipient == @user + if @message.save and not request.xhr? flash[:notice] = t 'message.delete.deleted' if params[:referer] diff --git a/app/views/message/_message_summary.html.erb b/app/views/message/_message_summary.html.erb index 26001c0bd..ffdfd6c38 100644 --- a/app/views/message/_message_summary.html.erb +++ b/app/views/message/_message_summary.html.erb @@ -4,5 +4,5 @@ <%= l message_summary.sent_on, :format => :friendly %> <%= button_to t('message.message_summary.unread_button'), {:controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'unread'}, { :remote => true } %> <%= button_to t('message.message_summary.read_button'), {:controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'read'}, { :remote => true } %> - <%= button_to t('message.message_summary.delete_button'), :controller => 'message', :action => 'delete', :message_id => message_summary.id, :referer => request.fullpath %> + <%= button_to t('message.message_summary.delete_button'), {:controller => 'message', :action => 'delete', :message_id => message_summary.id, :referer => request.fullpath}, { :remote => true } %> diff --git a/app/views/message/delete.js.erb b/app/views/message/delete.js.erb new file mode 100644 index 000000000..86677ab4a --- /dev/null +++ b/app/views/message/delete.js.erb @@ -0,0 +1,5 @@ +$("#inboxanchor").replaceWith("<%=j render :partial => "layouts/inbox" %>"); +$("#inbox-count").replaceWith("<%=j render :partial => "message_count" %>"); +$("#inbox-<%= @message.id %>").fadeOut(800, "linear", function () { + $(this).remove(); +}); diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb deleted file mode 100644 index 7d41cb641..000000000 --- a/config/initializers/secret_token.rb +++ /dev/null @@ -1,7 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -OpenStreetMap::Application.config.secret_token = '67881c9e6670d9b55b43885ea8eab34e32865ce436bdbde73e1967a11a26674906736de0aa1a0d24edf8ebcb653e1735413e6fd24e1201338e397d4a2392c614' diff --git a/config/locales/en.yml b/config/locales/en.yml index 0679e1325..3ff65904d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1264,14 +1264,12 @@ en: wrong_user: "You are logged in as `%{user}' but the message you have asked to reply to was not sent to that user. Please login as the correct user in order to reply." read: title: "Read message" - reading_your_messages: "Reading your messages" from: "From" subject: "Subject" date: "Date" reply_button: "Reply" unread_button: "Mark as unread" back_to_inbox: "Back to inbox" - reading_your_sent_messages: "Reading your sent messages" to: "To" back_to_outbox: "Back to outbox" wrong_user: "You are logged in as `%{user}' but the message you have asked to read was not sent by or to that user. Please login as the correct user in order to read it." diff --git a/script/deliver-message b/script/deliver-message index 3fd641f8d..e713b2cfc 100755 --- a/script/deliver-message +++ b/script/deliver-message @@ -7,16 +7,19 @@ exit 0 unless recipient = ARGV[0].match(/^([cm])-(\d+)-(.*)$/) if recipient[1] == "c" comment = DiaryComment.find(recipient[2]) digest = comment.digest + date = diary_comment.created_at from = comment.diary_entry.user to = comment.user else message = Message.find(recipient[2]) digest = message.digest + date = message.sent_on from = message.recipient to = message.sender end exit 0 unless recipient[3] == digest[0,6] +exit 0 if date < 1.month.ago message.update_attribute(:message_read, true) if message diff --git a/test/functional/diary_entry_controller_test.rb b/test/functional/diary_entry_controller_test.rb index 6a51cb142..5d0cb93ac 100644 --- a/test/functional/diary_entry_controller_test.rb +++ b/test/functional/diary_entry_controller_test.rb @@ -259,11 +259,115 @@ class DiaryEntryControllerTest < ActionController::TestCase end def test_create_diary_entry - #post :new + @request.cookies["_osm_username"] = users(:normal_user).display_name + + # Make sure that you are redirected to the login page when you + # are not logged in + get :new + assert_response :redirect + assert_redirected_to :controller => :user, :action => :login, :referer => "/diary/new" + + # Now try again when logged in + get :new, {}, {:user => users(:normal_user).id} + assert_response :success + assert_select "html", :count => 1 do + assert_select "head", :count => 1 do + assert_select "title", :text => /New Diary Entry/, :count => 1 + end + assert_select "body", :count => 1 do + assert_select "div.wrapper", :count => 1 do + assert_select "div.content-heading", :count => 1 do + 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 "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 + 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=Edit]", :count => 1 + assert_select "input[name=commit][type=submit][value=Preview]", :count => 1 + assert_select "input", :count => 7 + end + end + end + end + end + + # Now try creating a diary entry + new_title = "New Title" + new_body = "This is a new body for the diary entry" + new_latitude = "1.1" + new_longitude = "2.2" + new_language_code = "en" + assert_difference "DiaryEntry.count", 1 do + post(:new, {'commit' => 'save', + 'diary_entry'=>{'title' => new_title, 'body' => new_body, 'latitude' => new_latitude, + 'longitude' => new_longitude, 'language_code' => new_language_code} }, + {:user => users(:normal_user).id}) + end + assert_response :redirect + assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name + entry = DiaryEntry.find(4) + assert_equal users(:normal_user).id, entry.user_id + assert_equal new_title, entry.title + assert_equal new_body, entry.body + assert_equal new_latitude.to_f, entry.latitude + assert_equal new_longitude.to_f, entry.longitude + assert_equal new_language_code, entry.language_code end def test_creating_diary_comment + @request.cookies["_osm_username"] = users(:public_user).display_name + entry = diary_entries(:normal_user_entry_1) + + # Make sure that you are denied when you are not logged in + post :comment, :display_name => entry.user.display_name, :id => entry.id + assert_response :forbidden + # Verify that you get a not found error, when you pass a bogus id + post :comment, {:display_name => entry.user.display_name, :id => 9999}, {:user => users(:public_user).id} + assert_response :not_found + assert_select "html", :count => 1 do + assert_select "body", :count => 1 do + assert_select "div.wrapper", :count => 1 do + assert_select "div.content-heading", :count => 1 do + assert_select "h2", :text => "No entry with the id: 9999", :count => 1 + end + end + end + end + + # Now try again with the right id + assert_difference "ActionMailer::Base.deliveries.size", 1 do + assert_difference "DiaryComment.count", 1 do + post :comment, {:display_name => entry.user.display_name, :id => entry.id, :diary_comment => {:body => "New comment"}}, {:user => users(:public_user).id} + end + end + assert_response :redirect + assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id + email = ActionMailer::Base.deliveries.first + assert_equal [ users(:normal_user).email ], email.to + assert_equal "[OpenStreetMap] #{users(:public_user).display_name} commented on your diary entry", email.subject + assert_match /New comment/, email.text_part.decoded + assert_match /New comment/, email.html_part.decoded + ActionMailer::Base.deliveries.clear + comment = DiaryComment.find(4) + assert_equal entry.id, comment.diary_entry_id + assert_equal users(:public_user).id, comment.user_id + assert_equal "New comment", comment.body + + # Now view the diary entry, and check the new comment is present + get :view, :display_name => entry.user.display_name, :id => entry.id + assert_response :success + assert_select ".diary-comment", :count => 1 do + assert_select "#comment4", :count => 1 do + assert_select "a[href='/user/#{users(:public_user).display_name}']", :text => users(:public_user).display_name, :count => 1 + end + assert_select ".richtext", :text => /New comment/, :count => 1 + end end # Check that you can get the expected response and template for all available languages