Permalink
Browse files

Merge branch 'wdtk' into develop

Conflicts:
    app/controllers/admin_request_controller.rb
    config/httpd.conf
    spec/models/info_request_spec.rb
  • Loading branch information...
2 parents 1cb96ca + 9fb7527 commit b59164bf2658058cf8e7360c6d1bd53c557b8972 @crowbot crowbot committed Aug 16, 2012
@@ -36,7 +36,7 @@ def expire_for_request(info_request)
# also force a search reindexing (so changed text reflected in search)
info_request.reindex_request_events
- # and remove from varnsi
+ # and remove from varnish
info_request.purge_in_cache
end
@@ -28,8 +28,8 @@ def show
@info_request = InfoRequest.find(params[:id])
# XXX is this *really* the only way to render a template to a
# variable, rather than to the response?
- vars = OpenStruct.new(:name_to => @info_request.user_name,
- :name_from => MySociety::Config.get("CONTACT_NAME", 'Alaveteli'),
+ vars = OpenStruct.new(:name_to => @info_request.user_name,
+ :name_from => MySociety::Config.get("CONTACT_NAME", 'Alaveteli'),
:info_request => @info_request, :reason => params[:reason],
:info_request_url => 'http://' + MySociety::Config.get('DOMAIN') + request_url(@info_request),
:site_name => site_name)
@@ -81,6 +81,8 @@ def update
:old_handle_rejected_responses => old_handle_rejected_responses, :handle_rejected_responses => @info_request.handle_rejected_responses,
:old_tag_string => old_tag_string, :tag_string => @info_request.tag_string
})
+ # expire cached files
+ expire_for_request(@info_request)
flash[:notice] = 'Request successfully updated.'
redirect_to request_admin_url(@info_request)
else
@@ -95,7 +97,8 @@ def fully_destroy
url_title = @info_request.url_title
@info_request.fully_destroy
-
+ # expire cached files
+ expire_for_request(@info_request)
flash[:notice] = "Request #{url_title} has been completely destroyed. Email of user who made request: " + user.email
redirect_to admin_url('request/list')
end
@@ -166,14 +169,16 @@ def destroy_incoming
@incoming_message.fully_destroy
@incoming_message.info_request.log_event("destroy_incoming",
{ :editor => admin_http_auth_user(), :deleted_incoming_message_id => incoming_message_id })
-
+ # expire cached files
+ expire_for_request(@info_request)
flash[:notice] = 'Incoming message successfully destroyed.'
redirect_to request_admin_url(@info_request)
end
def redeliver_incoming
incoming_message = IncomingMessage.find(params[:redeliver_incoming_message_id])
message_ids = params[:url_title].split(",").each {|x| x.strip}
+ previous_request = incoming_message.info_request
destination_request = nil
ActiveRecord::Base.transaction do
for m in message_ids
@@ -184,7 +189,7 @@ def redeliver_incoming
end
if destination_request.nil?
flash[:error] = "Failed to find destination request '" + m + "'"
- return redirect_to request_admin_url(incoming_message.info_request)
+ return redirect_to request_admin_url(previous_request)
end
raw_email_data = incoming_message.raw_email.data
@@ -201,6 +206,8 @@ def redeliver_incoming
flash[:notice] = "Message has been moved to request(s). Showing the last one:"
end
+ # expire cached files
+ expire_for_request(previous_request)
incoming_message.fully_destroy
end
redirect_to request_admin_url(destination_request)
@@ -344,14 +351,14 @@ def hide_request
explanation = params[:explanation]
info_request = InfoRequest.find(params[:id])
info_request.prominence = "requester_only"
-
+
info_request.log_event("hide", {
:editor => admin_http_auth_user(),
:reason => params[:reason],
:subject => subject,
:explanation => explanation
})
-
+
info_request.set_described_state(params[:reason])
info_request.save!
@@ -360,6 +367,8 @@ def hide_request
subject,
params[:explanation]
)
+ # expire cached files
+ expire_for_request(info_request)
flash[:notice] = _("Your message to {{recipient_user_name}} has been sent",:recipient_user_name=>CGI.escapeHTML(info_request.user.name))
redirect_to request_admin_url(info_request)
end
@@ -213,13 +213,16 @@ def foi_fragment_cache_all_for_request(info_request)
foi_cache_path = File.expand_path(File.join(File.dirname(__FILE__), '../../cache'))
return File.join(foi_cache_path, path)
end
+
def foi_fragment_cache_exists?(key_path)
return File.exists?(key_path)
end
+
def foi_fragment_cache_read(key_path)
logger.info "Reading from fragment cache #{key_path}"
return File.read(key_path)
end
+
def foi_fragment_cache_write(key_path, content)
FileUtils.mkdir_p(File.dirname(key_path))
logger.info "Writing to fragment cache #{key_path}"
@@ -313,7 +313,7 @@ def new
# case the list of errors will also contain a more specific error
# describing the reason it is invalid.
@info_request.errors.delete("outgoing_messages")
-
+
render :action => 'new'
return
end
@@ -659,6 +659,11 @@ def authenticate_attachment
@info_request = incoming_message.info_request # used by view
render :template => 'request/hidden', :status => 410 # gone
end
+ # Is this a completely public request that we can cache attachments for
+ # to be served up without authentication?
+ if incoming_message.info_request.all_can_view?
+ @files_can_be_cached = true
+ end
end
def report_request
@@ -668,7 +673,7 @@ def report_request
:email => _("Then you can report the request '{{title}}'", :title => info_request.title),
:email_subject => _("Report an offensive or unsuitable request")
)
-
+
if !info_request.attention_requested
info_request.set_described_state('attention_requested', @user)
info_request.attention_requested = true # tells us if attention has ever been requested
@@ -689,6 +694,7 @@ def cache_attachments
key = params.merge(:only_path => true)
key_path = foi_fragment_cache_path(key)
if foi_fragment_cache_exists?(key_path)
+ logger.info("Reading cache for #{key_path}")
raise PermissionDenied.new("Directory listing not allowed") if File.directory?(key_path)
cached = foi_fragment_cache_read(key_path)
response.content_type = AlaveteliFileTypes.filename_to_mimetype(params[:file_name].join("/")) || 'application/octet-stream'
@@ -703,7 +709,10 @@ def cache_attachments
# various fragment cache functions using Ruby Marshall to write the file
# which adds a header, so isnt compatible with images that have been
# extracted elsewhere from PDFs)
- foi_fragment_cache_write(key_path, response.body)
+ if @files_can_be_cached == true
+ logger.info("Writing cache for #{key_path}")
+ foi_fragment_cache_write(key_path, response.body)
+ end
end
end
end
View
@@ -104,7 +104,7 @@ def must_be_valid_state
errors.add(:described_state, "is not a valid state") if
!InfoRequest.enumerate_states.include? described_state
end
-
+
# The request must either be internal, in which case it has
# a foreign key reference to a User object and no external_url or external_user_name,
# or else be external in which case it has no user_id but does have an external_url,
@@ -120,15 +120,15 @@ def must_be_internal_or_external
errors.add(:external_url, "must be null for an internal request") if !external_url.nil?
end
end
-
+
def is_external?
!external_url.nil?
end
-
+
def user_name
is_external? ? external_user_name : user.name
end
-
+
def user_name_slug
if is_external?
if external_user_name.nil?
@@ -708,10 +708,10 @@ def recipient_email_valid_for_followup?
return self.public_body.is_followupable?
end
def recipient_name_and_email
- return TMail::Address.address_from_name_and_email(
- _("{{law_used}} requests at {{public_body}}",
- :law_used => self.law_used_short,
- :public_body => self.public_body.short_or_long_name),
+ return TMail::Address.address_from_name_and_email(
+ _("{{law_used}} requests at {{public_body}}",
+ :law_used => self.law_used_short,
+ :public_body => self.public_body.short_or_long_name),
self.recipient_email).to_s
end
@@ -1032,6 +1032,12 @@ def user_can_view?(user)
return true
end
+ # Is this request visible to everyone?
+ def all_can_view?
+ return true if ['normal', 'backpage'].include?(self.prominence)
+ return false
+ end
+
def indexed_by_search?
if self.prominence == 'backpage' || self.prominence == 'hidden' || self.prominence == 'requester_only'
return false
@@ -157,3 +157,8 @@ VARNISH_HOST: localhost
# Adding a value here will enable Google Analytics on all non-admin pages.
GA_CODE: ''
+
+# We need to add the WDTK survey variables here, or else the deployment
+# system will cry.
+SURVEY_SECRET: ''
+SURVEY_URL: ''
View
@@ -5,7 +5,7 @@
#
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org
-#
+#
# $Id: httpd.conf,v 1.31 2009-09-02 13:05:48 matthew Exp $
# This is needed for the PHP spell checker
@@ -25,7 +25,7 @@ RewriteEngine On
# it.
RewriteCond %{LA-U:REMOTE_USER} (.+)
RewriteRule . - [E=RU:%1]
-RequestHeader add X-Forwarded-User %{RU}e
+RequestHeader add X-Forwarded-User %{RU}e
# Old /files URL to new subdomain (as can't use Alias with passenger,
# so we do it on its own domain). This is for custom admin upload
View
@@ -1,15 +1,44 @@
namespace :temp do
- desc "Remove plaintext passwords from post_redirect params"
- task :remove_post_redirect_passwords => :environment do
- PostRedirect.find_each(:conditions => ['post_params_yaml is not null']) do |post_redirect|
- if post_redirect.post_params && post_redirect.post_params[:signchangeemail] && post_redirect.post_params[:signchangeemail][:password]
- params = post_redirect.post_params
- params[:signchangeemail].delete(:password)
- post_redirect.post_params = params
- post_redirect.save!
- end
+ desc "Remove plaintext passwords from post_redirect params"
+ task :remove_post_redirect_passwords => :environment do
+ PostRedirect.find_each(:conditions => ['post_params_yaml is not null']) do |post_redirect|
+ if post_redirect.post_params && post_redirect.post_params[:signchangeemail] && post_redirect.post_params[:signchangeemail][:password]
+ params = post_redirect.post_params
+ params[:signchangeemail].delete(:password)
+ post_redirect.post_params = params
+ post_redirect.save!
+ end
+ end
+ end
+
+ desc 'Remove file caches for requests that are not publicly visible or have been destroyed'
+ task :remove_obsolete_info_request_caches => :environment do
+ dryrun = ENV['DRYRUN'] == '0' ? false : true
+ verbose = ENV['VERBOSE'] == '0' ? false : true
+ if dryrun
+ puts "Running in dryrun mode"
+ end
+ request_cache_path = File.join(Rails.root, 'cache', 'views', 'request', '*', '*')
+ Dir.glob(request_cache_path) do |request_subdir|
+ info_request_id = File.basename(request_subdir)
+ puts "Looking for InfoRequest with id #{info_request_id}" if verbose
+ begin
+ info_request = InfoRequest.find(info_request_id)
+ puts "Got InfoRequest #{info_request_id}" if verbose
+ if ! info_request.all_can_view?
+ puts "Deleting cache at #{request_subdir} for hidden/requester_only InfoRequest #{info_request_id}"
+ if ! dryrun
+ FileUtils.rm_rf(request_subdir)
+ end
+ end
+ rescue ActiveRecord::RecordNotFound
+ puts "Deleting cache at #{request_subdir} for deleted InfoRequest #{info_request_id}"
+ if ! dryrun
+ FileUtils.rm_rf(request_subdir)
+ end
+ end
+ end
end
- end
end
Oops, something went wrong.

0 comments on commit b59164b

Please sign in to comment.