aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/incoming_message.rb16
-rw-r--r--app/models/info_request_event.rb6
-rw-r--r--app/models/public_body.rb30
3 files changed, 24 insertions, 28 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index dff516f0e..7e1567bd1 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -506,14 +506,9 @@ class IncomingMessage < ActiveRecord::Base
# Find any uudecoded things buried in it, yeuchly
uus = text.scan(/^begin.+^`\n^end\n/m)
attachments = []
- for uu in uus
+ uus.each do |uu|
# Decode the string
- content = nil
- tempfile = Tempfile.new('foiuu')
- tempfile.print uu
- tempfile.flush
- content = AlaveteliExternalCommand.run("uudecode", "-o", "/dev/stdout", tempfile.path)
- tempfile.close
+ content = uu.sub(/\Abegin \d+ [^\n]*\n/, '').unpack('u').first
# Make attachment type from it, working out filename and mime type
filename = uu.match(/^begin\s+[0-9]+\s+(.*)$/)[1]
calc_mime = AlaveteliFileTypes.filename_and_content_to_mimetype(filename, content)
@@ -524,15 +519,14 @@ class IncomingMessage < ActiveRecord::Base
content_type = 'application/octet-stream'
end
hexdigest = Digest::MD5.hexdigest(content)
- attachment = self.foi_attachments.find_or_create_by_hexdigest(hexdigest)
+ attachment = foi_attachments.find_or_create_by_hexdigest(hexdigest)
attachment.update_attributes(:filename => filename,
:content_type => content_type,
- :body => content,
- :display_size => "0K")
+ :body => content)
attachment.save!
attachments << attachment
end
- return attachments
+ attachments
end
def get_attachments_for_display
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 29c1ce965..263de20a0 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -327,15 +327,15 @@ class InfoRequestEvent < ActiveRecord::Base
def is_incoming_message?
- !self.incoming_message_selective_columns("incoming_messages.id").nil?
+ incoming_message_id? or (incoming_message if new_record?)
end
def is_outgoing_message?
- !self.outgoing_message.nil?
+ outgoing_message_id? or (outgoing_message if new_record?)
end
def is_comment?
- !self.comment.nil?
+ comment_id? or (comment if new_record?)
end
# Display version of status
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index fec1cefb6..5053523a3 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -160,25 +160,27 @@ class PublicBody < ActiveRecord::Base
# like find_by_url_name but also search historic url_name if none found
def self.find_by_url_name_with_historic(name)
- found = PublicBody.find(:all,
- :conditions => ["public_body_translations.url_name=?", name],
- :joins => :translations,
- :readonly => false)
- # If many bodies are found (usually because the url_name is the same across
- # locales) return any of them
- return found.first if found.size >= 1
-
- # If none found, then search the history of short names
- old = PublicBody::Version.find_all_by_url_name(name)
- # Find unique public bodies in it
- old = old.map { |x| x.public_body_id }
- old = old.uniq
+ # If many bodies are found (usually because the url_name is the same
+ # across locales) return any of them.
+ found = joins(:translations).
+ where("public_body_translations.url_name = ?", name).
+ readonly(false).
+ first
+
+ return found if found
+
+ # If none found, then search the history of short names and find unique
+ # public bodies in it
+ old = PublicBody::Version.
+ where(:url_name => name).
+ pluck('DISTINCT public_body_id')
+
# Maybe return the first one, so we show something relevant,
# rather than throwing an error?
raise "Two bodies with the same historical URL name: #{name}" if old.size > 1
return unless old.size == 1
# does acts_as_versioned provide a method that returns the current version?
- return PublicBody.find(old.first)
+ PublicBody.find(old.first)
end
# Set the first letter, which is used for faster queries