aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin_controller.rb6
-rw-r--r--app/controllers/admin_request_controller.rb4
-rw-r--r--app/controllers/api_controller.rb2
-rw-r--r--app/controllers/application_controller.rb17
-rw-r--r--app/controllers/general_controller.rb6
-rw-r--r--app/controllers/help_controller.rb2
-rw-r--r--app/controllers/holiday_controller.rb4
-rw-r--r--app/controllers/request_controller.rb13
-rw-r--r--app/controllers/services_controller.rb6
-rw-r--r--app/controllers/user_controller.rb4
-rw-r--r--app/helpers/config_helper.rb4
-rwxr-xr-xapp/helpers/link_to_helper.rb4
-rw-r--r--app/helpers/mailer_helper.rb4
-rw-r--r--app/models/application_mailer.rb2
-rw-r--r--app/models/contact_mailer.rb2
-rw-r--r--app/models/exim_log.rb2
-rw-r--r--app/models/incoming_message.rb9
-rw-r--r--app/models/info_request.rb19
-rw-r--r--app/models/outgoing_mailer.rb6
-rw-r--r--app/models/outgoing_message.rb2
-rw-r--r--app/models/public_body.rb2
-rw-r--r--app/models/raw_email.rb3
-rw-r--r--app/models/request_mailer.rb4
-rw-r--r--app/models/track_mailer.rb4
-rw-r--r--app/models/track_thing.rb2
-rw-r--r--app/models/user.rb15
-rw-r--r--app/views/general/_footer.rhtml2
-rw-r--r--app/views/layouts/default.rhtml6
-rw-r--r--app/views/request/_sidebar.rhtml2
-rw-r--r--app/views/request/simple_correspondence.rhtml2
-rw-r--r--app/views/user/rate_limited.rhtml2
-rw-r--r--app/views/user/set_profile_about_me.rhtml2
-rw-r--r--config/environment.rb22
-rw-r--r--config/initializers/session_store.rb2
-rw-r--r--config/initializers/theme_loader.rb3
-rw-r--r--db/migrate/101_add_hash_to_info_request.rb2
-rw-r--r--lib/alaveteli_external_command.rb5
-rw-r--r--lib/configuration.rb65
-rw-r--r--lib/tasks/themes.rake8
-rwxr-xr-xscript/handle-mail-replies.rb3
-rw-r--r--spec/controllers/user_controller_spec.rb2
-rw-r--r--spec/integration/admin_spec.rb4
-rw-r--r--spec/models/incoming_message_spec.rb3
-rw-r--r--spec/models/request_mailer_spec.rb8
-rw-r--r--spec/spec_helper.rb7
45 files changed, 165 insertions, 133 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 08528f8a8..b0c936a62 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -48,7 +48,7 @@ class AdminController < ApplicationController
end
def authenticate
- if MySociety::Config.get('SKIP_ADMIN_AUTH', false)
+ if Configuration::skip_admin_auth
session[:using_admin] = 1
return
else
@@ -70,10 +70,8 @@ class AdminController < ApplicationController
end
end
else
- config_username = MySociety::Config.get('ADMIN_USERNAME', '')
- config_password = MySociety::Config.get('ADMIN_PASSWORD', '')
authenticate_or_request_with_http_basic do |user_name, password|
- if user_name == config_username && password == config_password
+ if user_name == Configuration::admin_username && password == Configuration::admin_password
session[:using_admin] = 1
request.env['REMOTE_USER'] = user_name
else
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index 53ff2957b..b8f2de968 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -42,9 +42,9 @@ class AdminRequestController < AdminController
# XXX is this *really* the only way to render a template to a
# variable, rather than to the response?
vars = OpenStruct.new(:name_to => @info_request.user_name,
- :name_from => MySociety::Config.get("CONTACT_NAME", 'Alaveteli'),
+ :name_from => Configuration::contact_name,
:info_request => @info_request, :reason => params[:reason],
- :info_request_url => 'http://' + MySociety::Config.get('DOMAIN') + request_url(@info_request),
+ :info_request_url => 'http://' + Configuration::domain + request_url(@info_request),
:site_name => site_name)
template = File.read(File.join(File.dirname(__FILE__), "..", "views", "admin_request", "hidden_user_explanation.rhtml"))
@request_hidden_user_explanation = ERB.new(template).result(vars.instance_eval { binding })
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 409a432eb..aa5e85db3 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -248,6 +248,6 @@ class ApiController < ApplicationController
private
def make_url(*args)
- "http://" + MySociety::Config.get("DOMAIN", '127.0.0.1:3000') + "/" + args.join("/")
+ "http://" + Configuration::domain + "/" + args.join("/")
end
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index ce18e6ef5..4e319ae5c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -56,7 +56,7 @@ class ApplicationController < ActionController::Base
end
def set_gettext_locale
- if MySociety::Config.get('USE_DEFAULT_BROWSER_LANGUAGE', true)
+ if Configuration::use_default_browser_language
requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale
else
requested_locale = params[:locale] || session[:locale] || cookies[:locale] || I18n.default_locale
@@ -89,7 +89,7 @@ class ApplicationController < ActionController::Base
# egrep "CONSUME MEMORY: [0-9]{7} KB" production.log
around_filter :record_memory
def record_memory
- record_memory = MySociety::Config.get('DEBUG_RECORD_MEMORY', false)
+ record_memory = Configuration::debug_record_memory
if record_memory
logger.info "Processing request for #{request.url} with Rails process #{Process.pid}"
File.read("/proc/#{Process.pid}/status").match(/VmRSS:\s+(\d+)/)
@@ -333,11 +333,10 @@ class ApplicationController < ActionController::Base
#
def check_read_only
- read_only = MySociety::Config.get('READ_ONLY', '')
- if !read_only.empty?
+ if !Configuration::read_only.empty?
flash[:notice] = _("<p>{{site_name}} is currently in maintenance. You can only view existing requests. You cannot make new ones, add followups or annotations, or otherwise change the database.</p> <p>{{read_only}}</p>",
:site_name => site_name,
- :read_only => read_only)
+ :read_only => Configuration::read_only)
redirect_to frontpage_url
end
@@ -557,13 +556,11 @@ class ApplicationController < ActionController::Base
end
def country_from_ip
- gaze = MySociety::Config.get('GAZE_URL', '')
- default = MySociety::Config.get('ISO_COUNTRY_CODE', '')
country = ""
- if !gaze.empty?
- country = quietly_try_to_open("#{gaze}/gaze-rest?f=get_country_from_ip;ip=#{request.remote_ip}")
+ if !Configuration::gaze_url.empty?
+ country = quietly_try_to_open("#{Configuration::gaze_url}/gaze-rest?f=get_country_from_ip;ip=#{request.remote_ip}")
end
- country = default if country.empty?
+ country = Configuration::iso_country_code if country.empty?
return country
end
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 839064fcd..9e47af22a 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -24,7 +24,7 @@ class GeneralController < ApplicationController
behavior_cache :tag => [session[:user_id], request.url] do
# get some example searches and public bodies to display
# either from config, or based on a (slow!) query if not set
- body_short_names = MySociety::Config.get('FRONTPAGE_PUBLICBODY_EXAMPLES', '').split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ")
+ body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ")
@locale = self.locale_from_params()
locale_condition = 'public_body_translations.locale = ?'
conditions = [locale_condition, @locale]
@@ -71,7 +71,7 @@ class GeneralController < ApplicationController
def blog
medium_cache
@feed_autodetect = []
- @feed_url = "#{MySociety::Config.get('BLOG_FEED', '')}?lang=#{self.locale_from_params()}"
+ @feed_url = "#{Configuration::blog_feed}?lang=#{self.locale_from_params()}"
@blog_items = []
if not @feed_url.empty?
content = quietly_try_to_open(@feed_url)
@@ -82,7 +82,7 @@ class GeneralController < ApplicationController
@feed_autodetect = [{:url => @feed_url, :title => "#{site_name} blog"}]
end
end
- @twitter_user = MySociety::Config.get('TWITTER_USERNAME', '')
+ @twitter_user = Configuration::twitter_username
end
# Just does a redirect from ?query= search to /query
diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb
index c7affd57c..ba04b7e22 100644
--- a/app/controllers/help_controller.rb
+++ b/app/controllers/help_controller.rb
@@ -20,7 +20,7 @@ class HelpController < ApplicationController
end
def contact
- @contact_email = MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost')
+ @contact_email = Configuration::contact_email
@contact_email = @contact_email.gsub(/@/, "&#64;")
# if they clicked remove for link to request/body, remove it
diff --git a/app/controllers/holiday_controller.rb b/app/controllers/holiday_controller.rb
index 9430c0756..82fa2852e 100644
--- a/app/controllers/holiday_controller.rb
+++ b/app/controllers/holiday_controller.rb
@@ -14,9 +14,7 @@ class HolidayController < ApplicationController
def due_date
if params[:holiday]
@request_date = Date.strptime(params[:holiday]) or raise "Invalid date"
- days_later = MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20)
- working_or_calendar_days = MySociety::Config.get('WORKING_OR_CALENDAR_DAYS', 'working')
- @due_date = Holiday.due_date_from(@request_date, days_later, working_or_calendar_days)
+ @due_date = Holiday.due_date_from(@request_date, Configuration::reply_late_after_days, Configuration::working_or_calendar_days)
@skipped = Holiday.all(
:conditions => [ 'day >= ? AND day <= ?',
@request_date.strftime("%F"), @due_date.strftime("%F")
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 268ecc73a..9ad328a0c 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -46,7 +46,7 @@ class RequestController < ApplicationController
end
def show
- if !MySociety::Config.get('VARNISH_HOST').nil?
+ if !Configuration::varnish_host.nil?
# If varnish is set up to accept PURGEs, then cache for a
# long time
long_cache
@@ -369,7 +369,7 @@ class RequestController < ApplicationController
replied by then.</p>
<p>If you write about this request (for example in a forum or a blog) please link to this page, and add an
annotation below telling people about your writing.</p>",:law_used_full=>@info_request.law_used_full,
- :late_number_of_days => MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20))
+ :late_number_of_days => Configuration::reply_late_after_days)
redirect_to show_new_request_path(:url_title => @info_request.url_title)
end
@@ -457,7 +457,7 @@ class RequestController < ApplicationController
flash[:notice] = _("<p>Thank you! Hope you don't have to wait much longer.</p> <p>By law, you should have got a response promptly, and normally before the end of <strong>{{date_response_required_by}}</strong>.</p>",:date_response_required_by=>simple_date(@info_request.date_response_required_by))
redirect_to request_url(@info_request)
elsif @info_request.calculate_status == 'waiting_response_very_overdue'
- flash[:notice] = _("<p>Thank you! Your request is long overdue, by more than {{very_late_number_of_days}} working days. Most requests should be answered within {{late_number_of_days}} working days. You might like to complain about this, see below.</p>", :very_late_number_of_days => MySociety::Config.get('REPLY_VERY_LATE_AFTER_DAYS', 40), :late_number_of_days => MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20))
+ flash[:notice] = _("<p>Thank you! Your request is long overdue, by more than {{very_late_number_of_days}} working days. Most requests should be answered within {{late_number_of_days}} working days. You might like to complain about this, see below.</p>", :very_late_number_of_days => Configuration::reply_very_late_after_days, :late_number_of_days => Configuration::reply_late_after_days)
redirect_to unhappy_url(@info_request)
elsif @info_request.calculate_status == 'not_held'
flash[:notice] = _("<p>Thank you! Here are some ideas on what to do next:</p>
@@ -489,7 +489,7 @@ class RequestController < ApplicationController
elsif @info_request.calculate_status == 'gone_postal'
redirect_to respond_to_last_url(@info_request) + "?gone_postal=1"
elsif @info_request.calculate_status == 'internal_review'
- flash[:notice] = _("<p>Thank you! Hopefully your wait isn't too long.</p><p>You should get a response within {{late_number_of_days}} days, or be told if it will take longer (<a href=\"{{review_url}}\">details</a>).</p>",:late_number_of_days => MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20), :review_url => unhappy_url(@info_request) + "#internal_review")
+ flash[:notice] = _("<p>Thank you! Hopefully your wait isn't too long.</p><p>You should get a response within {{late_number_of_days}} days, or be told if it will take longer (<a href=\"{{review_url}}\">details</a>).</p>",:late_number_of_days => Configuration.reply_late_after_days, :review_url => unhappy_url(@info_request) + "#internal_review")
redirect_to request_url(@info_request)
elsif @info_request.calculate_status == 'error_message'
flash[:notice] = _("<p>Thank you! We'll look into what happened and try and fix it up.</p><p>If the error was a delivery failure, and you can find an up to date FOI email address for the authority, please tell us using the form below.</p>")
@@ -875,11 +875,10 @@ class RequestController < ApplicationController
if !File.exists?(file_path)
FileUtils.mkdir_p(File.dirname(file_path))
Zip::ZipFile.open(file_path, Zip::ZipFile::CREATE) { |zipfile|
- convert_command = MySociety::Config.get("HTML_TO_PDF_COMMAND")
+ convert_command = Configuration::html_to_pdf_command
done = false
if File.exists?(convert_command)
- domain = MySociety::Config.get("DOMAIN")
- url = "http://#{domain}#{request_url(info_request)}?print_stylesheet=1"
+ url = "http://#{Configuration::domain}#{request_url(info_request)}?print_stylesheet=1"
tempfile = Tempfile.new('foihtml2pdf')
output = AlaveteliExternalCommand.run(convert_command, url, tempfile.path)
if !output.nil?
diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb
index 40e0faaf7..ead5d73b7 100644
--- a/app/controllers/services_controller.rb
+++ b/app/controllers/services_controller.rb
@@ -6,7 +6,7 @@ class ServicesController < ApplicationController
def other_country_message
text = ""
- iso_country_code = MySociety::Config.get('ISO_COUNTRY_CODE').downcase
+ iso_country_code = Configuration::iso_country_code.downcase
if country_from_ip.downcase != iso_country_code
found_country = WorldFOIWebsites.by_code(country_from_ip)
found_country_name = !found_country.nil? && found_country[:country_name]
@@ -36,9 +36,9 @@ class ServicesController < ApplicationController
:content_type => "text/plain",
:layout => false,
:locals => {:name_to => info_request.user_name,
- :name_from => MySociety::Config.get("CONTACT_NAME", 'Alaveteli'),
+ :name_from => Configuration::contact_name,
:info_request => info_request, :reason => params[:reason],
- :info_request_url => 'http://' + MySociety::Config.get('DOMAIN') + request_url(info_request),
+ :info_request_url => 'http://' + Configuration::domain + request_url(info_request),
:site_name => site_name}
end
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 0a9e1d781..c48f75204 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -138,7 +138,7 @@ class UserController < ApplicationController
# Login form
def signin
work_out_post_redirect
- @request_from_foreign_country = country_from_ip != MySociety::Config.get('ISO_COUNTRY_CODE', 'GB')
+ @request_from_foreign_country = country_from_ip != Configuration::iso_country_code
# make sure we have cookies
if session.instance_variable_get(:@dbman)
if not session.instance_variable_get(:@dbman).instance_variable_get(:@original)
@@ -192,7 +192,7 @@ class UserController < ApplicationController
# Create new account form
def signup
work_out_post_redirect
- @request_from_foreign_country = country_from_ip != MySociety::Config.get('ISO_COUNTRY_CODE', 'GB')
+ @request_from_foreign_country = country_from_ip != Configuration::iso_country_code
# Make the user and try to save it
@user_signup = User.new(params[:user_signup])
error = false
diff --git a/app/helpers/config_helper.rb b/app/helpers/config_helper.rb
index 543b60256..0f18c0c4b 100644
--- a/app/helpers/config_helper.rb
+++ b/app/helpers/config_helper.rb
@@ -1,9 +1,9 @@
module ConfigHelper
def site_name
- MySociety::Config.get('SITE_NAME', 'Alaveteli')
+ Configuration::site_name
end
def force_registration_on_new_request
- MySociety::Config.get('FORCE_REGISTRATION_ON_NEW_REQUEST', false)
+ Configuration::force_registration_on_new_request
end
end \ No newline at end of file
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb
index cae17ebd3..c8ad7bc30 100755
--- a/app/helpers/link_to_helper.rb
+++ b/app/helpers/link_to_helper.rb
@@ -221,7 +221,7 @@ module LinkToHelper
# Admin pages
def admin_url(relative_path)
- admin_url_prefix = MySociety::Config.get("ADMIN_BASE_URL", "")
+ admin_url_prefix = Configuration::admin_base_url
admin_url_prefix = admin_general_index_path+"/" if admin_url_prefix.empty?
return admin_url_prefix + relative_path
end
@@ -241,7 +241,7 @@ module LinkToHelper
def main_url(relative_path, append = nil)
- url_prefix = "http://" + MySociety::Config.get("DOMAIN", '127.0.0.1:3000')
+ url_prefix = "http://" + Configuration::domain
url = url_prefix + relative_path
if !append.nil?
begin
diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb
index c0a950d47..be2ce47aa 100644
--- a/app/helpers/mailer_helper.rb
+++ b/app/helpers/mailer_helper.rb
@@ -1,7 +1,5 @@
module MailerHelper
def contact_from_name_and_email
- contact_name = MySociety::Config.get("CONTACT_NAME", 'Alaveteli')
- contact_email = MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost')
- return "#{contact_name} <#{contact_email}>"
+ "#{Configuration::contact_name} <#{Configuration::contact_email}>"
end
end
diff --git a/app/models/application_mailer.rb b/app/models/application_mailer.rb
index 044006f7c..3a11733a8 100644
--- a/app/models/application_mailer.rb
+++ b/app/models/application_mailer.rb
@@ -16,7 +16,7 @@ class ApplicationMailer < ActionMailer::Base
self.raise_delivery_errors = true
def blackhole_email
- MySociety::Config.get("BLACKHOLE_PREFIX", 'do-not-reply-to-this-address')+"@"+MySociety::Config.get("INCOMING_EMAIL_DOMAIN", "localhost")
+ Configuration::blackhole_prefix+"@"+Configuration::incoming_email_domain
end
# URL generating functions are needed by all controllers (for redirects),
diff --git a/app/models/contact_mailer.rb b/app/models/contact_mailer.rb
index 6e781d48c..adeac8eac 100644
--- a/app/models/contact_mailer.rb
+++ b/app/models/contact_mailer.rb
@@ -52,7 +52,7 @@ class ContactMailer < ApplicationMailer
:from_user => @from,
:recipient_user => recipient_user,
}
- bcc MySociety::Config::get("CONTACT_EMAIL")
+ bcc Configuration::contact_email
end
end
diff --git a/app/models/exim_log.rb b/app/models/exim_log.rb
index 82000efa1..e1861150f 100644
--- a/app/models/exim_log.rb
+++ b/app/models/exim_log.rb
@@ -63,7 +63,7 @@ class EximLog < ActiveRecord::Base
order = 0
for line in f
order = order + 1
- email_domain = MySociety::Config.get("INCOMING_EMAIL_DOMAIN", "localhost")
+ email_domain = Configuration::incoming_email_domain
emails = line.scan(/request-[^\s]+@#{email_domain}/).sort.uniq
for email in emails
info_request = InfoRequest.find_by_incoming_email(email)
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 13fc316cd..f3844a153 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -253,7 +253,7 @@ class IncomingMessage < ActiveRecord::Base
text.gsub!(self.info_request.public_body.request_email, _("[{{public_body}} request email]", :public_body => self.info_request.public_body.short_or_long_name))
end
text.gsub!(self.info_request.incoming_email, _('[FOI #{{request}} email]', :request => self.info_request.id.to_s) )
- text.gsub!(MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost'), _("[{{site_name}} contact email]", :site_name => MySociety::Config.get('SITE_NAME', 'Alaveteli')) )
+ text.gsub!(Configuration::contact_email, _("[{{site_name}} contact email]", :site_name => Configuration::site_name) )
end
# Replaces all email addresses in (possibly binary data) with equal length alternative ones.
@@ -279,7 +279,7 @@ class IncomingMessage < ActiveRecord::Base
if censored_uncompressed_text != uncompressed_text
# then use the altered file (recompressed)
recompressed_text = nil
- if MySociety::Config.get('USE_GHOSTSCRIPT_COMPRESSION') == true
+ if Configuration::use_ghostscript_compression == true
command = ["gs", "-sDEVICE=pdfwrite", "-dCompatibilityLevel=1.4", "-dPDFSETTINGS=/screen", "-dNOPAUSE", "-dQUIET", "-dBATCH", "-sOutputFile=-", "-"]
else
command = ["pdftk", "-", "output", "-", "compress"]
@@ -376,8 +376,7 @@ class IncomingMessage < ActiveRecord::Base
text.gsub!(/(Mobile|Mob)([\s\/]*(Fax|Tel))*\s*:?[\s\d]*\d/, "[mobile number]")
# Remove WhatDoTheyKnow signup links
- domain = MySociety::Config.get('DOMAIN')
- text.gsub!(/http:\/\/#{domain}\/c\/[^\s]+/, "[WDTK login link]")
+ text.gsub!(/http:\/\/#{Configuration::domain}\/c\/[^\s]+/, "[WDTK login link]")
# Remove things from censor rules
self.info_request.apply_censor_rules_to_text!(text)
@@ -649,7 +648,7 @@ class IncomingMessage < ActiveRecord::Base
begin
text = Iconv.conv('utf-8//IGNORE', source_charset, text) +
_("\n\n[ {{site_name}} note: The above text was badly encoded, and has had strange characters removed. ]",
- :site_name => MySociety::Config.get('SITE_NAME', 'Alaveteli'))
+ :site_name => Configuration::site_name)
rescue Iconv::InvalidEncoding, Iconv::IllegalSequence
if source_charset != "utf-8"
source_charset = "utf-8"
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 141440c6d..85168e6d4 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -689,23 +689,18 @@ public
# last_event_forming_initial_request. There may be more obscure
# things, e.g. fees, not properly covered.
def date_response_required_by
- days_later = MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20)
- working_or_calendar_days = MySociety::Config.get('WORKING_OR_CALENDAR_DAYS', 'working')
- return Holiday.due_date_from(self.date_initial_request_last_sent_at, days_later, working_or_calendar_days)
+ Holiday.due_date_from(self.date_initial_request_last_sent_at, Configuration::reply_late_after_days, Configuration::working_or_calendar_days)
end
# This is a long stop - even with UK public interest test extensions, 40
# days is a very long time.
def date_very_overdue_after
last_sent = last_event_forming_initial_request
- very_late_days_later = MySociety::Config.get('REPLY_VERY_LATE_AFTER_DAYS', 40)
- school_very_late_days_later = MySociety::Config.get('SPECIAL_REPLY_VERY_LATE_AFTER_DAYS', 60)
- working_or_calendar_days = MySociety::Config.get('WORKING_OR_CALENDAR_DAYS', 'working')
if self.public_body.is_school?
# schools have 60 working days maximum (even over a long holiday)
- return Holiday.due_date_from(self.date_initial_request_last_sent_at, school_very_late_days_later, working_or_calendar_days)
+ Holiday.due_date_from(self.date_initial_request_last_sent_at, Configuration::special_reply_very_late_after_days, Configuration::working_or_calendar_days)
else
# public interest test ICO guidance gives 40 working maximum
- return Holiday.due_date_from(self.date_initial_request_last_sent_at, very_late_days_later, working_or_calendar_days)
+ Holiday.due_date_from(self.date_initial_request_last_sent_at, Configuration::reply_very_late_after_days, Configuration::working_or_calendar_days)
end
end
@@ -905,10 +900,10 @@ public
end
def InfoRequest.magic_email_for_id(prefix_part, id)
- magic_email = MySociety::Config.get("INCOMING_EMAIL_PREFIX", "")
+ magic_email = Configuration::incoming_email_prefix
magic_email += prefix_part + id.to_s
magic_email += "-" + InfoRequest.hash_from_id(id)
- magic_email += "@" + MySociety::Config.get("INCOMING_EMAIL_DOMAIN", "localhost")
+ magic_email += "@" + Configuration::incoming_email_domain
return magic_email
end
@@ -919,7 +914,7 @@ public
end
def InfoRequest.hash_from_id(id)
- return Digest::SHA1.hexdigest(id.to_s + MySociety::Config.get("INCOMING_EMAIL_SECRET", 'dummysecret'))[0,8]
+ return Digest::SHA1.hexdigest(id.to_s + Configuration::incoming_email_secret)[0,8]
end
# Called by find_by_incoming_email - and used to be called by separate
@@ -1143,7 +1138,7 @@ public
before_save :purge_in_cache
def purge_in_cache
- if !MySociety::Config.get('VARNISH_HOST').nil? && !self.id.nil?
+ if !Configuration::varnish_host.nil? && !self.id.nil?
# we only do this for existing info_requests (new ones have a nil id)
path = url_for(:controller => 'request', :action => 'show', :url_title => self.url_title, :only_path => true, :locale => :none)
req = PurgeRequest.find_by_url(path)
diff --git a/app/models/outgoing_mailer.rb b/app/models/outgoing_mailer.rb
index 8562c5b68..2e5e9c6ae 100644
--- a/app/models/outgoing_mailer.rb
+++ b/app/models/outgoing_mailer.rb
@@ -24,7 +24,7 @@ class OutgoingMailer < ApplicationMailer
@subject = info_request.email_subject_request
@headers["message-id"] = OutgoingMailer.id_for_message(outgoing_message)
@body = {:info_request => info_request, :outgoing_message => outgoing_message,
- :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') }
+ :contact_email => Configuration::contact_email }
end
# Later message to public body regarding existing request
@@ -36,7 +36,7 @@ class OutgoingMailer < ApplicationMailer
@headers["message-id"] = OutgoingMailer.id_for_message(outgoing_message)
@body = {:info_request => info_request, :outgoing_message => outgoing_message,
:incoming_message_followup => incoming_message_followup,
- :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') }
+ :contact_email => Configuration::contact_email }
end
# XXX the condition checking valid_to_reply_to? also appears in views/request/_followup.rhtml,
@@ -91,7 +91,7 @@ class OutgoingMailer < ApplicationMailer
message_id = "ogm-" + outgoing_message.id.to_s
t = Time.now
message_id += "+" + '%08x%05x-%04x' % [t.to_i, t.tv_usec, rand(0xffff)]
- message_id += "@" + MySociety::Config.get("INCOMING_EMAIL_DOMAIN", "localhost")
+ message_id += "@" + Configuration::incoming_email_domain
return "<" + message_id + ">"
end
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index 0ce1ee11c..cb2f1efdc 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -87,7 +87,7 @@ class OutgoingMessage < ActiveRecord::Base
"'" + self.info_request.title + "'." +
"\n\n\n\n [ " + self.get_internal_review_insert_here_note + " ] \n\n\n\n" +
"A full history of my FOI request and all correspondence is available on the Internet at this address:\n" +
- "http://" + MySociety::Config.get("DOMAIN", '127.0.0.1:3000') + "/request/" + self.info_request.url_title
+ "http://" + Configuration::domain + "/request/" + self.info_request.url_title
else
""
end
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 2cf1ce8a2..e9a90bce3 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -336,7 +336,7 @@ class PublicBody < ActiveRecord::Base
pb = PublicBody.new(
:name => 'Internal admin authority',
:short_name => "",
- :request_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost'),
+ :request_email => Configuration::contact_email,
:home_page => "",
:notes => "",
:publication_scheme => "",
diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb
index 3bb794684..c7b8eb017 100644
--- a/app/models/raw_email.rb
+++ b/app/models/raw_email.rb
@@ -28,8 +28,7 @@ class RawEmail < ActiveRecord::Base
if ENV["RAILS_ENV"] == "test"
return File.join(Rails.root, 'files/raw_email_test')
else
- return File.join(MySociety::Config.get('RAW_EMAILS_LOCATION',
- 'files/raw_emails'),
+ return File.join(Configuration::raw_emails_location,
request_id[0..2], request_id)
end
end
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb
index ba9285fc6..4316a9be9 100644
--- a/app/models/request_mailer.rb
+++ b/app/models/request_mailer.rb
@@ -55,7 +55,7 @@ class RequestMailer < ApplicationMailer
:filename => "original.eml", :transfer_encoding => '7bit', :content_disposition => 'inline'
@body = {
:info_request => info_request,
- :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost')
+ :contact_email => Configuration::contact_email
}
end
@@ -303,7 +303,7 @@ class RequestMailer < ApplicationMailer
# Send email alerts for new responses which haven't been classified. By default,
# it goes out 3 days after last update of event, then after 10, then after 24.
def self.alert_new_response_reminders
- MySociety::Config.get("NEW_RESPONSE_REMINDER_AFTER_DAYS", [3, 10, 24]).each_with_index do |days, i|
+ Configuration::new_response_reminder_after_days.each_with_index do |days, i|
self.alert_new_response_reminders_internal(days, "new_response_reminder_#{i+1}")
end
end
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb
index 92da7c376..6e2dd5109 100644
--- a/app/models/track_mailer.rb
+++ b/app/models/track_mailer.rb
@@ -27,9 +27,7 @@ class TrackMailer < ApplicationMailer
end
def contact_from_name_and_email
- contact_name = MySociety::Config.get("TRACK_SENDER_NAME", 'Alaveteli')
- contact_email = MySociety::Config.get("TRACK_SENDER_EMAIL", 'contact@localhost')
- return "#{contact_name} <#{contact_email}>"
+ "#{Configuration::track_sender_name} <#{Configuration::track_sender_email}>"
end
# Send email alerts for tracked things. Never more than one email
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb
index d0fc62e12..9a553b382 100644
--- a/app/models/track_thing.rb
+++ b/app/models/track_thing.rb
@@ -253,7 +253,7 @@ class TrackThing < ActiveRecord::Base
:title_in_email => self.public_body.law_only_short + " requests to '" + self.public_body.name + "'",
:title_in_rss => self.public_body.law_only_short + " requests to '" + self.public_body.name + "'",
# Authentication
- :web => _("To follow requests made using {{site_name}} to the public authority '{{public_body_name}}'", :site_name=>MySociety::Config.get('SITE_NAME', 'Alaveteli'), :public_body_name=>CGI.escapeHTML(self.public_body.name)),
+ :web => _("To follow requests made using {{site_name}} to the public authority '{{public_body_name}}'", :site_name=>Configuration::site_name, :public_body_name=>CGI.escapeHTML(self.public_body.name)),
:email => _("Then you will be notified whenever someone requests something or gets a response from '{{public_body_name}}'.", :public_body_name=>CGI.escapeHTML(self.public_body.name)),
:email_subject => _("Confirm you want to follow requests to '{{public_body_name}}'", :public_body_name=>self.public_body.name),
# RSS sorting
diff --git a/app/models/user.rb b/app/models/user.rb
index bb1b54d70..59f6c971c 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -208,13 +208,12 @@ class User < ActiveRecord::Base
# The "internal admin" is a special user for internal use.
def User.internal_admin_user
- contact_email = MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost')
- u = User.find_by_email(contact_email)
+ u = User.find_by_email(Configuration::contact_email)
if u.nil?
password = PostRedirect.generate_random_token
u = User.new(
:name => 'Internal admin user',
- :email => contact_email,
+ :email => Configuration::contact_email,
:password => password,
:password_confirmation => password
)
@@ -282,18 +281,16 @@ class User < ActiveRecord::Base
return false if self.no_limit
# Has the user issued as many as MAX_REQUESTS_PER_USER_PER_DAY requests in the past 24 hours?
- daily_limit = MySociety::Config.get("MAX_REQUESTS_PER_USER_PER_DAY")
- return false if daily_limit.nil?
+ return false if Configuration::max_requests_per_user_per_day.nil?
recent_requests = InfoRequest.count(:conditions => ["user_id = ? and created_at > now() - '1 day'::interval", self.id])
- return (recent_requests >= daily_limit)
+ return (recent_requests >= Configuration::max_requests_per_user_per_day)
end
def next_request_permitted_at
return nil if self.no_limit
- daily_limit = MySociety::Config.get("MAX_REQUESTS_PER_USER_PER_DAY")
- n_most_recent_requests = InfoRequest.all(:conditions => ["user_id = ? and created_at > now() - '1 day'::interval", self.id], :order => "created_at DESC", :limit => daily_limit)
- return nil if n_most_recent_requests.size < daily_limit
+ n_most_recent_requests = InfoRequest.all(:conditions => ["user_id = ? and created_at > now() - '1 day'::interval", self.id], :order => "created_at DESC", :limit => Configuration::max_requests_per_user_per_day)
+ return nil if n_most_recent_requests.size < Configuration::max_requests_per_user_per_day
nth_most_recent_request = n_most_recent_requests[-1]
return nth_most_recent_request.created_at + 1.day
diff --git a/app/views/general/_footer.rhtml b/app/views/general/_footer.rhtml
index efcd8f96b..ab5ab2c47 100644
--- a/app/views/general/_footer.rhtml
+++ b/app/views/general/_footer.rhtml
@@ -1,6 +1,6 @@
<div id="footer">
<%= link_to _("Contact {{site_name}}", :site_name => site_name), help_contact_url %>
-| <img src="/images/twitter-16.png" alt="twitter icon" class="twitter-icon"> <a href="https://twitter.com/<%= MySociety::Config.get('TWITTER_USERNAME') %>"><%= _("Follow us on twitter") %></a>
+| <img src="/images/twitter-16.png" alt="twitter icon" class="twitter-icon"> <a href="https://twitter.com/<%= Configuration::twitter_username %>"><%= _("Follow us on twitter") %></a>
<%= render :partial => 'general/credits' %>
</div>
<div class="after-footer">&nbsp;</div>
diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml
index e4022661f..21479239c 100644
--- a/app/views/layouts/default.rhtml
+++ b/app/views/layouts/default.rhtml
@@ -139,15 +139,13 @@
<input type="text">
</div>
<%
- ga_code = MySociety::Config.get('GA_CODE', '')
-
- unless ga_code.empty? %>
+ unless Configuration::ga_code.empty? %>
<script>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
- var pageTracker = _gat._getTracker("<%=ga_code%>");
+ var pageTracker = _gat._getTracker("<%= Configuration::ga_code %>");
pageTracker._trackPageview();
</script>
diff --git a/app/views/request/_sidebar.rhtml b/app/views/request/_sidebar.rhtml
index dc0d2eb31..18684943a 100644
--- a/app/views/request/_sidebar.rhtml
+++ b/app/views/request/_sidebar.rhtml
@@ -31,7 +31,7 @@
<h2><%= _("Act on what you've learnt") %></h2>
<div class="act_link">
- <% tweet_link = "https://twitter.com/share?url=#{h(request.url)}&via=#{h(MySociety::Config.get('TWITTER_USERNAME', ''))}&text='#{h(@info_request.title)}'&related=#{_('alaveteli_foi:The software that runs {{site_name}}', :site_name => h(site_name))}" %>
+ <% tweet_link = "https://twitter.com/share?url=#{h(request.url)}&via=#{h(Configuration::twitter_username)}&text='#{h(@info_request.title)}'&related=#{_('alaveteli_foi:The software that runs {{site_name}}', :site_name => h(site_name))}" %>
<%= link_to '<img src="/images/twitter-16.png" alt="twitter icon">', tweet_link %>
<%= link_to _("Tweet this request"), tweet_link %>
</div>
diff --git a/app/views/request/simple_correspondence.rhtml b/app/views/request/simple_correspondence.rhtml
index bcbc795e7..0da9ef172 100644
--- a/app/views/request/simple_correspondence.rhtml
+++ b/app/views/request/simple_correspondence.rhtml
@@ -1,4 +1,4 @@
-<%= _('This is a plain-text version of the Freedom of Information request "{{request_title}}". The latest, full version is available online at {{full_url}}', :request_title => @info_request.title, :full_url => "http://#{MySociety::Config.get('DOMAIN')}#{show_request_path(:url_title=>@info_request.url_title)}") %>.
+<%= _('This is a plain-text version of the Freedom of Information request "{{request_title}}". The latest, full version is available online at {{full_url}}', :request_title => @info_request.title, :full_url => "http://#{Configuration::domain}#{show_request_path(:url_title=>@info_request.url_title)}") %>.
<% for info_request_event in @info_request_events %>
<%
diff --git a/app/views/user/rate_limited.rhtml b/app/views/user/rate_limited.rhtml
index d5accf114..d52deebab 100644
--- a/app/views/user/rate_limited.rhtml
+++ b/app/views/user/rate_limited.rhtml
@@ -2,7 +2,7 @@
<h1><%=@title%></h1>
-<p><%= _("You have hit the rate limit on new requests. Users are ordinarily limited to {{max_requests_per_user_per_day}} requests in any rolling 24-hour period. You will be able to make another request in {{can_make_another_request}}.", :max_requests_per_user_per_day => MySociety::Config.get("MAX_REQUESTS_PER_USER_PER_DAY"), :can_make_another_request => distance_of_time_in_words(Time.now, @next_request_permitted_at))%></p>
+<p><%= _("You have hit the rate limit on new requests. Users are ordinarily limited to {{max_requests_per_user_per_day}} requests in any rolling 24-hour period. You will be able to make another request in {{can_make_another_request}}.", :max_requests_per_user_per_day => Configuration::max_requests_per_user_per_day, :can_make_another_request => distance_of_time_in_words(Time.now, @next_request_permitted_at))%></p>
<p><%= _("There is a limit on the number of requests you can make in a day, because we don’t want public authorities to be bombarded with large numbers of inappropriate requests. If you feel you have a good reason to ask for the limit to be lifted in your case, please <a href='{{help_contact_path}}'>get in touch</a>.", :help_contact_path => help_contact_path) %></p>
diff --git a/app/views/user/set_profile_about_me.rhtml b/app/views/user/set_profile_about_me.rhtml
index 8d8b32758..4fe1047da 100644
--- a/app/views/user/set_profile_about_me.rhtml
+++ b/app/views/user/set_profile_about_me.rhtml
@@ -26,7 +26,7 @@
<%= _(' Include relevant links, such as to a campaign page, your blog or a
twitter account. They will be made clickable.
e.g.')%>
- <a href="https://twitter.com/<%= MySociety::Config.get('TWITTER_USERNAME') %>">https://twitter.com/<%= MySociety::Config.get('TWITTER_USERNAME') %></a>
+ <a href="https://twitter.com/<%= Configuration::twitter_username %>">https://twitter.com/<%= Configuration::twitter_username %></a>
</p>
</div>
diff --git a/config/environment.rb b/config/environment.rb
index 250d3eed0..3348ef92a 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -29,7 +29,7 @@ load "util.rb"
# without effecting method behaviour
# and adds fallback gem call removed in https://github.com/rails/rails/commit/4c3725723f15fab0a424cb1318b82b460714b72f
require File.join(File.dirname(__FILE__), '../lib/old_rubygems_patch')
-
+require 'configuration'
# Application version
ALAVETELI_VERSION = '0.6.6'
@@ -78,8 +78,8 @@ Rails::Initializer.run do |config|
end
# See Rails::Configuration for more options
- ENV['RECAPTCHA_PUBLIC_KEY'] = MySociety::Config::get("RECAPTCHA_PUBLIC_KEY", 'x');
- ENV['RECAPTCHA_PRIVATE_KEY'] = MySociety::Config::get("RECAPTCHA_PRIVATE_KEY", 'x');
+ ENV['RECAPTCHA_PUBLIC_KEY'] = Configuration::recaptcha_public_key
+ ENV['RECAPTCHA_PRIVATE_KEY'] = Configuration::recaptcha_private_key
end
# Add new inflection rules using the following format
@@ -98,22 +98,22 @@ end
# The Rails cache is set up by the Interlock plugin to use memcached
# Domain for URLs (so can work for scripts, not just web pages)
-ActionMailer::Base.default_url_options[:host] = MySociety::Config.get("DOMAIN", 'localhost:3000')
+ActionMailer::Base.default_url_options[:host] = Configuration::domain
# So that javascript assets use full URL, so proxied admin URLs read javascript OK
-if (MySociety::Config.get("DOMAIN", "") != "")
+if (Configuration::domain != "")
ActionController::Base.asset_host = Proc.new { |source, request|
if ENV["RAILS_ENV"] != "test" && request.fullpath.match(/^\/admin\//)
- MySociety::Config.get("ADMIN_PUBLIC_URL", "")
+ Configuration::admin_public_url
else
- MySociety::Config.get("DOMAIN", 'localhost:3000')
+ Configuration::domain
end
}
end
# fallback locale and available locales
-available_locales = MySociety::Config.get('AVAILABLE_LOCALES', '').split(/ /)
-default_locale = MySociety::Config.get('DEFAULT_LOCALE', '')
+available_locales = Configuration::available_locales.split(/ /)
+default_locale = Configuration::default_locale
FastGettext.default_available_locales = available_locales
I18n.locale = default_locale
@@ -140,5 +140,5 @@ require 'world_foi_websites.rb'
require 'alaveteli_external_command.rb'
require 'quiet_opener.rb'
-ExceptionNotification::Notifier.sender_address = MySociety::Config::get('EXCEPTION_NOTIFICATIONS_FROM')
-ExceptionNotification::Notifier.exception_recipients = MySociety::Config::get('EXCEPTION_NOTIFICATIONS_TO')
+ExceptionNotification::Notifier.sender_address = Configuration::exception_notifications_from
+ExceptionNotification::Notifier.exception_recipients = Configuration::exception_notifications_to
diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb
index a05d2c7d1..8cfa333f2 100644
--- a/config/initializers/session_store.rb
+++ b/config/initializers/session_store.rb
@@ -7,7 +7,7 @@
ActionController::Base.session = {
:key => '_wdtk_cookie_session',
- :secret => MySociety::Config.get("COOKIE_STORE_SESSION_SECRET", 'this default is insecure as code is open source, please override for live sites in config/general; this will do for local development')
+ :secret => Configuration::cookie_store_session_secret
}
ActionController::Base.session_store = :cookie_store
diff --git a/config/initializers/theme_loader.rb b/config/initializers/theme_loader.rb
index 8908dc07e..877149e9d 100644
--- a/config/initializers/theme_loader.rb
+++ b/config/initializers/theme_loader.rb
@@ -2,9 +2,8 @@
# It is used by our config/routes.rb to decide which route extension files to load.
$alaveteli_route_extensions = []
-theme_urls = MySociety::Config.get("THEME_URLS", [])
if ENV["RAILS_ENV"] != "test" # Don't let the themes interfere with Alaveteli specs
- for url in theme_urls.reverse
+ for url in Configuration::theme_urls.reverse
theme_name = url.sub(/.*\/(.*).git/, "\\1")
theme_main_include = File.expand_path "../../../vendor/plugins/#{theme_name}/lib/alavetelitheme.rb", __FILE__
if File.exists? theme_main_include
diff --git a/db/migrate/101_add_hash_to_info_request.rb b/db/migrate/101_add_hash_to_info_request.rb
index 20608aac1..e21bf0989 100644
--- a/db/migrate/101_add_hash_to_info_request.rb
+++ b/db/migrate/101_add_hash_to_info_request.rb
@@ -6,7 +6,7 @@ class AddHashToInfoRequest < ActiveRecord::Migration
# Create the missing events for requests already sent
InfoRequest.find(:all).each do |info_request|
- info_request.idhash = Digest::SHA1.hexdigest(info_request.id.to_s + MySociety::Config.get("INCOMING_EMAIL_SECRET", 'dummysecret'))[0,8]
+ info_request.idhash = Digest::SHA1.hexdigest(info_request.id.to_s + Configuration::incoming_email_secret)[0,8]
info_request.save!
puts info_request.idhash
end
diff --git a/lib/alaveteli_external_command.rb b/lib/alaveteli_external_command.rb
index 7d32be904..3bfc34e3a 100644
--- a/lib/alaveteli_external_command.rb
+++ b/lib/alaveteli_external_command.rb
@@ -14,16 +14,15 @@ module AlaveteliExternalCommand
if program_name =~ %r(^/)
program_path = program_name
else
- utility_search_path = MySociety::Config.get("UTILITY_SEARCH_PATH", ["/usr/bin", "/usr/local/bin"])
found = false
- utility_search_path.each do |d|
+ Configuration::utility_search_path.each do |d|
program_path = File.join(d, program_name)
if File.file? program_path and File.executable? program_path
found = true
break
end
end
- raise "Could not find #{program_name} in any of #{utility_search_path.join(', ')}" if !found
+ raise "Could not find #{program_name} in any of #{Configuration::utility_search_path.join(', ')}" if !found
end
xc = ExternalCommand.new(program_path, *args)
diff --git a/lib/configuration.rb b/lib/configuration.rb
new file mode 100644
index 000000000..ad9b52b4c
--- /dev/null
+++ b/lib/configuration.rb
@@ -0,0 +1,65 @@
+# Configuration values with defaults
+
+# TODO: Make this return different values depending on the current rails environment
+
+module Configuration
+ DEFAULTS = {
+ :ADMIN_BASE_URL => '/admin/',
+ :ADMIN_PASSWORD => '',
+ :ADMIN_PUBLIC_URL => '',
+ :ADMIN_USERNAME => '',
+ :AVAILABLE_LOCALES => '',
+ :BLACKHOLE_PREFIX => 'do-not-reply-to-this-address',
+ :BLOG_FEED => '',
+ :CONTACT_EMAIL => 'contact@localhost',
+ :CONTACT_NAME => 'Alaveteli',
+ :COOKIE_STORE_SESSION_SECRET => 'this default is insecure as code is open source, please override for live sites in config/general; this will do for local development',
+ :DEBUG_RECORD_MEMORY => false,
+ :DEFAULT_LOCALE => '',
+ :DOMAIN => 'localhost:3000',
+ :EXCEPTION_NOTIFICATIONS_FROM => nil,
+ :EXCEPTION_NOTIFICATIONS_TO => nil,
+ :FORCE_REGISTRATION_ON_NEW_REQUEST => false,
+ :FORWARD_NONBOUNCE_RESPONSES_TO => 'user-support@localhost',
+ :FRONTPAGE_PUBLICBODY_EXAMPLES => '',
+ :GA_CODE => '',
+ :GAZE_URL => '',
+ :HTML_TO_PDF_COMMAND => nil,
+ :INCOMING_EMAIL_DOMAIN => 'localhost',
+ :INCOMING_EMAIL_PREFIX => '',
+ :INCOMING_EMAIL_SECRET => 'dummysecret',
+ :ISO_COUNTRY_CODE => 'GB',
+ :MAX_REQUESTS_PER_USER_PER_DAY => nil,
+ :NEW_RESPONSE_REMINDER_AFTER_DAYS => [3, 10, 24],
+ :RAW_EMAILS_LOCATION => 'files/raw_emails',
+ :READ_ONLY => '',
+ :RECAPTCHA_PRIVATE_KEY => 'x',
+ :RECAPTCHA_PUBLIC_KEY => 'x',
+ :REPLY_LATE_AFTER_DAYS => 20,
+ :REPLY_VERY_LATE_AFTER_DAYS => 40,
+ :SITE_NAME => 'Alaveteli',
+ :SKIP_ADMIN_AUTH => false,
+ :SPECIAL_REPLY_VERY_LATE_AFTER_DAYS => 60,
+ :THEME_URL => "",
+ :THEME_URLS => [],
+ :TRACK_SENDER_EMAIL => 'contact@localhost',
+ :TRACK_SENDER_NAME => 'Alaveteli',
+ :TWITTER_USERNAME => '',
+ :USE_DEFAULT_BROWSER_LANGUAGE => true,
+ :USE_GHOSTSCRIPT_COMPRESSION => nil,
+ # UTILITY_SEARCH_PATH isn't mentioned in general.yml-example
+ :UTILITY_SEARCH_PATH => ["/usr/bin", "/usr/local/bin"],
+ :VARNISH_HOST => nil,
+ :WORKING_OR_CALENDAR_DAYS => 'working',
+ }
+
+ def Configuration.method_missing(name)
+ key = name.to_s.upcase
+ if DEFAULTS.has_key?(key.to_sym)
+ MySociety::Config.get(key, DEFAULTS[key.to_sym])
+ else
+ super
+ end
+ end
+end
+
diff --git a/lib/tasks/themes.rake b/lib/tasks/themes.rake
index 6eb64b4b0..f06cf6312 100644
--- a/lib/tasks/themes.rake
+++ b/lib/tasks/themes.rake
@@ -86,12 +86,10 @@ namespace :themes do
desc "Install themes specified in the config file's THEME_URLS"
task :install => :environment do
verbose = true
- theme_urls = MySociety::Config.get("THEME_URLS", [])
- theme_urls.each{ |theme_url| install_theme(theme_url, verbose) }
- theme_url = MySociety::Config.get("THEME_URL", "")
- if ! theme_url.blank?
+ Configuration::theme_urls.each{ |theme_url| install_theme(theme_url, verbose) }
+ if ! Configuration::theme_url.blank?
# Old version of the above, for backwards compatibility
- install_theme(theme_url, verbose, deprecated=true)
+ install_theme(Configuration::theme_url, verbose, deprecated=true)
end
end
end \ No newline at end of file
diff --git a/script/handle-mail-replies.rb b/script/handle-mail-replies.rb
index eba6f44cf..b227864b5 100755
--- a/script/handle-mail-replies.rb
+++ b/script/handle-mail-replies.rb
@@ -158,8 +158,7 @@ def is_oof?(message)
end
def forward_on(raw_message)
- forward_non_bounces_to = MySociety::Config.get("FORWARD_NONBOUNCE_RESPONSES_TO", "user-support@localhost")
- IO.popen("/usr/sbin/sendmail -i #{forward_non_bounces_to}", "w") do |f|
+ IO.popen("/usr/sbin/sendmail -i #{Configuration::forward_nonbounce_responses_to}", "w") do |f|
f.write(raw_message);
f.close;
end
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index 32398c053..386d1b04b 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -337,7 +337,7 @@ describe UserController, "when sending another user a message" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
- mail.body.should include("Bob Smith has used #{MySociety::Config.get('SITE_NAME')} to send you the message below")
+ mail.body.should include("Bob Smith has used #{Configuration::site_name} to send you the message below")
mail.body.should include("Just a test!")
#mail.to_addrs.first.to_s.should == users(:silly_name_user).name_and_email # XXX fix some nastiness with quoting name_and_email
mail.from_addrs.first.to_s.should == users(:bob_smith_user).name_and_email
diff --git a/spec/integration/admin_spec.rb b/spec/integration/admin_spec.rb
index caf741749..e148ea3ca 100644
--- a/spec/integration/admin_spec.rb
+++ b/spec/integration/admin_spec.rb
@@ -12,10 +12,8 @@ describe "When administering the site" do
response.should be_success
# Now fetch the "log in as" link to log in as Bob
- admin_username = MySociety::Config.get('ADMIN_USERNAME')
- admin_password = MySociety::Config.get('ADMIN_PASSWORD')
get_via_redirect "/admin/user/login_as/#{users(:bob_smith_user).id}", nil, {
- "Authorization" => "Basic " + Base64.encode64("#{admin_username}:#{admin_password}").strip
+ "Authorization" => "Basic " + Base64.encode64("#{Configuration::admin_username}:#{Configuration::admin_password}").strip
}
response.should be_success
session[:user_id].should == users(:bob_smith_user).id
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index bc73ef071..03a3c8dc3 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -312,8 +312,7 @@ describe IncomingMessage, " when censoring data" do
end
it "should apply hard-coded privacy rules to HTML files" do
- domain = MySociety::Config.get('DOMAIN')
- data = "http://#{domain}/c/cheese"
+ data = "http://#{Configuration::domain}/c/cheese"
@im.html_mask_stuff!(data)
data.should == "[WDTK login link]"
end
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 98681a9e9..269208405 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -33,7 +33,7 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
- mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ]
+ mail.to.should == [ Configuration::contact_email ]
deliveries.clear
end
@@ -53,7 +53,7 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
- mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ]
+ mail.to.should == [ Configuration::contact_email ]
deliveries.clear
end
@@ -73,7 +73,7 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
- mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ]
+ mail.to.should == [ Configuration::contact_email ]
deliveries.clear
end
@@ -157,7 +157,7 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
- mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ]
+ mail.to.should == [ Configuration::contact_email ]
deliveries.clear
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 6a4d0f2d5..248dff70e 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -143,15 +143,14 @@ def validate_as_body(html)
end
def basic_auth_login(request, username = nil, password = nil)
- username = MySociety::Config.get('ADMIN_USERNAME') if username.nil?
- password = MySociety::Config.get('ADMIN_PASSWORD') if password.nil?
+ username = Configuration::admin_username if username.nil?
+ password = Configuration::admin_password if password.nil?
request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{username}:#{password}")
end
# Monkeypatch! Validate HTML in tests.
-utility_search_path = MySociety::Config.get("UTILITY_SEARCH_PATH", ["/usr/bin", "/usr/local/bin"])
$html_validation_script_found = false
-utility_search_path.each do |d|
+Configuration::utility_search_path.each do |d|
$html_validation_script = File.join(d, "validate")
$html_validation_script_options = ["--charset=utf-8"]
if File.file? $html_validation_script and File.executable? $html_validation_script