diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/foi_attachment.rb | 81 | ||||
-rw-r--r-- | app/models/info_request_batch.rb | 7 | ||||
-rw-r--r-- | app/models/public_body.rb | 15 | ||||
-rw-r--r-- | app/models/request_classification.rb | 4 | ||||
-rw-r--r-- | app/models/spam_address.rb | 10 | ||||
-rw-r--r-- | app/models/user.rb | 37 |
6 files changed, 50 insertions, 104 deletions
diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb index ecd4a1872..6f198249a 100644 --- a/app/models/foi_attachment.rb +++ b/app/models/foi_attachment.rb @@ -292,83 +292,10 @@ class FoiAttachment < ActiveRecord::Base end # For "View as HTML" of attachment - def body_as_html(dir) - html = nil - wrapper_id = "wrapper" - - # simple cases, can never fail - if self.content_type == 'text/plain' - text = self.body.strip - text = CGI.escapeHTML(text) - text = MySociety::Format.make_clickable(text) - html = text.gsub(/\n/, '<br>') - return '<!DOCTYPE html><html><head><title></title></head><body>' + html + "</body></html>", wrapper_id - end - - # the extractions will also produce image files, which go in the - # current directory, so change to the directory the function caller - # wants everything in - - html = nil - if ['application/pdf', 'application/rtf'].include?(self.content_type) - text = self.body - Dir.chdir(dir) do - if RUBY_VERSION.to_f >= 1.9 - tempfile = Tempfile.new('foiextract', '.', :encoding => text.encoding) - else - tempfile = Tempfile.new('foiextract', '.') - end - tempfile.print text - tempfile.flush - - - if self.content_type == 'application/pdf' - # We set a timeout here, because pdftohtml can spiral out of control - # on some PDF files and we don't want to crash the whole server. - html = AlaveteliExternalCommand.run("pdftohtml", "-nodrm", "-zoom", "1.0", "-stdout", "-enc", "UTF-8", "-noframes", tempfile.path, :timeout => 30) - elsif self.content_type == 'application/rtf' - html = AlaveteliExternalCommand.run("unrtf", "--html", tempfile.path, :timeout => 120) - end - - tempfile.close - tempfile.delete - end - end - if html.nil? - if self.has_google_docs_viewer? - html = '' # force error and using Google docs viewer - else - raise "No HTML conversion available for type " + self.content_type - end - end - - - - # We need to look at: - # a) Any error code - # b) The output size, as pdftohtml does not return an error code upon error. - # c) For cases when there is no text in the body of the HTML, or - # images, so nothing will be rendered. This is to detect some bug in - # pdftohtml, which sometimes makes it return just <hr>s and no other - # content. - html.match(/(\<body[^>]*\>.*)/mi) - body = $1.to_s - body_without_tags = body.gsub(/\s+/,"").gsub(/\<[^\>]*\>/, "") - contains_images = html.match(/<img/mi) ? true : false - if html.size == 0 || !$?.success? || (body_without_tags.size == 0 && !contains_images) - ret = "<html><head></head><body>"; - if self.has_google_docs_viewer? - wrapper_id = "wrapper_google_embed" - protocol = AlaveteliConfiguration::force_ssl ? 'https' : 'http' - ret = ret + "<iframe src='#{protocol}://docs.google.com/viewer?url=<attachment-url-here>&embedded=true' width='100%' height='100%' style='border: none;'></iframe>"; - else - ret = ret + "<p>Sorry, we were unable to convert this file to HTML. Please use the download link at the top right.</p>" - end - ret = ret + "</body></html>" - return ret, wrapper_id - end - - return html, wrapper_id + def body_as_html(dir, opts = {}) + attachment_url = opts.fetch(:attachment_url, nil) + to_html_opts = opts.merge(:tmpdir => dir, :attachment_url => attachment_url) + AttachmentToHTML.to_html(self, to_html_opts) end end diff --git a/app/models/info_request_batch.rb b/app/models/info_request_batch.rb index 498ab4951..d7c5eb9af 100644 --- a/app/models/info_request_batch.rb +++ b/app/models/info_request_batch.rb @@ -1,13 +1,14 @@ # == Schema Information -# Schema version: 20131024114346 # # Table name: info_request_batches # # id :integer not null, primary key # title :text not null # user_id :integer not null -# created_at :datetime -# updated_at :datetime +# created_at :datetime not null +# updated_at :datetime not null +# body :text +# sent_at :datetime # class InfoRequestBatch < ActiveRecord::Base diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 7b1ded820..9cb344f14 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -6,7 +6,7 @@ # # id :integer not null, primary key # name :text not null -# short_name :text not null +# short_name :text default(""), not null # request_email :text not null # version :integer not null # last_edit_editor :string(255) not null @@ -37,7 +37,8 @@ class PublicBody < ActiveRecord::Base validates_presence_of :name, :message => N_("Name can't be blank") validates_presence_of :url_name, :message => N_("URL name can't be blank") - validates_uniqueness_of :short_name, :message => N_("Short name is already taken"), :if => Proc.new { |pb| pb.short_name != "" } + validates_uniqueness_of :short_name, :message => N_("Short name is already taken"), :allow_blank => true + validates_uniqueness_of :url_name, :message => N_("URL name is already taken") validates_uniqueness_of :name, :message => N_("Name is already taken") validate :request_email_if_requestable @@ -505,7 +506,15 @@ class PublicBody < ActiveRecord::Base public_body.publication_scheme = public_body.publication_scheme || "" public_body.last_edit_editor = editor public_body.last_edit_comment = 'Created from spreadsheet' - public_body.save! + + begin + public_body.save! + rescue ActiveRecord::RecordInvalid + public_body.errors.full_messages.each do |msg| + errors.push "error: line #{ line }: #{ msg } for authority '#{ name }'" + end + next + end end end end diff --git a/app/models/request_classification.rb b/app/models/request_classification.rb index 6873d468b..478a543d3 100644 --- a/app/models/request_classification.rb +++ b/app/models/request_classification.rb @@ -5,8 +5,8 @@ # id :integer not null, primary key # user_id :integer # info_request_event_id :integer -# created_at :datetime -# updated_at :datetime +# created_at :datetime not null +# updated_at :datetime not null # class RequestClassification < ActiveRecord::Base diff --git a/app/models/spam_address.rb b/app/models/spam_address.rb index 15c9d1ab8..b3ad329d8 100644 --- a/app/models/spam_address.rb +++ b/app/models/spam_address.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: spam_addresses +# +# id :integer not null, primary key +# email :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# + class SpamAddress < ActiveRecord::Base attr_accessible :email diff --git a/app/models/user.rb b/app/models/user.rb index e63ce8129..d75622b37 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,26 +1,25 @@ # == Schema Information -# Schema version: 20131024114346 # # Table name: users # -# id :integer not null, primary key -# email :string(255) not null -# name :string(255) not null -# hashed_password :string(255) not null -# salt :string(255) not null -# created_at :datetime not null -# updated_at :datetime not null -# email_confirmed :boolean default(FALSE), not null -# url_name :text not null -# last_daily_track_email :datetime default(2000-01-01 00:00:00 UTC) -# admin_level :string(255) default("none"), not null -# ban_text :text default(""), not null -# about_me :text default(""), not null -# locale :string(255) -# email_bounced_at :datetime -# email_bounce_message :text default(""), not null -# no_limit :boolean default(FALSE), not null -# receive_email_alerts :boolean default(TRUE), not null +# id :integer not null, primary key +# email :string(255) not null +# name :string(255) not null +# hashed_password :string(255) not null +# salt :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# email_confirmed :boolean default(FALSE), not null +# url_name :text not null +# last_daily_track_email :datetime default(Sat Jan 01 00:00:00 UTC 2000) +# admin_level :string(255) default("none"), not null +# ban_text :text default(""), not null +# about_me :text default(""), not null +# locale :string(255) +# email_bounced_at :datetime +# email_bounce_message :text default(""), not null +# no_limit :boolean default(FALSE), not null +# receive_email_alerts :boolean default(TRUE), not null # can_make_batch_requests :boolean default(FALSE), not null # |