Commit d3ed5d2963ce38488bbbacaf147cdca9c356f8ce
Committed by
Antonio Terceiro
1 parent
e9c01b00
Exists in
staging
and in
42 other branches
ActionItem628: send message in last language useb by user
Showing
5 changed files
with
46 additions
and
0 deletions
Show diff stats
app/controllers/public/account_controller.rb
| @@ -17,6 +17,7 @@ class AccountController < ApplicationController | @@ -17,6 +17,7 @@ class AccountController < ApplicationController | ||
| 17 | return unless request.post? | 17 | return unless request.post? |
| 18 | self.current_user = User.authenticate(params[:user][:login], params[:user][:password]) if params[:user] | 18 | self.current_user = User.authenticate(params[:user][:login], params[:user][:password]) if params[:user] |
| 19 | if logged_in? | 19 | if logged_in? |
| 20 | + self.current_user.person.update_attribute(:last_lang, cookies[:lang]) | ||
| 20 | if params[:remember_me] == "1" | 21 | if params[:remember_me] == "1" |
| 21 | self.current_user.remember_me | 22 | self.current_user.remember_me |
| 22 | cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } | 23 | cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } |
| @@ -60,6 +61,7 @@ class AccountController < ApplicationController | @@ -60,6 +61,7 @@ class AccountController < ApplicationController | ||
| 60 | 61 | ||
| 61 | # action to perform logout from the application | 62 | # action to perform logout from the application |
| 62 | def logout | 63 | def logout |
| 64 | + self.current_user.person.update_attribute(:last_lang, cookies[:lang]) | ||
| 63 | self.current_user.forget_me if logged_in? | 65 | self.current_user.forget_me if logged_in? |
| 64 | cookies.delete :auth_token | 66 | cookies.delete :auth_token |
| 65 | reset_session | 67 | reset_session |
app/models/person.rb
| @@ -12,6 +12,15 @@ class Person < Profile | @@ -12,6 +12,15 @@ class Person < Profile | ||
| 12 | Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } | 12 | Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } |
| 13 | end | 13 | end |
| 14 | 14 | ||
| 15 | + settings_items :last_lang, :type => :string | ||
| 16 | + def last_lang | ||
| 17 | + if self.data[:last_lang].nil? or self.data[:last_lang].empty? | ||
| 18 | + Noosfero.default_locale | ||
| 19 | + else | ||
| 20 | + self.data[:last_lang] | ||
| 21 | + end | ||
| 22 | + end | ||
| 23 | + | ||
| 15 | def suggested_friend_groups | 24 | def suggested_friend_groups |
| 16 | (friend_groups + [ _('friends'), _('work'), _('school'), _('family') ]).map {|i| i if !i.empty?}.compact.uniq | 25 | (friend_groups + [ _('friends'), _('work'), _('school'), _('family') ]).map {|i| i if !i.empty?}.compact.uniq |
| 17 | end | 26 | end |
script/task-notifier
| 1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
| 2 | require File.dirname(__FILE__) + '/../config/environment' | 2 | require File.dirname(__FILE__) + '/../config/environment' |
| 3 | +include GetText | ||
| 4 | +ActionController::Base.init_gettext 'noosfero' | ||
| 3 | 5 | ||
| 4 | # when in production set RAILS_ENV to 'production' | 6 | # when in production set RAILS_ENV to 'production' |
| 5 | 7 | ||
| 6 | Person.with_pending_tasks.each do |p| | 8 | Person.with_pending_tasks.each do |p| |
| 9 | + set_locale_all p.last_lang | ||
| 7 | PendingTaskNotifier.deliver_notification(p) | 10 | PendingTaskNotifier.deliver_notification(p) |
| 8 | RAILS_DEFAULT_LOGGER.info('deliver notification for ' + p.identifier) | 11 | RAILS_DEFAULT_LOGGER.info('deliver notification for ' + p.identifier) |
| 9 | end | 12 | end |
test/functional/account_controller_test.rb
| @@ -279,6 +279,27 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -279,6 +279,27 @@ class AccountControllerTest < Test::Unit::TestCase | ||
| 279 | assert_redirected_to :controller => 'profile_editor' | 279 | assert_redirected_to :controller => 'profile_editor' |
| 280 | end | 280 | end |
| 281 | 281 | ||
| 282 | + should 'save last lang after logout' do | ||
| 283 | + user = create_user('save_lang').person | ||
| 284 | + assert user.update_attribute(:last_lang, 'unknow') | ||
| 285 | + assert_equal 'unknow', user.last_lang | ||
| 286 | + login_as user.identifier | ||
| 287 | + get :logout | ||
| 288 | + user.reload | ||
| 289 | + assert_not_equal 'unknow', user.last_lang | ||
| 290 | + assert_equal @response.cookies[:lang], user.last_lang | ||
| 291 | + end | ||
| 292 | + | ||
| 293 | + should 'save last lang after login' do | ||
| 294 | + user = create_user('save_lang').person | ||
| 295 | + assert user.update_attribute(:last_lang, 'unknow') | ||
| 296 | + assert_equal 'unknow', user.last_lang | ||
| 297 | + | ||
| 298 | + post :login, :user => {:login => 'save_lang', :password => 'save_lang'} | ||
| 299 | + | ||
| 300 | + assert_not_equal 'unknow', Person['save_lang'].last_lang | ||
| 301 | + end | ||
| 302 | + | ||
| 282 | ################################ | 303 | ################################ |
| 283 | # # | 304 | # # |
| 284 | # Enterprise activation tests # | 305 | # Enterprise activation tests # |
test/unit/person_test.rb
| @@ -376,4 +376,15 @@ class PersonTest < Test::Unit::TestCase | @@ -376,4 +376,15 @@ class PersonTest < Test::Unit::TestCase | ||
| 376 | assert_equal p.pending_tasks_for_organization(c), c.tasks | 376 | assert_equal p.pending_tasks_for_organization(c), c.tasks |
| 377 | end | 377 | end |
| 378 | 378 | ||
| 379 | + should 'has default locale as last lang' do | ||
| 380 | + p = create_user('user_lang_test').person | ||
| 381 | + assert_equal Noosfero.default_locale, p.last_lang | ||
| 382 | + end | ||
| 383 | + | ||
| 384 | + should 'be able to change last lang' do | ||
| 385 | + p = create_user('user_lang_test').person | ||
| 386 | + assert p.update_attribute(:last_lang, 'pt_BR') | ||
| 387 | + assert_equal 'pt_BR', Person['user_lang_test'].last_lang | ||
| 388 | + end | ||
| 389 | + | ||
| 379 | end | 390 | end |