Skip to content

Commit

Permalink
New configuration system
Browse files Browse the repository at this point in the history
* Throw away old system
* Add new system
* Add new example files
* Replace all calls
* add the most important docs
* Add Specs
* rename disable_ssl_requirement to require_ssl
* cloudfiles isn't used/called in our code
* since community_spotlight.list is only used as enable flag replace it with such one and remove all legacy and irelevant codepaths around it
* die if session secret is unset and on heroku
* First basic infrastructure for version information
  • Loading branch information
jhass committed Sep 26, 2012
1 parent 5bea630 commit 2a4db54
Show file tree
Hide file tree
Showing 118 changed files with 1,574 additions and 1,244 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ app/assets/images/custom/*


# Configuration files
config/app_config.yml
config/app.yml
config/application.yml
config/diaspora.yml
config/heroku.yml
config/script_server*.yml
config/fb_config.yml
config/oauth_keys.yml
config/script_server.yml
config/initializers/secret_token.rb
config/redis.conf
config/deploy_config.yml
Expand Down
24 changes: 24 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 0.0.1.0pre

## New configuration system!

Copy over config/diaspora.yml.example to config/diaspora.yml and migrate your settings! An updated Heroku guide including basic hints on howto migrate is [here](https://github.com/diaspora/diaspora/wiki/Installing-on-heroku).

The new configuration system allows all possible settings to be overriden by environment variables. This makes it possible to deploy heroku without checking any credentials into git. Read the top of `config/diaspora.yml.example` for an explanation on how to convert the setting names to environment variables.

### Environment variable changes:

#### deprectated

* REDISTOGO_URL in favour of REDIS_URL or ENVIRONMENT_REDIS

#### removed

* application_yml - Obsolete, all settings are settable via environment variables now

#### renamed

* SINGLE_PROCESS_MODE -> ENVIRONMENT_SINGLE_PROCESS_MODE
* SINGLE_PROCESS -> ENVIRONMENT_SINGLE_PROCESS_MODE
* NO_SSL -> ENVIRONMENT_REQUIRE_SSL
* ASSET_HOST -> ENVIRONMENT_ASSETS_HOST
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ group :heroku do
gem 'unicorn', '4.3.1', :require => false
end

gem 'settingslogic', :git => 'https://github.com/binarylogic/settingslogic.git'
# database

gem "activerecord-import", "0.2.11"
Expand Down
7 changes: 0 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ GIT
activesupport (>= 2.3.0)
nokogiri (>= 1.3.3)

GIT
remote: https://github.com/binarylogic/settingslogic.git
revision: 4884d455bf18d92723cb8190cfd2dbf87f3aafd5
specs:
settingslogic (2.0.8)

GIT
remote: https://github.com/plataformatec/markerb.git
revision: 93b1e8bea9b8fa89ef930f78ba562f596c022198
Expand Down Expand Up @@ -519,7 +513,6 @@ DEPENDENCIES
ruby-oembed (= 0.8.7)
sass-rails (= 3.2.5)
selenium-webdriver (= 2.25.0)
settingslogic!
spork (= 1.0.0rc3)
thin (= 1.4.1)
timecop (= 0.5.1)
Expand Down
12 changes: 8 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base

before_filter :ensure_http_referer_is_set
before_filter :set_locale
before_filter :set_git_header if (AppConfig[:git_update] && AppConfig[:git_revision])
before_filter :set_diaspora_header
before_filter :set_grammatical_gender
before_filter :mobile_switch

Expand Down Expand Up @@ -61,9 +61,13 @@ def ensure_page
params[:page] = params[:page] ? params[:page].to_i : 1
end

def set_git_header
headers['X-Git-Update'] = AppConfig[:git_update] if AppConfig[:git_update].present?
headers['X-Git-Revision'] = AppConfig[:git_revision] if AppConfig[:git_revision].present?
def set_diaspora_header
headers['X-Diaspora-Version'] = AppConfig.version_string

if AppConfig.git_available?
headers['X-Git-Update'] = AppConfig.git_update if AppConfig.git_update.present?
headers['X-Git-Revision'] = AppConfig.git_revision if AppConfig.git_revision.present?
end
end

def set_locale
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create
end

def check_if_invites_open
unless AppConfig[:open_invitations]
unless AppConfig.settings.invitations.open?
flash[:error] = I18n.t 'invitations.create.no_more'

redirect_to :back
Expand Down
6 changes: 0 additions & 6 deletions app/controllers/publics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ class PublicsController < ApplicationController
require Rails.root.join('lib', 'postzord', 'receiver', 'private')
include Diaspora::Parser

# We use newrelic_ignore to prevent artifical RPM bloat; however,
# I am commenting this line out for the time being to debug some apparent
# issues on Heroku.
#
# newrelic_ignore if EnvironmentConfiguration.using_new_relic?

skip_before_filter :set_header_data
skip_before_filter :set_grammatical_gender
before_filter :check_for_xml, :only => [:receive, :receive_public]
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def new

private
def check_valid_invite!
return true unless AppConfig[:registrations_closed] #this sucks
return true if AppConfig.settings.enable_registrations? #this sucks
return true if invite && invite.can_be_used?
flash[:error] = t('registrations.invalid_invite')
redirect_to new_user_session_path
end

def check_registrations_open_or_vaild_invite!
return true if invite.present?
if AppConfig[:registrations_closed]
unless AppConfig.settings.enable_registrations?
flash[:error] = t('registrations.closed')
redirect_to new_user_session_path
end
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/analytics_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def include_mixpanel
<<-JS.html_safe
(function(d,c){var a,b,g,e;a=d.createElement('script');a.type='text/javascript';a.async=!0;a.src=('https:'===d.location.protocol?'https:':'http:')+'//api.mixpanel.com/site_media/js/api/mixpanel.2.js';b=d.getElementsByTagName('script')[0];b.parentNode.insertBefore(a,b);c._i=[];c.init=function(a,d,f){var b=c;'undefined'!==typeof f?b=c[f]=[]:f='mixpanel';g='disable track track_pageview track_links track_forms register register_once unregister identify name_tag set_config'.split(' ');
for(e=0;e<g.length;e++)(function(a){b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,0)))}})(g[e]);c._i.push([a,d,f])};window.mixpanel=c})(document,[]);
mixpanel.init("#{AppConfig[:mixpanel_uid]}");
mixpanel.init("#{AppConfig.privacy.mixpanel_uid}");
JS
end
end
Expand All @@ -35,7 +35,7 @@ def include_chartbeat
include_analytics "chartbeat" do
javascript_tag do
<<-JS.html_safe
var _sf_async_config = { uid: #{AppConfig[:chartbeat_uid]}, domain: "#{AppConfig[:pod_uri].host}" };
var _sf_async_config = { uid: #{AppConfig.privacy.chartbeat_uid}, domain: "#{AppConfig.pod_uri.host}" };
(function() {
function loadChartbeat() {
window._sf_endpt = (new Date()).getTime();
Expand Down Expand Up @@ -64,6 +64,6 @@ def include_analytics(service, &block)
end

def configured?(service)
AppConfig["#{service}_uid".to_sym].present?
AppConfig.privacy.send("#{service}_uid").present?
end
end
end
8 changes: 4 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module ApplicationHelper
def pod_name
AppConfig[:pod_name].present? ? AppConfig[:pod_name] : "DIASPORA*"
AppConfig.settings.pod_name.present? ? AppConfig.settings.pod_name : "DIASPORA*"
end

def how_long_ago(obj)
Expand All @@ -21,7 +21,7 @@ def bookmarklet
end

def raw_bookmarklet( height = 250, width = 620)
"javascript:(function(){f='#{AppConfig[:pod_url]}bookmarklet?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'&notes='+encodeURIComponent(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text))+'&v=1&';a=function(){if(!window.open(f+'noui=1&jump=doclose','diasporav1','location=yes,links=no,scrollbars=no,toolbar=no,width=#{width},height=#{height}'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()"
"javascript:(function(){f='#{AppConfig.environment.url}bookmarklet?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'&notes='+encodeURIComponent(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text))+'&v=1&';a=function(){if(!window.open(f+'noui=1&jump=doclose','diasporav1','location=yes,links=no,scrollbars=no,toolbar=no,width=#{width},height=#{height}'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()"
end

def magic_bookmarklet_link
Expand All @@ -37,7 +37,7 @@ def contacts_link
end

def all_services_connected?
current_user.services.size == AppConfig[:configured_services].size
current_user.services.size == AppConfig.configured_services.size
end

def popover_with_close_html(without_close_html)
Expand All @@ -56,7 +56,7 @@ def modernizer_responsive_tag
# vendored jquery_ujs
def jquery_include_tag
buf = []
if AppConfig[:jquery_cdn]
if AppConfig.privacy.jquery_cdn?
version = Jquery::Rails::JQUERY_VERSION
buf << [ javascript_include_tag("//ajax.googleapis.com/ajax/libs/jquery/#{version}/jquery.min.js") ]
buf << [ javascript_tag("!window.jQuery && document.write(unescape('#{j javascript_include_tag("jquery")}'));") ]
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/open_graph_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def og_type
end

def og_namespace(object)
namespace = AppConfig[:open_graph_namespace].present? ? AppConfig[:open_graph_namespace] : 'joindiaspora'
namespace = AppConfig.services.facebook.open_graph_namespace.present? ? AppConfig.services.facebook.open_graph_namespace : 'joindiaspora'
"#{namespace}:frame"
end

Expand All @@ -54,4 +54,4 @@ def default_image_url
"#{root_url.chop}#{image_path('asterisk.png')}"
end
end
end
end
2 changes: 1 addition & 1 deletion app/helpers/people_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def person_href(person, opts={})

# Rails.application.routes.url_helpers is needed since this is indirectly called from a model
def local_or_remote_person_path(person, opts={})
opts.merge!(:protocol => AppConfig[:pod_uri].scheme, :host => AppConfig[:pod_uri].authority)
opts.merge!(:protocol => AppConfig.pod_uri.scheme, :host => AppConfig.pod_uri.authority)
absolute = opts.delete(:absolute)

if person.local?
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/posts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def post_page_title(post, opts={})
def post_iframe_url(post_id, opts={})
opts[:width] ||= 516
opts[:height] ||= 315
host = AppConfig[:pod_uri].site
host = AppConfig.pod_uri.site
"<iframe src='#{Rails.application.routes.url_helpers.post_url(post_id, :host => host)}' width='#{opts[:width]}px' height='#{opts[:height]}px' frameBorder='0'></iframe>".html_safe
end
end
2 changes: 1 addition & 1 deletion app/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def prefilled_username
end

def display_registration_link?
!AppConfig[:registrations_closed] && devise_mapping.registerable? && controller_name != 'registrations'
!AppConfig.settings.enable_registrations? && devise_mapping.registerable? && controller_name != 'registrations'
end

def display_password_reset_link?
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/diaspora_devise_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class DiasporaDeviseMailer < Devise::Mailer
default :from => AppConfig[:smtp_sender_address]
default :from => AppConfig.mail.sender_address

def self.mailer_name
"devise/mailer"
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/notification_mailers/also_commented.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def set_headers(comment_id)
@comment = Comment.find_by_id(comment_id)

if mail?
@headers[:from] = "\"#{@comment.author_name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>"
@headers[:from] = "\"#{@comment.author_name} (Diaspora*)\" <#{AppConfig.mail.sender_address}>"
@headers[:subject] = truncate(@comment.comment_email_subject, :length => TRUNCATION_LEN)
@headers[:subject] = "Re: #{@headers[:subject]}"
end
Expand Down
6 changes: 3 additions & 3 deletions app/mailers/notification_mailers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def name_and_address(name, email)
private
def default_headers
headers = {
:from => AppConfig[:smtp_sender_address],
:host => "#{AppConfig[:pod_uri]}",
:from => AppConfig.mail.sender_address.get,
:host => "#{AppConfig.pod_uri.host}",
:to => name_and_address(@recipient.name, @recipient.email)
}

headers[:from] = "\"#{@sender.name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>" if @sender.present?
headers[:from] = "\"#{@sender.name} (Diaspora*)\" <#{AppConfig.mail.sender_address}>" if @sender.present?

headers
end
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/notification_mailers/comment_on_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CommentOnPost < NotificationMailers::Base
def set_headers(comment_id)
@comment = Comment.find(comment_id)

@headers[:from] = "\"#{@comment.author_name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>"
@headers[:from] = "\"#{@comment.author_name} (Diaspora*)\" <#{AppConfig.mail.sender_address}>"
@headers[:subject] = truncate(@comment.comment_email_subject, :length => TRUNCATION_LEN)
@headers[:subject] = "Re: #{@headers[:subject]}"
end
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/notification_mailers/private_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def set_headers(message_id)
@conversation = @message.conversation
@participants = @conversation.participants

@headers[:from] = "\"#{@message.author_name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>"
@headers[:from] = "\"#{@message.author_name} (Diaspora*)\" <#{AppConfig.mail.sender_address}>"
@headers[:subject] = @conversation.subject.strip
@headers[:subject] = "Re: #{@headers[:subject]}" if @conversation.messages.size > 1
end
Expand Down
10 changes: 5 additions & 5 deletions app/mailers/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def single_admin(string, recipient, opts={})
end

default_opts = {:to => @receiver.email,
:from => AppConfig[:smtp_sender_address],
:subject => I18n.t('notifier.single_admin.subject'), :host => AppConfig[:pod_uri].host}
:from => AppConfig.mail.sender_address,
:subject => I18n.t('notifier.single_admin.subject'), :host => AppConfig.pod_uri.host}
default_opts.merge!(opts)


Expand All @@ -42,9 +42,9 @@ def invite(email, message, inviter, invitation_code, locale)
@locale = locale
@invitation_code = invitation_code

mail_opts = {:to => email, :from => AppConfig[:smtp_sender_address],
:subject => I18n.t('notifier.invited_you', :name => @inviter.name),
:host => AppConfig[:pod_uri].host}
mail_opts = {:to => email, :from => AppConfig.mail.sender_address,
:subject => I18n.t('notifier.invited_you', :name => @inviter.name),
:host => AppConfig.pod_uri.host}

I18n.with_locale(locale) do
mail(mail_opts) do |format|
Expand Down
Loading

0 comments on commit 2a4db54

Please sign in to comment.