diff --git a/MIGRATION_ISSUES b/MIGRATION_ISSUES index 9432a8b..2eac927 100644 --- a/MIGRATION_ISSUES +++ b/MIGRATION_ISSUES @@ -8,4 +8,10 @@ * initializers session_store.rb inflections.rb... don't exist -* rails gems version have to be forced on Gemfile or it will use incompatible pre3vious versions (3.1.3) \ No newline at end of file +* rails gems version have to be forced on Gemfile or it will use incompatible pre3vious versions (3.1.3) + +* Sweepers are now natively supported on Rails 3. Would be nice to refactor it + +* On Rails 3 it is no more possible to add allowed tags to avoid scape. The html_safe initializer is an option. + +* controller_paths are no more supported on Rails 3 \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index d7f9938..cddf354 100644 --- a/config/application.rb +++ b/config/application.rb @@ -11,19 +11,47 @@ end module Rails3 class Application < Rails::Application + def noosfero_session_secret + require 'fileutils' + target_dir = File.join(File.dirname(__FILE__), '/../tmp') + FileUtils.mkdir_p(target_dir) + file = File.join(target_dir, 'session.secret') + if !File.exists?(file) + secret = (1..128).map { %w[0 1 2 3 4 5 6 7 8 9 a b c d e f][rand(16)] }.join('') + File.open(file, 'w') do |f| + f.puts secret + end + end + File.read(file).strip + end + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Custom directories with classes and modules you want to be autoloadable. - # config.autoload_paths += %W(#{config.root}/extras) + config.autoload_paths += %W( #{Rails.root}/app/sweepers ) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Activate observers that should always be running. - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer + # Sweepers are observers + # don't load the sweepers while loading the database + ignore_rake_commands = %w[ + db:schema:load + gems:install + clobber + noosfero:translations:compile + makemo + ] + if $PROGRAM_NAME =~ /rake$/ && (ignore_rake_commands.include?(ARGV.first)) + $NOOSFERO_LOAD_PLUGINS = false + else + $NOOSFERO_LOAD_PLUGINS = true + config.active_record.observers = :article_sweeper, :role_assignment_sweeper, :friendship_sweeper, :category_sweeper, :block_sweeper + end # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. @@ -31,7 +59,7 @@ module Rails3 # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de + config.i18n.default_locale = nil # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" @@ -58,5 +86,14 @@ module Rails3 # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' + + # Your secret key for verifying cookie session data integrity. + # If you change this key, all old sessions 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. + config.action_dispatch.session = { + :key => '_noosfero_session', + :secret => noosfero_session_secret() + } end end diff --git a/config/environment.rb b/config/environment.rb index d1e1b28..da92d54 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -27,74 +27,14 @@ def noosfero_session_secret File.read(file).strip end -Rails::Initializer.run do |config| - # Settings in config/environments/* take precedence those specified here - - # Skip frameworks you're not going to use (only works if using vendor/rails) - # config.frameworks -= [ :action_web_service, :action_mailer ] - - # Add additional load paths for your own custom dirs - # config.load_paths += %W( #{Rails.root}/extras ) - config.load_paths += %W( #{Rails.root}/app/sweepers ) - - # Force all environments to use the same logger level - # (by default production uses :info, the others :debug) - # config.log_level = :debug - - # Use the database for sessions instead of the file system - # (create the session table with 'rake db:sessions:create') - # config.action_controller.session_store = :active_record_store - - # Use SQL instead of Active Record's schema dumper when creating the test database. - # This is necessary if your schema can't be completely dumped by the schema dumper, - # like if you have constraints or database-specific column types - # config.active_record.schema_format = :sql - - # Activate observers that should always be running - # config.active_record.observers = :cacher, :garbage_collector - - # don't load the sweepers while loading the database - ignore_rake_commands = %w[ - db:schema:load - gems:install - clobber - noosfero:translations:compile - makemo - ] - if $PROGRAM_NAME =~ /rake$/ && (ignore_rake_commands.include?(ARGV.first)) - $NOOSFERO_LOAD_PLUGINS = false - else - $NOOSFERO_LOAD_PLUGINS = true - config.active_record.observers = :article_sweeper, :role_assignment_sweeper, :friendship_sweeper, :category_sweeper, :block_sweeper - end - # Make Active Record use UTC-base instead of local time - # config.active_record.default_timezone = :utc - - # Your secret key for verifying cookie session data integrity. - # If you change this key, all old sessions 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. - config.action_controller.session = { - :session_key => '_noosfero_session', - :secret => noosfero_session_secret(), - } - - # Adds custom attributes to the Set of allowed html attributes for the #sanitize helper - config.action_view.sanitized_allowed_attributes = 'align', 'border', 'alt', 'vspace', 'hspace', 'width', 'heigth', 'value', 'type', 'data', 'style', 'target', 'codebase', 'archive', 'classid', 'code', 'flashvars', 'scrolling', 'frameborder' - - # Adds custom tags to the Set of allowed html tags for the #sanitize helper - config.action_view.sanitized_allowed_tags = 'object', 'embed', 'param', 'table', 'tr', 'th', 'td', 'applet', 'comment', 'iframe' - - # See Rails::Configuration for more options - - extra_controller_dirs.each do |item| - $LOAD_PATH << item - config.controller_paths << item - end -end -extra_controller_dirs.each do |item| - (ActiveSupport.const_defined?('Dependencies') ? ActiveSupport::Dependencies : ::Dependencies).load_paths << item -end +#FIXME controller_paths are no more supported on Rails 3 +#extra_controller_dirs.each do |item| +# $LOAD_PATH << item +# config.controller_paths << item +#end +#extra_controller_dirs.each do |item| +# (ActiveSupport.const_defined?('Dependencies') ? ActiveSupport::Dependencies : ::Dependencies).load_paths << item +#end # Add new inflection rules using the following format # (all these examples are active by default): @@ -109,10 +49,8 @@ end ActiveRecord::Base.store_full_sti_class = true -# if you want to override this, do it in config/local.rb ! -Noosfero.default_locale = nil - -Tag.hierarchical = true +#FIXME: Probably act_as_taggable_on is not being loaded or this should be on another place +#Tag.hierarchical = true # several local libraries require 'noosfero' diff --git a/config/initializers/html_safe.rb b/config/initializers/html_safe.rb new file mode 100644 index 0000000..eb01bd0 --- /dev/null +++ b/config/initializers/html_safe.rb @@ -0,0 +1,9 @@ +#From: https://github.com/coletivoEITA/noosfero-ecosol/blob/57908cde4fe65dfe22298a8a7f6db5dba1e7cc75/config/initializers/html_safe.rb + +# Disable Rails html autoescaping. This is due to noosfero using too much helpers/models to output html. +# It it would change too much code and make it hard to maintain. +class Object + def html_safe? + true + end +end \ No newline at end of file -- libgit2 0.21.2