diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin_request_controller.rb | 16 | ||||
-rw-r--r-- | app/models/incoming_message.rb | 7 | ||||
-rw-r--r-- | app/models/public_body.rb | 50 | ||||
-rw-r--r-- | app/models/user.rb | 7 | ||||
-rw-r--r-- | app/views/request/_correspondence.rhtml | 4 |
5 files changed, 54 insertions, 30 deletions
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb index 9559fde03..c86972eb3 100644 --- a/app/controllers/admin_request_controller.rb +++ b/app/controllers/admin_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: admin_request_controller.rb,v 1.27 2008-11-04 00:13:25 francis Exp $ +# $Id: admin_request_controller.rb,v 1.28 2008-12-18 18:55:22 francis Exp $ class AdminRequestController < ApplicationController layout "admin" @@ -217,12 +217,14 @@ class AdminRequestController < ApplicationController @holding_pen = true email = @raw_email.incoming_message.mail.from_addrs[0].spec - domain = email - domain =~ /@(.*)/ - domain = $1 - - @public_bodies = PublicBody.find(:all, :order => "name", - :conditions => [ "lower(request_email) like lower('%'||?||'%')", domain ]) + domain = PublicBody.extract_domain_from_email(email) + + if domain.nil? + @public_bodies = [] + else + @public_bodies = PublicBody.find(:all, :order => "name", + :conditions => [ "lower(request_email) like lower('%'||?||'%')", domain ]) + end end end diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 913611cb1..74a8f64f7 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -19,7 +19,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: incoming_message.rb,v 1.175 2008-12-04 20:03:47 francis Exp $ +# $Id: incoming_message.rb,v 1.176 2008-12-18 18:55:22 francis Exp $ # TODO # Move some of the (e.g. quoting) functions here into rblib, as they feel @@ -926,6 +926,11 @@ class IncomingMessage < ActiveRecord::Base return self.mail.safe_from end + def mail_from_domain + return PublicBody.extract_domain_from_email(self.mail.from_addrs[0].spec) + end + + # Has message arrived "recently"? def recently_arrived (Time.now - self.created_at) <= 3.days diff --git a/app/models/public_body.rb b/app/models/public_body.rb index e389d559f..be6e49acf 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -24,7 +24,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body.rb,v 1.124 2008-12-02 12:41:33 francis Exp $ +# $Id: public_body.rb,v 1.125 2008-12-18 18:55:22 francis Exp $ require 'csv' require 'set' @@ -275,17 +275,10 @@ class PublicBody < ActiveRecord::Base end # extract the domain name from the FOI request email - url = self.request_email - url =~ /@(.*)/ - if $1.nil? + url = self.request_email_domain + if url.nil? return nil end - url = $1 - - # remove special email domains for UK Government addresses - url.sub!(".gsi.", ".") - url.sub!(".x.", ".") - url.sub!(".pnn.", ".") # add standard URL prefix return "http://www." + url @@ -406,13 +399,8 @@ class PublicBody < ActiveRecord::Base # Does this user have the power of FOI officer for this body? def is_foi_officer?(user) - user_domain = user.email - user_domain =~ /@(.*)/ - user_domain = $1 - - our_domain = self.request_email - our_domain =~ /@(.*)/ - our_domain = $1 + user_domain = user.email_domain + our_domain = self.request_email_domain if user_domain.nil? or our_domain.nil? return false @@ -421,9 +409,31 @@ class PublicBody < ActiveRecord::Base return our_domain == user_domain end def foi_officer_domain_required - our_domain = self.request_email - our_domain =~ /@(.*)/ - return $1 + return self.request_email_domain + end + + # Domain name of the request email + def request_email_domain + return PublicBody.extract_domain_from_email(self.request_email) + end + + # Return the domain part of an email address, canonicalised and with common + # extra UK Government server name parts removed. + def PublicBody.extract_domain_from_email(email) + email =~ /@(.*)/ + if $1.nil? + return nil + end + + # take lower case + ret = $1.downcase + + # remove special email domains for UK Government addresses + ret.sub!(".gsi.", ".") + ret.sub!(".x.", ".") + ret.sub!(".pnn.", ".") + + return ret end end diff --git a/app/models/user.rb b/app/models/user.rb index 472929144..62347713c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,7 +22,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user.rb,v 1.77 2008-12-04 15:03:42 francis Exp $ +# $Id: user.rb,v 1.78 2008-12-18 18:55:22 francis Exp $ require 'digest/sha1' @@ -219,6 +219,11 @@ class User < ActiveRecord::Base self.admin_level == 'super' end + # Returns domain part of user's email address + def email_domain + return PublicBody.extract_domain_from_email(self.email) + end + private def self.encrypted_password(password, salt) diff --git a/app/views/request/_correspondence.rhtml b/app/views/request/_correspondence.rhtml index e530efc4a..33036f97a 100644 --- a/app/views/request/_correspondence.rhtml +++ b/app/views/request/_correspondence.rhtml @@ -29,7 +29,9 @@ if not incoming_message.nil? <% if !incoming_message.safe_mail_from.nil? && incoming_message.safe_mail_from.strip != @info_request.public_body.name.strip %> <%= incoming_message.safe_mail_from %><br> <% end %> - <%=h @info_request.public_body.name %><br> + <% if incoming_message.safe_mail_from.nil? || (incoming_message.mail_from_domain == @info_request.public_body.request_email_domain) %> + <%=h @info_request.public_body.name %><br> + <% end %> <br><%= simple_date(incoming_message.sent_at) %> </h2> |