Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update how preferences work.

- Typus now uses default I18n.default_locale as the default language.
- We do not set_preferences after updating a user.
- Creating a new user automatically assigns I18n.default_locale.
  • Loading branch information...
commit f1166d6b51477d03b4b624ee386813504cb646cb 1 parent ab800cc
Francesc Esplugas authored
View
11 app/controllers/typus_controller.rb
@@ -23,11 +23,14 @@ class TypusController < ApplicationController
before_filter :verify_typus_users_table_schema
before_filter :reload_config_et_roles
+
before_filter :require_login,
:except => [ :sign_up, :sign_in, :sign_out,
:recover_password, :reset_password,
:quick_edit ]
+ before_filter :set_typus_preferences, :only => [ :dashboard ]
+
before_filter :check_if_user_can_perform_action_on_resource_without_model,
:except => [ :sign_up, :sign_in, :sign_out,
:dashboard,
@@ -38,13 +41,7 @@ class TypusController < ApplicationController
:only => [ :recover_password, :reset_password ]
def dashboard
- begin
- I18n.locale = @current_user.preferences[:locale]
- flash[:notice] = _("There are not defined applications in config/typus/*.yml.") if Typus.applications.empty?
- rescue
- @current_user.update_attributes :preferences => { :locale => Typus::Configuration.options[:default_locale] }
- retry
- end
+ flash[:notice] = _("There are not defined applications in config/typus/*.yml.") if Typus.applications.empty?
end
def sign_in
View
1  generators/typus/templates/initializer.rb
@@ -3,7 +3,6 @@
# System wide options
Typus::Configuration.options[:app_name] = '<%= options[:app_name] %>'
-# Typus::Configuration.options[:default_locale] = :en
# Typus::Configuration.options[:email] = 'admin@example.com'
# Typus::Configuration.options[:file_preview] = :typus_preview
# Typus::Configuration.options[:file_thumbnail] = :typus_thumbnail
View
1  lib/typus/configuration.rb
@@ -5,7 +5,6 @@ module Configuration
# Default options which can be overwritten from the initializer.
typus_options = { :app_name => 'Typus',
:config_folder => 'config/typus',
- :default_locale => :en,
:email => nil,
:file_preview => :typus_preview,
:file_thumbnail => :typus_thumbnail,
View
14 lib/typus/user.rb
@@ -26,7 +26,6 @@ def enable_as_typus_user
validates_presence_of :role
before_save :initialize_salt, :encrypt_password, :initialize_token
- before_save :set_preferences
serialize :preferences
@@ -48,7 +47,8 @@ def generate(*args)
new :email => options[:email],
:password => options[:password],
:password_confirmation => options[:password],
- :role => options[:role]
+ :role => options[:role],
+ :preferences => { :locale => I18n.default_locale.to_s }
end
end
@@ -105,24 +105,16 @@ def is_root?
end
def language
- preferences[:locale] rescue Typus::Configuration.options[:default_locale]
+ preferences[:locale]
end
def language=(locale)
options = { :locale => locale }
- set_preferences if self.preferences.nil?
self.preferences.merge!(options)
end
protected
- # OPTIMIZE: Cleanup ...
- def set_preferences
- if self.preferences.nil? || self.preferences[:locale].nil? || self.preferences[:locale].blank?
- self.preferences = { :locale => Typus::Configuration.options[:default_locale] }
- end
- end
-
def generate_hash(string)
Digest::SHA1.hexdigest(string)
end
View
1  test/lib/configuration_test.rb
@@ -11,7 +11,6 @@ def test_should_verify_application_wide_configuration_options
return if File.exist?(initializer)
assert_equal 'Typus', Typus::Configuration.options[:app_name]
assert_equal 'vendor/plugins/typus/test/config/working', Typus::Configuration.options[:config_folder]
- assert_equal :en, Typus::Configuration.options[:default_locale]
assert_equal nil, Typus::Configuration.options[:email]
assert_equal :typus_preview, Typus::Configuration.options[:file_preview]
assert_equal :typus_thumbnail, Typus::Configuration.options[:file_thumbnail]
Please sign in to comment.
Something went wrong with that request. Please try again.