diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/incoming_message.rb | 6 | ||||
-rw-r--r-- | app/models/info_request.rb | 4 | ||||
-rw-r--r-- | app/models/public_body.rb | 26 |
3 files changed, 29 insertions, 7 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 7908f21e7..334c8f2ed 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -18,7 +18,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.45 2008-02-26 15:13:51 francis Exp $ +# $Id: incoming_message.rb,v 1.46 2008-02-27 12:04:10 francis Exp $ # TODO @@ -100,10 +100,10 @@ class IncomingMessage < ActiveRecord::Base # if they are public anyway. For now just be precautionary and only # put in descriptions of them in square brackets. if not self.info_request.public_body.request_email.empty? - text = text.gsub(self.info_request.public_body.request_email, "[" + self.info_request.public_body.short_name + " request email]") + text = text.gsub(self.info_request.public_body.request_email, "[" + self.info_request.public_body.short_or_long_name + " request email]") end if not self.info_request.public_body.complaint_email.empty? - text = text.gsub(self.info_request.public_body.complaint_email, "[" + self.info_request.public_body.short_name + " complaint email]") + text = text.gsub(self.info_request.public_body.complaint_email, "[" + self.info_request.public_body.short_or_long_name + " complaint email]") end text = text.gsub(self.info_request.incoming_email, "[FOI #" + self.info_request.id.to_s + " email]") text = text.gsub(self.info_request.envelope_email, "[FOI #" + self.info_request.id.to_s + " bounce email]") diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 3ea3b59cc..72bbf8b6a 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -20,7 +20,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request.rb,v 1.46 2008-02-26 15:13:51 francis Exp $ +# $Id: info_request.rb,v 1.47 2008-02-27 12:04:10 francis Exp $ require 'digest/sha1' @@ -257,7 +257,7 @@ public end end def recipient_name_and_email - return "FOI requests at " + self.public_body.short_name + " <" + self.recipient_email + ">" + return "FOI requests at " + self.public_body.short_or_long_name + " <" + self.recipient_email + ">" end # History of some things that have happened diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 5fdcb85e3..9c4956b68 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -21,11 +21,11 @@ # 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.21 2008-02-26 15:13:51 francis Exp $ +# $Id: public_body.rb,v 1.22 2008-02-27 12:04:10 francis Exp $ class PublicBody < ActiveRecord::Base validates_presence_of :name - validates_presence_of :short_name + validates_presence_of :url_name validates_presence_of :request_email has_many :info_requests @@ -47,6 +47,28 @@ class PublicBody < ActiveRecord::Base acts_as_versioned self.non_versioned_columns << 'created_at' << 'updated_at' + # When name or short name is changed, also change the url name + def short_name=(short_name) + write_attribute(:short_name, short_name) + update_url_name + end + def name=(name) + write_attribute(:name, name) + update_url_name + end + def update_url_name + url_name = MySociety::Format.simplify_url_part(short_or_long_name) + write_attribute(:url_name, url_name) + end + # Return the short name if present, or else long name + def short_or_long_name + if self.short_name.nil? # can happen during construction + self.name + else + self.short_name.empty? ? self.name : self.short_name + end + end + # Given an input string of tags, sets all tags to that string def tag_string=(tag_string) tags = tag_string.split(/\s+/).uniq |