diff options
31 files changed, 386 insertions, 123 deletions
diff --git a/.ruby-version b/.ruby-version index 2aaf2528c..7fa1d1ef4 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-1.9.3-p392 +2.0.0-p353 diff --git a/.travis.yml b/.travis.yml index 051dc0fae..d6ed72cf6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ branches: rvm: - 1.8.7 - 1.9.3 + - 2.0.0 before_install: - gem install rake --version=0.9.2.2 - git submodule update --init --recursive @@ -23,7 +23,7 @@ gem 'jquery-ui-rails' gem 'json' gem 'mahoro' gem 'memcache-client' -gem 'net-http-local' +gem 'net-http-local', :platforms => [:ruby_18, :ruby_19] gem 'net-purge' gem 'newrelic_rpm' gem 'rack' diff --git a/Gemfile.lock b/Gemfile.lock index 6c0c99eeb..62258c0c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -261,7 +261,7 @@ GEM multi_json (~> 1.0, >= 1.0.2) unicode (0.4.4) unidecoder (1.1.2) - vpim (0.695) + vpim (13.11.11) webrat (0.7.3) nokogiri (>= 1.2.0) rack (>= 1.0) @@ -19,7 +19,7 @@ drop a line to hello@alaveteli.org to let us know that you're using Alaveteli. Some documentation can be found in the [`doc/` folder](https://github.com/mysociety/alaveteli/tree/master/doc). -There's background information and a more documentation on +There's background information and more documentation on [our wiki](https://github.com/mysociety/alaveteli/wiki/Home/), and lots of useful information (including a blog) on [the project website](http://alaveteli.org) @@ -35,9 +35,10 @@ If you find what looks like a bug: If you want to contribute an enhancement or a fix: * Fork the project on GitHub. +* Make a topic branch from the rails-3-develop branch. * Make your changes with tests. * Commit the changes without making changes to any files that aren't related to your enhancement or fix. -* Send a pull request. +* Send a pull request against the rails-3-develop branch. Looking for the latest stable release? It's on the [master branch](https://github.com/mysociety/alaveteli/tree/master). diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index e0da234b0..88e275960 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -143,6 +143,8 @@ class AdminPublicBodyController < AdminController @errors = "" if request.post? dry_run_only = (params['commit'] == 'Upload' ? false : true) + # (FIXME: both of these cases could now be changed to use + # PublicBody.import_csv_from_file.) # Read file from params if params[:csv_file] csv_contents = params[:csv_file].read diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index aac078829..b01a67027 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -17,6 +17,10 @@ class GeneralController < ApplicationController # Display blog entries def blog + if AlaveteliConfiguration::blog_feed.empty? + raise ActiveRecord::RecordNotFound.new("Page not enabled") + end + medium_cache @feed_autodetect = [] @feed_url = AlaveteliConfiguration::blog_feed diff --git a/app/mailers/request_mailer.rb b/app/mailers/request_mailer.rb index c8a19afa8..af1a75df9 100644 --- a/app/mailers/request_mailer.rb +++ b/app/mailers/request_mailer.rb @@ -19,7 +19,8 @@ class RequestMailer < ApplicationMailer end mail(:from => from_user.name_and_email, - :to => info_request.incoming_name_and_email) + :to => info_request.incoming_name_and_email, + :subject => info_request.email_subject_followup) end # Used when a response is uploaded using the API diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 8e474c797..933825d2a 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -260,13 +260,13 @@ class PublicBody < ActiveRecord::Base # When name or short name is changed, also change the url name def short_name=(short_name) - globalize.write(I18n.locale, :short_name, short_name) + globalize.write(Globalize.locale, :short_name, short_name) self[:short_name] = short_name self.update_url_name end def name=(name) - globalize.write(I18n.locale, :name, name) + globalize.write(Globalize.locale, :name, name) self[:name] = name self.update_url_name end @@ -369,10 +369,24 @@ class PublicBody < ActiveRecord::Base class ImportCSVDryRun < StandardError end - # Import from CSV. Just tests things and returns messages if dry_run is true. - # Returns an array of [array of errors, array of notes]. If there are errors, - # always rolls back (as with dry_run). + # Import from a string in CSV format. + # Just tests things and returns messages if dry_run is true. + # Returns an array of [array of errors, array of notes]. If there + # are errors, always rolls back (as with dry_run). def self.import_csv(csv, tag, tag_behaviour, dry_run, editor, available_locales = []) + tmp_csv = nil + Tempfile.open('alaveteli') do |f| + f.write csv + tmp_csv = f + end + PublicBody.import_csv_from_file(tmp_csv.path, tag, tag_behaviour, dry_run, editor, available_locales) + end + + # Import from a CSV file. + # Just tests things and returns messages if dry_run is true. + # Returns an array of [array of errors, array of notes]. If there + # are errors, always rolls back (as with dry_run). + def self.import_csv_from_file(csv_filename, tag, tag_behaviour, dry_run, editor, available_locales = []) errors = [] notes = [] available_locales = [I18n.default_locale] if available_locales.empty? @@ -398,7 +412,8 @@ class PublicBody < ActiveRecord::Base set_of_importing = Set.new() field_names = { 'name'=>1, 'request_email'=>2 } # Default values in case no field list is given line = 0 - CSV.parse(csv) do |row| + + CSV.foreach(csv_filename) do |row| line = line + 1 # Parse the first line as a field list if it starts with '#' @@ -727,7 +742,8 @@ class PublicBody < ActiveRecord::Base # either from config, or based on a (slow!) query if not set body_short_names = AlaveteliConfiguration::frontpage_publicbody_examples.split(/\s*;\s*/) locale_condition = 'public_body_translations.locale = ?' - conditions = [locale_condition, locale] + underscore_locale = locale.gsub '-', '_' + conditions = [locale_condition, underscore_locale] bodies = [] I18n.with_locale(locale) do if body_short_names.empty? diff --git a/app/views/admin_public_body/_form.html.erb b/app/views/admin_public_body/_form.html.erb index 18bf1d15b..5a80386ec 100644 --- a/app/views/admin_public_body/_form.html.erb +++ b/app/views/admin_public_body/_form.html.erb @@ -51,12 +51,6 @@ </div> </div> <div class="control-group"> - <label for="<%= form_tag_id(t.object_name, :disclosure_log, locale) %>" class="control-label"><%=_("Disclosure log URL")%></label> - <div class="controls"> - <%= t.text_field :disclosure_log, :size => 60, :id => form_tag_id(t.object_name, :disclosure_log, locale), :class => "span3" %> - </div> - </div> - <div class="control-group"> <label for="<%= form_tag_id(t.object_name, :notes, locale) %>" class="control-label"><%=_("Public notes")%></label> <div class="controls"> <%= t.text_area :notes, :rows => 3, :id => form_tag_id(t.object_name, :notes, locale), :class => "span6" %> @@ -89,6 +83,12 @@ </div> </div> <div class="control-group"> + <label for="public_body_disclosure_log" class="control-label"><%=_("Disclosure log URL")%></label> + <div class="controls"> + <%= f.text_field :disclosure_log, :size => 60, :class => "span4" %> + </div> +</div> +<div class="control-group"> <label for="public_body_last_edit_comment" class="control-label"><strong>Comment</strong> for this edit</label> <div class="controls"> <%= f.text_area :last_edit_comment, :rows => 3, :class => "span6" %></p> diff --git a/app/views/comment/_single_comment.html.erb b/app/views/comment/_single_comment.html.erb index d2edc8dbe..a6d234b34 100644 --- a/app/views/comment/_single_comment.html.erb +++ b/app/views/comment/_single_comment.html.erb @@ -17,10 +17,10 @@ </div> <p class="event_actions"> <% if !comment.id.nil? %> - <%= link_to "Link to this", comment_path(comment), :class => "link_to_this" %> <% if !@user.nil? && @user.admin_page_links? %> - | <%= link_to "Admin", admin_request_edit_comment_path(comment) %> + <%= link_to "Admin", admin_request_edit_comment_path(comment) %> | <% end %> + <%= link_to "Link to this", comment_path(comment), :class => "link_to_this" %> <!-- | <%= link_to _('Report abuse'), comment_path(comment) %> --> <% end %> </p> diff --git a/app/views/general/_footer.html.erb b/app/views/general/_footer.html.erb index 04c60be3d..2e10a0f94 100644 --- a/app/views/general/_footer.html.erb +++ b/app/views/general/_footer.html.erb @@ -1,6 +1,8 @@ <div id="footer"> <%= link_to _("Contact {{site_name}}", :site_name => site_name), help_contact_path %> +<% unless AlaveteliConfiguration::twitter_username.blank? %> | <%= image_tag "twitter-16.png", :alt => "twitter icon", :class => "twitter-icon" %> <a href="https://twitter.com/<%= AlaveteliConfiguration::twitter_username %>"><%= _("Follow us on twitter") %></a> +<% end %> <%= render :partial => 'general/credits' %> </div> <div class="after-footer"> </div> diff --git a/app/views/general/_stylesheet_includes.html.erb b/app/views/general/_stylesheet_includes.html.erb index b3f32054c..7a1648efd 100644 --- a/app/views/general/_stylesheet_includes.html.erb +++ b/app/views/general/_stylesheet_includes.html.erb @@ -17,6 +17,6 @@ <%= stylesheet_link_tag 'ie7.css' %> <![endif]--> <% if AlaveteliConfiguration::force_registration_on_new_request %> - <%= stylesheet_link_tag 'jquery.fancybox-1.3.4.pack.js', :rel => "stylesheet" %> + <%= stylesheet_link_tag 'jquery.fancybox-1.3.4.css', :rel => "stylesheet" %> <% end %> <% end %> diff --git a/app/views/general/_topnav.html.erb b/app/views/general/_topnav.html.erb index c7f2cedea..d37bd97d1 100644 --- a/app/views/general/_topnav.html.erb +++ b/app/views/general/_topnav.html.erb @@ -4,7 +4,9 @@ <li class="<%= 'selected' if params[:controller] == 'request' and ['new', 'select_authority'].include?(params[:action]) %>"><%= link_to _("Make a request"), select_authority_path, :id => 'make-request-link' %></li> <li class="<%= 'selected' if params[:controller] == 'request' and !['new', 'select_authority'].include?(params[:action]) %>"><%= link_to _("View requests"), request_list_successful_path %></li> <li class="<%= 'selected' if params[:controller] == 'public_body' %>"><%= link_to _("View authorities"), list_public_bodies_default_path %></li> +<% unless AlaveteliConfiguration::blog_feed.empty? %> <li class="<%= 'selected' if params[:controller] == 'general' and params[:action] == 'blog' %>"><%= link_to _("Read blog"), blog_path %></li> +<% end %> <li class="<%= 'selected' if params[:controller] == 'help' %>"><%= link_to _("Help"), help_about_path %></li> </ul> </div> diff --git a/app/views/layouts/no_chrome.html.erb b/app/views/layouts/no_chrome.html.erb index 589e1bb76..e613b8ca2 100644 --- a/app/views/layouts/no_chrome.html.erb +++ b/app/views/layouts/no_chrome.html.erb @@ -14,7 +14,6 @@ <%= stylesheet_link_tag 'application', :title => "Main", :rel => "stylesheet" %> <%= stylesheet_link_tag 'fonts', :rel => "stylesheet" %> - <%= stylesheet_link_tag 'theme', :rel => "stylesheet" %> <!--[if LT IE 7]> <%= stylesheet_link_tag 'ie6', :rel => "stylesheet" %> <![endif]--> diff --git a/app/views/request/_act.html.erb b/app/views/request/_act.html.erb new file mode 100644 index 000000000..1199cb4a2 --- /dev/null +++ b/app/views/request/_act.html.erb @@ -0,0 +1,15 @@ +<h2><%= _("Act on what you've learnt") %></h2> + +<div class="act_link"> + <% tweet_link = "https://twitter.com/share?" + {:url => request.url, :via => AlaveteliConfiguration::twitter_username, :text => "'#{@info_request.title}'", :related => _('alaveteli_foi:The software that runs {{site_name}}', :site_name => site_name)}.to_query %> + <% link_to tweet_link do %> + <%= image_tag "twitter-16.png", :alt => "twitter icon" %> + <% end %> + <%= link_to _("Tweet this request"), tweet_link %> +</div> +<div class="act_link"> + <%= link_to "http://wordpress.com/" do %> + <%= image_tag "wordpress.png", :class => "rss" %> + <% end %> + <%= link_to _("Start your own blog"), "http://wordpress.com/"%> +</div> diff --git a/app/views/request/_bubble.html.erb b/app/views/request/_bubble.html.erb index 8827d114d..e038bb3dc 100644 --- a/app/views/request/_bubble.html.erb +++ b/app/views/request/_bubble.html.erb @@ -13,7 +13,7 @@ :file_name => a.display_filename + '.html') %> <% img_filename = "icon_" + a.content_type.sub('/', '_') + "_large.png" - full_filename = File.expand_path(File.join(File.dirname(__FILE__), "../../assets/images", img_filename)) + full_filename = File.expand_path(Rails.root.join('app', 'assets', 'images', img_filename)) if File.exist?(full_filename) %> <%= link_to image_tag(img_filename, :class => "attachment_image", :alt => "Attachment"), attachment_path %> <% else %> diff --git a/app/views/request/_sidebar.html.erb b/app/views/request/_sidebar.html.erb index 8400cd6ac..0f7965ffa 100644 --- a/app/views/request/_sidebar.html.erb +++ b/app/views/request/_sidebar.html.erb @@ -33,22 +33,7 @@ <%= link_to _("Report this request"), new_request_report_path(:request_id => @info_request.url_title) %> <% end %> <% end %> - <h2><%= _("Act on what you've learnt") %></h2> - - <div class="act_link"> - <% tweet_link = "https://twitter.com/share?" + {:url => request.url, :via => AlaveteliConfiguration::twitter_username, :text => "'#{@info_request.title}'", :related => _('alaveteli_foi:The software that runs {{site_name}}', :site_name => site_name)}.to_query %> - <% link_to tweet_link do %> - <%= image_tag "twitter-16.png", :alt => "twitter icon" %> - <% end %> - <%= link_to _("Tweet this request"), tweet_link %> - </div> - <div class="act_link"> - <%= link_to "http://wordpress.com/" do %> - <%= image_tag "wordpress.png", :class => "rss" %> - <% end %> - <%= link_to _("Start your own blog"), "http://wordpress.com/"%> - </div> - + <%= render :partial => 'request/act' %> <%= render :partial => 'request/next_actions' %> <% cache_if_caching_fragments(@similar_cache_key, :expires_in => 1.day) do %> diff --git a/commonlib b/commonlib -Subproject 8070e4c27c903d886963d662db40bb91d56f8c5 +Subproject ad27f5409ef3ed1b800aa08c1d70a018443dcfd diff --git a/config/application.rb b/config/application.rb index dba3a0c57..3c749a531 100644 --- a/config/application.rb +++ b/config/application.rb @@ -94,6 +94,7 @@ module Alaveteli # ... while these are individual files that can't easily be # grouped: config.assets.precompile += ['jquery.fancybox-1.3.4.pack.js', + 'jquery.fancybox-1.3.4.css', 'jquery.Jcrop.css', 'excanvas.min.js', 'fonts.css', diff --git a/lib/mail_handler/mail_handler.rb b/lib/mail_handler/mail_handler.rb index 918f91180..53033d440 100644 --- a/lib/mail_handler/mail_handler.rb +++ b/lib/mail_handler/mail_handler.rb @@ -59,7 +59,7 @@ module MailHandler end # e.g. http://www.whatdotheyknow.com/request/copy_of_current_swessex_scr_opt#incoming-9928 - if content_type == 'application/acrobat' + if content_type == 'application/acrobat' or content_type == 'document/pdf' content_type = 'application/pdf' end diff --git a/lib/quiet_opener.rb b/lib/quiet_opener.rb index ae6605c43..16ea27b8e 100644 --- a/lib/quiet_opener.rb +++ b/lib/quiet_opener.rb @@ -1,6 +1,8 @@ require 'open-uri' require 'net-purge' -require 'net/http/local' +if RUBY_VERSION.to_f < 2.0 + require 'net/http/local' +end def quietly_try_to_open(url) begin @@ -12,17 +14,36 @@ def quietly_try_to_open(url) return result end +# On Ruby versions before 2.0, we need to use the net-http-local gem +# to force the use of 127.0.0.1 as the local interface for the +# connection. However, at the time of writing this gem doesn't work +# on Ruby 2.0 and it's not necessary with that Ruby version - one can +# supply a :local_host option to Net::HTTP:start. So, this helper +# function is to abstract away that difference, and can be used as you +# would Net::HTTP.start(host) when passed a block. +def http_from_localhost(host) + if RUBY_VERSION.to_f >= 2.0 + Net::HTTP.start(host, :local_host => '127.0.0.1') do |http| + yield http + end + else + Net::HTTP.bind '127.0.0.1' do + Net::HTTP.start(host) do |http| + yield http + end + end + end +end + def quietly_try_to_purge(host, url) begin result = "" result_body = "" - Net::HTTP.bind '127.0.0.1' do - Net::HTTP.start(host) {|http| - request = Net::HTTP::Purge.new(url) - response = http.request(request) - result = response.code - result_body = response.body - } + http_from_localhost(host) do |http| + request = Net::HTTP::Purge.new(url) + response = http.request(request) + result = response.code + result_body = response.body end rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET, Errno::ENETUNREACH Rails.logger.warn("PURGE: Unable to reach host #{host}") diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 0e8397fde..c8183c745 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -54,12 +54,12 @@ namespace :import do STDERR.puts "Now importing the public bodies..." # Now it's (probably) safe to try to import: - errors, notes = PublicBody.import_csv(tmp_csv.path, - tag='', - tag_behaviour='replace', - dryrun, - editor="#{ENV['USER']} (Unix user)", - I18n.available_locales) do |row_number, fields| + errors, notes = PublicBody.import_csv_from_file(tmp_csv.path, + tag='', + tag_behaviour='replace', + dryrun, + editor="#{ENV['USER']} (Unix user)", + I18n.available_locales) do |row_number, fields| percent_complete = (100 * row_number.to_f / number_of_rows).to_i STDERR.print "#{row_number} out of #{number_of_rows} " STDERR.puts "(#{percent_complete}% complete)" diff --git a/lib/tasks/themes.rake b/lib/tasks/themes.rake index 65b142a63..4a864d141 100644 --- a/lib/tasks/themes.rake +++ b/lib/tasks/themes.rake @@ -1,104 +1,123 @@ +require Rails.root.join('commonlib', 'rblib', 'git') + namespace :themes do - def plugin_dir + # Alias the module so we don't need the MySociety prefix here + Git = MySociety::Git + + def all_themes_dir File.join(Rails.root,"lib","themes") end def theme_dir(theme_name) - File.join(plugin_dir, theme_name) + File.join(all_themes_dir, theme_name) end - def old_theme_dir(theme_name) + def old_all_themes_dir(theme_name) File.join(Rails.root, "vendor", "plugins", theme_name) end def possible_theme_dirs(theme_name) - [theme_dir(theme_name), old_theme_dir(theme_name)] - end - - def checkout(commitish) - puts "Checking out #{commitish}" if verbose - system "git checkout #{commitish}" + [theme_dir(theme_name), old_all_themes_dir(theme_name)] end - def checkout_tag(version) - checkout usage_tag(version) - end - - def checkout_remote_branch(branch) - checkout "origin/#{branch}" + def installed?(theme_name) + possible_theme_dirs(theme_name).any? { |dir| File.directory? dir } end def usage_tag(version) "use-with-alaveteli-#{version}" end - def install_theme_using_git(name, uri, verbose=false, options={}) - install_path = theme_dir(name) - Dir.chdir(plugin_dir) do - clone_command = "git clone #{uri} #{name}" - if system(clone_command) - Dir.chdir install_path do - # First try to checkout a specific branch of the theme - tag_checked_out = checkout_remote_branch(AlaveteliConfiguration::theme_branch) if AlaveteliConfiguration::theme_branch - if !tag_checked_out - # try to checkout a tag exactly matching ALAVETELI VERSION - tag_checked_out = checkout_tag(ALAVETELI_VERSION) - end - if ! tag_checked_out - # if we're on a hotfix release (four sequence elements or more), - # look for a usage tag matching the minor release (three sequence elements) - # and check that out if found - if hotfix_version = /^(\d+\.\d+\.\d+)(\.\d+)+/.match(ALAVETELI_VERSION) - base_version = hotfix_version[1] - tag_checked_out = checkout_tag(base_version) - end - end - if ! tag_checked_out - puts "No specific tag for this version: using HEAD" if verbose - end - puts "removing: .git .gitignore" if verbose - rm_rf %w(.git .gitignore) - end - else - rm_rf install_path - raise "#{clone_command} failed! Stopping." - end - end - end - def uninstall(theme_name, verbose=false) possible_theme_dirs(theme_name).each do |dir| if File.directory?(dir) run_hook(theme_name, 'uninstall', verbose) - puts "Removing '#{dir}'" if verbose - rm_r dir - else - puts "Plugin doesn't exist: #{dir}" end end end def run_hook(theme_name, hook_name, verbose=false) - hook_file = File.join(theme_dir(theme_name), "#{hook_name}.rb") + directory = theme_dir(theme_name) + hook_file = File.join(directory, "#{hook_name}.rb") if File.exist? hook_file - puts "Running #{hook_name} hook for #{theme_name}" if verbose + puts "Running #{hook_name} hook in #{directory}" if verbose load hook_file end end - def installed?(theme_name) - possible_theme_dirs(theme_name).any? { |dir| File.directory? dir } + def move_old_theme(old_theme_directory) + puts "There was an old-style theme at #{old_theme_directory}" if verbose + moved_directory = "#{old_theme_directory}-moved" + begin + File.rename old_theme_directory, moved_directory + rescue Errno::ENOTEMPTY, Errno::EEXIST + raise "Tried to move #{old_theme_directory} out of the way, " \ + "but #{moved_directory} already existed" + end + end + + def committishes_to_try + result = [] + theme_branch = AlaveteliConfiguration::theme_branch + result.push "origin/#{theme_branch}" if theme_branch + result.push usage_tag(ALAVETELI_VERSION) + hotfix_match = /^(\d+\.\d+\.\d+)(\.\d+)+/.match(ALAVETELI_VERSION) + result.push usage_tag(hotfix_match[1]) if hotfix_match + result + end + + def checkout_best_option(theme_name) + theme_directory = theme_dir theme_name + all_failed = true + committishes_to_try.each do |committish| + if Git.committish_exists? theme_directory, committish + puts "Checking out #{committish}" if verbose + Git.checkout theme_directory, committish + all_failed = false + break + else + puts "Failed to find #{committish}; skipping..." if verbose + end + end + puts "Falling to using HEAD instead" if all_failed and verbose end def install_theme(theme_url, verbose, deprecated=false) - FileUtils.mkdir_p plugin_dir + FileUtils.mkdir_p all_themes_dir deprecation_string = deprecated ? " using deprecated THEME_URL" : "" theme_name = theme_url_to_theme_name theme_url puts "Installing theme #{theme_name}#{deprecation_string} from #{theme_url}" + # Make sure any uninstall hooks have been run: uninstall(theme_name, verbose) if installed?(theme_name) - install_theme_using_git(theme_name, theme_url, verbose) + theme_directory = theme_dir theme_name + # Is there an old-style theme directory there? If so, move it + # out of the way so that there's no risk that work is lost: + if File.directory? theme_directory + unless Git.non_bare_repository? theme_directory + move_old_theme theme_directory + end + end + # If there isn't a directory there already, clone it into place: + unless File.directory? theme_directory + unless system "git", "clone", theme_url, theme_directory + raise "Cloning from #{theme_url} to #{theme_directory} failed" + end + end + # Set the URL for origin in case it has changed, and fetch from there: + Git.remote_set_url theme_directory, 'origin', theme_url + Git.fetch theme_directory, 'origin' + # Check that checking-out a new commit will be safe: + unless Git.status_clean theme_directory + raise "There were uncommitted changes in #{theme_directory}" + end + unless Git.is_HEAD_pushed? theme_directory + raise "The current work in #{theme_directory} is unpushed" + end + # Now try to checkout various commits in order of preference: + checkout_best_option theme_name + # Finally run the install hooks: run_hook(theme_name, 'install', verbose) run_hook(theme_name, 'post_install', verbose) end @@ -112,4 +131,5 @@ namespace :themes do install_theme(AlaveteliConfiguration::theme_url, verbose, deprecated=true) end end + end diff --git a/public/robots.txt b/public/robots.txt index 279573d31..969e10826 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -8,7 +8,10 @@ # Crawl-delay: 1 # http://www.bing.com/community/blogs/webmaster/archive/2009/08/10/crawl-delay-and-the-bing-crawler-msnbot.aspx -# This file uses the non-standard extension characters * and $, which are supported by Google and Yahoo! +# This file uses the non-standard extension characters * and $, which +# are supported by Google and Yahoo! and the 'Allow' directive, which +# is supported by Google. + # http://code.google.com/web/controlcrawlindex/docs/robots_txt.html # http://help.yahoo.com/l/us/yahoo/search/webcrawler/slurp-02.html @@ -23,6 +26,7 @@ Disallow: */user/contact/ Disallow: */feed/ Disallow: */profile/ Disallow: */signin +Allow: */request/*/response/*/attach/* Disallow: */request/*/response/ Disallow: */body/*/view_email$ diff --git a/script/switch-theme.rb b/script/switch-theme.rb index e6afcebb9..980853687 100755 --- a/script/switch-theme.rb +++ b/script/switch-theme.rb @@ -31,6 +31,7 @@ require 'tempfile' +$no_theme_name = 'none' theme_directory = ENV['ALAVETELI_THEMES_DIR'] alaveteli_directory = File.expand_path(File.join(File.dirname(__FILE__), "..")) @@ -53,7 +54,9 @@ $available_themes = Dir.entries(theme_directory).find_all do |local_theme_name| next unless File.directory? full_path next unless File.directory? File.join(full_path, '.git') local_theme_name -end +end.sort + +$available_themes.unshift $no_theme_name if $available_themes.empty? STDERR.puts "There were no theme directories found in '#{theme_directory}'" @@ -62,7 +65,7 @@ end def usage_and_exit STDERR.puts "Usage: #{$0} <THEME-NAME>" - $available_themes.sort.each do |theme_name| + $available_themes.each do |theme_name| STDERR.puts " #{theme_name}" end exit 1 @@ -108,13 +111,19 @@ symlink(File.basename(theme_filename), config_directory, "general.yml") -symlink(File.join(full_theme_path, 'public'), - File.join(alaveteli_directory, 'public'), - 'alavetelitheme') +public_directory = File.join(alaveteli_directory, 'public') -symlink(full_theme_path, - File.join(alaveteli_directory, 'lib', 'themes'), - requested_theme) +if requested_theme == $no_theme_name + File.unlink File.join(public_directory, 'alavetelitheme') +else + symlink(File.join(full_theme_path, 'public'), + public_directory, + 'alavetelitheme') + + symlink(full_theme_path, + File.join(alaveteli_directory, 'lib', 'themes'), + requested_theme) +end STDERR.puts """Switched to #{requested_theme}! You will need to: diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index e67cc9492..7590a5b42 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -42,6 +42,17 @@ describe GeneralController, 'when getting the blog feed' do assigns[:blog_items].count.should == 1 end + context 'if no feed is configured' do + + before do + AlaveteliConfiguration.stub!(:blog_feed).and_return('') + end + + it 'should raise an ActiveRecord::RecordNotFound error' do + lambda{ get :blog }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end describe GeneralController, "when showing the frontpage" do diff --git a/spec/fixtures/files/document-pdf.email b/spec/fixtures/files/document-pdf.email new file mode 100644 index 000000000..f4fc6f0fe --- /dev/null +++ b/spec/fixtures/files/document-pdf.email @@ -0,0 +1,110 @@ +From authority@example.org Tue Dec 3 11:13:02 2013 +Return-path: <authority@example.org> +Envelope-to: requester@example.org +Delivery-date: Tue, 03 Dec 2013 11:13:00 +0000 +From: Test Authority <authority@example.org> +To: requester@example.org +Subject: testing a PDF attachment with the wrong content-type +Date: Tue, 03 Dec 2013 11:12:45 +0000 +Message-ID: <87li09xuasdfasdfpoija@blahblah> +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="=-=-=" + +--=-=-= +Content-Type: text/plain + +Here's a PDF attachement which has a document/pdf content-type, +when it really should be application/pdf. + + +--=-=-= +Content-Type: application/pdf +Content-Disposition: attachment; filename=tiny-example.pdf +Content-Transfer-Encoding: base64 +Content-Description: a very small example PDF + +JVBERi0xLjUKJbXtrvsKMyAwIG9iago8PCAvTGVuZ3RoIDQgMCBSCiAgIC9GaWx0ZXIgL0ZsYXRl +RGVjb2RlCj4+CnN0cmVhbQp4nCvkMlAAwaJ0Bf1EA4X0Yi6nEC5DA1M9IwNLYzNjsBwS18hIz9TI +0tBSwdzIQs/Y3MLAzEQhJJdLP03XQBeoUCEkjStawyM1JydfUTM2xIvLNYQrkAsAJG8VmQplbmRz +dHJlYW0KZW5kb2JqCjQgMCBvYmoKICAgOTIKZW5kb2JqCjIgMCBvYmoKPDwKICAgL0V4dEdTdGF0 +ZSA8PAogICAgICAvYTAgPDwgL0NBIDEgL2NhIDEgPj4KICAgPj4KICAgL0ZvbnQgPDwKICAgICAg +L2YtMC0wIDUgMCBSCiAgID4+Cj4+CmVuZG9iago2IDAgb2JqCjw8IC9UeXBlIC9QYWdlCiAgIC9Q +YXJlbnQgMSAwIFIKICAgL01lZGlhQm94IFsgMCAwIDU5NS4yNzU1NzQgODQxLjg4OTc3MSBdCiAg +IC9Db250ZW50cyAzIDAgUgogICAvR3JvdXAgPDwKICAgICAgL1R5cGUgL0dyb3VwCiAgICAgIC9T +IC9UcmFuc3BhcmVuY3kKICAgICAgL0kgdHJ1ZQogICAgICAvQ1MgL0RldmljZVJHQgogICA+Pgog +ICAvUmVzb3VyY2VzIDIgMCBSCj4+CmVuZG9iago3IDAgb2JqCjw8IC9MZW5ndGggOCAwIFIKICAg +L0ZpbHRlciAvRmxhdGVEZWNvZGUKICAgL0xlbmd0aDEgMzcxNgo+PgpzdHJlYW0KeJzlVnt0lMUV +v/P9vtndZB/5drMbiUlww7ookJCQECCAzYJBBSrlETXYxgayxIjQJAQVTOOCFARE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DEyIDAgUgo+PgpzdGFydHhyZWYKNDMxMAolJUVP +Rgo= +--=-=-=-- + diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index bc027eaec..49a65dade 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -409,6 +409,12 @@ describe 'when getting attachment attributes' do attributes[1][:body].length.should == 7769 end + it 'should treat a document/pdf attachment as application/pdf' do + mail = get_fixture_mail('document-pdf.email') + attributes = MailHandler.get_attachment_attributes(mail) + attributes[1][:content_type].should == "application/pdf" + end + it 'should produce a consistent set of url_part_numbers, content_types, within_rfc822_subjects and filenames from an example mail with lots of attachments' do mail = get_fixture_mail('many-attachments-date-header.email') diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb index 4e0765921..516d13127 100644 --- a/spec/mailers/request_mailer_spec.rb +++ b/spec/mailers/request_mailer_spec.rb @@ -332,6 +332,27 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla end +describe RequestMailer, 'when generating a fake response for an upload' do + + before do + @foi_officer = mock_model(User, :name_and_email => "FOI officer's name and email") + @request_user = mock_model(User) + @public_body = mock_model(PublicBody, :name => 'Test public body') + @info_request = mock_model(InfoRequest, :user => @request_user, + :email_subject_followup => 'Re: Freedom of Information - Test request', + :incoming_name_and_email => 'Someone <someone@example.org>') + end + + it 'should should generate a "fake response" email with a reasonable subject line' do + fake_email = RequestMailer.fake_response(@info_request, + @foi_officer, + "The body of the email...", + "blah.txt", + "The content of blah.txt") + fake_email.subject.should == "Re: Freedom of Information - Test request" + end + +end describe RequestMailer, 'when sending a new response email' do diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 23842ccff..ed24ced52 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -213,6 +213,15 @@ describe PublicBody, " when saving" do public_body.name.should == "Mark's Public Body" end + it 'should update the right translation when in a locale with an underscore' do + AlaveteliLocalization.set_locales('he_IL', 'he_IL') + public_body = public_bodies(:humpadink_public_body) + translation_count = public_body.translations.size + public_body.name = 'Renamed' + public_body.save! + public_body.translations.size.should == translation_count + end + it 'should not create a new version when nothing has changed' do @public_body.versions.size.should == 0 set_default_attributes(@public_body) @@ -473,6 +482,20 @@ describe PublicBody, " when loading CSV files" do PublicBody.count.should == original_count end + + it "should be able to load CSV from a file as well as a string" do + # Essentially the same code is used for import_csv_from_file + # as import_csv, so this is just a basic check that + # import_csv_from_file can load from a file at all. (It would + # be easy to introduce a regression that broke this, because + # of the confusing change in behaviour of CSV.parse between + # Ruby 1.8 and 1.9.) + original_count = PublicBody.count + filename = file_fixture_name('fake-authority-type-with-field-names.csv') + PublicBody.import_csv_from_file(filename, '', 'replace', false, 'someadmin') + PublicBody.count.should == original_count + 3 + end + end describe PublicBody do @@ -604,3 +627,12 @@ describe PublicBody, "when calculating statistics" do end end + +describe PublicBody, 'when asked for popular bodies' do + + it 'should return bodies correctly when passed the hyphenated version of the locale' do + AlaveteliConfiguration.stub!(:frontpage_publicbody_examples).and_return('') + PublicBody.popular_bodies('he-IL').should == [public_bodies(:humpadink_public_body)] + end + +end |