diff options
-rw-r--r-- | Gemfile.lock | 2 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 29 | ||||
-rw-r--r-- | app/controllers/services_controller.rb | 6 | ||||
-rw-r--r-- | app/models/info_request.rb | 13 | ||||
-rw-r--r-- | app/models/request_mailer.rb | 37 | ||||
-rw-r--r-- | app/models/user.rb | 11 | ||||
-rw-r--r-- | app/views/general/frontpage.rhtml | 11 | ||||
-rw-r--r-- | app/views/layouts/default.rhtml | 2 | ||||
-rw-r--r-- | app/views/request/_request_listing_via_event.rhtml | 10 | ||||
-rw-r--r-- | config/.gitignore | 1 | ||||
-rw-r--r-- | config/general.yml-example | 2 | ||||
-rw-r--r-- | config/httpd.conf | 2 | ||||
-rw-r--r-- | config/newrelic.yml-example | 54 | ||||
-rw-r--r-- | doc/INSTALL.md | 6 | ||||
-rw-r--r-- | lib/world_foi_websites.rb | 6 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 63 |
16 files changed, 178 insertions, 77 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index 58c5bcbe0..86329ab86 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,7 +20,7 @@ GEM activesupport (2.3.14) annotate (2.4.0) archive-tar-minitar (0.5.2) - capistrano (2.13.3) + capistrano (2.13.4) highline net-scp (>= 1.0.0) net-sftp (>= 2.0.0) diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 396e6593a..3296db6b7 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -446,18 +446,19 @@ class RequestController < ApplicationController return end + calculated_status = @info_request.calculate_status # Display advice for requester on what to do next, as appropriate - if @info_request.calculate_status == 'waiting_response' + if calculated_status == 'waiting_response' flash[:notice] = _("<p>Thank you! Hopefully your wait isn't too long.</p> <p>By law, you should get a response promptly, and normally before the end of <strong> {{date_response_required_by}}</strong>.</p>",:date_response_required_by=>simple_date(@info_request.date_response_required_by)) redirect_to request_url(@info_request) - elsif @info_request.calculate_status == 'waiting_response_overdue' + elsif calculated_status == 'waiting_response_overdue' flash[:notice] = _("<p>Thank you! Hope you don't have to wait much longer.</p> <p>By law, you should have got a response promptly, and normally before the end of <strong>{{date_response_required_by}}</strong>.</p>",:date_response_required_by=>simple_date(@info_request.date_response_required_by)) redirect_to request_url(@info_request) - elsif @info_request.calculate_status == 'waiting_response_very_overdue' + elsif calculated_status == 'waiting_response_very_overdue' flash[:notice] = _("<p>Thank you! Your request is long overdue, by more than {{very_late_number_of_days}} working days. Most requests should be answered within {{late_number_of_days}} working days. You might like to complain about this, see below.</p>", :very_late_number_of_days => Configuration::reply_very_late_after_days, :late_number_of_days => Configuration::reply_late_after_days) redirect_to unhappy_url(@info_request) - elsif @info_request.calculate_status == 'not_held' + elsif calculated_status == 'not_held' flash[:notice] = _("<p>Thank you! Here are some ideas on what to do next:</p> <ul> <li>To send your request to another authority, first copy the text of your request below, then <a href=\"{{find_authority_url}}\">find the other authority</a>.</li> @@ -472,37 +473,37 @@ class RequestController < ApplicationController :complain_url => CGI.escapeHTML(unhappy_url(@info_request)), :other_means_url => CGI.escapeHTML(unhappy_url(@info_request)) + "#other_means") redirect_to request_url(@info_request) - elsif @info_request.calculate_status == 'rejected' + elsif calculated_status == 'rejected' flash[:notice] = _("Oh no! Sorry to hear that your request was refused. Here is what to do now.") redirect_to unhappy_url(@info_request) - elsif @info_request.calculate_status == 'successful' + elsif calculated_status == 'successful' flash[:notice] = _("<p>We're glad you got all the information that you wanted. If you write about or make use of the information, please come back and add an annotation below saying what you did.</p><p>If you found {{site_name}} useful, <a href=\"{{donation_url}}\">make a donation</a> to the charity which runs it.</p>", :site_name=>site_name, :donation_url => "http://www.mysociety.org/donate/") redirect_to request_url(@info_request) - elsif @info_request.calculate_status == 'partially_successful' + elsif calculated_status == 'partially_successful' flash[:notice] = _("<p>We're glad you got some of the information that you wanted. If you found {{site_name}} useful, <a href=\"{{donation_url}}\">make a donation</a> to the charity which runs it.</p><p>If you want to try and get the rest of the information, here's what to do now.</p>", :site_name=>site_name, :donation_url=>"http://www.mysociety.org/donate/") redirect_to unhappy_url(@info_request) - elsif @info_request.calculate_status == 'waiting_clarification' + elsif calculated_status == 'waiting_clarification' flash[:notice] = _("Please write your follow up message containing the necessary clarifications below.") redirect_to respond_to_last_url(@info_request) - elsif @info_request.calculate_status == 'gone_postal' + elsif calculated_status == 'gone_postal' redirect_to respond_to_last_url(@info_request) + "?gone_postal=1" - elsif @info_request.calculate_status == 'internal_review' + elsif calculated_status == 'internal_review' flash[:notice] = _("<p>Thank you! Hopefully your wait isn't too long.</p><p>You should get a response within {{late_number_of_days}} days, or be told if it will take longer (<a href=\"{{review_url}}\">details</a>).</p>",:late_number_of_days => Configuration.reply_late_after_days, :review_url => unhappy_url(@info_request) + "#internal_review") redirect_to request_url(@info_request) - elsif @info_request.calculate_status == 'error_message' + elsif calculated_status == 'error_message' flash[:notice] = _("<p>Thank you! We'll look into what happened and try and fix it up.</p><p>If the error was a delivery failure, and you can find an up to date FOI email address for the authority, please tell us using the form below.</p>") redirect_to help_general_url(:action => 'contact') - elsif @info_request.calculate_status == 'requires_admin' + elsif calculated_status == 'requires_admin' flash[:notice] = _("Please use the form below to tell us more.") redirect_to help_general_url(:action => 'contact') - elsif @info_request.calculate_status == 'user_withdrawn' + elsif calculated_status == 'user_withdrawn' flash[:notice] = _("If you have not done so already, please write a message below telling the authority that you have withdrawn your request. Otherwise they will not know it has been withdrawn.") redirect_to respond_to_last_url(@info_request) else if @@custom_states_loaded return self.theme_describe_state(@info_request) else - raise "unknown calculate_status " + @info_request.calculate_status + raise "unknown calculate_status " + calculated_status end end end diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index ead5d73b7..38bf51772 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -9,13 +9,13 @@ class ServicesController < ApplicationController iso_country_code = Configuration::iso_country_code.downcase if country_from_ip.downcase != iso_country_code found_country = WorldFOIWebsites.by_code(country_from_ip) - found_country_name = !found_country.nil? && found_country[:country_name] old_fgt_locale = FastGettext.locale begin FastGettext.locale = FastGettext.best_locale_in(request.env['HTTP_ACCEPT_LANGUAGE']) - if found_country_name - text = _("Hello! You can make Freedom of Information requests within {{country_name}} at {{link_to_website}}", :country_name => found_country_name, :link_to_website => "<a href=\"#{found_country[:url]}\">#{found_country[:name]}</a>") + if found_country && found_country[:country_name] && found_country[:url] && found_country[:name] + text = _("Hello! You can make Freedom of Information requests within {{country_name}} at {{link_to_website}}", + :country_name => found_country[:country_name], :link_to_website => "<a href=\"#{found_country[:url]}\">#{found_country[:name]}</a>") else current_country = WorldFOIWebsites.by_code(iso_country_code)[:country_name] text = _("Hello! We have an <a href=\"/help/alaveteli?country_name=#{CGI.escape(current_country)}\">important message</a> for visitors outside {{country_name}}", :country_name => current_country) diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 74a67b9d9..47424e573 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -584,12 +584,11 @@ public # waiting_classification # waiting_response_overdue # waiting_response_very_overdue - def calculate_status - if @@custom_states_loaded - return self.theme_calculate_status - else - self.base_calculate_status + def calculate_status(cached_value_ok=false) + if cached_value_ok && @cached_calculated_status + return @cached_calculated_status end + @cached_calculated_status = @@custom_states_loaded ? self.theme_calculate_status : self.base_calculate_status end def base_calculate_status @@ -871,8 +870,8 @@ public end end - def display_status - InfoRequest.get_status_description(self.calculate_status) + def display_status(cached_value_ok=false) + InfoRequest.get_status_description(self.calculate_status(cached_value_ok)) end # Completely delete this request and all objects depending on it diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index 413e93e25..90c4c6b53 100644 --- a/app/models/request_mailer.rb +++ b/app/models/request_mailer.rb @@ -256,24 +256,47 @@ class RequestMailer < ApplicationMailer def self.alert_overdue_requests() info_requests = InfoRequest.find(:all, :conditions => [ - "described_state = 'waiting_response' and awaiting_description = ? and user_id is not null", false + "described_state = 'waiting_response' + AND awaiting_description = ? + AND user_id is not null + AND (SELECT id + FROM user_info_request_sent_alerts + WHERE alert_type = 'very_overdue_1' + AND info_request_id = info_requests.id + AND user_id = info_requests.user_id + AND info_request_event_id = (SELECT max(id) + FROM info_request_events + WHERE event_type in ('sent', + 'followup_sent', + 'resent', + 'followup_resent') + AND info_request_id = info_requests.id) + ) IS NULL", false ], :include => [ :user ] ) for info_request in info_requests alert_event_id = info_request.last_event_forming_initial_request.id # Only overdue requests - if ['waiting_response_overdue', 'waiting_response_very_overdue'].include?(info_request.calculate_status) - if info_request.calculate_status == 'waiting_response_overdue' + calculated_status = info_request.calculate_status + if ['waiting_response_overdue', 'waiting_response_very_overdue'].include?(calculated_status) + if calculated_status == 'waiting_response_overdue' alert_type = 'overdue_1' - elsif info_request.calculate_status == 'waiting_response_very_overdue' + elsif calculated_status == 'waiting_response_very_overdue' alert_type = 'very_overdue_1' else raise "unknown request status" end # For now, just to the user who created the request - sent_already = UserInfoRequestSentAlert.find(:first, :conditions => [ "alert_type = ? and user_id = ? and info_request_id = ? and info_request_event_id = ?", alert_type, info_request.user_id, info_request.id, alert_event_id]) + sent_already = UserInfoRequestSentAlert.find(:first, :conditions => [ "alert_type = ? + AND user_id = ? + AND info_request_id = ? + AND info_request_event_id = ?", + alert_type, + info_request.user_id, + info_request.id, + alert_event_id]) if sent_already.nil? # Alert not yet sent for this user, so send it store_sent = UserInfoRequestSentAlert.new @@ -284,9 +307,9 @@ class RequestMailer < ApplicationMailer # Only send the alert if the user can act on it by making a followup # (otherwise they are banned, and there is no point sending it) if info_request.user.can_make_followup? - if info_request.calculate_status == 'waiting_response_overdue' + if calculated_status == 'waiting_response_overdue' RequestMailer.deliver_overdue_alert(info_request, info_request.user) - elsif info_request.calculate_status == 'waiting_response_very_overdue' + elsif calculated_status == 'waiting_response_very_overdue' RequestMailer.deliver_very_overdue_alert(info_request, info_request.user) else raise "unknown request status" diff --git a/app/models/user.rb b/app/models/user.rb index 59f6c971c..4a68d60d1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -246,6 +246,11 @@ class User < ActiveRecord::Base # Does the user magically gain powers as if they owned every request? # e.g. Can classify it def owns_every_request? + self.super? + end + + # Does this user have extraordinary powers? + def super? self.admin_level == 'super' end @@ -255,18 +260,18 @@ class User < ActiveRecord::Base # Can the user see every request, even hidden ones? def User.view_hidden_requests?(user) - !user.nil? && user.admin_level == 'super' + !user.nil? && user.super? end # Should the user be kept logged into their own account # if they follow a /c/ redirect link belonging to another user? def User.stay_logged_in_on_redirect?(user) - !user.nil? && user.admin_level == 'super' + !user.nil? && user.super? end # Does the user get "(admin)" links on each page on the main site? def admin_page_links? - self.admin_level == 'super' + self.super? end # Is it public that they are banned? def public_banned? diff --git a/app/views/general/frontpage.rhtml b/app/views/general/frontpage.rhtml index 7f25cdd14..ec7b9bd8f 100644 --- a/app/views/general/frontpage.rhtml +++ b/app/views/general/frontpage.rhtml @@ -63,11 +63,18 @@ <ul> <% for event in @request_events %> <li> - <%= public_body_link(event.info_request.public_body) %> <%= _('answered a request about') %> + <% if @request_events_all_successful %> + <%= _("{{public_body_link}} answered a request about", + :public_body_link => public_body_link(event.info_request.public_body)) %> + <% else %> + <%= _("{{public_body_link}} was sent a request about", + :public_body_link => public_body_link(event.info_request.public_body)) %> + <% end %> + <%=link_to h(event.info_request.title), request_url(event.info_request)%> <%= _('{{length_of_time}} ago', :length_of_time => time_ago_in_words(event.described_at)) %> <p class="excerpt" onclick="document.location.href='<%=request_url(event.info_request)%>'"><%= excerpt(event.search_text_main(true), "", 200) %></p> - </li> + </li> <% end %> </ul> <p><strong> diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml index 0dd493fd0..7b4c0f6a1 100644 --- a/app/views/layouts/default.rhtml +++ b/app/views/layouts/default.rhtml @@ -139,7 +139,7 @@ <input type="text"> </div> <% - unless Configuration::ga_code.empty? %> + unless Configuration::ga_code.empty? || (@user && @user.super?) %> <script> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); diff --git a/app/views/request/_request_listing_via_event.rhtml b/app/views/request/_request_listing_via_event.rhtml index e3abfe393..ee1cc079a 100644 --- a/app/views/request/_request_listing_via_event.rhtml +++ b/app/views/request/_request_listing_via_event.rhtml @@ -17,13 +17,13 @@ end %> </span> <div class="requester"> <% if event.event_type == 'sent' %> - <%= _('Request sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>request_user_link_absolute(info_request),:date=>simple_date(event.created_at )) %> + <%= _('Request sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>request_user_link_absolute(info_request),:date=>simple_date(event.created_at )) %> <% elsif event.event_type == 'followup_sent' %> <%=event.display_status %> - <%= _('sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>request_user_link_absolute(info_request),:date=>simple_date(event.created_at )) %> + <%= _('sent to {{public_body_name}} by {{info_request_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>request_user_link_absolute(info_request),:date=>simple_date(event.created_at )) %> <% elsif event.event_type == 'response' %> <%=event.display_status %> - <%= _('by {{public_body_name}} to {{info_request_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>request_user_link_absolute(info_request),:date=>simple_date(event.created_at )) %> + <%= _('by {{public_body_name}} to {{info_request_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>request_user_link_absolute(info_request),:date=>simple_date(event.created_at )) %> <% elsif event.event_type == 'comment' %> <%= _('Request to {{public_body_name}} by {{info_request_user}}. Annotated by {{event_comment_user}} on {{date}}.',:public_body_name=>public_body_link_absolute(info_request.public_body),:info_request_user=>user_link_absolute(info_request.user),:event_comment_user=>user_link_absolute(event.comment.user),:date=>simple_date(event.created_at)) %> <% else %> @@ -35,12 +35,12 @@ end %> </div> <span class="bottomline icon_<%= info_request.calculate_status %>"> <strong> - <%= info_request.display_status %> + <%= info_request.display_status(cached_value_ok=true) %> </strong><br> </span> </div> <div class="request_right"> - <span class="desc"> + <span class="desc"> <%= highlight_and_excerpt(event.search_text_main(true), @highlight_words, 150) %> </span> </div> diff --git a/config/.gitignore b/config/.gitignore index 78d586ea8..5ad2de008 100644 --- a/config/.gitignore +++ b/config/.gitignore @@ -7,3 +7,4 @@ logrotate memcached.yml *.deployed deploy.yml +newrelic.yml diff --git a/config/general.yml-example b/config/general.yml-example index 9646e45c8..1b30ffce6 100644 --- a/config/general.yml-example +++ b/config/general.yml-example @@ -160,7 +160,7 @@ MAX_REQUESTS_PER_USER_PER_DAY: 6 # unset if you aren't running behind varnish VARNISH_HOST: localhost -# Adding a value here will enable Google Analytics on all non-admin pages. +# Adding a value here will enable Google Analytics on all non-admin pages for non-admin users. GA_CODE: '' # If you want to override *all* the public body request emails with your own diff --git a/config/httpd.conf b/config/httpd.conf index 440da0d87..acf37d97c 100644 --- a/config/httpd.conf +++ b/config/httpd.conf @@ -46,7 +46,7 @@ RewriteRule ^/request/((\d{1,3})\d*)/(response/\d+/attach/(html/)?\d+/.+) /views <IfModule mod_passenger.c> # Set this to something like 100 if you have memory leak issues - PassengerMaxRequests 20 + PassengerMaxRequests 500 PassengerResolveSymlinksInDocumentRoot on # Recommend setting this to 3 or less on servers with 512MB RAM PassengerMaxPoolSize 6 diff --git a/config/newrelic.yml-example b/config/newrelic.yml-example index 8da7e26bd..ce19cca54 100644 --- a/config/newrelic.yml-example +++ b/config/newrelic.yml-example @@ -15,7 +15,7 @@ common: &default_settings # account. This key binds your Agent's data to your account in the # New Relic service. #license_key: '' - + # Agent Enabled (Ruby/Rails Only) # Use this setting to force the agent to run or not run. # Default is 'auto' which means the agent will install and run only @@ -23,21 +23,21 @@ common: &default_settings # it from running with Rake or the console. Set to false to # completely turn the agent off regardless of the other settings. # Valid values are true, false and auto. - # agent_enabled: auto - + agent_enabled: false + # Application Name # Set this to be the name of your application as you'd like it show # up in New Relic. New Relic will then auto-map instances of your application # into a New Relic "application" on your home dashboard page. If you want # to map this instance into multiple apps, like "AJAX Requests" and # "All UI" then specify a semicolon-separated list of up to three - # distinct names. If you comment this out, it defaults to the + # distinct names. If you comment this out, it defaults to the # capitalized RAILS_ENV (i.e., Production, Staging, etc) app_name: My Application - # When "true", the agent collects performance data about your + # When "true", the agent collects performance data about your # application and reports this data to the New Relic service at - # newrelic.com. This global switch is normally overridden for each + # newrelic.com. This global switch is normally overridden for each # environment below. (formerly called 'enabled') monitor_mode: true @@ -49,7 +49,7 @@ common: &default_settings # information separate from that of your application. Specify its # log level here. log_level: info - + # The newrelic agent communicates with the New Relic service via http by # default. If you want to communicate via https to increase # security, then turn on SSL by setting this value to true. Note, @@ -86,7 +86,7 @@ common: &default_settings # Rails: the RoR filter_parameter_logging excludes parameters # Java: create a config setting called "ignored_params" and set it to # a comma separated list of HTTP parameter names. - # ex: ignored_params: credit_card, ssn, password + # ex: ignored_params: credit_card, ssn, password capture_params: false # Transaction tracer captures deep information about slow @@ -94,12 +94,12 @@ common: &default_settings # minute. Included in the transaction is the exact call sequence of # the transactions including any SQL statements issued. transaction_tracer: - + # Transaction tracer is enabled by default. Set this to false to # turn it off. This feature is only available at the Professional # product level. enabled: true - + # Threshold in seconds for when to collect a transaction # trace. When the response time of a controller action exceeds # this threshold, a transaction trace will be recorded and sent to @@ -107,13 +107,13 @@ common: &default_settings # which will use the threshold for an dissatisfying Apdex # controller action - four times the Apdex T value. transaction_threshold: apdex_f - + # When transaction tracer is on, SQL statements can optionally be # recorded. The recorder has three modes, "off" which sends no # SQL, "raw" which sends the SQL statement in its original form, # and "obfuscated", which strips out numeric and string literals. record_sql: obfuscated - + # Threshold in seconds for when to collect stack trace for a SQL # call. In other words, when SQL statements exceed this threshold, # then capture and send to New Relic the current stack trace. This is @@ -125,24 +125,24 @@ common: &default_settings # set to false when using other adapters. # explain_enabled: true - # Threshold for query execution time below which query plans will not + # Threshold for query execution time below which query plans will not # not be captured. Relevant only when `explain_enabled` is true. # explain_threshold: 0.5 - + # Error collector captures information about uncaught exceptions and # sends them to New Relic for viewing error_collector: - + # Error collector is enabled by default. Set this to false to turn # it off. This feature is only available at the Professional # product level. enabled: true - - # Rails Only - tells error collector whether or not to capture a - # source snippet around the place of the error when errors are View + + # Rails Only - tells error collector whether or not to capture a + # source snippet around the place of the error when errors are View # related. - capture_source: true - + capture_source: true + # To stop specific errors from reporting to New Relic, set this property # to comma-separated values. Default is to ignore routing errors, # which are how 404's get triggered. @@ -152,7 +152,7 @@ common: &default_settings # won't run. Useful when you are using the agent to monitor an # external resource # disable_samplers: true - + # If you aren't interested in visibility in these areas, you can # disable the instrumentation to reduce overhead. # @@ -160,8 +160,8 @@ common: &default_settings # disable_activerecord_instrumentation: true # disable_memcache_instrumentation: true # disable_dj: true - - # Certain types of instrumentation such as GC stats will not work if + + # Certain types of instrumentation such as GC stats will not work if # you are running multi-threaded. Please let us know. # multi_threaded = false @@ -179,17 +179,17 @@ development: <<: *default_settings # Turn off communication to New Relic service in development mode (also # 'enabled'). - # NOTE: for initial evaluation purposes, you may want to temporarily + # NOTE: for initial evaluation purposes, you may want to temporarily # turn agent communication on in development mode. monitor_mode: false - # Rails Only - when running in Developer Mode, the New Relic Agent will + # Rails Only - when running in Developer Mode, the New Relic Agent will # present performance information on the last 100 transactions you have # executed since starting the app server. # NOTE: There is substantial overhead when running in developer mode. - # Do not use for production or load testing. + # Do not use for production or load testing. developer_mode: true - + # Enable textmate links # textmate: true diff --git a/doc/INSTALL.md b/doc/INSTALL.md index b805ee0c5..e36d10e2b 100644 --- a/doc/INSTALL.md +++ b/doc/INSTALL.md @@ -222,6 +222,12 @@ Interlock Rails plugin, to cache content using memcached. You probably don't want this in your development profile; the example `memcached.yml` file disables this behaviour. +Finally, copy `config/newrelic.yml-example` to `config/newrelic.yml`. +This file contains configuration information for the New Relic +performance management system. By default, monitoring is switched off +by the `agent_enabled: false` setting. See https://github.com/newrelic/rpm +for instructions on switching on local and remote performance analysis. + # Deployment In the 'alaveteli' directory, run: diff --git a/lib/world_foi_websites.rb b/lib/world_foi_websites.rb index f175afd3d..8cfd0dfae 100644 --- a/lib/world_foi_websites.rb +++ b/lib/world_foi_websites.rb @@ -45,7 +45,11 @@ class WorldFOIWebsites {:name => "Acceso Intelligente", :country_name => "Chile", :country_iso_code => "CL", - :url => "http://accesointeligente.org"}] + :url => "http://accesointeligente.org"}, + {:country_name => "Australia", + :country_iso_code => "AU", + # The Australian site is not yet live. So, not including name & url yet. + }] return world_foi_websites end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 77f43b618..b0223588e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -245,7 +245,7 @@ describe RequestController, "when showing one request" do response.should have_tag('#anyone_actions', /Add an annotation/) end end - + describe 'when the request does not allow comments' do it 'should not have a comment link' do get :show, { :url_title => 'spam_1' }, @@ -253,7 +253,7 @@ describe RequestController, "when showing one request" do response.should_not have_tag('#anyone_actions', /Add an annotation/) end end - + describe 'when the request is being viewed by an admin' do describe 'if the request is awaiting description' do @@ -1709,15 +1709,17 @@ describe RequestController, "sending overdue request alerts" do mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email end - it "should send not actually send the overdue alert if the user is banned" do + it "should send not actually send the overdue alert if the user is banned but should + record it as sent" do user = info_requests(:naughty_chicken_request).user user.ban_text = 'Banned' user.save! - + UserInfoRequestSentAlert.find_all_by_user_id(user.id).count.should == 0 RequestMailer.alert_overdue_requests deliveries = ActionMailer::Base.deliveries deliveries.size.should == 0 + UserInfoRequestSentAlert.find_all_by_user_id(user.id).count.should > 0 end it "should send a very overdue alert mail to creators of very overdue requests" do @@ -1746,6 +1748,59 @@ describe RequestController, "sending overdue request alerts" do assigns[:info_request].should == info_requests(:naughty_chicken_request) end + it "should not resend alerts to people who've already received them" do + chicken_request = info_requests(:naughty_chicken_request) + chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days + chicken_request.outgoing_messages[0].save! + RequestMailer.alert_overdue_requests + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 1 + RequestMailer.alert_overdue_requests + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 1 + end + + it 'should send alerts for requests where the last event forming the initial request is a followup + being sent following a request for clarification' do + chicken_request = info_requests(:naughty_chicken_request) + chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days + chicken_request.outgoing_messages[0].save! + RequestMailer.alert_overdue_requests + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 1 + + # Request is waiting clarification + chicken_request.set_described_state('waiting_clarification') + + # Followup message is sent + outgoing_message = OutgoingMessage.new(:status => 'ready', + :message_type => 'followup', + :info_request_id => chicken_request.id, + :body => 'Some text', + :what_doing => 'normal_sort') + outgoing_message.send_message + outgoing_message.save! + + chicken_request = InfoRequest.find(chicken_request.id) + + # Last event forming the request is now the followup + chicken_request.last_event_forming_initial_request.event_type.should == 'followup_sent' + + # This isn't overdue, so no email + RequestMailer.alert_overdue_requests + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 1 + + # Make the followup older + outgoing_message.last_sent_at = Time.now() - 60.days + outgoing_message.save! + + # Now it should be alerted on + RequestMailer.alert_overdue_requests + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 2 + end + end describe RequestController, "sending unclassified new response reminder alerts" do |