<commit_before># app/controllers/request_controller.rb:
# Show information about one particular request.
#
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: <EMAIL>; WWW: http://www.mysociety.org/
#
# $Id: request_controller.rb,v 1.192 2009-10-19 19:26:40 francis Exp $

require 'alaveteli_file_types'
require 'zip/zip'
require 'open-uri'

class RequestController < ApplicationController
    before_filter :check_read_only, :only => [ :new, :show_response, :describe_state, :upload_response ]
    protect_from_forgery :only => [ :new, :show_response, :describe_state, :upload_response ] # See ActionController::RequestForgeryProtection for details

    MAX_RESULTS = 500
    PER_PAGE = 25
    
    @@custom_states_loaded = false
    begin
        if ENV["RAILS_ENV"] != "test"
            require 'customstates'
            include RequestControllerCustomStates
            @@custom_states_loaded = true
        end
    rescue MissingSourceFile, NameError
    end

    def select_authority
        # Check whether we force the user to sign in right at the start, or we allow her
        # to start filling the request anonymously
        if force_registration_on_new_request && !authenticated?(
                :web => _("To send your FOI request"),
                :email => _("Then you'll be allowed to send FOI requests."),
                :email_subject => _("Confirm your email address")
            )
            # do nothing - as "authenticated?" has done the redirect to signin page for us
            return
        end
        if !params[:query].nil?
            query = params[:query]
            @xapian_requests = perform_search_typeahead(query, PublicBody)
        end
        medium_cache
    end
    
    def show
        medium_cache
        @locale = self.locale_from_params()
        PublicBody.with_locale(@locale) do  

            # Look up by old style numeric identifiers
            if params[:url_title].match(/^[0-9]+$/)
                @info_request = InfoRequest.find(params[:url_title].to_i)
                redirect_to request_url(@info_request)
                return
            end

            # Look up by new style text names 
            @info_request = InfoRequest.find_by_url_title(params[:url_title])
            if @info_request.nil?
                raise ActiveRecord::RecordNotFound.new("Request not found")
            end
            set_last_request(@info_request)

            # Test for whole request being hidden
            if !@info_request.user_can_view?(authenticated_user)
                render :template => 'request/hidden', :status => 410 # gone
                return
            end
           
            # Other parameters
            @info_request_events = @info_request.info_request_events
            @status = @info_request.calculate_status
            @collapse_quotes = params[:unfold] ? false : true
            @update_status = params[:update_status] ? true : false    
            @old_unclassified = @info_request.is_old_unclassified? && !authenticated_user.nil?
            
            if @update_status
                return if !@is_owning_user && !authenticated_as_user?(@info_request.user,
                        :web => _("To update the status of this FOI request"),
                        :email => _("Then you can update the status of your request to ") + @info_request.public_body.name + ".",
                        :email_subject => _("Update the status of your request to ") + @info_request.public_body.name
                    )
            end
            

            @last_info_request_event_id = @info_request.last_event_id_needing_description
            @new_responses_count = @info_request.events_needing_description.select {|i| i.event_type == 'response'}.size

            # Sidebar stuff
            # ... requests that have similar imporant terms
            behavior_cache :tag => ['similar', @info_request.id] do
                begin
                    limit = 10
                    @xapian_similar = ::ActsAsXapian::Similar.new([InfoRequestEvent], @info_request.info_request_events, 
                      :limit => limit, :collapse_by_prefix => 'request_collapse')
                    @xapian_similar_more = (@xapian_similar.matches_estimated > limit)
                rescue
                    @xapian_similar = nil
                end
            end
         
            # Track corresponding to this page
            @track_thing = TrackThing.create_track_for_request(@info_request)
            @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ]<commit_msg>Remove trailing spaces<commit_after># app/controllers/request_controller.rb:
# Show information about one particular request.
#
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: <EMAIL>; WWW: http://www.mysociety.org/
#
# $Id: request_controller.rb,v 1.192 2009-10-19 19:26:40 francis Exp $

require 'alaveteli_file_types'
require 'zip/zip'
require 'open-uri'

class RequestController < ApplicationController
    before_filter :check_read_only, :only => [ :new, :show_response, :describe_state, :upload_response ]
    protect_from_forgery :only => [ :new, :show_response, :describe_state, :upload_response ] # See ActionController::RequestForgeryProtection for details

    MAX_RESULTS = 500
    PER_PAGE = 25
    
    @@custom_states_loaded = false
    begin
        if ENV["RAILS_ENV"] != "test"
            require 'customstates'
            include RequestControllerCustomStates
            @@custom_states_loaded = true
        end
    rescue MissingSourceFile, NameError
    end

    def select_authority
        # Check whether we force the user to sign in right at the start, or we allow her
        # to start filling the request anonymously
        if force_registration_on_new_request && !authenticated?(
                :web => _("To send your FOI request"),
                :email => _("Then you'll be allowed to send FOI requests."),
                :email_subject => _("Confirm your email address")
            )
            # do nothing - as "authenticated?" has done the redirect to signin page for us
            return
        end
        if !params[:query].nil?
            query = params[:query]
            @xapian_requests = perform_search_typeahead(query, PublicBody)
        end
        medium_cache
    end
    
    def show
        medium_cache
        @locale = self.locale_from_params()
        PublicBody.with_locale(@locale) do  

            # Look up by old style numeric identifiers
            if params[:url_title].match(/^[0-9]+$/)
                @info_request = InfoRequest.find(params[:url_title].to_i)
                redirect_to request_url(@info_request)
                return
            end

            # Look up by new style text names 
            @info_request = InfoRequest.find_by_url_title(params[:url_title])
            if @info_request.nil?
                raise ActiveRecord::RecordNotFound.new("Request not found")
            end
            set_last_request(@info_request)

            # Test for whole request being hidden
            if !@info_request.user_can_view?(authenticated_user)
                render :template => 'request/hidden', :status => 410 # gone
                return
            end
           
            # Other parameters
            @info_request_events = @info_request.info_request_events
            @status = @info_request.calculate_status
            @collapse_quotes = params[:unfold] ? false : true
            @update_status = params[:update_status] ? true : false
            @old_unclassified = @info_request.is_old_unclassified? && !authenticated_user.nil?
            
            if @update_status
                return if !@is_owning_user && !authenticated_as_user?(@info_request.user,
                        :web => _("To update the status of this FOI request"),
                        :email => _("Then you can update the status of your request to ") + @info_request.public_body.name + ".",
                        :email_subject => _("Update the status of your request to ") + @info_request.public_body.name
                    )
            end
            

            @last_info_request_event_id = @info_request.last_event_id_needing_description
            @new_responses_count = @info_request.events_needing_description.select {|i| i.event_type == 'response'}.size

            # Sidebar stuff
            # ... requests that have similar imporant terms
            behavior_cache :tag => ['similar', @info_request.id] do
                begin
                    limit = 10
                    @xapian_similar = ::ActsAsXapian::Similar.new([InfoRequestEvent], @info_request.info_request_events, 
                      :limit => limit, :collapse_by_prefix => 'request_collapse')
                    @xapian_similar_more = (@xapian_similar.matches_estimated > limit)
                rescue
                    @xapian_similar = nil
                end
            end
         
            # Track corresponding to this page
            @track_thing = TrackThing.create_track_for_request(@info_request)
            @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ]
{'fraction_non_alphanumeric': 0.08746666666666666, 'fraction_numerical': 0.007253333333333333, 'mean_word_length': 2.122211122211122, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3207587', 'n_tokens_mistral': 2634, 'n_tokens_neox': 2463, 'n_words': 624}