diff options
-rw-r--r-- | app/controllers/application_controller.rb | 16 | ||||
-rw-r--r-- | app/models/track_mailer.rb | 4 | ||||
-rw-r--r-- | app/models/track_thing.rb | 16 | ||||
-rw-r--r-- | app/models/user.rb | 9 | ||||
-rw-r--r-- | app/models/user_mailer.rb | 2 | ||||
-rw-r--r-- | app/views/track_mailer/event_digest.rhtml | 12 | ||||
-rw-r--r-- | db/migrate/102_add_locale_to_users.rb | 11 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 1 | ||||
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 15 | ||||
-rw-r--r-- | spec/controllers/user_controller_spec.rb | 13 | ||||
-rw-r--r-- | spec/fixtures/users.yml | 3 | ||||
-rw-r--r-- | spec/models/track_mailer_spec.rb | 3 | ||||
-rw-r--r-- | vendor/plugins/action_mailer_layouts/CHANGELOG | 21 | ||||
-rw-r--r-- | vendor/plugins/action_mailer_layouts/README | 35 | ||||
-rw-r--r-- | vendor/plugins/action_mailer_layouts/init.rb | 7 | ||||
-rw-r--r-- | vendor/plugins/action_mailer_layouts/plugin.rb | 48 |
16 files changed, 84 insertions, 132 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6d14d0d7a..a2a628f10 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,8 +14,14 @@ class ApplicationController < ActionController::Base # Standard headers, footers and navigation for whole site layout "default" include FastGettext::Translation # make functions like _, n_, N_ etc available) + + # Note: a filter stops the chain if it redirects or renders something + before_filter :authentication_check before_filter :set_gettext_locale + before_filter :check_in_post_redirect + before_filter :session_remember_me before_filter :set_vary_header + # scrub sensitive parameters from the logs filter_parameter_logging :password @@ -48,7 +54,14 @@ class ApplicationController < ActionController::Base else requested_locale = params[:locale] || session[:locale] || cookies[:locale] || I18n.default_locale end + requested_locale = FastGettext.best_locale_in(requested_locale) session[:locale] = FastGettext.set_locale(requested_locale) + if !@user.nil? + if @user.locale != requested_locale + @user.locale = session[:locale] + @user.save! + end + end end # scrub sensitive parameters from the logs @@ -85,7 +98,6 @@ class ApplicationController < ActionController::Base # Set cookie expiry according to "remember me" checkbox, as per "An easier # and more flexible hack" on this page: # http://wiki.rubyonrails.org/rails/pages/HowtoChangeSessionOptions - before_filter :session_remember_me def session_remember_me # Reset the "sliding window" session expiry time. if request.env['rack.session.options'] @@ -263,7 +275,6 @@ class ApplicationController < ActionController::Base end # If we are in a faked redirect to POST request, then set post params. - before_filter :check_in_post_redirect def check_in_post_redirect if params[:post_redirect] and session[:post_redirect_token] post_redirect = PostRedirect.find_by_token(session[:post_redirect_token]) @@ -272,7 +283,6 @@ class ApplicationController < ActionController::Base end # Default layout shows user in corner, so needs access to it - before_filter :authentication_check def authentication_check if session[:user_id] @user = authenticated_user diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index 4b7c603a7..f8bef4d61 100644 --- a/app/models/track_mailer.rb +++ b/app/models/track_mailer.rb @@ -85,7 +85,11 @@ class TrackMailer < ApplicationMailer # If we have anything to send, then send everything for the user in one mail if email_about_things.size > 0 # Send the email + + previous_locale = I18n.locale + I18n.locale = user.get_locale TrackMailer.deliver_event_digest(user, email_about_things) + I18n.locale = previous_locale end # Record that we've now sent those alerts to that user diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index 06514dd4e..b74f7dad5 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -192,16 +192,16 @@ class TrackThing < ActiveRecord::Base if self.track_type == 'request_updates' @params = { # Website - :list_description => "'<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>', a request", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :list_description => _("'{{link_to_request}}', a request", :link_to_request => "<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how :verb_on_page => _("Track this request by email"), :verb_on_page_already => _("You are already tracking this request by email"), # Email - :title_in_email => "New updates for the request '" + self.info_request.title + "'", - :title_in_rss => "New updates for the request '" + self.info_request.title + "'", + :title_in_email => _("New updates for the request '{{request_title}}'", :request_title => self.info_request.title), + :title_in_rss => _("New updates for the request '{{request_title}}'", :request_title => self.info_request.title), # Authentication - :web => "To follow updates to the request '" + CGI.escapeHTML(self.info_request.title) + "'", - :email => "Then you will be emailed whenever the request '" + CGI.escapeHTML(self.info_request.title) + "' is updated.", - :email_subject => "Confirm you want to follow updates to the request '" + self.info_request.title + "'", + :web => _("To follow updates to the request '{{request_title}}'", :request_title => CGI.escapeHTML(self.info_request.title)), + :email => _("Then you will be emailed whenever the request '{{request_title}}' is updated.", :request_title => CGI.escapeHTML(self.info_request.title)), + :email_subject => _("Confirm you want to follow updates to the request '{{request_title}}'", :request_title => self.info_request.title), # RSS sorting :feed_sortby => 'newest' } @@ -243,7 +243,7 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'public_body_updates' @params = { # Website - :list_description => "'<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>', a public authority", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :list_description => _("'{{link_to_authority}}', a public authority", :link_to_authority => "<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how :verb_on_page => _("Track requests to {{public_body_name}} by email",:public_body_name=>CGI.escapeHTML(self.public_body.name)), :verb_on_page_already => _("You are already tracking requests to {{public_body_name}} by email", :public_body_name=>CGI.escapeHTML(self.public_body.name)), # Email @@ -259,7 +259,7 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'user_updates' @params = { # Website - :list_description => "'<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>', a person", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :list_description => _("'{{link_to_user}}', a person", :link_to_user => "<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how :verb_on_page => _("Track this person by email"), :verb_on_page_already => _("You are already tracking this person by email"), # Email diff --git a/app/models/user.rb b/app/models/user.rb index fddb6b035..c3c3da6f7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -96,6 +96,15 @@ class User < ActiveRecord::Base end end end + + def get_locale + if !self.locale.nil? + locale = self.locale + else + locale = I18n.locale + end + return locale.to_s + end def visible_comments self.comments.find(:all, :conditions => 'visible') diff --git a/app/models/user_mailer.rb b/app/models/user_mailer.rb index 0972e167d..7adf5b63c 100644 --- a/app/models/user_mailer.rb +++ b/app/models/user_mailer.rb @@ -46,7 +46,5 @@ class UserMailer < ApplicationMailer @body[:old_email] = old_email @body[:new_email] = new_email end - - end diff --git a/app/views/track_mailer/event_digest.rhtml b/app/views/track_mailer/event_digest.rhtml index 46f230da1..089b778f8 100644 --- a/app/views/track_mailer/event_digest.rhtml +++ b/app/views/track_mailer/event_digest.rhtml @@ -18,17 +18,17 @@ # e.g. Julian Burgess sent a request to Royal Mail Group (15 May 2008) if event.event_type == 'response' url = main_url(incoming_message_url(event.incoming_message)) - main_text += event.info_request.public_body.name + " sent a response to " + event.info_request.user.name + main_text += _("{{public_body}} sent a response to {{user_name}}", :public_body => event.info_request.public_body.name, :user_name => event.info_request.user.name) elsif event.event_type == 'followup_sent' url = main_url(outgoing_message_url(event.outgoing_message)) - main_text += event.info_request.user.name + " sent a follow up message to " + event.info_request.public_body.name + main_text += _("{{user_name}} sent a follow up message to {{public_body}}", :user_name => event.info_request.user.name, :public_body => event.info_request.public_body.name) elsif event.event_type == 'sent' # this is unlikely to happen in real life, but happens in the test code url = main_url(outgoing_message_url(event.outgoing_message)) - main_text += event.info_request.user.name + " sent a request to " + event.info_request.public_body.name + main_text += _("{{user_name}} sent a request to {{public_body}}", :user_name => event.info_request.user.name, :public_body => event.info_request.public_body.name) elsif event.event_type == 'comment' url = main_url(comment_url(event.comment)) - main_text += event.comment.user.name + " added an annotation" + main_text += _("{{user_name}} added an annotation", :user_name => event.comment.user.name) else raise "unknown type in event_digest " + event.event_type end @@ -57,10 +57,10 @@ main_text += "\n" end -%><%=main_text%>Alter your subscription +%><%=main_text%><%= _("Alter your subscription")%> ======================= -Please click on the link below to cancel or alter these emails. +<% _("Please click on the link below to cancel or alter these emails.") %> <%=@unsubscribe_url%> -- <%= _('the {{site_name}} team', :site_name=>site_name) %> diff --git a/db/migrate/102_add_locale_to_users.rb b/db/migrate/102_add_locale_to_users.rb new file mode 100644 index 000000000..a299a8561 --- /dev/null +++ b/db/migrate/102_add_locale_to_users.rb @@ -0,0 +1,11 @@ +class AddLocaleToUsers < ActiveRecord::Migration + def self.up + add_column :users, :locale, :string + end + def self.down + remove_column :users, :locale + end +end + + + diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index f3084af12..55b5fc5e3 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -450,6 +450,7 @@ describe RequestController, "when making a new request" do @user.stub!(:get_undescribed_requests).and_return([]) @user.stub!(:can_leave_requests_undescribed?).and_return(false) @user.stub!(:can_file_requests?).and_return(true) + @user.stub!(:locale).and_return("en") User.stub!(:find).and_return(@user) @body = mock_model(PublicBody, :id => 314, :eir_only? => false, :is_requestable? => true, :name => "Test Quango") diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 2f3f903f9..c3dc98a67 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -16,6 +16,7 @@ describe TrackController, "when making a new track on a request" do @user = mock_model(User) User.stub!(:find).and_return(@user) + @user.stub!(:locale).and_return("en") end it "should require login when making new track" do @@ -69,7 +70,6 @@ describe TrackController, "when sending alerts for a track" do mail.body.should include('added an annotation') # comment included mail.body.should =~ /This a the daftest comment the world has ever seen/ # comment text included - # Check subscription managing link # XXX We can't do this, as it is redirecting to another controller. I'm # apparently meant to be writing controller unit tests here, not functional @@ -93,6 +93,19 @@ describe TrackController, "when sending alerts for a track" do deliveries.size.should == 0 end + it "should send localised alerts" do + # set the time the comment event happened at to within the last week + ire = info_request_events(:silly_comment_event) + ire.created_at = Time.now - 3.days + ire.save! + user = users(:silly_name_user) + user.locale = "es" + user.save! + TrackMailer.alert_tracks + deliveries = ActionMailer::Base.deliveries + mail = deliveries[0] + mail.body.should include('el equipo de Alaveteli') + end end describe TrackController, "when viewing RSS feed for a track" do diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index e373c8df6..0ba542630 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -178,6 +178,19 @@ describe UserController, "when signing up" do deliveries[0].body.should include("not reveal your email") end + it "should send confirmation mail in other languages or different locales" do + session[:locale] = "es" + post :signup, {:user_signup => { :email => 'new@localhost', :name => 'New Person', + :password => 'sillypassword', :password_confirmation => 'sillypassword', + } + } + response.should render_template('confirm') + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + deliveries[0].body.should include("No revelaremos su dirección de correo") + end + it "should send special 'already signed up' mail if you fill the form in with existing registered email " do post :signup, { :user_signup => { :email => 'silly@localhost', :name => 'New Person', :password => 'sillypassword', :password_confirmation => 'sillypassword' } diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml index 2485c95a0..c54ac0985 100644 --- a/spec/fixtures/users.yml +++ b/spec/fixtures/users.yml @@ -10,6 +10,7 @@ bob_smith_user: email_confirmed: true admin_level: 'none' ban_text: '' + locale: 'en' about_me: 'I like making requests about fancy dogs and naughty chickens and stuff.' silly_name_user: id: "2" @@ -23,6 +24,7 @@ silly_name_user: email_confirmed: false admin_level: 'none' ban_text: '' + locale: 'en' about_me: '' admin_user: id: "3" @@ -36,4 +38,5 @@ admin_user: email_confirmed: false admin_level: 'super' ban_text: '' + locale: '' about_me: '' diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb index 828904d02..b90ca7e52 100644 --- a/spec/models/track_mailer_spec.rb +++ b/spec/models/track_mailer_spec.rb @@ -21,7 +21,8 @@ describe TrackMailer do @user = mock_model(User, :no_xapian_reindex= => false, :last_daily_track_email= => true, :save! => true, - :url_name => 'test-name') + :url_name => 'test-name', + :get_locale => 'en') User.stub!(:find).and_return([@user]) @user.stub!(:no_xapian_reindex=) end diff --git a/vendor/plugins/action_mailer_layouts/CHANGELOG b/vendor/plugins/action_mailer_layouts/CHANGELOG deleted file mode 100644 index 0b3f47667..000000000 --- a/vendor/plugins/action_mailer_layouts/CHANGELOG +++ /dev/null @@ -1,21 +0,0 @@ -2008-06-03 -* Added support for Rails 2.0 and 2.1. Thanks to Scott Windsor. - -2008-02-08 -* Added support for *.<format>.erb layouts and templates. Thanks to Eric Wollensen. - -2007-12-20 -* Fixed a bug present when specifying the layout with a string (eg: layout 'subdir/layout_template') in a multipart mail, which caused the plugin to only render one part and not the other. Thanks to Andres Koetsier. - -2007-12-12 -* Now works with Rails 2.0. - -2007-11-27 -* Now supports helpers defined in the mailer class. Thanks to Marshall Roch. - -2007-24-07 -* Now requires actionmailer-1.3.3. - -2007-05-07 -* No longer have to specify a :layout. The layout name is now inferred from the mailer class name. Thanks to Peter Boctor. -* Helper methods are now available to action mailer layouts. Thanks to Peter Boctor.
\ No newline at end of file diff --git a/vendor/plugins/action_mailer_layouts/README b/vendor/plugins/action_mailer_layouts/README deleted file mode 100644 index 92b19a69d..000000000 --- a/vendor/plugins/action_mailer_layouts/README +++ /dev/null @@ -1,35 +0,0 @@ -== Action Mailer Layouts - -Original Homepage: http://cardboardrocket.com/pages/action_mailer_layouts -Original svn: http://svn.cardboardrocket.com/action_mailer_layouts - -A plugin to enable layouts for ActionMailer templates. - -Adds a new 'layout' property to the ActionMailer::Base class. Specify the name -of the layout you want to use. The plugin will look in app/views/layouts for your -layout. If no layout is specified, the plugin will look for a layout that matches -the name of your mailer class. - -For example: - -If your mailer class is called UserNotifier and you are rendering the activation.rhtml -template, then the plugin will attempt to load the user_notifier.rhtml layout. If you are -rendering the activation.text.html.rhtml template, the plugin will look for the -user_notifier.text.html.rhtml layout. In other words, the plugin attempts to load the -layout named after the your ActionMailer class. - -You can overload this behavior by setting the layout property of your mailer: - -class UserNotfier < ActionMailer::Base - def activation(user) - @recipients = user.email - @from = 'you@domain.com' - @sent_on = Time.now - @subject = 'Activate your account!' - @layout = :email - end -end - -This arrangement will cause the plugin to render the content in -views/user_notifier/activation.text.html.rhtml in the views/layouts/email.text.html.rhtml -layout.
\ No newline at end of file diff --git a/vendor/plugins/action_mailer_layouts/init.rb b/vendor/plugins/action_mailer_layouts/init.rb deleted file mode 100644 index 8289c4eb9..000000000 --- a/vendor/plugins/action_mailer_layouts/init.rb +++ /dev/null @@ -1,7 +0,0 @@ -begin - require File.join(File.dirname(__FILE__), 'plugin.rb') - ActionController::Base.logger.fatal '** Loaded layouts plugin for ActionMailer' -rescue Exception => e - puts e.inspect - ActionController::Base.logger.fatal e if ActionController::Base.logger -end
\ No newline at end of file diff --git a/vendor/plugins/action_mailer_layouts/plugin.rb b/vendor/plugins/action_mailer_layouts/plugin.rb deleted file mode 100644 index ef0cbc37c..000000000 --- a/vendor/plugins/action_mailer_layouts/plugin.rb +++ /dev/null @@ -1,48 +0,0 @@ -module ActionMailer - class Base - - # Specify the layout name - adv_attr_accessor :layout - - alias_method :render_message_without_layouts, :render_message - - def render_message(method_name, body) - layout = @layout ? @layout.to_s.clone : self.class.to_s.underscore - - filename = if method_name.respond_to?(:filename) - method_name.filename - else - method_name - end - - md = /([^\.]+)\.([^\.]+\.[^\.]+)\.(erb|rhtml|rxml)$/.match(filename) - - layout << ".#{md.captures[1]}" if md && md.captures[1] - layout << ".#{md.captures[2]}" if md && md.captures[2] - - if File.exists?(File.join(layouts_path, layout)) - body[:content_for_layout] = render_message_without_layouts(method_name, body) - - # TODO: extract content_for blocks and somehow put them in body[:content_for_...] - - initialize_layout_template_class(body).render(:file => "/#{layout}") - else - render_message_without_layouts(method_name, body) - end - end - - def initialize_layout_template_class(assigns) - # for Rails 2.1 (and greater), we have to process view paths first! - ActionView::TemplateFinder.process_view_paths(layouts_path) if defined?(ActionView::TemplateFinder) - - returning(template = ActionView::Base.new(layouts_path, assigns, self)) do - template.extend self.class.master_helper_module - template.extend ActionView::Helpers::CaptureHelper - end - end - - def layouts_path - File.join(template_root, 'layouts') - end - end -end
\ No newline at end of file |