aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin_general_controller.rb7
-rw-r--r--app/controllers/admin_public_body_categories_controller.rb84
-rw-r--r--app/controllers/admin_public_body_change_requests_controller.rb8
-rw-r--r--app/controllers/admin_public_body_controller.rb2
-rw-r--r--app/controllers/admin_public_body_headings_controller.rb113
-rw-r--r--app/controllers/admin_request_controller.rb25
-rw-r--r--app/controllers/admin_spam_addresses_controller.rb4
-rw-r--r--app/controllers/general_controller.rb2
-rw-r--r--app/controllers/health_checks_controller.rb16
-rw-r--r--app/controllers/public_body_controller.rb4
-rw-r--r--app/controllers/request_controller.rb33
-rw-r--r--app/controllers/user_controller.rb15
12 files changed, 293 insertions, 20 deletions
diff --git a/app/controllers/admin_general_controller.rb b/app/controllers/admin_general_controller.rb
index 753208c9a..f2414eeab 100644
--- a/app/controllers/admin_general_controller.rb
+++ b/app/controllers/admin_general_controller.rb
@@ -7,13 +7,6 @@
class AdminGeneralController < AdminController
def index
- # ensure we have a trailing slash
- current_uri = request.env['REQUEST_URI']
- if params[:suppress_redirect].nil? && !(current_uri =~ /\/$/)
- redirect_to admin_general_index_url + "/"
- return
- end
-
# Overview counts of things
@public_body_count = PublicBody.count
diff --git a/app/controllers/admin_public_body_categories_controller.rb b/app/controllers/admin_public_body_categories_controller.rb
new file mode 100644
index 000000000..fda09fa4a
--- /dev/null
+++ b/app/controllers/admin_public_body_categories_controller.rb
@@ -0,0 +1,84 @@
+class AdminPublicBodyCategoriesController < AdminController
+ def index
+ @locale = self.locale_from_params
+ @category_headings = PublicBodyHeading.all
+ @without_heading = PublicBodyCategory.without_headings
+ end
+
+ def new
+ @category = PublicBodyCategory.new
+ render :formats => [:html]
+ end
+
+ def edit
+ @category = PublicBodyCategory.find(params[:id])
+ @tagged_public_bodies = PublicBody.find_by_tag(@category.category_tag)
+ end
+
+ def update
+ @category = PublicBodyCategory.find(params[:id])
+ @tagged_public_bodies = PublicBody.find_by_tag(@category.category_tag)
+ heading_ids = []
+
+ I18n.with_locale(I18n.default_locale) do
+ if params[:public_body_category][:category_tag] && PublicBody.find_by_tag(@category.category_tag).count > 0 && @category.category_tag != params[:public_body_category][:category_tag]
+ flash[:notice] = 'There are authorities associated with this category, so the tag can\'t be renamed'
+ else
+ if params[:headings]
+ heading_ids = params[:headings].values
+ removed_headings = @category.public_body_heading_ids - heading_ids
+ added_headings = heading_ids - @category.public_body_heading_ids
+
+ unless removed_headings.empty?
+ # remove the link objects
+ deleted_links = PublicBodyCategoryLink.where(
+ :public_body_category_id => @category.id,
+ :public_body_heading_id => [removed_headings]
+ )
+ deleted_links.delete_all
+
+ #fix the category object
+ @category.public_body_heading_ids = heading_ids
+ end
+
+ added_headings.each do |heading_id|
+ PublicBodyHeading.find(heading_id).add_category(@category)
+ end
+ end
+
+ if @category.update_attributes(params[:public_body_category])
+ flash[:notice] = 'Category was successfully updated.'
+ end
+ end
+
+ render :action => 'edit'
+ end
+ end
+
+ def create
+ I18n.with_locale(I18n.default_locale) do
+ @category = PublicBodyCategory.new(params[:public_body_category])
+ if @category.save
+ if params[:headings]
+ params[:headings].values.each do |heading_id|
+ PublicBodyHeading.find(heading_id).add_category(@category)
+ end
+ end
+ flash[:notice] = 'Category was successfully created.'
+ redirect_to admin_categories_path
+ else
+ render :action => 'new'
+ end
+ end
+ end
+
+ def destroy
+ @locale = self.locale_from_params
+ I18n.with_locale(@locale) do
+ category = PublicBodyCategory.find(params[:id])
+ category.destroy
+ flash[:notice] = "Category was successfully destroyed."
+ redirect_to admin_categories_path
+ end
+ end
+end
diff --git a/app/controllers/admin_public_body_change_requests_controller.rb b/app/controllers/admin_public_body_change_requests_controller.rb
index d76cdc0e5..6ff03a2bd 100644
--- a/app/controllers/admin_public_body_change_requests_controller.rb
+++ b/app/controllers/admin_public_body_change_requests_controller.rb
@@ -7,8 +7,12 @@ class AdminPublicBodyChangeRequestsController < AdminController
def update
@change_request = PublicBodyChangeRequest.find(params[:id])
@change_request.close!
- @change_request.send_response(params[:subject], params[:response])
- flash[:notice] = 'The change request has been closed and the user has been notified'
+ if params[:subject] && params[:response]
+ @change_request.send_response(params[:subject], params[:response])
+ flash[:notice] = 'The change request has been closed and the user has been notified'
+ else
+ flash[:notice] = 'The change request has been closed'
+ end
redirect_to admin_general_index_path
end
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index 120419a27..f7a80476c 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_body_controller.rb
@@ -4,8 +4,6 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
-require "public_body_categories"
-
class AdminPublicBodyController < AdminController
def index
list
diff --git a/app/controllers/admin_public_body_headings_controller.rb b/app/controllers/admin_public_body_headings_controller.rb
new file mode 100644
index 000000000..c7c80e802
--- /dev/null
+++ b/app/controllers/admin_public_body_headings_controller.rb
@@ -0,0 +1,113 @@
+class AdminPublicBodyHeadingsController < AdminController
+
+ def edit
+ @heading = PublicBodyHeading.find(params[:id])
+ render :formats => [:html]
+ end
+
+ def update
+ I18n.with_locale(I18n.default_locale) do
+ @heading = PublicBodyHeading.find(params[:id])
+ if @heading.update_attributes(params[:public_body_heading])
+ flash[:notice] = 'Category heading was successfully updated.'
+ end
+ render :action => 'edit'
+ end
+ end
+
+ def reorder
+ transaction = reorder_headings(params[:headings])
+ if transaction[:success]
+ render :nothing => true, :status => :ok
+ else
+ render :text => transaction[:error], :status => :unprocessable_entity
+ end
+ end
+
+ def reorder_categories
+ transaction = reorder_categories_for_heading(params[:id], params[:categories])
+ if transaction[:success]
+ render :nothing => true, :status => :ok and return
+ else
+ render :text => transaction[:error], :status => :unprocessable_entity
+ end
+ end
+
+ def new
+ @heading = PublicBodyHeading.new
+ render :formats => [:html]
+ end
+
+ def create
+ I18n.with_locale(I18n.default_locale) do
+ @heading = PublicBodyHeading.new(params[:public_body_heading])
+ if @heading.save
+ flash[:notice] = 'Category heading was successfully created.'
+ redirect_to admin_categories_url
+ else
+ render :action => 'new'
+ end
+ end
+ end
+
+ def destroy
+ @locale = self.locale_from_params()
+ I18n.with_locale(@locale) do
+ heading = PublicBodyHeading.find(params[:id])
+
+ if heading.public_body_categories.count > 0
+ flash[:notice] = "There are categories associated with this heading, so can't destroy it"
+ redirect_to edit_admin_heading_url(heading)
+ return
+ end
+
+ heading.destroy
+ flash[:notice] = "Category heading was successfully destroyed."
+ redirect_to admin_categories_url
+ end
+ end
+
+ protected
+
+ def reorder_headings(headings)
+ error = nil
+ ActiveRecord::Base.transaction do
+ headings.each_with_index do |heading_id, index|
+ begin
+ heading = PublicBodyHeading.find(heading_id)
+ rescue ActiveRecord::RecordNotFound => e
+ error = e.message
+ raise ActiveRecord::Rollback
+ end
+ heading.display_order = index
+ unless heading.save
+ error = heading.errors.full_messages.join(",")
+ raise ActiveRecord::Rollback
+ end
+ end
+ end
+ { :success => error.nil? ? true : false, :error => error }
+ end
+
+ def reorder_categories_for_heading(heading_id, categories)
+ error = nil
+ ActiveRecord::Base.transaction do
+ categories.each_with_index do |category_id, index|
+ conditions = { :public_body_category_id => category_id,
+ :public_body_heading_id => heading_id }
+ link = PublicBodyCategoryLink.where(conditions).first
+ unless link
+ error = "Couldn't find PublicBodyCategoryLink for category #{category_id}, heading #{heading_id}"
+ raise ActiveRecord::Rollback
+ end
+ link.category_display_order = index
+ unless link.save
+ error = link.errors.full_messages.join(",")
+ raise ActiveRecord::Rollback
+ end
+ end
+ end
+ { :success => error.nil? ? true : false, :error => error }
+ end
+
+end
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index 21120e4ad..8f023bf12 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -37,7 +37,30 @@ class AdminRequestController < AdminController
def resend
@outgoing_message = OutgoingMessage.find(params[:outgoing_message_id])
- @outgoing_message.resend_message
+ @outgoing_message.prepare_message_for_resend
+
+ mail_message = case @outgoing_message.message_type
+ when 'initial_request'
+ OutgoingMailer.initial_request(
+ @outgoing_message.info_request,
+ @outgoing_message
+ ).deliver
+ when 'followup'
+ OutgoingMailer.followup(
+ @outgoing_message.info_request,
+ @outgoing_message,
+ @outgoing_message.incoming_message_followup
+ ).deliver
+ else
+ raise "Message id #{id} has type '#{message_type}' which cannot be resent"
+ end
+
+ @outgoing_message.record_email_delivery(
+ mail_message.to_addrs.join(', '),
+ mail_message.message_id,
+ 'resent'
+ )
+
flash[:notice] = "Outgoing message resent"
redirect_to admin_request_show_url(@outgoing_message.info_request)
end
diff --git a/app/controllers/admin_spam_addresses_controller.rb b/app/controllers/admin_spam_addresses_controller.rb
index f5c7e93da..fff7e2a4a 100644
--- a/app/controllers/admin_spam_addresses_controller.rb
+++ b/app/controllers/admin_spam_addresses_controller.rb
@@ -10,7 +10,7 @@ class AdminSpamAddressesController < AdminController
if @spam_address.save
notice = "#{ @spam_address.email } has been added to the spam addresses list"
- redirect_to spam_addresses_path, :notice => notice
+ redirect_to admin_spam_addresses_path, :notice => notice
else
@spam_addresses = SpamAddress.all
render :index
@@ -21,7 +21,7 @@ class AdminSpamAddressesController < AdminController
@spam_address = SpamAddress.find(params[:id])
@spam_address.destroy
notice = "#{ @spam_address.email } has been removed from the spam addresses list"
- redirect_to spam_addresses_path, :notice => notice
+ redirect_to admin_spam_addresses_path, :notice => notice
end
end
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 158492eb2..2c8abbaf4 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -32,7 +32,7 @@ class GeneralController < ApplicationController
if !content.empty?
@data = XmlSimple.xml_in(content)
@channel = @data['channel'][0]
- @blog_items = @channel['item']
+ @blog_items = @channel.fetch('item') { [] }
@feed_autodetect = [{:url => @feed_url, :title => "#{site_name} blog"}]
end
end
diff --git a/app/controllers/health_checks_controller.rb b/app/controllers/health_checks_controller.rb
new file mode 100644
index 000000000..473a1aacc
--- /dev/null
+++ b/app/controllers/health_checks_controller.rb
@@ -0,0 +1,16 @@
+class HealthChecksController < ApplicationController
+
+ def index
+ @health_checks = HealthChecks.all
+
+ respond_to do |format|
+ if HealthChecks.ok?
+ format.html { render :action => :index, :layout => false }
+ else
+ format.html { render :action => :index, :layout => false , :status => 500 }
+ end
+ end
+
+ end
+
+end
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index d2c84d820..e64644a1b 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -111,7 +111,7 @@ class PublicBodyController < ApplicationController
if @tag.nil? || @tag == 'all'
@tag = 'all'
elsif @tag == 'other'
- category_list = PublicBodyCategories.get.tags.map{ |c| %Q('#{ c }') }.join(",")
+ category_list = PublicBodyCategory.get.tags.map{ |c| %Q('#{ c }') }.join(",")
where_condition += base_tag_condition + " AND has_tag_string_tags.name in (#{category_list})) = 0"
elsif @tag.scan(/./mu).size == 1
@tag = Unicode.upcase(@tag)
@@ -132,7 +132,7 @@ class PublicBodyController < ApplicationController
elsif @tag.size == 1
@description = _("beginning with ‘{{first_letter}}’", :first_letter => @tag)
else
- category_name = PublicBodyCategories.get.by_tag[@tag]
+ category_name = PublicBodyCategory.get.by_tag[@tag]
if category_name.nil?
@description = _("matching the tag ‘{{tag_name}}’", :tag_name => @tag)
else
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 3fa0ef0ce..9e2c291dc 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -365,8 +365,21 @@ class RequestController < ApplicationController
end
# This automatically saves dependent objects, such as @outgoing_message, in the same transaction
@info_request.save!
- # TODO: send_message needs the database id, so we send after saving, which isn't ideal if the request broke here.
- @outgoing_message.send_message
+
+ # TODO: Sending the message needs the database id, so we send after
+ # saving, which isn't ideal if the request broke here.
+ if @outgoing_message.sendable?
+ mail_message = OutgoingMailer.initial_request(
+ @outgoing_message.info_request,
+ @outgoing_message
+ ).deliver
+
+ @outgoing_message.record_email_delivery(
+ mail_message.to_addrs.join(', '),
+ mail_message.message_id
+ )
+ end
+
flash[:notice] = _("<p>Your {{law_used_full}} request has been <strong>sent on its way</strong>!</p>
<p><strong>We will email you</strong> when there is a response, or after {{late_number_of_days}} working days if the authority still hasn't
replied by then.</p>
@@ -668,13 +681,27 @@ class RequestController < ApplicationController
end
# Send a follow up message
- @outgoing_message.send_message
+ @outgoing_message.sendable?
+
+ mail_message = OutgoingMailer.followup(
+ @outgoing_message.info_request,
+ @outgoing_message,
+ @outgoing_message.incoming_message_followup
+ ).deliver
+
+ @outgoing_message.record_email_delivery(
+ mail_message.to_addrs.join(', '),
+ mail_message.message_id
+ )
+
@outgoing_message.save!
+
if @outgoing_message.what_doing == 'internal_review'
flash[:notice] = _("Your internal review request has been sent on its way.")
else
flash[:notice] = _("Your follow up message has been sent on its way.")
end
+
redirect_to request_url(@info_request)
end
else
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index f23343ddb..baeaab18a 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -49,13 +49,28 @@ class UserController < ApplicationController
# TODO: really should just use SQL query here rather than Xapian.
if @show_requests
begin
+
+ request_states = @display_user.info_requests.pluck(:described_state).uniq
+
+ option_item = Struct.new(:value, :text)
+ @request_states = request_states.map do |state|
+ option_item.new(state, InfoRequest.get_status_description(state))
+ end
+
requests_query = 'requested_by:' + @display_user.url_name
comments_query = 'commented_by:' + @display_user.url_name
if !params[:user_query].nil?
requests_query += " " + params[:user_query]
comments_query += " " + params[:user_query]
@match_phrase = _("{{search_results}} matching '{{query}}'", :search_results => "", :query => params[:user_query])
+
+ unless params[:request_latest_status].blank?
+ requests_query << ' latest_status:' << params[:request_latest_status]
+ comments_query << ' latest_status:' << params[:request_latest_status]
+ @match_phrase << _(" filtered by status: '{{status}}'", :status => params[:request_latest_status])
+ end
end
+
@xapian_requests = perform_search([InfoRequestEvent], requests_query, 'newest', 'request_collapse')
@xapian_comments = perform_search([InfoRequestEvent], comments_query, 'newest', nil)