From d3ed5d2963ce38488bbbacaf147cdca9c356f8ce Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Thu, 11 Dec 2008 18:35:50 -0300 Subject: [PATCH] ActionItem628: send message in last language useb by user --- app/controllers/public/account_controller.rb | 2 ++ app/models/person.rb | 9 +++++++++ script/task-notifier | 3 +++ test/functional/account_controller_test.rb | 21 +++++++++++++++++++++ test/unit/person_test.rb | 11 +++++++++++ 5 files changed, 46 insertions(+), 0 deletions(-) diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 92aff3c..627f96b 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -17,6 +17,7 @@ class AccountController < ApplicationController return unless request.post? self.current_user = User.authenticate(params[:user][:login], params[:user][:password]) if params[:user] if logged_in? + self.current_user.person.update_attribute(:last_lang, cookies[:lang]) if params[:remember_me] == "1" self.current_user.remember_me cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } @@ -60,6 +61,7 @@ class AccountController < ApplicationController # action to perform logout from the application def logout + self.current_user.person.update_attribute(:last_lang, cookies[:lang]) self.current_user.forget_me if logged_in? cookies.delete :auth_token reset_session diff --git a/app/models/person.rb b/app/models/person.rb index 8f10edf..bd039b3 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -12,6 +12,15 @@ class Person < Profile Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } end + settings_items :last_lang, :type => :string + def last_lang + if self.data[:last_lang].nil? or self.data[:last_lang].empty? + Noosfero.default_locale + else + self.data[:last_lang] + end + end + def suggested_friend_groups (friend_groups + [ _('friends'), _('work'), _('school'), _('family') ]).map {|i| i if !i.empty?}.compact.uniq end diff --git a/script/task-notifier b/script/task-notifier index 2009c1f..d515be5 100755 --- a/script/task-notifier +++ b/script/task-notifier @@ -1,9 +1,12 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/environment' +include GetText +ActionController::Base.init_gettext 'noosfero' # when in production set RAILS_ENV to 'production' Person.with_pending_tasks.each do |p| + set_locale_all p.last_lang PendingTaskNotifier.deliver_notification(p) RAILS_DEFAULT_LOGGER.info('deliver notification for ' + p.identifier) end diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 832b324..1f8cb8b 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -279,6 +279,27 @@ class AccountControllerTest < Test::Unit::TestCase assert_redirected_to :controller => 'profile_editor' end + should 'save last lang after logout' do + user = create_user('save_lang').person + assert user.update_attribute(:last_lang, 'unknow') + assert_equal 'unknow', user.last_lang + login_as user.identifier + get :logout + user.reload + assert_not_equal 'unknow', user.last_lang + assert_equal @response.cookies[:lang], user.last_lang + end + + should 'save last lang after login' do + user = create_user('save_lang').person + assert user.update_attribute(:last_lang, 'unknow') + assert_equal 'unknow', user.last_lang + + post :login, :user => {:login => 'save_lang', :password => 'save_lang'} + + assert_not_equal 'unknow', Person['save_lang'].last_lang + end + ################################ # # # Enterprise activation tests # diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 30f6db6..ea1cba4 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -376,4 +376,15 @@ class PersonTest < Test::Unit::TestCase assert_equal p.pending_tasks_for_organization(c), c.tasks end + should 'has default locale as last lang' do + p = create_user('user_lang_test').person + assert_equal Noosfero.default_locale, p.last_lang + end + + should 'be able to change last lang' do + p = create_user('user_lang_test').person + assert p.update_attribute(:last_lang, 'pt_BR') + assert_equal 'pt_BR', Person['user_lang_test'].last_lang + end + end -- libgit2 0.21.2