aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/activesupport_cache_extensions.rb2
-rw-r--r--lib/alaveteli_external_command.rb5
-rw-r--r--lib/configuration.rb65
-rw-r--r--lib/public_body_categories.rb2
-rw-r--r--lib/tasks/config_files.rake56
-rw-r--r--lib/tasks/stats.rake96
-rw-r--r--lib/tasks/themes.rake8
-rw-r--r--lib/tasks/translation.rake192
-rw-r--r--lib/tasks/usage.rb26
-rw-r--r--lib/tmail_extensions.rb3
-rw-r--r--lib/world_foi_websites.rb4
11 files changed, 418 insertions, 41 deletions
diff --git a/lib/activesupport_cache_extensions.rb b/lib/activesupport_cache_extensions.rb
index 5a894b64b..f15d72894 100644
--- a/lib/activesupport_cache_extensions.rb
+++ b/lib/activesupport_cache_extensions.rb
@@ -3,8 +3,6 @@
#
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
-#
-# $Id: activesupport_cache_extensions.rb,v 1.1 2009-07-01 11:07:32 francis Exp $
# Monkeypatch! ./activesupport/lib/active_support/cache/file_store.rb
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..5f761a1f6
--- /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_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],
+ :OVERRIDE_ALL_PUBLIC_BODY_REQUEST_EMAILS => '',
+ :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 => ["/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/public_body_categories.rb b/lib/public_body_categories.rb
index b4aa71a40..c6f0a6690 100644
--- a/lib/public_body_categories.rb
+++ b/lib/public_body_categories.rb
@@ -3,8 +3,6 @@
#
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
-#
-# $Id: public_body_categories.rb,v 1.1 2009-09-14 14:45:48 francis Exp $
class PublicBodyCategories
diff --git a/lib/tasks/config_files.rake b/lib/tasks/config_files.rake
new file mode 100644
index 000000000..d3843f3a4
--- /dev/null
+++ b/lib/tasks/config_files.rake
@@ -0,0 +1,56 @@
+require File.join(File.dirname(__FILE__), 'usage')
+namespace :config_files do
+
+ include Usage
+
+ def convert_ugly(file, replacements)
+ converted_lines = []
+ ugly_var = /\!\!\(\*= \$([^ ]+) \*\)\!\!/
+ File.open(file, 'r').each do |line|
+ line = line.gsub(ugly_var) do |match|
+ var = $1.to_sym
+ replacement = replacements[var]
+ if replacement == nil
+ if ! (skip[var] == true)
+ raise "Unhandled variable in .ugly file: $#{var}"
+ else
+ match
+ end
+ else
+ replacements[var]
+ end
+ end
+ converted_lines << line
+ end
+ converted_lines
+ end
+
+ desc 'Convert Debian .ugly init script in config to a form suitable for installing in /etc/init.d'
+ task :convert_init_script => :environment do
+ example = 'rake config_files:convert_init_script DEPLOY_USER=deploy VHOST_DIR=/dir/above/alaveteli SCRIPT_FILE=config/alert-tracks-debian.ugly '
+ check_for_env_vars(['DEPLOY_USER', 'VHOST_DIR', 'SCRIPT_FILE'], example)
+
+ deploy_user = ENV['DEPLOY_USER']
+ vhost_dir = ENV['VHOST_DIR']
+ script_file = ENV['SCRIPT_FILE']
+
+ replacements = { :user => deploy_user,
+ :vhost_dir => vhost_dir }
+
+ daemon_name = File.basename(script_file, '-debian.ugly')
+ replacements.update(:daemon_name => "foi-#{daemon_name}")
+ converted = convert_ugly(script_file, replacements)
+ rails_env_file = File.expand_path(File.join(Rails.root, 'config', 'rails_env.rb'))
+ if !File.exists?(rails_env_file)
+ converted.each do |line|
+ line.gsub!(/^#\s*RAILS_ENV=your_rails_env/, "RAILS_ENV=#{Rails.env}")
+ line.gsub!(/^#\s*export RAILS_ENV/, "export RAILS_ENV")
+ end
+ end
+ converted.each do |line|
+ puts line
+ end
+ end
+
+
+end \ No newline at end of file
diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake
index e1b58905d..9d7d70540 100644
--- a/lib/tasks/stats.rake
+++ b/lib/tasks/stats.rake
@@ -1,48 +1,94 @@
-namespace :stats do
-
- desc 'Produce transaction stats'
- task :show => :environment do
+namespace :stats do
+
+ desc 'Produce transaction stats'
+ task :show => :environment do
month_starts = (Date.new(2009, 1)..Date.new(2011, 8)).select { |d| d.day == 1 }
headers = ['Period',
- 'Requests sent',
- 'Annotations added',
- 'Track this request email signups',
- 'Comments on own requests',
+ 'Requests sent',
+ 'Annotations added',
+ 'Track this request email signups',
+ 'Comments on own requests',
'Follow up messages sent']
puts headers.join("\t")
month_starts.each do |month_start|
month_end = month_start.end_of_month
period = "#{month_start}-#{month_end}"
- date_conditions = ['created_at >= ?
- AND created_at < ?',
+ date_conditions = ['created_at >= ?
+ AND created_at < ?',
month_start, month_end+1]
request_count = InfoRequest.count(:conditions => date_conditions)
comment_count = Comment.count(:conditions => date_conditions)
- track_conditions = ['track_type = ?
- AND track_medium = ?
- AND created_at >= ?
- AND created_at < ?',
+ track_conditions = ['track_type = ?
+ AND track_medium = ?
+ AND created_at >= ?
+ AND created_at < ?',
'request_updates', 'email_daily', month_start, month_end+1]
email_request_track_count = TrackThing.count(:conditions => track_conditions)
- comment_on_own_request_conditions = ['comments.user_id = info_requests.user_id
- AND comments.created_at >= ?
+ comment_on_own_request_conditions = ['comments.user_id = info_requests.user_id
+ AND comments.created_at >= ?
AND comments.created_at < ?',
month_start, month_end+1]
comment_on_own_request_count = Comment.count(:conditions => comment_on_own_request_conditions,
:include => :info_request)
-
- followup_conditions = ['message_type = ?
- AND created_at >= ?
+
+ followup_conditions = ['message_type = ?
+ AND created_at >= ?
AND created_at < ?',
'followup', month_start, month_end+1]
follow_up_count = OutgoingMessage.count(:conditions => followup_conditions)
- puts [period,
- request_count,
- comment_count,
- email_request_track_count,
- comment_on_own_request_count,
+ puts [period,
+ request_count,
+ comment_count,
+ email_request_track_count,
+ comment_on_own_request_count,
follow_up_count].join("\t")
end
end
-
+
+ desc 'Produce stats on volume of requests to authorities matching a set of tags. Specify tags as TAGS=tagone,tagtwo'
+ task :volumes_by_authority_tag => :environment do
+ tags = ENV['TAGS'].split(',')
+ first_request_datetime = InfoRequest.minimum(:created_at)
+ start_year = first_request_datetime.strftime("%Y").to_i
+ start_month = first_request_datetime.strftime("%m").to_i
+ end_year = Time.now.strftime("%Y").to_i
+ end_month = Time.now.strftime("%m").to_i
+ puts "Start year: #{start_year}"
+ puts "Start month: #{start_month}"
+ puts "End year: #{end_year}"
+ puts "End month: #{end_month}"
+ public_bodies = []
+ tags.each do |tag|
+ tag_bodies = PublicBody.find_by_tag(tag)
+ puts "Bodies with tag '#{tag}': #{tag_bodies.size}"
+ public_bodies += tag_bodies
+ end
+ public_body_ids = public_bodies.map{ |body| body.id }.uniq
+ public_body_condition_string = 'AND public_bodies.id in (?)'
+ month_starts = (Date.new(start_year, start_month)..Date.new(end_year, end_month)).select { |d| d.day == 1 }
+ headers = ['Period',
+ 'Requests sent',
+ 'Requests sent as % of total sent in period']
+ puts headers.join("\t")
+ month_starts.each do |month_start|
+ month_end = month_start.end_of_month
+ period = "#{month_start}-#{month_end}"
+ date_condition_string = 'info_requests.created_at >= ? AND info_requests.created_at < ?'
+ conditions = [date_condition_string + " " + public_body_condition_string,
+ month_start,
+ month_end+1,
+ public_body_ids]
+ request_count = InfoRequest.count(:conditions => conditions,
+ :include => :public_body)
+
+ total_count = InfoRequest.count(:conditions => [date_condition_string, month_start, month_end+1])
+ if total_count > 0
+ percent = ((request_count.to_f / total_count.to_f ) * 100).round(2)
+ else
+ percent = 0.0
+ end
+ puts [period, request_count, percent].join("\t")
+ 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/lib/tasks/translation.rake b/lib/tasks/translation.rake
new file mode 100644
index 000000000..f6611cc80
--- /dev/null
+++ b/lib/tasks/translation.rake
@@ -0,0 +1,192 @@
+require File.join(File.dirname(__FILE__), 'usage')
+namespace :translation do
+
+ include Usage
+
+ def write_email(email, email_description, output_file)
+ mail_object = TMail::Mail.parse(email.to_s)
+ output_file.write("\n")
+ output_file.write("Description of email: #{email_description}\n")
+ output_file.write("Subject line: #{mail_object.subject}\n")
+ output_file.write("\n")
+ if mail_object.parts.empty?
+ output_file.write(mail_object.to_s)
+ else
+ mail_object.parts.each do |part|
+ output_file.write("Message part **\n")
+ output_file.write(part.body.to_s)
+ end
+ end
+ output_file.write("\n")
+ output_file.write("********\n")
+ end
+
+ desc "Create previews of translated emails"
+ task :preview_emails => :environment do
+ check_for_env_vars(['INFO_REQUEST_ID',
+ 'FOLLOW_UP_ID',
+ 'INCOMING_MESSAGE_ID',
+ 'COMMENT_ID',
+ 'TRACK_THING_ID',
+ 'DIR'], nil)
+ info_request = InfoRequest.find(ENV['INFO_REQUEST_ID'])
+ if info_request.outgoing_messages.empty?
+ raise "Info request #{info_request.id} does not have any outgoing messages"
+ end
+ initial_request = info_request.outgoing_messages.first
+ follow_up = OutgoingMessage.find(ENV['FOLLOW_UP_ID'])
+ incoming_message = IncomingMessage.find(ENV['INCOMING_MESSAGE_ID'])
+ comment = Comment.find(ENV['COMMENT_ID'])
+ track_thing = TrackThing.find(ENV['TRACK_THING_ID'])
+
+ output_file = File.open(File.join(ENV['DIR'], 'message_preview.txt'), 'w')
+
+ # outgoing mailer
+ request_email = OutgoingMailer.create_initial_request(info_request, initial_request)
+ write_email(request_email, 'Initial Request', output_file)
+
+ followup_email = OutgoingMailer.create_followup(info_request, follow_up, nil)
+ write_email(followup_email, 'Follow up', output_file)
+
+ # contact mailer
+ contact_email = ContactMailer.create_message(info_request.user_name,
+ info_request.user.email,
+ 'A test message',
+ 'Hello!',
+ info_request.user,
+ info_request,
+ info_request.public_body)
+
+ write_email(contact_email, 'Contact email (to admin)', output_file)
+
+ user_contact_email = ContactMailer.create_user_message(info_request.user,
+ info_request.user,
+ 'http://www.example.com/user',
+ 'A test message',
+ 'Hello!')
+ write_email(user_contact_email, 'Contact email (user to user)', output_file)
+
+ admin_contact_email = ContactMailer.create_from_admin_message(info_request.user,
+ 'A test message',
+ 'Hello!')
+ write_email(admin_contact_email, 'Contact email (admin to user)', output_file)
+
+ # request mailer
+ fake_response_email = RequestMailer.create_fake_response(info_request,
+ info_request.user,
+ "test body",
+ "attachment.txt",
+ "test attachment text")
+ write_email(fake_response_email,
+ 'Email created when someone uploads a response directly',
+ output_file)
+
+ content = File.read(File.join(Rails.root,
+ 'spec',
+ 'fixtures',
+ 'files',
+ 'incoming-request-plain.email'))
+ response_mail = TMail::Mail.parse(content)
+
+ response_mail.from = "authority@example.com"
+ stopped_responses_email = RequestMailer.create_stopped_responses(info_request,
+ response_mail,
+ content)
+ write_email(stopped_responses_email,
+ 'Bounce if someone sends email to a request that has had responses stopped',
+ output_file)
+
+ requires_admin_email = RequestMailer.create_requires_admin(info_request)
+ write_email(requires_admin_email, 'Drawing admin attention to a response', output_file)
+
+
+ new_response_email = RequestMailer.create_new_response(info_request, incoming_message)
+ write_email(new_response_email,
+ 'Telling the requester that a new response has arrived',
+ output_file)
+
+ overdue_alert_email = RequestMailer.create_overdue_alert(info_request, info_request.user)
+ write_email(overdue_alert_email,
+ 'Telling the requester that the public body is late in replying',
+ output_file)
+
+ very_overdue_alert_email = RequestMailer.create_very_overdue_alert(info_request, info_request.user)
+ write_email(very_overdue_alert_email,
+ 'Telling the requester that the public body is very late in replying',
+ output_file)
+
+ response_reminder_alert_email = RequestMailer.create_new_response_reminder_alert(info_request,
+ incoming_message)
+ write_email(response_reminder_alert_email,
+ 'Telling the requester that they need to say if the new response contains info or not',
+ output_file)
+
+ old_unclassified_email = RequestMailer.create_old_unclassified_updated(info_request)
+ write_email(old_unclassified_email,
+ 'Telling the requester that someone updated their old unclassified request',
+ output_file)
+
+ not_clarified_alert_email = RequestMailer.create_not_clarified_alert(info_request, incoming_message)
+ write_email(not_clarified_alert_email,
+ 'Telling the requester that they need to clarify their request',
+ output_file)
+
+ comment_on_alert_email = RequestMailer.create_comment_on_alert(info_request, comment)
+ write_email(comment_on_alert_email,
+ 'Telling requester that somebody added an annotation to their request',
+ output_file)
+
+ comment_on_alert_plural_email = RequestMailer.create_comment_on_alert_plural(info_request, 2, comment)
+ write_email(comment_on_alert_plural_email,
+ 'Telling requester that somebody added multiple annotations to their request',
+ output_file)
+
+ # track mailer
+ xapian_object = InfoRequest.full_search([InfoRequestEvent],
+ track_thing.track_query,
+ 'described_at',
+ true,
+ nil,
+ 100,
+ 1)
+ event_digest_email = TrackMailer.create_event_digest(info_request.user,
+ [[track_thing,
+ xapian_object.results,
+ xapian_object]])
+ write_email(event_digest_email, 'Alerts on things the user is tracking', output_file)
+
+ # user mailer
+ site_name = Configuration::site_name
+ reasons = {
+ :web => "",
+ :email => _("Then you can sign in to {{site_name}}", :site_name => site_name),
+ :email_subject => _("Confirm your account on {{site_name}}", :site_name => site_name)
+ }
+ confirm_login_email = UserMailer.create_confirm_login(info_request.user,
+ reasons,
+ 'http://www.example.com')
+ write_email(confirm_login_email, 'Confirm a user login', output_file)
+
+ already_registered_email = UserMailer.create_already_registered(info_request.user,
+ reasons,
+ 'http://www.example.com')
+ write_email(already_registered_email, 'Tell a user they are already registered', output_file)
+
+ new_email = 'new_email@example.com'
+ changeemail_confirm_email = UserMailer.create_changeemail_confirm(info_request.user,
+ new_email,
+ 'http://www.example.com')
+ write_email(changeemail_confirm_email,
+ 'Confirm that the user wants to change their email',
+ output_file)
+
+ changeemail_already_used = UserMailer.create_changeemail_already_used('old_email@example.com',
+ new_email)
+ write_email(changeemail_already_used,
+ 'Tell a user that the email they want to change to is already used',
+ output_file)
+
+ output_file.close
+ end
+
+end \ No newline at end of file
diff --git a/lib/tasks/usage.rb b/lib/tasks/usage.rb
new file mode 100644
index 000000000..d6aac454d
--- /dev/null
+++ b/lib/tasks/usage.rb
@@ -0,0 +1,26 @@
+module Usage
+
+ def usage_message message
+ puts ''
+ puts message
+ puts ''
+ exit 0
+ end
+
+ def check_for_env_vars(env_vars, example)
+ missing = []
+ env_vars.each do |env_var|
+ unless ENV[env_var]
+ missing << env_var
+ end
+ end
+ if !missing.empty?
+ usage = "Usage: This task requires #{env_vars.to_sentence} - missing #{missing.to_sentence}"
+ if example
+ usage += "\nExample: #{example}"
+ end
+ usage_message usage
+ end
+ end
+
+end \ No newline at end of file
diff --git a/lib/tmail_extensions.rb b/lib/tmail_extensions.rb
index f35565352..6a533e658 100644
--- a/lib/tmail_extensions.rb
+++ b/lib/tmail_extensions.rb
@@ -3,8 +3,7 @@
#
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
-#
-# $Id: tmail_extensions.rb,v 1.7 2009-10-02 23:31:01 francis Exp $
+
require 'racc/parser'
require 'tmail'
require 'tmail/scanner'
diff --git a/lib/world_foi_websites.rb b/lib/world_foi_websites.rb
index fec40ed64..f175afd3d 100644
--- a/lib/world_foi_websites.rb
+++ b/lib/world_foi_websites.rb
@@ -13,7 +13,7 @@ class WorldFOIWebsites
{:name => "Ask The EU",
:country_name => "European Union",
:country_iso_code => "",
- :url => "http://asktheu.org"},
+ :url => "http://asktheeu.org"},
{:name => "MuckRock.com",
:country_name => "United States of America",
:country_iso_code => "US",
@@ -45,7 +45,7 @@ class WorldFOIWebsites
{:name => "Acceso Intelligente",
:country_name => "Chile",
:country_iso_code => "CL",
- :url => "accesointeligente.org"}]
+ :url => "http://accesointeligente.org"}]
return world_foi_websites
end