aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
Commit message (Collapse)AuthorAgeLines
* Correctly set uuencoded attachment file size2508-hotfix-bad-uudecodeGareth Rees2015-06-04-2/+1
|
* Use Ruby to decode uuencoded attachmentsGareth Rees2015-06-03-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Ruby can natively decode uuencoded text with String#unpack. [1] This avoids the uuencode program dependency and avoids writing tempfiles. The actual implementation is taken from mail [2]. The UnixToUnix module is not available in our bundled version of mail. This commit includes a spec to illustrate the failure of uuencode(1) to decode the particular attachment in incoming-request-bad-uuencoding-2. email. Parsing with uuencode returns the following error: External Command: Error from command "uudecode -o /dev/stdout /tmp/foiuu20150530-14811-u6j936": uudecode: /tmp/foiuu20150530-14811-u6j936: No `end' line The file _is_ created and appears to be OK, but the exit code is 1. This causes AlaveteliExternalCommand to fail and return nil. See #2508 [3] for the bug report. [1] http://ruby-doc.org/core-1.8.7/String.html#method-i-unpack [2] https://github.com/mikel/mail/blob/bc4c9bb9321e9d36a678692f2f562d3146b63f78/lib/mail/encodings/unix_to_unix.rb#L7 [3] https://github.com/mysociety/alaveteli/issues/2508
* Clean IncomingMessage#_uudecode_and_save_attachmentsGareth Rees2015-06-03-3/+3
| | | | | each instead of for remove self avoid explicit return
* Handle unparsed email contents as binary.Louise Crow2015-05-26-2/+17
| | | | | | | | | | | I think I was wrong in a83b379fd2d676172855825d0592937b234371e2 in assuming that all email gets properly encoded for transfer. Looking at the mail gem load method https://github.com/mikel/mail/blob/b159e0a542962fdd5e292a48cfffa560d7cf412e/lib/mail/mail.rb#L175a, it reads raw email content from a file in binary mode. So this commit makes both reading and writing the raw_email a binary mode operation and adds a data_as_text method for displaying the data in the admin interface that coerces it to valid utf-8.
* Use mb_chars to prevent slicing multibyte chars under ruby 1.8Louise Crow2015-05-15-1/+1
| | | | | | | | | | mb_chars provides a multibyte-aware wrapper for strings. It should have no effect on ruby 1.9.3 and above. Although ruby 1.8.7 wouldn't raise errors on a badly sliced multibyte string, on upgrading to ruby 1.9.3 and above, string operations such as gsub, match and join may produce ArgumentErrors with the message "invalid byte sequence in UTF-8". Additionally, a database with 'UTF-8' encoding may produce the error "PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding "UTF8""
* Merge branch 'master' of ssh://git.mysociety.org/data/git/public/alaveteli ↵Louise Crow2015-05-15-2/+9
|\ | | | | | | into hotfix/0.21.0.30
| * Discard rejected responses with malformed From:Gareth Rees2015-05-13-1/+6
| | | | | | | | | | | | | | | | | | Stops the RequestMailer trying to send a stopped_responses mail if the To: address can’t be parsed from the incoming message. ArgumentError: An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.
| * Add explaining commentsGareth Rees2015-05-13-0/+2
| |
| * Sensible error messageGareth Rees2015-05-13-1/+1
| |
* | Add UTF-8 encoding line.hotfix/0.29.0.30Louise Crow2015-05-15-0/+1
|/ | | | | | | Without this line, strings created in the file will use the default external encoding set by the ENV variable LANG. When processes are forked or run in cron, this may not be preserved, so better to set explicitly.
* Rescue from Holidays::UnknownRegionErrorhotfix/0.21.0.24Gareth Rees2015-04-29-4/+8
| | | | | If you run an Alaveteli in a region where we can’t show holiday suggestions the holiday import page breaks. This commit rescues from an unavailable region so that we display a friendly error message.
* Tidy InfoRequest#initial_request_textGareth Rees2015-04-27-5/+2
|
* Only load the outgoing messages that will be usedGareth Rees2015-04-27-1/+1
| | | | | | | | | | | | | | | | Prevents loading of all outgoing messages related to the info request. Before OutgoingMessage Load (1.5ms) SELECT "outgoing_messages".* FROM "outgoing_messages" WHERE "outgoing_messages"."info_request_id" = 137 ORDER BY created_at After OutgoingMessage Load (0.8ms) SELECT "outgoing_messages".* FROM "outgoing_messages" WHERE "outgoing_messages"."info_request_id" = 137 ORDER BY created_at LIMIT 1
* Improve performance initializing OutgoingMessageGareth Rees2015-04-27-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reduces the amount of queries to associated objects by directly checking the database before setting the default body content. Before > info_request.outgoing_messages OutgoingMessage Load (0.4ms) SELECT "outgoing_messages".* FROM "outgoing_messages" WHERE "outgoing_messages"."info_request_id" = 137 ORDER BY created_at InfoRequest Load (0.5ms) SELECT "info_requests".* FROM "info_requests" WHERE "info_requests"."id" = 137 LIMIT 1 PublicBody Load (0.5ms) SELECT "public_bodies".* FROM "public_bodies" WHERE "public_bodies"."id" = 16 LIMIT 1 HasTagString::HasTagStringTag Load (0.4ms) SELECT "has_tag_string_tags".* FROM "has_tag_string_tags" WHERE "has_tag_string_tags"."model_id" = 16 AND (model = 'PublicBody') CensorRule Load (0.4ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."info_request_id" IS NULL AND "censor_rules"."public_body_id" IS NULL AND "censor_rules"."user_id" IS NULL User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 13 LIMIT 1 (0.5ms) SELECT COUNT(*) FROM "censor_rules" WHERE "censor_rules"."user_id" = 13 CensorRule Load (0.5ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."info_request_id" = 137 ORDER BY created_at desc CensorRule Load (0.5ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."public_body_id" = 16 ORDER BY created_at desc InfoRequest Load (0.5ms) SELECT "info_requests".* FROM "info_requests" WHERE "info_requests"."id" = 137 LIMIT 1 PublicBody Load (0.5ms) SELECT "public_bodies".* FROM "public_bodies" WHERE "public_bodies"."id" = 16 LIMIT 1 HasTagString::HasTagStringTag Load (0.6ms) SELECT "has_tag_string_tags".* FROM "has_tag_string_tags" WHERE "has_tag_string_tags"."model_id" = 16 AND (model = 'PublicBody') CensorRule Load (0.5ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."info_request_id" IS NULL AND "censor_rules"."public_body_id" IS NULL AND "censor_rules"."user_id" IS NULL User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 13 LIMIT 1 (0.5ms) SELECT COUNT(*) FROM "censor_rules" WHERE "censor_rules"."user_id" = 13 CensorRule Load (0.4ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."info_request_id" = 137 ORDER BY created_at desc CensorRule Load (0.5ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."public_body_id" = 16 ORDER BY created_at desc => [#<OutgoingMessage id: 36, info_request_id: 137, body: "Some information please", status: "sent", message_type: "initial_request", created_at: "2015-04-17 10:50:21", updated_at: "2015-04-17 10:50:21", last_sent_at: "2015-04-17 10:50:21", incoming_message_followup_id: nil, what_doing: "normal_sort", prominence: "normal", prominence_reason: nil>, #<OutgoingMessage id: 37, info_request_id: 137, body: "Dear Example Public Body 6,\r\n\r\nc'mooooooonnnnnn\r\n\r\n...", status: "sent", message_type: "followup", created_at: "2015-04-20 12:18:30", updated_at: "2015-04-20 12:18:30", last_sent_at: "2015-04-20 12:18:30", incoming_message_followup_id: 30, what_doing: "normal_sort", prominence: "normal", prominence_reason: nil>] After > info_request.outgoing_messages OutgoingMessage Load (0.8ms) SELECT "outgoing_messages".* FROM "outgoing_messages" WHERE "outgoing_messages"."info_request_id" = 137 ORDER BY created_at => [#<OutgoingMessage id: 36, info_request_id: 137, body: "Some information please", status: "sent", message_type: "initial_request", created_at: "2015-04-17 10:50:21", updated_at: "2015-04-17 10:50:21", last_sent_at: "2015-04-17 10:50:21", incoming_message_followup_id: nil, what_doing: "normal_sort", prominence: "normal", prominence_reason: nil>, #<OutgoingMessage id: 37, info_request_id: 137, body: "Dear Example Public Body 6,\r\n\r\nc'mooooooonnnnnn\r\n\r\n...", status: "sent", message_type: "followup", created_at: "2015-04-20 12:18:30", updated_at: "2015-04-20 12:18:30", last_sent_at: "2015-04-20 12:18:30", incoming_message_followup_id: 30, what_doing: "normal_sort", prominence: "normal", prominence_reason: nil>]
* Don't translate validation messages yet.Louise Crow2015-03-24-3/+3
| | | | | | They're only visible in the admin interface. See https://github.com/mysociety/alaveteli/issues/1353 for details.
* Fix translating Public Body HeadingsGareth Rees2015-03-18-18/+25
| | | | | Fixes submission of form containing both existing and new translations
* Fix translating Public Body CategoriesGareth Rees2015-03-18-17/+43
|
* Fix translating Public BodiesGareth Rees2015-03-18-28/+17
|
* Merge branch '59-localised-authority-links' into rails-3-developLouise Crow2015-03-05-29/+0
|\ | | | | | | | | Conflicts: app/views/public_body/show.html.erb
| * Use routing helper to generate localised urls.Louise Crow2015-03-05-25/+0
| |
| * Remove 'html' param.Louise Crow2015-03-05-7/+3
| | | | | | | | | | There's only one call to this function in the rest of the code. That has 'html' set to true.
* | Merge branch 'remove-public-body-categories' into rails-3-developLouise Crow2015-03-05-5/+0
|\ \
| * | Remove deprecated code. Fixes #2015.Louise Crow2015-02-26-5/+0
| |/
* / WIP commit of public body page redesignMartin Wright2015-03-02-2/+1
|/
* Merge branch 'rails-3-develop' of ↵Louise Crow2015-02-24-2/+10
|\ | | | | | | ssh://git.mysociety.org/data/git/public/alaveteli into rails-3-develop
| * Add User#banned?Gareth Rees2015-02-24-2/+10
| | | | | | | | | | | | | | - Redefined User#public_banned? to User#banned? - Add specs for User#banned? - Deprecate User#public_banned? - Replace use of User#public_banned? with User#banned?
* | Merge branch 'allow-custom-state-testing' into rails-3-developLouise Crow2015-02-24-5/+3
|\ \ | |/ |/|
| * Allow custom states to be tested.Louise Crow2015-02-09-5/+3
| | | | | | | | | | | | Since https://github.com/mysociety/alaveteli/commit/80ad2d4c31075ffc994e8c48ea25e6e3c486c364 no themes have been loaded by tests unless explicitly specified, so I think it's safe to remove the code added in https://github.com/mysociety/alaveteli/commit/3dfc53f6b82b3c5da79a4c710d45b859f61f4f5f
* | Merge branch '2134-fix-same-attribute-value-across-locales' into rails-3-developLouise Crow2015-02-23-80/+99
|\ \
| * | Refactor massive import method into smaller instance level methodsLouise Crow2015-02-23-89/+83
| | |
| * | Use standard spacing for hashes, new lines for commentsLouise Crow2015-02-23-2/+3
| | |
| * | Test localised value for import against existing localised valueLouise Crow2015-02-23-2/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously the call to public_body.send would return the value for the default locale if no value was set in the current locale, meaning that translations for attributes that were the same as the attribute values in the default locale were not being loaded. Fixes #2134.
* | | Move logic to modelLouise Crow2015-02-20-0/+5
| | |
* | | Use correct method name in error.Louise Crow2015-02-20-1/+1
| | |
* | | Refactor common logicLouise Crow2015-02-20-15/+7
| | |
* | | Standard separation of methods.Louise Crow2015-02-20-1/+3
| |/ |/| | | | | Comment above a method should apply to that method only
* | Remove unused lineLouise Crow2015-02-09-1/+0
| |
* | Merge branch 'hotfix/0.20.0.6' into rails-3-developLouise Crow2015-02-05-3/+16
|\ \ | | | | | | | | | | | | Conflicts: spec/models/public_body_spec.rb
| * | Deprecate PublicBody#translations_attributes=(Array)Gareth Rees2015-02-03-0/+13
| | | | | | | | | | | | Array handling will no longer be supported in release 0.22
| * | Fix submission of form containing both existing and new translationsLouise Crow2015-02-03-2/+2
| | |
| * | Add specs for PublicBody#translated_versions=Gareth Rees2015-01-30-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Also fixes #empty_translation? to check for String and Symbol keys named 'locale'. Specs use a pre-change check to assert difference. For some reason rspec change matcher fails with 'nil is not a symbol'.
* | | Use each_with_index rather than magic booleanGareth Rees2015-02-04-2/+2
| | |
* | | Use map instead of creating empty arrayGareth Rees2015-02-04-3/+4
| | |
* | | Nicer capitalize first letter onlyGareth Rees2015-02-04-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | String#capitalize downcases remaining letters, so: > 'heLLo WorLd'.capitalize # => "Hello world" Our version only works on the first character of the String, preserving the case of the rest of the String: > 'heLLo WorLd'.sub(/\S/) { |m| Unicode.upcase(m) } # => 'HeLLo WorLd' Also handle unicode.
* | | Use each instead of forGareth Rees2015-01-23-1/+1
| | |
* | | Remove home-grown Array#to_sentence dupGareth Rees2015-01-23-8/+4
| |/ |/| | | | | | | - to_sentence does the same job as the removed code. - Clean up the conditional with .any? and implicit returns
* | Remove duplicate method.Louise Crow2015-01-12-10/+0
| |
* | Update table attribute metadataLouise Crow2014-12-23-11/+8
| | | | | | | | | | Some fields have moved to different models, or exist in translation tables.
* | Merge branch 'brakeman_fixes' into rails-3-developLouise Crow2014-12-18-13/+10
|\ \
| * | Improve InfoRequestEvent#incoming_message_selective_columns SQLGareth Rees2014-12-18-5/+4
| | |