diff options
Diffstat (limited to 'app/controllers')
35 files changed, 166 insertions, 79 deletions
diff --git a/app/controllers/admin_censor_rule_controller.rb b/app/controllers/admin_censor_rule_controller.rb index 3387fd832..6c060a610 100644 --- a/app/controllers/admin_censor_rule_controller.rb +++ b/app/controllers/admin_censor_rule_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_censor_rule_controller.rb: # For modifying requests. # diff --git a/app/controllers/admin_comment_controller.rb b/app/controllers/admin_comment_controller.rb index 0aafb122a..030afb645 100644 --- a/app/controllers/admin_comment_controller.rb +++ b/app/controllers/admin_comment_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_comment_controller.rb: # Controller for editing comments from the admin interface. # @@ -15,12 +16,12 @@ class AdminCommentController < AdminController old_body = @comment.body old_visible = @comment.visible - @comment.visible = params[:comment][:visible] == "true" ? true : false + @comment.visible = params[:comment][:visible] == "true" if @comment.update_attributes(params[:comment]) @comment.info_request.log_event("edit_comment", { :comment_id => @comment.id, - :editor => admin_current_user(), + :editor => admin_current_user, :old_body => old_body, :body => @comment.body, :old_visible => old_visible, diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 7760c372b..400047215 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # controllers/admin.rb: # All admin controllers are dervied from this. # diff --git a/app/controllers/admin_general_controller.rb b/app/controllers/admin_general_controller.rb index f2414eeab..8efe0c7b9 100644 --- a/app/controllers/admin_general_controller.rb +++ b/app/controllers/admin_general_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_controller.rb: # Controller for main admin pages. # @@ -7,29 +8,29 @@ class AdminGeneralController < AdminController def index - # Overview counts of things - @public_body_count = PublicBody.count - - @info_request_count = InfoRequest.count - @outgoing_message_count = OutgoingMessage.count - @incoming_message_count = IncomingMessage.count - - @user_count = User.count - @track_thing_count = TrackThing.count - - @comment_count = Comment.count - # Tasks to do @requires_admin_requests = InfoRequest.find_in_state('requires_admin') @error_message_requests = InfoRequest.find_in_state('error_message') @attention_requests = InfoRequest.find_in_state('attention_requested') - @blank_contacts = PublicBody.find(:all, :conditions => ["request_email = ''"], - :order => "updated_at") + @blank_contacts = PublicBody. + includes(:tags, :translations). + where(:request_email => ""). + order(:updated_at). + select { |pb| !pb.defunct? } @old_unclassified = InfoRequest.find_old_unclassified(:limit => 20, :conditions => ["prominence = 'normal'"]) - @holding_pen_messages = InfoRequest.holding_pen_request.incoming_messages - @new_body_requests = PublicBodyChangeRequest.new_body_requests.open - @body_update_requests = PublicBodyChangeRequest.body_update_requests.open + @holding_pen_messages = InfoRequest. + includes(:incoming_messages => :raw_email). + holding_pen_request. + incoming_messages + @new_body_requests = PublicBodyChangeRequest. + includes(:public_body, :user). + new_body_requests. + open + @body_update_requests = PublicBodyChangeRequest. + includes(:public_body, :user). + body_update_requests. + open end def timeline diff --git a/app/controllers/admin_holiday_imports_controller.rb b/app/controllers/admin_holiday_imports_controller.rb index 8596936f0..a740caa2b 100644 --- a/app/controllers/admin_holiday_imports_controller.rb +++ b/app/controllers/admin_holiday_imports_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminHolidayImportsController < AdminController def new diff --git a/app/controllers/admin_holidays_controller.rb b/app/controllers/admin_holidays_controller.rb index 9177ebd44..cd93a21b6 100644 --- a/app/controllers/admin_holidays_controller.rb +++ b/app/controllers/admin_holidays_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminHolidaysController < AdminController def index diff --git a/app/controllers/admin_incoming_message_controller.rb b/app/controllers/admin_incoming_message_controller.rb index bc653bf53..db7bed34c 100644 --- a/app/controllers/admin_incoming_message_controller.rb +++ b/app/controllers/admin_incoming_message_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminIncomingMessageController < AdminController def edit @@ -13,7 +14,7 @@ class AdminIncomingMessageController < AdminController if @incoming_message.save @incoming_message.info_request.log_event('edit_incoming', :incoming_message_id => @incoming_message.id, - :editor => admin_current_user(), + :editor => admin_current_user, :old_prominence => old_prominence, :prominence => @incoming_message.prominence, :old_prominence_reason => old_prominence_reason, @@ -33,7 +34,7 @@ class AdminIncomingMessageController < AdminController @incoming_message.fully_destroy @incoming_message.info_request.log_event("destroy_incoming", - { :editor => admin_current_user(), :deleted_incoming_message_id => incoming_message_id }) + { :editor => admin_current_user, :deleted_incoming_message_id => incoming_message_id }) # expire cached files expire_for_request(@info_request) flash[:notice] = 'Incoming message successfully destroyed.' @@ -63,7 +64,7 @@ class AdminIncomingMessageController < AdminController incoming_message_id = incoming_message.id incoming_message.info_request.log_event("redeliver_incoming", { - :editor => admin_current_user(), + :editor => admin_current_user, :destination_request => destination_request.id, :deleted_incoming_message_id => incoming_message_id }) diff --git a/app/controllers/admin_info_request_event_controller.rb b/app/controllers/admin_info_request_event_controller.rb index 17d147582..6862ff116 100644 --- a/app/controllers/admin_info_request_event_controller.rb +++ b/app/controllers/admin_info_request_event_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_info_request_event_controller.rb: # Controller for FOI request event manipulation from the admin interface. # diff --git a/app/controllers/admin_outgoing_message_controller.rb b/app/controllers/admin_outgoing_message_controller.rb index 2ee811dc0..56e27b108 100644 --- a/app/controllers/admin_outgoing_message_controller.rb +++ b/app/controllers/admin_outgoing_message_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminOutgoingMessageController < AdminController def edit @@ -11,7 +12,7 @@ class AdminOutgoingMessageController < AdminController @outgoing_message.fully_destroy @outgoing_message.info_request.log_event("destroy_outgoing", - { :editor => admin_current_user(), :deleted_outgoing_message_id => outgoing_message_id }) + { :editor => admin_current_user, :deleted_outgoing_message_id => outgoing_message_id }) flash[:notice] = 'Outgoing message successfully destroyed.' redirect_to admin_request_url(@info_request) @@ -29,7 +30,7 @@ class AdminOutgoingMessageController < AdminController if @outgoing_message.save @outgoing_message.info_request.log_event("edit_outgoing", { :outgoing_message_id => @outgoing_message.id, - :editor => admin_current_user(), + :editor => admin_current_user, :old_body => old_body, :body => @outgoing_message.body, :old_prominence => old_prominence, diff --git a/app/controllers/admin_public_body_categories_controller.rb b/app/controllers/admin_public_body_categories_controller.rb index a86171c76..e365255f8 100644 --- a/app/controllers/admin_public_body_categories_controller.rb +++ b/app/controllers/admin_public_body_categories_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminPublicBodyCategoriesController < AdminController def index @locale = self.locale_from_params diff --git a/app/controllers/admin_public_body_change_requests_controller.rb b/app/controllers/admin_public_body_change_requests_controller.rb index 6ff03a2bd..be632b6cd 100644 --- a/app/controllers/admin_public_body_change_requests_controller.rb +++ b/app/controllers/admin_public_body_change_requests_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminPublicBodyChangeRequestsController < AdminController def edit diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index 7de27121a..b3c2c1dfd 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_public_body_controller.rb: # Controller for editing public bodies from the admin interface. # @@ -11,7 +12,7 @@ class AdminPublicBodyController < AdminController end def show - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do @public_body = PublicBody.find(params[:id]) @info_requests = @public_body.info_requests.paginate :order => "created_at desc", @@ -43,7 +44,7 @@ class AdminPublicBodyController < AdminController if params[:change_request_id] @change_request = PublicBodyChangeRequest.find(params[:change_request_id]) end - params[:public_body][:last_edit_editor] = admin_current_user() + params[:public_body][:last_edit_editor] = admin_current_user @public_body = PublicBody.new(params[:public_body]) if @public_body.save if @change_request @@ -84,7 +85,7 @@ class AdminPublicBodyController < AdminController @change_request = PublicBodyChangeRequest.find(params[:change_request_id]) end I18n.with_locale(I18n.default_locale) do - params[:public_body][:last_edit_editor] = admin_current_user() + params[:public_body][:last_edit_editor] = admin_current_user @public_body = PublicBody.find(params[:id]) if @public_body.update_attributes(params[:public_body]) if @change_request @@ -101,7 +102,7 @@ class AdminPublicBodyController < AdminController end def destroy - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do public_body = PublicBody.find(params[:id]) @@ -158,7 +159,7 @@ class AdminPublicBodyController < AdminController @notes = "" @errors = "" if request.post? - dry_run_only = (params['commit'] == 'Upload' ? false : true) + dry_run_only = params['commit'] != 'Upload' # (FIXME: both of these cases could now be changed to use # PublicBody.import_csv_from_file.) # Read file from params @@ -177,7 +178,7 @@ class AdminPublicBodyController < AdminController params[:tag], params[:tag_behaviour], true, - admin_current_user(), + admin_current_user, I18n.available_locales) if errors.size == 0 @@ -191,7 +192,7 @@ class AdminPublicBodyController < AdminController params[:tag], params[:tag_behaviour], false, - admin_current_user(), + admin_current_user, I18n.available_locales) if errors.size != 0 raise "dry run mismatched real run" @@ -234,7 +235,7 @@ class AdminPublicBodyController < AdminController end def lookup_query - @locale = self.locale_from_params() + @locale = locale_from_params underscore_locale = @locale.gsub '-', '_' I18n.with_locale(@locale) do @query = params[:query] diff --git a/app/controllers/admin_public_body_headings_controller.rb b/app/controllers/admin_public_body_headings_controller.rb index a7fe27390..f0568510a 100644 --- a/app/controllers/admin_public_body_headings_controller.rb +++ b/app/controllers/admin_public_body_headings_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminPublicBodyHeadingsController < AdminController def new @@ -84,7 +85,7 @@ class AdminPublicBodyHeadingsController < AdminController end end end - { :success => error.nil? ? true : false, :error => error } + { :success => error.nil?, :error => error } end def reorder_categories_for_heading(heading_id, categories) @@ -105,7 +106,7 @@ class AdminPublicBodyHeadingsController < AdminController end end end - { :success => error.nil? ? true : false, :error => error } + { :success => error.nil?, :error => error } end end diff --git a/app/controllers/admin_raw_email_controller.rb b/app/controllers/admin_raw_email_controller.rb index 1b3ee2871..7a802d914 100644 --- a/app/controllers/admin_raw_email_controller.rb +++ b/app/controllers/admin_raw_email_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_raw_email_controller.rb: # Controller for managing raw emails from the admin interface. # diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb index 1e083f57e..eaf6c337d 100644 --- a/app/controllers/admin_request_controller.rb +++ b/app/controllers/admin_request_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_request_controller.rb: # Controller for viewing FOI requests from the admin interface. # @@ -47,16 +48,16 @@ class AdminRequestController < AdminController @info_request.title = params[:info_request][:title] @info_request.prominence = params[:info_request][:prominence] - @info_request.awaiting_description = params[:info_request][:awaiting_description] == "true" ? true : false + @info_request.awaiting_description = params[:info_request][:awaiting_description] == "true" @info_request.allow_new_responses_from = params[:info_request][:allow_new_responses_from] @info_request.handle_rejected_responses = params[:info_request][:handle_rejected_responses] @info_request.tag_string = params[:info_request][:tag_string] - @info_request.comments_allowed = params[:info_request][:comments_allowed] == "true" ? true : false + @info_request.comments_allowed = params[:info_request][:comments_allowed] == "true" if @info_request.valid? @info_request.save! @info_request.log_event("edit", - { :editor => admin_current_user(), + { :editor => admin_current_user, :old_title => old_title, :title => @info_request.title, :old_prominence => old_prominence, :prominence => @info_request.prominence, :old_described_state => old_described_state, :described_state => params[:info_request][:described_state], @@ -104,7 +105,7 @@ class AdminRequestController < AdminController info_request.user = destination_user info_request.save! info_request.log_event("move_request", { - :editor => admin_current_user(), + :editor => admin_current_user, :old_user_url_name => old_user.url_name, :user_url_name => destination_user.url_name }) @@ -114,21 +115,14 @@ class AdminRequestController < AdminController end redirect_to admin_request_url(info_request) elsif params[:commit] == 'Move request to authority' && !params[:public_body_url_name].blank? - old_public_body = info_request.public_body destination_public_body = PublicBody.find_by_url_name(params[:public_body_url_name]) - if destination_public_body.nil? - flash[:error] = "Couldn't find public body '" + params[:public_body_url_name] + "'" - else - info_request.public_body = destination_public_body - info_request.save! - info_request.log_event("move_request", { - :editor => admin_current_user(), - :old_public_body_url_name => old_public_body.url_name, - :public_body_url_name => destination_public_body.url_name - }) - info_request.reindex_request_events - flash[:notice] = "Request has been moved to new body" + if info_request.move_to_public_body(destination_public_body, + :editor => admin_current_user, + :reindex => true) + flash[:notice] = "Request has been moved to new body" + else + flash[:error] = "Couldn't find public body '#{ params[:public_body_url_name] }'" end redirect_to admin_request_url(info_request) @@ -182,7 +176,7 @@ class AdminRequestController < AdminController info_request.prominence = "requester_only" info_request.log_event("hide", { - :editor => admin_current_user(), + :editor => admin_current_user, :reason => params[:reason], :subject => subject, :explanation => explanation diff --git a/app/controllers/admin_spam_addresses_controller.rb b/app/controllers/admin_spam_addresses_controller.rb index fff7e2a4a..d8be52bc7 100644 --- a/app/controllers/admin_spam_addresses_controller.rb +++ b/app/controllers/admin_spam_addresses_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class AdminSpamAddressesController < AdminController def index diff --git a/app/controllers/admin_track_controller.rb b/app/controllers/admin_track_controller.rb index 63ee5c12e..e6e5835e6 100644 --- a/app/controllers/admin_track_controller.rb +++ b/app/controllers/admin_track_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_track_controller.rb: # Show email alerts / RSS feeds from admin interface. # diff --git a/app/controllers/admin_user_controller.rb b/app/controllers/admin_user_controller.rb index 7ef461594..8ebc450f6 100644 --- a/app/controllers/admin_user_controller.rb +++ b/app/controllers/admin_user_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/admin_user_controller.rb: # Controller for viewing user accounts from the admin interface. # @@ -85,8 +86,7 @@ class AdminUserController < AdminController end def modify_comment_visibility - @visibility_value = params.key?(:hide_selected) ? false : true - Comment.update_all(["visible=?", @visibility_value], :id => params[:comment_ids]) + Comment.update_all(["visible = ?", !params[:hide_selected]], :id => params[:comment_ids]) redirect_to :back end diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 6f83d89d6..3b8991f28 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ApiController < ApplicationController before_filter :check_api_key before_filter :check_external_request, @@ -41,7 +42,7 @@ class ApiController < ApplicationController :status => 'ready', :message_type => 'initial_request', :body => json["body"], - :last_sent_at => Time.now(), + :last_sent_at => Time.now, :what_doing => 'normal_sort', :info_request => request ) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e80c6a823..a76e6630a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- # controllers/application.rb: # Parent class of all controllers in FOI site. Filters added to this controller # apply to all controllers in the application. Likewise, all the methods added @@ -206,7 +206,7 @@ class ApplicationController < ActionController::Base def foi_fragment_cache_part_path(param) path = url_for(param) id = param['id'] || param[:id] - first_three_digits = id.to_s()[0..2] + first_three_digits = id.to_s[0..2] path = path.sub("/request/", "/request/" + first_three_digits + "/") return path end diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb index 890e9faaa..b5c438c95 100644 --- a/app/controllers/comment_controller.rb +++ b/app/controllers/comment_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/comment_controller.rb: # Show annotations upon a request or other object. # diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 380da285e..53288c2f4 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/general_controller.rb: # For pages like front page, general search, that aren't specific to a # particular model. @@ -14,7 +15,7 @@ class GeneralController < ApplicationController # New, improved front page! def frontpage medium_cache - @locale = self.locale_from_params() + @locale = locale_from_params successful_query = InfoRequestEvent.make_query_from_params( :latest_status => ['successful'] ) @track_thing = TrackThing.create_track_for_search_query(successful_query) @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), @@ -32,7 +33,7 @@ class GeneralController < ApplicationController @feed_autodetect = [] @feed_url = AlaveteliConfiguration::blog_feed separator = @feed_url.include?('?') ? '&' : '?' - @feed_url = "#{@feed_url}#{separator}lang=#{self.locale_from_params()}" + @feed_url = "#{@feed_url}#{separator}lang=#{locale_from_params}" @blog_items = [] if not @feed_url.empty? content = quietly_try_to_open(@feed_url) diff --git a/app/controllers/health_checks_controller.rb b/app/controllers/health_checks_controller.rb index 473a1aacc..122a02193 100644 --- a/app/controllers/health_checks_controller.rb +++ b/app/controllers/health_checks_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class HealthChecksController < ApplicationController def index diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb index 93215ccad..cfe1b6ad5 100644 --- a/app/controllers/help_controller.rb +++ b/app/controllers/help_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/help_controller.rb: # Show information about one particular request. # diff --git a/app/controllers/holiday_controller.rb b/app/controllers/holiday_controller.rb index efc20701d..422612fc7 100644 --- a/app/controllers/holiday_controller.rb +++ b/app/controllers/holiday_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/holiday_controller.rb: # Calculate dates # diff --git a/app/controllers/info_request_batch_controller.rb b/app/controllers/info_request_batch_controller.rb index b66658757..e1b684f30 100644 --- a/app/controllers/info_request_batch_controller.rb +++ b/app/controllers/info_request_batch_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class InfoRequestBatchController < ApplicationController def show diff --git a/app/controllers/public_body_change_requests_controller.rb b/app/controllers/public_body_change_requests_controller.rb index 773308546..d43f9398a 100644 --- a/app/controllers/public_body_change_requests_controller.rb +++ b/app/controllers/public_body_change_requests_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class PublicBodyChangeRequestsController < ApplicationController before_filter :catch_spam, :only => [:create] diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 854e79a19..1b01dc837 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- # app/controllers/public_body_controller.rb: # Show information about a public body. # @@ -24,7 +24,7 @@ class PublicBodyController < ApplicationController redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name], 'body'), :status => :moved_permanently return end - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do @public_body = PublicBody.find_by_url_name_with_historic(params[:url_name]) raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil? @@ -40,6 +40,8 @@ class PublicBodyController < ApplicationController set_last_body(@public_body) + @number_of_visible_requests = @public_body.info_requests.visible.count + top_url = frontpage_url @searched_to_send_request = false referrer = request.env['HTTP_REFERER'] @@ -83,7 +85,7 @@ class PublicBodyController < ApplicationController @public_body = PublicBody.find_by_url_name_with_historic(params[:url_name]) raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil? - I18n.with_locale(self.locale_from_params()) do + I18n.with_locale(locale_from_params) do if params[:submitted_view_email] if verify_recaptcha flash.discard(:error) @@ -106,7 +108,7 @@ class PublicBodyController < ApplicationController @tag = params[:tag] - @locale = self.locale_from_params + @locale = locale_from_params underscore_locale = @locale.gsub '-', '_' underscore_default_locale = I18n.default_locale.to_s.gsub '-', '_' diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index a1dd53125..83474ad65 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- class ReportsController < ApplicationController def create @info_request = InfoRequest.find_by_url_title!(params[:request_id]) diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index e847cae1e..45229fd7e 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -1,4 +1,4 @@ -# encoding: UTF-8 +# -*- encoding : utf-8 -*- # app/controllers/request_controller.rb: # Show information about one particular request. # @@ -75,7 +75,7 @@ class RequestController < ApplicationController else medium_cache end - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do # Look up by old style numeric identifiers @@ -96,12 +96,12 @@ class RequestController < ApplicationController set_last_request(@info_request) # assign variables from request parameters - @collapse_quotes = params[:unfold] ? false : true + @collapse_quotes = !params[:unfold] # Don't allow status update on external requests, otherwise accept param if @info_request.is_external? @update_status = false else - @update_status = params[:update_status] ? true : false + @update_status = params[:update_status] end assign_variables_for_show_template(@info_request) @@ -164,7 +164,7 @@ class RequestController < ApplicationController def list medium_cache @view = params[:view] - @locale = self.locale_from_params() + @locale = locale_from_params @page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect @per_page = PER_PAGE @max_results = MAX_RESULTS @@ -566,9 +566,9 @@ class RequestController < ApplicationController @info_request = InfoRequest.find(params[:id].to_i) set_last_request(@info_request) - @collapse_quotes = params[:unfold] ? false : true + @collapse_quotes = !params[:unfold] @is_owning_user = @info_request.is_owning_user?(authenticated_user) - @gone_postal = params[:gone_postal] ? true : false + @gone_postal = params[:gone_postal] if !@is_owning_user @gone_postal = false end @@ -848,7 +848,7 @@ class RequestController < ApplicationController # FOI officers can upload a response def upload_response - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do @info_request = InfoRequest.find_by_url_title!(params[:url_title]) @@ -914,7 +914,7 @@ class RequestController < ApplicationController end def download_entire_request - @locale = self.locale_from_params() + @locale = locale_from_params I18n.with_locale(@locale) do @info_request = InfoRequest.find_by_url_title!(params[:url_title]) if authenticated?( diff --git a/app/controllers/request_game_controller.rb b/app/controllers/request_game_controller.rb index 7eadc1204..2915b5c2f 100644 --- a/app/controllers/request_game_controller.rb +++ b/app/controllers/request_game_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/request_game_controller.rb: # The 'categorise old requests' game # @@ -22,7 +23,7 @@ class RequestGameController < ApplicationController :site_name => site_name) end - @league_table_28_days = RequestClassification.league_table(10, [ "created_at >= ?", Time.now() - 28.days ]) + @league_table_28_days = RequestClassification.league_table(10, [ "created_at >= ?", Time.now - 28.days ]) @league_table_all_time = RequestClassification.league_table(10) @play_urls = true end diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 9b3a3396f..4d06072df 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # controllers/services_controller.rb: require 'open-uri' diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb index 4b272797f..cbefb6291 100644 --- a/app/controllers/track_controller.rb +++ b/app/controllers/track_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/track_controller.rb: # Publically visible email alerts and RSS - think an alert system crossed with # social bookmarking. @@ -214,6 +215,4 @@ class TrackController < ApplicationController redirect_to URI.parse(params[:r]).path end - end - diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index d66b4aa8e..bb4ba28d1 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # app/controllers/user_controller.rb: # Show information about a user. # @@ -176,7 +177,7 @@ class UserController < ApplicationController return else if !@post_redirect.nil? - @user_signin = User.authenticate_from_form(params[:user_signin], @post_redirect.reason_params[:user_name] ? true : false) + @user_signin = User.authenticate_from_form(params[:user_signin], @post_redirect.reason_params[:user_name]) end if @post_redirect.nil? || @user_signin.errors.size > 0 # Failed to authenticate @@ -372,7 +373,7 @@ class UserController < ApplicationController if (not session[:user_circumstance]) or (session[:user_circumstance] != "change_email") # don't store the password in the db params[:signchangeemail].delete(:password) - post_redirect = PostRedirect.new(:uri => signchangeemail_url(), + post_redirect = PostRedirect.new(:uri => signchangeemail_url, :post_params => params, :circumstance => "change_email" # special login that lets you change your email ) @@ -509,7 +510,7 @@ class UserController < ApplicationController else flash[:notice] = _("<p>Thanks for updating your profile photo.</p> <p><strong>Next...</strong> You can put some text about you and your research on your profile.</p>") - redirect_to set_profile_about_me_url() + redirect_to set_profile_about_me_url end else render :template => 'user/set_draft_profile_photo' @@ -595,7 +596,7 @@ class UserController < ApplicationController else flash[:notice] = _("<p>Thanks for changing the text about you on your profile.</p> <p><strong>Next...</strong> You can upload a profile photograph too.</p>") - redirect_to set_profile_photo_url() + redirect_to set_profile_photo_url end end diff --git a/app/controllers/widgets_controller.rb b/app/controllers/widgets_controller.rb new file mode 100644 index 000000000..333a38e86 --- /dev/null +++ b/app/controllers/widgets_controller.rb @@ -0,0 +1,64 @@ +# -*- encoding : utf-8 -*- +# app/controllers/widget_controller.rb: +# Handle widgets, if enabled +# +# Copyright (c) 2014 UK Citizens Online Democracy. All rights reserved. +# Email: hello@mysociety.org; WWW: http://www.mysociety.org/ + +require 'securerandom' + +class WidgetsController < ApplicationController + + before_filter :check_widget_config, :find_info_request, :check_prominence + skip_before_filter :set_x_frame_options_header, :only => [:show] + + def show + medium_cache + @track_thing = TrackThing.create_track_for_request(@info_request) + @status = @info_request.calculate_status + @count = @info_request.track_things.count + @info_request.widget_votes.count + 1 + + if @user + @existing_track = TrackThing.find_existing(@user, @track_thing) + end + unless @user || cookies[:widget_vote] + cookies.permanent[:widget_vote] = SecureRandom.hex(10) + end + render :action => 'show', :layout => false + end + + def new + long_cache + end + + # Track interest in a request from a non-logged in user + def update + if !@user && cookies[:widget_vote] + @info_request.widget_votes. + where(:cookie => cookies[:widget_vote]). + first_or_create + end + + track_thing = TrackThing.create_track_for_request(@info_request) + redirect_to do_track_path(track_thing), status => :temporary_redirect + end + + private + + def find_info_request + @info_request = InfoRequest.find(params[:request_id]) + end + + def check_widget_config + unless AlaveteliConfiguration::enable_widgets + raise ActiveRecord::RecordNotFound.new("Page not enabled") + end + end + + def check_prominence + unless @info_request.prominence == 'normal' + render :nothing => true, :status => :forbidden + end + end + +end |