Refactor config/ directory

* Get rid of early pathname requirement
* Use require_relative where approciate
* Drop unused files
* Imported new application.rb, environment.rb and environments/* from fresh Rails app
* Cleaned up boot.rb
* Load config in boot.rb
* Deduplicate environments/integration*.rb
* Move username blacklist into defaults.yml
* Ruby 1.9 Hash syntax everywhere
* Reorganize lib/diaspora/markdownify to match conventions
* Get rid of full path requires where possible
* Add dummy content to production section diaspora.yml.example to prevent warning
* Drop sqlite? method
* Move postgres? method into ConfigurationMethods
* Drop token authentication from User
This commit is contained in:
Jonne Haß 2013-05-05 13:45:49 +02:00
parent bf90dfffbd
commit ac147cc9f4
40 changed files with 267 additions and 456 deletions

View file

@ -2,8 +2,12 @@
## Refactor
* Refactored config/ directory [#4145](https://github.com/diaspora/diaspora/pull/4145).
## Bug fixes
* Don't use Pathname early to circumvent some rare initialization errors [#3816](https://github.com/diaspora/diaspora/issues/3816)
## Features

View file

@ -126,7 +126,7 @@ class Person < ActiveRecord::Base
def self.search_query_string(query)
query = query.downcase
like_operator = postgres? ? "ILIKE" : "LIKE"
like_operator = AppConfig.postgres? ? "ILIKE" : "LIKE"
where_clause = <<-SQL
profiles.full_name #{like_operator} ? OR
@ -155,7 +155,7 @@ class Person < ActiveRecord::Base
# @return [Array<String>] postgreSQL and mysql deal with null values in orders differently, it seems.
def self.search_order
@search_order ||= Proc.new {
order = if postgres?
order = if AppConfig.postgres?
"ASC"
else
"DESC"

View file

@ -23,7 +23,7 @@ class ShareVisibility < ActiveRecord::Base
def self.batch_import(contact_ids, share)
return false unless ShareVisibility.new(:shareable_id => share.id, :shareable_type => share.class.to_s).valid?
if postgres?
if AppConfig.postgres?
contact_ids.each do |contact_id|
ShareVisibility.find_or_create_by_contact_id_and_shareable_id_and_shareable_type(contact_id, share.id, share.class.base_class.to_s)
end

View file

@ -15,8 +15,7 @@ class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:token_authenticatable, :lockable, :lock_strategy => :none,
:unlock_strategy => :none
:lockable, :lock_strategy => :none, :unlock_strategy => :none
before_validation :strip_and_downcase_username
before_validation :set_current_language, :on => :create
@ -24,7 +23,7 @@ class User < ActiveRecord::Base
validates :username, :presence => true, :uniqueness => true
validates_format_of :username, :with => /\A[A-Za-z0-9_]+\z/
validates_length_of :username, :maximum => 32
validates_exclusion_of :username, :in => USERNAME_BLACKLIST
validates_exclusion_of :username, :in => AppConfig.settings.username_blacklist
validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES
validates_format_of :unconfirmed_email, :with => Devise.email_regexp, :allow_blank => true

View file

@ -1,23 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'pathname'
require Pathname.new(__FILE__).expand_path.dirname.join('boot')
require 'yaml'
require_relative 'boot'
require 'rails/all'
# Sanitize groups to make matching :assets easier
RAILS_GROUPS = Rails.groups(:assets => %w(development test)).map { |group| group.to_sym }
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*RAILS_GROUPS)
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
Bundler.require(*Rails.groups(:assets => %w(development test))) if defined?(Bundler)
module Diaspora
class Application < Rails::Application
@ -25,15 +9,15 @@ module Diaspora
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Add additional load paths for your own custom dirs
config.autoload_paths += %W{#{config.root}/app/presenters #{config.root}/app}
# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W{#{config.root}/app}
config.autoload_once_paths += %W{#{config.root}/lib}
# 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
# :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
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
@ -44,47 +28,71 @@ module Diaspora
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password, :xml,:message, :text, :bio]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Use SQL instead of Active Record's schema dumper when creating the 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
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
#config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w{
aspect-contacts.js
contact-list.js
finder.js
home.js
ie.js
inbox.js
jquery.js
jquery_ujs.js
jquery.textchange.js
login.js
mailchimp.js
main.js
mobile.js
profile.js
people.js
photos.js
profile.js
publisher.js
templates.js
validation.js
blueprint.css
bootstrap.css
bootstrap-complete.css
bootstrap-responsive.css
default.css
error_pages.css
login.css
mobile.css
new-templates.css
rtl.css
}
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
# Configure generators values. Many other options are available, be sure to check the documentation.
config.generators do |g|
g.template_engine :haml
g.test_framework :rspec
end
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
config.filter_parameters += [:xml]
config.filter_parameters += [:message]
config.filter_parameters += [:text]
config.filter_parameters += [:bio]
# Enable the asset pipeline
config.assets.enabled = true
config.assets.initialize_on_precompile = false
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# Javascripts
config.assets.precompile += [ "aspect-contacts.js", "contact-list.js", "finder.js",
"home.js", "ie.js", "inbox.js", "jquery.js", "jquery_ujs.js", "jquery.textchange.js",
"login.js", "mailchimp.js", "main.js", "mobile.js", "profile.js", "people.js", "photos.js",
"profile.js", "publisher.js", "templates.js", "validation.js" ]
# Stylesheets
config.assets.precompile += [ "blueprint.css", "bootstrap.css", "bootstrap-complete.css",
"bootstrap-responsive.css", "default.css", "error_pages.css", "login.css", "mobile.css",
"new-templates.css", "rtl.css" ]
# Rails Admin - these assets need to be added here since the Engine initializer
# doesn't run with initialize_on_precompile disabled. This list is taken
# directly from the Rails Admin Engine initializer.
config.assets.precompile += ['rails_admin/rails_admin.js', 'rails_admin/rails_admin.css',
'rails_admin/jquery.colorpicker.js', 'rails_admin/jquery.colorpicker.css']
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
end

View file

@ -1,17 +1,11 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'pathname'
require 'rubygems'
# Set up gems listed in the Gemfile.
gemfile = Pathname.new(__FILE__).dirname.join('..').expand_path.join('Gemfile')
begin
ENV['BUNDLE_GEMFILE'] = gemfile.to_s
require 'bundler'
Bundler.setup
rescue Bundler::GemNotFound => e
STDERR.puts e.message
STDERR.puts "Try running `bundle install`."
exit!
end if File.exist?(gemfile)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
# Ensure Builder is loaded
require 'active_support/builder' unless defined?(Builder)
# Load configuration early
require_relative 'load_config'

View file

@ -17,7 +17,7 @@ defaults:
concurrency: 5
retry: 10
backtrace: 15
log: "log/sidekiq.log"
log: 'log/sidekiq.log'
s3:
enable: false
key:
@ -50,7 +50,7 @@ defaults:
mixpanel_uid:
chartbeat_uid:
settings:
pod_name: "Diaspora*"
pod_name: 'Diaspora*'
enable_registrations: true
follow_diasporahq: true
invitations:
@ -61,6 +61,21 @@ defaults:
enable: false
suggest_email:
typhoeus_verbose: false
username_blacklist:
- 'admin'
- 'administrator'
- 'hostmaster'
- 'info'
- 'postmaster'
- 'root'
- 'ssladmin'
- 'ssladministrator'
- 'sslwebmaster'
- 'sysadmin'
- 'webmaster'
- 'support'
- 'contact'
- 'example_user1dsioaioedfhgoiesajdigtoearogjaidofgjo'
services:
facebook:
enable: false
@ -109,7 +124,7 @@ production:
i_am_a_dummy: # Remove if you add an actual override
test:
environment:
url: "http://localhost:9887/"
url: 'http://localhost:9887/'
single_process_mode: true
require_ssl: false
assets:
@ -127,14 +142,14 @@ test:
enable: true
integration1:
environment:
url: "http://localhost:45789/"
url: 'http://localhost:45789/'
single_process_mode: true
assets:
serve: true
require_ssl: false
integration2:
environment:
url: "http://localhost:34658/"
url: 'http://localhost:34658/'
single_process_mode: true
assets:
serve: true

View file

@ -328,6 +328,8 @@ configuration: ## Section
## Here you can make overides to settings defined above if you need
## to have them different in different environments.
production: ## Section
environment: ## Section
#redis_url: 'redis://production.example.org:6379'
development: ## Section
environment: ## Section

View file

@ -1,44 +1,5 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
# check what database you have
def postgres?
@using_postgres ||= defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
end
def sqlite?
@using_sqlite ||= defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter) && ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::SQLite3Adapter
end
# Load the rails application
require Pathname.new(__FILE__).dirname.expand_path.join('application')
# Load configuration system early
require Rails.root.join('config', 'load_config')
Haml::Template.options[:format] = :html5
Haml::Template.options[:escape_html] = true
# Blacklist of usernames
USERNAME_BLACKLIST = ['admin', 'administrator', 'hostmaster', 'info', 'postmaster', 'root', 'ssladmin',
'ssladministrator', 'sslwebmaster', 'sysadmin', 'webmaster', 'support', 'contact', 'example_user1dsioaioedfhgoiesajdigtoearogjaidofgjo']
require_relative 'application'
# Initialize the rails application
Diaspora::Application.initialize!
# allow token auth only for posting activitystream photos
module Devise
module Strategies
class TokenAuthenticatable < Authenticatable
private
def valid_params_request?
params[:controller] == "activity_streams/photos" && params[:action] == "create"
end
end
end
end
# Ensure Builder is loaded
require 'active_support/builder' unless defined?(Builder)

View file

@ -1,8 +1,5 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
Diaspora::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
@ -16,21 +13,14 @@ Diaspora::Application.configure do
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = false
# Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
config.assets.allow_debugging = true
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = [:stderr, :log]
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
#config.active_record.mass_assignment_sanitizer = :strict
@ -38,19 +28,10 @@ Diaspora::Application.configure do
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
#config.threadsafe!
# Monkeypatch around the nasty "2.5MB exception page" issue, caused by very large environment vars
# This snippet via: http://stackoverflow.com/questions/3114993/exception-pages-in-development-mode-take-upwards-of-15-30-seconds-to-render-why
# Relevant Rails ticket: https://rails.lighthouseapp.com/projects/8994/tickets/5027-_request_and_responseerb-and-diagnosticserb-take-an-increasingly-long-time-to-render-in-development-with-multiple-show-tables-calls
config.after_initialize do
module SmallInspect
def inspect
"<#{self.class.name} - tooooo long>"
end
end
[ActionController::Base, OmniAuth::Strategy, Warden::Proxy].each do |klazz|
klazz.send(:include, SmallInspect)
end
end
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end

View file

@ -0,0 +1,6 @@
require Rails.root.join('config', 'environment', 'development')
Diaspora::Application.configure do
# Enable threaded mode
config.threadsafe!
end

View file

@ -1,39 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
Diaspora::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.threadsafe!
# Monkeypatch around the nasty "2.5MB exception page" issue, caused by very large environment vars
# This snippet via: http://stackoverflow.com/questions/3114993/exception-pages-in-development-mode-take-upwards-of-15-30-seconds-to-render-why
# Relevant Rails ticket: https://rails.lighthouseapp.com/projects/8994/tickets/5027-_request_and_responseerb-and-diagnosticserb-take-an-increasingly-long-time-to-render-in-development-with-multiple-show-tables-calls
config.after_initialize do
module SmallInspect
def inspect
"<#{self.class.name} - tooooo long>"
end
end
[ActionController::Base, OmniAuth::Strategy, Warden::Proxy].each do |klazz|
klazz.send(:include, SmallInspect)
end
end
end

View file

@ -0,0 +1 @@
integration.rb

View file

@ -1,39 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
Diaspora::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = true
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
#config.threadsafe!
# Monkeypatch around the nasty "2.5MB exception page" issue, caused by very large environment vars
# This snippet via: http://stackoverflow.com/questions/3114993/exception-pages-in-development-mode-take-upwards-of-15-30-seconds-to-render-why
# Relevant Rails ticket: https://rails.lighthouseapp.com/projects/8994/tickets/5027-_request_and_responseerb-and-diagnosticserb-take-an-increasingly-long-time-to-render-in-development-with-multiple-show-tables-calls
config.after_initialize do
module SmallInspect
def inspect
"<#{self.class.name} - tooooo long>"
end
end
[ActionController::Base, OmniAuth::Strategy, Warden::Proxy].each do |klazz|
klazz.send(:include, SmallInspect)
end
end
end

View file

@ -0,0 +1 @@
integration.rb

View file

@ -1,11 +1,6 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
Diaspora::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# Settings specified here will take precedence over those in config/application.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
@ -13,48 +8,67 @@ Diaspora::Application.configure do
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Specifies the header that your server uses for sending files
#config.action_dispatch.x_sendfile_header = "X-Sendfile"
config.active_support.deprecation = :notify
# For nginx:
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
# If you have no front-end server that supports something like X-Sendfile,
# just comment this out and Rails will serve the files
# See everything in the log (default is :info)
# config.log_level = :debug
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Disable Rails's static asset server
# In production, Apache or nginx will already do this
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Compress JavaScript and CSS
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
if defined?(AppConfig) && AppConfig.environment.assets.host.present?
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
# For nginx:
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
if AppConfig.environment.assets.host.present?
config.action_controller.asset_host = AppConfig.environment.assets.host.get
end
config.threadsafe!
end
GC.enable_stats if GC.respond_to?(:enable_stats)
GC::Profiler.enable if defined?(GC::Profiler) && GC::Profiler.respond_to?(:enable)

View file

@ -1,50 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
Diaspora::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
# Specifies the header that your server uses for sending files
#config.action_dispatch.x_sendfile_header = "X-Sendfile"
config.active_support.deprecation = :notify
# For nginx:
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
# If you have no front-end server that supports something like X-Sendfile,
# just comment this out and Rails will serve the files
# See everything in the log (default is :info)
# config.log_level = :debug
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Disable Rails's static asset server
# In production, Apache or nginx will already do this
config.serve_static_assets = false
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
config.threadsafe!
end
# Sacrifice readability for a 10% performance boost
Haml::Template::options[:ugly] = true

View file

@ -1,9 +1,5 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
Diaspora::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# Settings specified here will take precedence over those in config/application.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
@ -11,7 +7,11 @@ Diaspora::Application.configure do
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Log error messages when you accidentally call methods on nil.
# Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
# Log error messages when you accidentally call methods on nil
config.whiny_nils = true
# Show full error reports and disable caching
@ -28,24 +28,10 @@ Diaspora::Application.configure do
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.active_support.deprecation = :stderr
# Raise exception on mass assignment protection for Active Record models
#config.active_record.mass_assignment_sanitizer = :strict
# Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
config.assets.enabled = true
config.assets.debug = false
# fixes url helper issue in rspec
#config.threadsafe!
# 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
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
end

View file

@ -1,2 +1,2 @@
require 'models/acts_as_taggable_on/tag'
ActsAsTaggableOn.force_lowercase = true
require Rails.root.join("app", "models", "acts_as_taggable_on", "tag")

View file

@ -1,11 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!

View file

@ -9,10 +9,10 @@ CarrierWave.configure do |config|
config.storage = :fog
config.cache_dir = Rails.root.join('tmp', 'uploads').to_s
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => AppConfig.environment.s3.key.get,
:aws_secret_access_key => AppConfig.environment.s3.secret.get,
:region => AppConfig.environment.s3.region.get
provider: 'AWS',
aws_access_key_id: AppConfig.environment.s3.key.get,
aws_secret_access_key: AppConfig.environment.s3.secret.get,
region: AppConfig.environment.s3.region.get
}
if AppConfig.environment.s3.cache?
config.fog_attributes['Cache-Control'] = 'max-age=31536000'

View file

@ -1,6 +1,6 @@
if AppConfig.heroku?
Rails.application.config.secret_token = AppConfig.secret_token
elsif !File.exists?( Rails.root.join('config', 'initializers', 'secret_token.rb'))
elsif !Rails.root.join('config', 'initializers', 'secret_token.rb').exist?
`bundle exec rake generate:secret_token`
require Rails.root.join('config', 'initializers', 'secret_token.rb')
end

View file

@ -1,5 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require Rails.root.join('lib', 'direction_detector')

View file

@ -1,9 +1,13 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
options = {:timeout => 25}
options = {
timeout: 25,
ssl: {
ca_file: AppConfig.environment.certificate_authorities.get
}
}
options[:ssl] = {:ca_file => AppConfig.environment.certificate_authorities}
Faraday.default_connection = Faraday::Connection.new(options) do |b|
b.use FaradayMiddleware::FollowRedirects
b.adapter Faraday.default_adapter

View file

@ -0,0 +1,2 @@
Haml::Template.options[:format] = :html5
Haml::Template.options[:escape_html] = true

View file

@ -1,14 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
end

View file

@ -1,6 +0,0 @@
class Fixnum
def to_json(options = nil)
to_s
end
end

View file

@ -6,15 +6,14 @@
if Rails.env == 'production'
Diaspora::Application.configure do
if AppConfig.privacy.google_analytics_key.present?
config.gem 'rack-google-analytics', :lib => 'rack/google-analytics'
config.middleware.use Rack::GoogleAnalytics, :tracker => AppConfig.privacy.google_analytics_key.get
require 'rack/google-analytics'
config.middleware.use Rack::GoogleAnalytics, tracker: AppConfig.privacy.google_analytics_key.get
end
if AppConfig.privacy.piwik.enable?
require 'rack/piwik'
config.gem 'rack-piwik', :lib => 'rack/piwik'
config.middleware.use Rack::Piwik, :piwik_url => AppConfig.privacy.piwik.host.get,
:piwik_id => AppConfig.privacy.piwik.site_id.get
config.middleware.use Rack::Piwik, piwik_url: AppConfig.privacy.piwik.host.get,
piwik_id: AppConfig.privacy.piwik.site_id.get
end
end
end

View file

@ -19,6 +19,7 @@ require 'markdownify_helper'
# Our libs
require 'collect_user_photos'
require 'diaspora'
require 'direction_detector'
require 'email_inviter'
require 'evil_query'
require 'federation_logger'
@ -33,4 +34,3 @@ require 'stream'
require 'template_picker'
require 'webfinger'
require 'webfinger_profile'

View file

@ -4,8 +4,10 @@
require Rails.root.join('lib', 'messagebus', 'mailer')
Diaspora::Application.configure do
config.action_mailer.default_url_options = {:protocol => AppConfig.pod_uri.scheme,
:host => AppConfig.pod_uri.authority }
config.action_mailer.default_url_options = {
protocol: AppConfig.pod_uri.scheme,
host: AppConfig.pod_uri.authority
}
config.action_mailer.asset_host = AppConfig.pod_uri.to_s
config.action_mailer.perform_deliveries = AppConfig.mail.enable?
@ -21,26 +23,26 @@ Diaspora::Application.configure do
elsif AppConfig.mail.method == "sendmail"
config.action_mailer.delivery_method = :sendmail
sendmail_settings = {
:location => AppConfig.mail.sendmail.location.get
location: AppConfig.mail.sendmail.location.get
}
sendmail_settings[:arguments] = "-i" if AppConfig.mail.sendmail.exim_fix?
config.action_mailer.sendmail_settings = sendmail_settings
elsif AppConfig.mail.method == "smtp"
config.action_mailer.delivery_method = :smtp
smtp_settings = {
:address => AppConfig.mail.smtp.host.get,
:port => AppConfig.mail.smtp.port.to_i,
:domain => AppConfig.mail.smtp.domain.get,
:enable_starttls_auto => false,
:openssl_verify_mode => AppConfig.mail.smtp.openssl_verify_mode.get
address: AppConfig.mail.smtp.host.get,
port: AppConfig.mail.smtp.port.to_i,
domain: AppConfig.mail.smtp.domain.get,
enable_starttls_auto: false,
openssl_verify_mode: AppConfig.mail.smtp.openssl_verify_mode.get
}
if AppConfig.mail.smtp.authentication != "none"
smtp_settings.merge!({
:authentication => AppConfig.mail.smtp.authentication.gsub('-', '_').to_sym,
:user_name => AppConfig.mail.smtp.username.get,
:password => AppConfig.mail.smtp.password.get,
:enable_starttls_auto => AppConfig.mail.smtp.starttls_auto?
authentication: AppConfig.mail.smtp.authentication.gsub('-', '_').to_sym,
user_name: AppConfig.mail.smtp.username.get,
password: AppConfig.mail.smtp.password.get,
enable_starttls_auto: AppConfig.mail.smtp.starttls_auto?
})
end

View file

@ -1,3 +1 @@
require Rails.root.join("lib", "diaspora", "markdownify_email")
Rails.application.config.markerb.renderer = Diaspora::Markdownify::Email

View file

@ -1,9 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone

View file

@ -16,8 +16,14 @@ Rails.application.config.middleware.use OmniAuth::Builder do
end
if AppConfig.services.facebook.enable?
provider :facebook, AppConfig.services.facebook.app_id, AppConfig.services.facebook.secret,
{ :display => "popup", :scope => "publish_actions,publish_stream,offline_access",
:client_options => {:ssl => {:ca_file => AppConfig.environment.certificate_authorities }}}
provider :facebook, AppConfig.services.facebook.app_id, AppConfig.services.facebook.secret, {
display: 'popup',
scope: 'publish_actions,publish_stream,offline_access',
client_options: {
ssl: {
ca_file: AppConfig.environment.certificate_authorities
}
}
}
end
end

View file

@ -4,7 +4,7 @@
# Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, :key => '_diaspora_session', :httponly => false
Rails.application.config.session_store :cookie_store, key: '_diaspora_session', httponly: false
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information

View file

@ -1,2 +0,0 @@
# if you wish to intercept emails to go to a particuar email address
#ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?

View file

@ -1,41 +1,36 @@
require 'configurate'
rails_root = Pathname.new(__FILE__).dirname.join('..').expand_path
rails_root = File.expand_path('../../', __FILE__)
rails_env = ENV['RACK_ENV']
rails_env ||= ENV['RAILS_ENV']
rails_env ||= 'development'
require rails_root.join('lib', 'configuration_methods')
require File.join(rails_root, 'lib', 'configuration_methods')
config_dir = rails_root.join("config")
if File.exists?(config_dir.join("application.yml"))
$stderr.puts "ATTENTION: There's a new configuration system, please remove your"
$stderr.puts " application.yml and migrate your settings."
end
config_dir = File.join rails_root, 'config'
AppConfig ||= Configurate::Settings.create do
add_provider Configurate::Provider::Dynamic
add_provider Configurate::Provider::Env
unless heroku? || rails_env == "test" || File.exists?(config_dir.join("diaspora.yml"))
unless heroku? || rails_env == "test" || File.exists?(File.join(config_dir, 'diaspora.yml'))
$stderr.puts "FATAL: Configuration not found. Copy over diaspora.yml.example"
$stderr.puts " to diaspora.yml and edit it to your needs."
Process.exit(1)
exit!
end
add_provider Configurate::Provider::YAML,
config_dir.join("diaspora.yml"),
namespace: rails_env, required: false
File.join(config_dir, 'diaspora.yml'),
namespace: rails_env, required: false unless rails_env == 'test'
add_provider Configurate::Provider::YAML,
config_dir.join("diaspora.yml"),
File.join(config_dir, 'diaspora.yml'),
namespace: "configuration", required: false
add_provider Configurate::Provider::YAML,
config_dir.join("defaults.yml"),
File.join(config_dir, 'defaults.yml'),
namespace: rails_env
add_provider Configurate::Provider::YAML,
config_dir.join("defaults.yml"),
File.join(config_dir, 'defaults.yml'),
namespace: "defaults"
extend Configuration::Methods
@ -45,6 +40,6 @@ AppConfig ||= Configurate::Settings.create do
environment.certificate_authorities.empty? ||
!File.file?(environment.certificate_authorities.get))
$stderr.puts "FATAL: Diaspora doesn't know where your certificate authorities are. Please ensure they are set to a valid path in diaspora.yml"
Process.exit(1)
exit!
end
end

View file

@ -1,5 +1,4 @@
require 'pathname'
require Pathname.new(__FILE__).expand_path.dirname.join('load_config')
require File.expand_path('../load_config', __FILE__)
# Enable and set these to run the worker as a different user/group
#user = 'diaspora'

View file

@ -104,13 +104,18 @@ module Configuration
path.to_s
end
def postgres?
defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) &&
ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
end
private
def get_git_info
return if git_info_present? || !git_available?
git_cmd = `git log -1 --pretty="format:%H %ci"`
if git_cmd =~ /^([\d\w]+?)\s(.+)$/
if git_cmd =~ /^(\w+?)\s(.+)$/
@git_revision = $1
@git_update = $2.strip
end

View file

@ -1,13 +1,6 @@
module Diaspora
module Markdownify
class HTML < Redcarpet::Render::HTML
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TagHelper
def autolink(link, type)
auto_link(link, :link => :urls, :html => { :target => "_blank" })
end
end
require 'diaspora/markdownify/html'
require 'diaspora/markdownify/email'
end
end

View file

@ -0,0 +1,13 @@
module Diaspora
module Markdownify
class HTML < Redcarpet::Render::HTML
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TagHelper
def autolink(link, type)
auto_link(link, :link => :urls, :html => { :target => "_blank" })
end
end
end
end

View file

@ -176,10 +176,8 @@ SQL
protected
def where_clause_sql
if postgres?
if AppConfig.postgres?
"WHERE users.created_at > NOW() - '1 month'::INTERVAL"
elsif sqlite?
raise "#where_clause_sql not yet written for SQLite"
else
"where users.created_at > FROM_UNIXTIME(#{(Time.now - 1.month).to_i})"
end