aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/censor_rule.rb69
-rw-r--r--app/views/public_body/_more_info.html.erb27
-rw-r--r--app/views/public_body/show.html.erb22
-rw-r--r--config/application.rb1
-rw-r--r--config/general.yml-example3
-rw-r--r--config/initializers/alaveteli.rb1
-rw-r--r--doc/CHANGES.md4
-rw-r--r--lib/alaveteli_localization.rb1
-rw-r--r--lib/routing_filters.rb8
-rw-r--r--spec/integration/localisation_spec.rb29
10 files changed, 101 insertions, 64 deletions
diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb
index 62cf8112f..3b5c2d805 100644
--- a/app/models/censor_rule.rb
+++ b/app/models/censor_rule.rb
@@ -26,22 +26,46 @@ class CensorRule < ActiveRecord::Base
belongs_to :user
belongs_to :public_body
- # a flag to allow the require_user_request_or_public_body validation to be skipped
+ # a flag to allow the require_user_request_or_public_body
+ # validation to be skipped
attr_accessor :allow_global
- validate :require_user_request_or_public_body, :unless => proc{ |rule| rule.allow_global == true }
- validate :require_valid_regexp, :if => proc{ |rule| rule.regexp? == true }
+
+ validate :require_user_request_or_public_body, :unless => proc { |rule| rule.allow_global == true }
+ validate :require_valid_regexp, :if => proc { |rule| rule.regexp? == true }
validates_presence_of :text,
:replacement,
:last_edit_comment,
:last_edit_editor
- scope :global, {:conditions => {:info_request_id => nil,
- :user_id => nil,
- :public_body_id => nil}}
+ scope :global, { :conditions => { :info_request_id => nil,
+ :user_id => nil,
+ :public_body_id => nil } }
+
+ def apply_to_text!(text_to_censor)
+ return nil if text_to_censor.nil?
+ text_to_censor.gsub!(to_replace, replacement)
+ end
+
+ def apply_to_binary!(binary_to_censor)
+ return nil if binary_to_censor.nil?
+ binary_to_censor.gsub!(to_replace) { |match| match.gsub(/./, 'x') }
+ end
+
+ def for_admin_column
+ self.class.content_columns.each do |column|
+ yield(column.human_name, send(column.name), column.type.to_s, column.name)
+ end
+ end
+
+ def is_global?
+ info_request_id.nil? && user_id.nil? && public_body_id.nil?
+ end
+
+ private
def require_user_request_or_public_body
- if self.info_request.nil? && self.user.nil? && self.public_body.nil?
+ if info_request.nil? && user.nil? && public_body.nil?
[:info_request, :user, :public_body].each do |a|
errors.add(a, "Rule must apply to an info request, a user or a body")
end
@@ -50,41 +74,18 @@ class CensorRule < ActiveRecord::Base
def require_valid_regexp
begin
- self.make_regexp()
+ make_regexp
rescue RegexpError => e
errors.add(:text, e.message)
end
end
def make_regexp
- return Regexp.new(self.text, Regexp::MULTILINE)
- end
-
- def apply_to_text!(text)
- if text.nil?
- return nil
- end
- to_replace = regexp? ? self.make_regexp() : self.text
- text.gsub!(to_replace, self.replacement)
- end
-
- def apply_to_binary!(binary)
- if binary.nil?
- return nil
- end
- to_replace = regexp? ? self.make_regexp() : self.text
- binary.gsub!(to_replace){ |match| match.gsub(/./, 'x') }
+ Regexp.new(text, Regexp::MULTILINE)
end
- def for_admin_column
- self.class.content_columns.each do |column|
- yield(column.human_name, self.send(column.name), column.type.to_s, column.name)
- end
- end
-
- def is_global?
- return true if (info_request_id.nil? && user_id.nil? && public_body_id.nil?)
- return false
+ def to_replace
+ regexp? ? make_regexp : text
end
end
diff --git a/app/views/public_body/_more_info.html.erb b/app/views/public_body/_more_info.html.erb
new file mode 100644
index 000000000..ff419192a
--- /dev/null
+++ b/app/views/public_body/_more_info.html.erb
@@ -0,0 +1,27 @@
+<h2><%= _('More about this authority')%></h2>
+
+<% if !public_body.calculated_home_page.nil? %>
+ <%= link_to _('Home page of authority'), public_body.calculated_home_page %><br>
+<% end %>
+
+<% if !public_body.publication_scheme.empty? %>
+ <%= link_to _('Publication scheme'), public_body.publication_scheme %><br>
+<% end %>
+
+<% unless public_body.disclosure_log.empty? %>
+ <%= link_to _('Disclosure log'), public_body.disclosure_log %><br>
+<% end %>
+
+<% if public_body.has_tag?("charity") %>
+ <% public_body.get_tag_values("charity").each do |tag_value| %>
+ <% if tag_value.match(/^SC/) %>
+ <%= link_to _('Charity registration'), "http://www.oscr.org.uk/CharityIndexDetails.aspx?id=" + tag_value %><br>
+ <% else %>
+ <%= link_to _('Charity registration'), "http://www.charity-commission.gov.uk/SHOWCHARITY/RegisterOfCharities/CharityFramework.aspx?RegisteredCharityNumber=" + tag_value %><br>
+ <% end %>
+ <% end %>
+<% end %>
+
+<%= link_to _('View FOI email address'), view_public_body_email_path(public_body.url_name) %><br>
+
+<%= link_to _("Ask us to update FOI email"), new_change_request_path(:body => public_body.url_name) %><br>
diff --git a/app/views/public_body/show.html.erb b/app/views/public_body/show.html.erb
index 9352747ea..011aea535 100644
--- a/app/views/public_body/show.html.erb
+++ b/app/views/public_body/show.html.erb
@@ -12,27 +12,7 @@
</p>
<%= render :partial => 'track/tracking_links', :locals => { :track_thing => @track_thing, :own_request => false, :location => 'sidebar' } %>
- <h2><%= _('More about this authority')%></h2>
- <% if !@public_body.calculated_home_page.nil? %>
- <%= link_to _('Home page of authority'), @public_body.calculated_home_page %><br>
- <% end %>
- <% if !@public_body.publication_scheme.empty? %>
- <%= link_to _('Publication scheme'), @public_body.publication_scheme %><br>
- <% end %>
- <% unless @public_body.disclosure_log.empty? %>
- <%= link_to _('Disclosure log'), @public_body.disclosure_log %><br>
- <% end %>
- <% if @public_body.has_tag?("charity") %>
- <% for tag_value in @public_body.get_tag_values("charity") %>
- <% if tag_value.match(/^SC/) %>
- <%= link_to _('Charity registration'), "http://www.oscr.org.uk/CharityIndexDetails.aspx?id=" + tag_value %><br>
- <% else %>
- <%= link_to _('Charity registration'), "http://www.charity-commission.gov.uk/SHOWCHARITY/RegisterOfCharities/CharityFramework.aspx?RegisteredCharityNumber=" + tag_value %><br>
- <% end %>
- <% end %>
- <% end %>
- <%= link_to _('View FOI email address'), view_public_body_email_path(@public_body.url_name) %><br>
- <%= link_to _("Ask us to update FOI email"), new_change_request_path(:body => @public_body.url_name) %><br>
+ <%= render :partial => 'more_info', :locals => { :public_body => @public_body } %>
</div>
<div id="header_left">
diff --git a/config/application.rb b/config/application.rb
index a514daf3a..ed4f07819 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -61,7 +61,6 @@ module Alaveteli
config.action_dispatch.rack_cache = nil
config.after_initialize do |app|
- require 'routing_filters.rb'
# Add a catch-all route to force routing errors to be handled by the application,
# rather than by middleware.
app.routes.append{ match '*path', :to => 'general#not_found' }
diff --git a/config/general.yml-example b/config/general.yml-example
index a80784712..ac96b5e50 100644
--- a/config/general.yml-example
+++ b/config/general.yml-example
@@ -1,6 +1,9 @@
# general.yml-example:
# Example values for the "general" config file.
#
+# Documentation on configuring Alaveteli is available at
+# http://alaveteli.org/docs/customising/
+#
# Configuration parameters, in YAML syntax.
#
# Copy this file to one called "general.yml" in the same directory. Or
diff --git a/config/initializers/alaveteli.rb b/config/initializers/alaveteli.rb
index 9a151e3e8..3a1220326 100644
--- a/config/initializers/alaveteli.rb
+++ b/config/initializers/alaveteli.rb
@@ -55,6 +55,7 @@ require 'date_quarter'
require 'public_body_csv'
require 'category_and_heading_migrator'
require 'public_body_categories'
+require 'routing_filters'
AlaveteliLocalization.set_locales(AlaveteliConfiguration::available_locales,
AlaveteliConfiguration::default_locale)
diff --git a/doc/CHANGES.md b/doc/CHANGES.md
index 40834d4d0..7a93f9cb0 100644
--- a/doc/CHANGES.md
+++ b/doc/CHANGES.md
@@ -9,7 +9,9 @@
your theme, you will now have to satisfy the additional validations on the
`:replacement`, `:last_edit_comment` and `:last_edit_editor` attributes.
* Public body categories will now be stored in the database rather than being read directly from the `lib/public_body_categories_LOCALE` files. Once you have upgraded, run `script/migrate-public-body-categories`to import the contents of the files into the database. All further changes will then need to be made via the administrative interface. You can then remove any `pubic_body_categories_[locale].rb` files from your theme. If your theme has any calls to `PublicBodyCategories` methods outside these files, you should update them to call the corresponding method on `PublicBodyCategory` instead.
-
+* `CensorRule#require_user_request_or_public_body`, `CensorRule#make_regexp` and
+ `CensorRule#require_valid_regexp` have become private methods. If you override
+ them in your theme, ensure they are preceded by the `private` keyword.
# Version 0.19
diff --git a/lib/alaveteli_localization.rb b/lib/alaveteli_localization.rb
index 6daab124a..2b6978c92 100644
--- a/lib/alaveteli_localization.rb
+++ b/lib/alaveteli_localization.rb
@@ -7,6 +7,7 @@ class AlaveteliLocalization
I18n.locale = default_locale
I18n.available_locales = available_locales.map { |locale_name| locale_name.to_sym }
I18n.default_locale = default_locale
+ RoutingFilter::Conditionallyprependlocale.locales = available_locales
end
def set_default_text_domain(name, path)
diff --git a/lib/routing_filters.rb b/lib/routing_filters.rb
index a9a62b8db..5b5da6870 100644
--- a/lib/routing_filters.rb
+++ b/lib/routing_filters.rb
@@ -22,5 +22,13 @@ module RoutingFilter
prepend_segment!(result, locale) if prepend_locale?(locale)
end
end
+
+ # Reset the locale pattern when the locales are set.
+ class << self
+ def locales=(locales)
+ @@locales_pattern = nil
+ @@locales = locales.map(&:to_sym)
+ end
+ end
end
end
diff --git a/spec/integration/localisation_spec.rb b/spec/integration/localisation_spec.rb
index 4f6b61ae1..037603ad5 100644
--- a/spec/integration/localisation_spec.rb
+++ b/spec/integration/localisation_spec.rb
@@ -24,14 +24,29 @@ describe "when generating urls" do
response.should_not contain @home_link_regex
end
- it 'should redirect requests for a public body in a locale to the canonical name in that locale' do
- get('/es/body/dfh')
- response.should redirect_to "/es/body/edfh"
- end
+ context 'when handling public body requests' do
+
+ before do
+ AlaveteliLocalization.set_locales(available_locales='es en', default_locale='en')
+ body = FactoryGirl.create(:public_body, :short_name => 'english_short')
+ I18n.with_locale(:es) do
+ body.short_name = 'spanish_short'
+ body.save!
+ end
+ end
+
+ it 'should redirect requests for a public body in a locale to the
+ canonical name in that locale' do
+ get('/es/body/english_short')
+ response.should redirect_to "/es/body/spanish_short"
+ end
- it 'should remember a filter view when redirecting a public body request to the canonical name' do
- get('/es/body/tgq/successful')
- response.should redirect_to "/es/body/etgq/successful"
+ it 'should remember a filter view when redirecting a public body
+ request to the canonical name' do
+ AlaveteliLocalization.set_locales(available_locales='es en', default_locale='en')
+ get('/es/body/english_short/successful')
+ response.should redirect_to "/es/body/spanish_short/successful"
+ end
end
describe 'when there is more than one locale' do