diff options
Diffstat (limited to 'app/models')
-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 |
3 files changed, 42 insertions, 22 deletions
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) |