diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/censor_rule.rb | 69 | ||||
-rw-r--r-- | app/views/public_body/_more_info.html.erb | 27 | ||||
-rw-r--r-- | app/views/public_body/show.html.erb | 22 |
3 files changed, 63 insertions, 55 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"> |