aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2007-10-24 11:39:37 +0000
committerfrancis <francis>2007-10-24 11:39:37 +0000
commitbc3b0c2e181697f240d3f8c863c4cdb03d4ca88d (patch)
tree2ab885540aa8a6586848f16ad719aa396d8146c4
parent8277d14fc923089bef47ac92520fabec3dea64b7 (diff)
Read in mySociety style configuration file, if it is there (use sensible defaults if not).
Actually send request to public body, or fake address on staging site. Fix minor bug with sending front page form public body to new request page.
-rw-r--r--app/controllers/application.rb6
-rw-r--r--app/controllers/request_controller.rb8
-rw-r--r--app/models/outgoing_message.rb15
-rw-r--r--app/models/request_mailer.rb12
-rw-r--r--app/views/layouts/default.rhtml7
-rw-r--r--app/views/request_mailer/initial_request.rhtml7
-rw-r--r--config/environment.rb14
-rw-r--r--config/general-example27
-rw-r--r--db/migrate/012_add_sent_outgoing_message.rb8
-rw-r--r--public/stylesheets/main.css6
-rw-r--r--todo.txt17
11 files changed, 99 insertions, 28 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index e86fe7338..0241ec66e 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -6,7 +6,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: application.rb,v 1.15 2007-10-16 21:17:14 louise Exp $
+# $Id: application.rb,v 1.16 2007-10-24 11:39:37 francis Exp $
class ApplicationController < ActionController::Base
@@ -138,5 +138,7 @@ class ApplicationController < ActionController::Base
return request.env["REMOTE_USER"]
end
end
-
end
+
+
+
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index dfc614e59..0f0a7167c 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: request_controller.rb,v 1.5 2007-10-16 21:17:14 louise Exp $
+# $Id: request_controller.rb,v 1.6 2007-10-24 11:39:37 francis Exp $
class RequestController < ApplicationController
@@ -16,12 +16,13 @@ class RequestController < ApplicationController
@info_request_pages, @info_requests = paginate :info_requests, :per_page => 25, :order => "created_at desc"
end
-
def frontpage
end
# Form for creating new request
def new
+ # Read parameters in - public body can be passed from front page
+ @info_request = InfoRequest.new(params[:info_request])
end
# Page new form posts to
@@ -41,7 +42,8 @@ class RequestController < ApplicationController
elsif authenticated?
@info_request.user = authenticated_user
@info_request.save
- flash[:notice] = "Your Freedom of Information request has been created."
+ @outgoing_message.send_message
+ flash[:notice] = "Your Freedom of Information request has been created and sent on its way."
redirect_to request_url(:id => @info_request)
end
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index ed2b415ae..4ed0f58ee 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -5,7 +5,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: outgoing_message.rb,v 1.5 2007-10-16 08:57:32 francis Exp $
+# $Id: outgoing_message.rb,v 1.6 2007-10-24 11:39:37 francis Exp $
class OutgoingMessage < ActiveRecord::Base
belongs_to :info_request
@@ -16,15 +16,20 @@ class OutgoingMessage < ActiveRecord::Base
validates_inclusion_of :message_type, :in => ['initial_request'] #, 'complaint']
+ # Deliver outgoing message
+ # Note: You can test this from script/console with, say:
+ # InfoRequest.find(1).outgoing_messages[0].send_message
def send_message
if message_type == 'initial_request'
if status == 'ready'
- # test this with:
- # InfoRequest.find(1).outgoing_messages[0].send_message
-
RequestMailer.deliver_initial_request(info_request, self)
+ sent_at = Time.now
+ status = 'sent'
+ save
+ elsif status == 'sent'
+ raise "Message id #{id} has already been sent"
else
- raise "Message id #{id} not ready for send_message"
+ raise "Message id #{id} not in state for send_message"
end
else
raise "Message id #{id} has type '#{message_type}' which send_message can't handle"
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb
index c6b99159e..0e1c2be12 100644
--- a/app/models/request_mailer.rb
+++ b/app/models/request_mailer.rb
@@ -4,15 +4,17 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: request_mailer.rb,v 1.1 2007-10-16 08:57:32 francis Exp $
+# $Id: request_mailer.rb,v 1.2 2007-10-24 11:39:37 francis Exp $
class RequestMailer < ActionMailer::Base
def initial_request(info_request, outgoing_message)
- @from = 'francis@flourish.org' # XXX
- @recipients = 'frabcus@fastmail.fm'
- # XXX check with staging site
- #@recipients = info_request.public_body.request_email
+ @from = info_request.user.email
+ if MySociety::Config.getbool("STAGING_SITE", 1)
+ @recipients = @from
+ else
+ @recipients = info_request.public_body.request_email
+ end
@subject = 'Freedom of Information Request - ' + info_request.title
@body = {:info_request => info_request, :outgoing_message => outgoing_message}
end
diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml
index b645876e7..d480d82e9 100644
--- a/app/views/layouts/default.rhtml
+++ b/app/views/layouts/default.rhtml
@@ -6,9 +6,14 @@
<%= stylesheet_link_tag 'main' %>
</head>
<body>
+ <% if MySociety::Config.getbool("STAGING_SITE", 1) %>
+ <div id="staging">
+ This is a test version of the site. FOI requests will not be sent to real public bodies.
+ </div>
+ <% end %>
<div id="header">
<h1>
- <a href="/">Government Spy</a>
+ <a href="/">GovernmentSpy</a>
<span id="beta">Beta</span>
</h1>
<div id="tagline">Freeing your information from them</div>
diff --git a/app/views/request_mailer/initial_request.rhtml b/app/views/request_mailer/initial_request.rhtml
index 795773c74..14f2d184f 100644
--- a/app/views/request_mailer/initial_request.rhtml
+++ b/app/views/request_mailer/initial_request.rhtml
@@ -2,6 +2,9 @@ Dear <%= @info_request.public_body.name %>,
<%= @outgoing_message.body %>
------------
+--
-This message was sent using FOIFA. Blah.
+Sent using GovernmentSpy, a project of UKCOD, registered charity number
+1076346. If this is not the correct address for Freedom of Information
+requests, please let us know by contacting team@governmentspy and we'll make
+sure future ones go to the right place.
diff --git a/config/environment.rb b/config/environment.rb
index 2e3fc4db2..2b3211690 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -10,6 +10,11 @@ RAILS_GEM_VERSION = '1.2.1' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
+# MySociety specific helper functions
+$:.push("../rblib")
+load "validate.rb"
+load "config.rb"
+
Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified here
@@ -42,6 +47,10 @@ Rails::Initializer.run do |config|
config.active_record.default_timezone = :utc
# See Rails::Configuration for more options
+
+ # Load intial mySociety config
+ MySociety::Config.set_file(File.join(config.root_path, 'config', 'general'), true)
+ MySociety::Config.load_default
end
# Add new inflection rules using the following format
@@ -62,10 +71,6 @@ ActiveRecord::Errors.default_error_messages[:blank] = "must be filled in"
# Include your application configuration below
-# Include our own helper functions
-$:.push("../rblib")
-load "validate.rb"
-
# Output HTML 4.0 compliant code, using method described in this ticket
# http://dev.rubyonrails.org/ticket/6009
ActionView::Helpers::TagHelper.module_eval do
@@ -74,3 +79,4 @@ ActionView::Helpers::TagHelper.module_eval do
end
end
+
diff --git a/config/general-example b/config/general-example
new file mode 100644
index 000000000..172145343
--- /dev/null
+++ b/config/general-example
@@ -0,0 +1,27 @@
+<?php
+/*
+ * general-example:
+ * Example values for the "general" config file.
+ *
+ * Configuration parameters, in PHP syntax. Configuration parameters are set
+ * using the PHP define('OPTION_...', '...') function. Both perl and PHP code
+ * parse this properly, so you can use comments and conditionals and whatnot,
+ * but unless essential it's better to keep it simple....
+ *
+ * Copy this file to one called "general" in the same directory. Or
+ * have multiple config files and use a symlink to change between them.
+ *
+ * Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
+ * Email: francis@mysociety.org; WWW: http://www.mysociety.org
+ *
+ * $Id: general-example,v 1.1 2007-10-24 11:39:38 francis Exp $
+ *
+ */
+
+// URL for use in emails etc.
+define('OPTION_BASE_URL', 'http://127.0.0.1:3000');
+
+// For test sites
+define('OPTION_STAGING_SITE', 1);
+
+?>
diff --git a/db/migrate/012_add_sent_outgoing_message.rb b/db/migrate/012_add_sent_outgoing_message.rb
new file mode 100644
index 000000000..f99c4d55f
--- /dev/null
+++ b/db/migrate/012_add_sent_outgoing_message.rb
@@ -0,0 +1,8 @@
+class AddSentOutgoingMessage < ActiveRecord::Migration
+ def self.up
+ add_column :outgiong_messages, :sent_at, :datetime
+ end
+
+ def self.down
+ end
+end
diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css
index f4e64d057..c78f5aa0f 100644
--- a/public/stylesheets/main.css
+++ b/public/stylesheets/main.css
@@ -25,6 +25,12 @@ a:hover, a:active {
/* Site-wide layout */
+#staging {
+ text-align: center;
+ border-bottom: solid 2px #ff0000;
+ background: #ffbbbb;
+}
+
#header {
border-bottom: solid 1px #4e451b;
margin: 0;
diff --git a/todo.txt b/todo.txt
index 5399c809d..fd42dad90 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,16 +1,11 @@
-Use something other than session for post redirect store, so can go via email
-If you recently made a request, then a login will try to make it again because
- all the stuff for the post redirect is in the session. Consider again
-
Send confirmation email
Send actual FOIFA request
Make it say "dear" as default letter
-Write some tests (try it their way, at every level)
+Make sure index for every controller shows all, and the /controller/:id URLs go to a show action
-Make sure index for every controller shows all, and the /controller/:id URls go to a show action
Escape/simplify short name properly in URLs of public bodies
For public bodies whose short names are renamed, make old URL still work and redirect
@@ -21,6 +16,12 @@ Shitty using sessions for redirect back - you lose if you click login
link elsewhere in same browser, and then do sign in on original.
It trashes your whole request.
+Use something other than session for post redirect store, so can go via email
+If you recently made a request, then a login will try to make it again because
+ all the stuff for the post redirect is in the session. Consider again
+
+Write some tests (try it their way, at every level)
+
Tidying
=======
@@ -55,8 +56,12 @@ Maybe we SHOULD reveal their email to the public body, why not?
Later
=====
+Add postal address at City University to request
+
Read wiki page lots
http://www.mysociety.org/moin.cgi/FreedomOfInformation
+And comments on proposal
+http://www.mysociety.org/2006/04/04/freedom-of-information-archive/
Check FOE site lots
http://community.foe.co.uk/tools/right_to_know/request_generator.html