aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin_censor_rule_controller.rb101
-rw-r--r--app/controllers/admin_comment_controller.rb36
-rw-r--r--app/controllers/admin_incoming_message_controller.rb12
-rw-r--r--app/controllers/admin_info_request_event_controller.rb24
-rw-r--r--app/controllers/admin_outgoing_message_controller.rb37
-rw-r--r--app/controllers/admin_public_body_controller.rb128
-rw-r--r--app/controllers/admin_raw_email_controller.rb45
-rw-r--r--app/controllers/admin_request_controller.rb133
-rw-r--r--app/controllers/admin_track_controller.rb12
-rw-r--r--app/controllers/admin_user_controller.rb37
-rw-r--r--app/helpers/admin_helper.rb6
-rwxr-xr-xapp/helpers/link_to_helper.rb4
-rw-r--r--app/mailers/request_mailer.rb2
-rw-r--r--app/views/admin_censor_rule/_show.html.erb4
-rw-r--r--app/views/admin_censor_rule/edit.html.erb5
-rw-r--r--app/views/admin_censor_rule/new.html.erb1
-rw-r--r--app/views/admin_comment/edit.html.erb (renamed from app/views/admin_request/edit_comment.html.erb)8
-rw-r--r--app/views/admin_general/_admin_navbar.html.erb8
-rw-r--r--app/views/admin_general/index.html.erb16
-rw-r--r--app/views/admin_incoming_message/_actions.html.erb (renamed from app/views/admin_request/_incoming_message_actions.html.erb)12
-rw-r--r--app/views/admin_incoming_message/edit.html.erb4
-rw-r--r--app/views/admin_outgoing_message/edit.html.erb9
-rw-r--r--app/views/admin_public_body/_one_list.html.erb4
-rw-r--r--app/views/admin_public_body/edit.html.erb9
-rw-r--r--app/views/admin_public_body/index.html.erb (renamed from app/views/admin_public_body/list.html.erb)6
-rw-r--r--app/views/admin_public_body/new.html.erb4
-rw-r--r--app/views/admin_public_body/show.html.erb2
-rw-r--r--app/views/admin_public_body_change_requests/edit.html.erb2
-rw-r--r--app/views/admin_raw_email/show.html.erb (renamed from app/views/admin_request/show_raw_email.html.erb)6
-rw-r--r--app/views/admin_request/_some_annotations.html.erb12
-rw-r--r--app/views/admin_request/_some_requests.html.erb4
-rw-r--r--app/views/admin_request/edit.html.erb8
-rw-r--r--app/views/admin_request/index.html.erb (renamed from app/views/admin_request/list.html.erb)0
-rw-r--r--app/views/admin_request/show.html.erb25
-rw-r--r--app/views/admin_track/_some_tracks.html.erb3
-rw-r--r--app/views/admin_track/index.html.erb (renamed from app/views/admin_track/list.html.erb)2
-rw-r--r--app/views/admin_user/_form.html.erb2
-rw-r--r--app/views/admin_user/_user_table.html.erb2
-rw-r--r--app/views/admin_user/banned.html.erb (renamed from app/views/admin_user/list_banned.html.erb)2
-rw-r--r--app/views/admin_user/edit.html.erb6
-rw-r--r--app/views/admin_user/index.html.erb (renamed from app/views/admin_user/list.html.erb)2
-rw-r--r--app/views/admin_user/show.html.erb16
-rw-r--r--app/views/comment/_single_comment.html.erb2
-rw-r--r--app/views/contact_mailer/add_public_body.text.erb4
-rw-r--r--app/views/contact_mailer/update_public_body_email.text.erb4
-rw-r--r--app/views/public_body/show.html.erb2
-rw-r--r--app/views/request/_incoming_correspondence.html.erb2
-rw-r--r--app/views/request/show.html.erb4
-rw-r--r--app/views/user/show.html.erb2
-rw-r--r--config/routes.rb159
-rw-r--r--spec/controllers/admin_censor_rule_controller_spec.rb592
-rw-r--r--spec/controllers/admin_comment_controller_spec.rb66
-rw-r--r--spec/controllers/admin_incoming_message_controller_spec.rb12
-rw-r--r--spec/controllers/admin_info_request_event_controller_spec.rb41
-rw-r--r--spec/controllers/admin_outgoing_message_controller_spec.rb2
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb4
-rw-r--r--spec/controllers/admin_raw_email_controller_spec.rb30
-rw-r--r--spec/controllers/admin_request_controller_spec.rb38
-rw-r--r--spec/controllers/admin_track_controller_spec.rb7
-rw-r--r--spec/controllers/admin_user_controller_spec.rb10
-rw-r--r--spec/controllers/public_body_change_requests_controller_spec.rb10
-rw-r--r--spec/factories/incoming_messages.rb3
-rw-r--r--spec/factories/info_request_events.rb12
-rw-r--r--spec/integration/admin_spec.rb61
-rw-r--r--spec/integration/download_request_spec.rb8
-rw-r--r--spec/integration/errors_spec.rb2
-rw-r--r--spec/integration/view_request_spec.rb2
-rw-r--r--spec/mailers/request_mailer_spec.rb3
68 files changed, 1050 insertions, 793 deletions
diff --git a/app/controllers/admin_censor_rule_controller.rb b/app/controllers/admin_censor_rule_controller.rb
index 68ca57510..3387fd832 100644
--- a/app/controllers/admin_censor_rule_controller.rb
+++ b/app/controllers/admin_censor_rule_controller.rb
@@ -5,11 +5,15 @@
# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
class AdminCensorRuleController < AdminController
+
+ before_filter :set_editor, :only => [:create, :update]
+ before_filter :find_and_check_rule, :only => [:edit, :update, :destroy]
+
def new
- if params[:info_request_id]
- @info_request = InfoRequest.find(params[:info_request_id])
+ if params[:request_id]
+ @info_request = InfoRequest.find(params[:request_id])
@censor_rule = @info_request.censor_rules.build
- @form_url = admin_info_request_censor_rules_path(@info_request)
+ @form_url = admin_request_censor_rules_path(@info_request)
end
if params[:user_id]
@@ -17,18 +21,13 @@ class AdminCensorRuleController < AdminController
@censor_rule = @censor_user.censor_rules.build
@form_url = admin_user_censor_rules_path(@censor_user)
end
-
- @censor_rule ||= CensorRule.new
- @form_url ||= admin_rule_create_path
end
def create
- params[:censor_rule][:last_edit_editor] = admin_current_user
-
- if params[:info_request_id]
- @info_request = InfoRequest.find(params[:info_request_id])
+ if params[:request_id]
+ @info_request = InfoRequest.find(params[:request_id])
@censor_rule = @info_request.censor_rules.build(params[:censor_rule])
- @form_url = admin_info_request_censor_rules_path(@info_request)
+ @form_url = admin_request_censor_rules_path(@info_request)
end
if params[:user_id]
@@ -37,26 +36,16 @@ class AdminCensorRuleController < AdminController
@form_url = admin_user_censor_rules_path(@censor_user)
end
- @censor_rule ||= CensorRule.new(params[:censor_rule])
- @form_url ||= admin_rule_create_path
-
if @censor_rule.save
- if !@censor_rule.info_request.nil?
- expire_for_request(@censor_rule.info_request)
- end
-
- if !@censor_rule.user.nil?
- expire_requests_for_user(@censor_rule.user)
- end
flash[:notice] = 'CensorRule was successfully created.'
- if !@censor_rule.info_request.nil?
- redirect_to admin_request_show_url(@censor_rule.info_request)
- elsif !@censor_rule.user.nil?
- redirect_to admin_user_show_url(@censor_rule.user)
- else
- raise "internal error"
+ if @censor_rule.info_request
+ expire_for_request(@censor_rule.info_request)
+ redirect_to admin_request_url(@censor_rule.info_request)
+ elsif @censor_rule.user
+ expire_requests_for_user(@censor_rule.user)
+ redirect_to admin_user_url(@censor_rule.user)
end
else
render :action => 'new'
@@ -64,63 +53,55 @@ class AdminCensorRuleController < AdminController
end
def edit
- @censor_rule = CensorRule.find(params[:id])
end
def update
- params[:censor_rule][:last_edit_editor] = admin_current_user
- @censor_rule = CensorRule.find(params[:id])
-
if @censor_rule.update_attributes(params[:censor_rule])
- unless @censor_rule.info_request.nil?
- expire_for_request(@censor_rule.info_request)
- end
-
- unless @censor_rule.user.nil?
- expire_requests_for_user(@censor_rule.user)
- end
flash[:notice] = 'CensorRule was successfully updated.'
- if !@censor_rule.info_request.nil?
- redirect_to admin_request_show_url(@censor_rule.info_request)
- elsif !@censor_rule.user.nil?
- redirect_to admin_user_show_url(@censor_rule.user)
- else
- raise "internal error"
+ if @censor_rule.info_request
+ expire_for_request(@censor_rule.info_request)
+ redirect_to admin_request_url(@censor_rule.info_request)
+ elsif @censor_rule.user
+ expire_requests_for_user(@censor_rule.user)
+ redirect_to admin_user_url(@censor_rule.user)
end
+
else
render :action => 'edit'
end
end
def destroy
- @censor_rule = CensorRule.find(params[:censor_rule_id])
info_request = @censor_rule.info_request
user = @censor_rule.user
-
@censor_rule.destroy
- unless info_request.nil?
- expire_for_request(info_request)
- end
-
- unless user.nil?
- expire_requests_for_user(user)
- end
-
flash[:notice] = "CensorRule was successfully destroyed."
- if !info_request.nil?
- redirect_to admin_request_show_url(info_request)
- elsif !user.nil?
- redirect_to admin_user_show_url(user)
- else
- raise "internal error"
+ if info_request
+ expire_for_request(info_request)
+ redirect_to admin_request_url(info_request)
+ elsif user
+ expire_requests_for_user(user) if user
+ redirect_to admin_user_url(user)
end
+
end
private
+ def set_editor
+ params[:censor_rule][:last_edit_editor] = admin_current_user
+ end
+
+ def find_and_check_rule
+ @censor_rule = CensorRule.find(params[:id])
+ unless (@censor_rule.user || @censor_rule.info_request)
+ flash[:notice] = 'Only user and request censor rules can be edited'
+ redirect_to admin_general_index_path
+ end
+ end
end
diff --git a/app/controllers/admin_comment_controller.rb b/app/controllers/admin_comment_controller.rb
new file mode 100644
index 000000000..0aafb122a
--- /dev/null
+++ b/app/controllers/admin_comment_controller.rb
@@ -0,0 +1,36 @@
+# app/controllers/admin_comment_controller.rb:
+# Controller for editing comments from the admin interface.
+#
+# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
+# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
+
+class AdminCommentController < AdminController
+
+ def edit
+ @comment = Comment.find(params[:id])
+ end
+
+ def update
+ @comment = Comment.find(params[:id])
+
+ old_body = @comment.body
+ old_visible = @comment.visible
+ @comment.visible = params[:comment][:visible] == "true" ? true : false
+
+ if @comment.update_attributes(params[:comment])
+ @comment.info_request.log_event("edit_comment",
+ { :comment_id => @comment.id,
+ :editor => admin_current_user(),
+ :old_body => old_body,
+ :body => @comment.body,
+ :old_visible => old_visible,
+ :visible => @comment.visible,
+ })
+ flash[:notice] = 'Comment successfully updated.'
+ redirect_to admin_request_url(@comment.info_request)
+ else
+ render :action => 'edit'
+ end
+ end
+
+end
diff --git a/app/controllers/admin_incoming_message_controller.rb b/app/controllers/admin_incoming_message_controller.rb
index 6b50d0e36..bc653bf53 100644
--- a/app/controllers/admin_incoming_message_controller.rb
+++ b/app/controllers/admin_incoming_message_controller.rb
@@ -20,14 +20,14 @@ class AdminIncomingMessageController < AdminController
:prominence_reason => @incoming_message.prominence_reason)
expire_for_request(@incoming_message.info_request)
flash[:notice] = 'Incoming message successfully updated.'
- redirect_to admin_request_show_url(@incoming_message.info_request)
+ redirect_to admin_request_url(@incoming_message.info_request)
else
render :action => 'edit'
end
end
def destroy
- @incoming_message = IncomingMessage.find(params[:incoming_message_id])
+ @incoming_message = IncomingMessage.find(params[:id])
@info_request = @incoming_message.info_request
incoming_message_id = @incoming_message.id
@@ -37,11 +37,11 @@ class AdminIncomingMessageController < AdminController
# expire cached files
expire_for_request(@info_request)
flash[:notice] = 'Incoming message successfully destroyed.'
- redirect_to admin_request_show_url(@info_request)
+ redirect_to admin_request_url(@info_request)
end
def redeliver
- incoming_message = IncomingMessage.find(params[:redeliver_incoming_message_id])
+ incoming_message = IncomingMessage.find(params[:id])
message_ids = params[:url_title].split(",").each {|x| x.strip}
previous_request = incoming_message.info_request
destination_request = nil
@@ -54,7 +54,7 @@ class AdminIncomingMessageController < AdminController
end
if destination_request.nil?
flash[:error] = "Failed to find destination request '" + m + "'"
- return redirect_to admin_request_show_url(previous_request)
+ return redirect_to admin_request_url(previous_request)
end
raw_email_data = incoming_message.raw_email.data
@@ -74,7 +74,7 @@ class AdminIncomingMessageController < AdminController
expire_for_request(previous_request)
incoming_message.fully_destroy
end
- redirect_to admin_request_show_url(destination_request)
+ redirect_to admin_request_url(destination_request)
end
end
diff --git a/app/controllers/admin_info_request_event_controller.rb b/app/controllers/admin_info_request_event_controller.rb
new file mode 100644
index 000000000..17d147582
--- /dev/null
+++ b/app/controllers/admin_info_request_event_controller.rb
@@ -0,0 +1,24 @@
+# app/controllers/admin_info_request_event_controller.rb:
+# Controller for FOI request event manipulation from the admin interface.
+#
+# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
+# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
+
+class AdminInfoRequestEventController < AdminController
+
+ # used so due dates get fixed
+ def update
+ @info_request_event = InfoRequestEvent.find(params[:id])
+ if @info_request_event.event_type != 'response'
+ raise Exception("can only mark responses as requires clarification")
+ end
+ @info_request_event.described_state = 'waiting_clarification'
+ @info_request_event.calculated_state = 'waiting_clarification'
+ # TODO: deliberately don't update described_at so doesn't reenter search?
+ @info_request_event.save!
+
+ flash[:notice] = "Old response marked as having been a clarification"
+ redirect_to admin_request_url(@info_request_event.info_request)
+ end
+
+end
diff --git a/app/controllers/admin_outgoing_message_controller.rb b/app/controllers/admin_outgoing_message_controller.rb
index ec0981677..2ee811dc0 100644
--- a/app/controllers/admin_outgoing_message_controller.rb
+++ b/app/controllers/admin_outgoing_message_controller.rb
@@ -5,7 +5,7 @@ class AdminOutgoingMessageController < AdminController
end
def destroy
- @outgoing_message = OutgoingMessage.find(params[:outgoing_message_id])
+ @outgoing_message = OutgoingMessage.find(params[:id])
@info_request = @outgoing_message.info_request
outgoing_message_id = @outgoing_message.id
@@ -14,7 +14,7 @@ class AdminOutgoingMessageController < AdminController
{ :editor => admin_current_user(), :deleted_outgoing_message_id => outgoing_message_id })
flash[:notice] = 'Outgoing message successfully destroyed.'
- redirect_to admin_request_show_url(@info_request)
+ redirect_to admin_request_url(@info_request)
end
def update
@@ -38,10 +38,41 @@ class AdminOutgoingMessageController < AdminController
:prominence_reason => @outgoing_message.prominence_reason })
flash[:notice] = 'Outgoing message successfully updated.'
expire_for_request(@outgoing_message.info_request)
- redirect_to admin_request_show_url(@outgoing_message.info_request)
+ redirect_to admin_request_url(@outgoing_message.info_request)
else
render :action => 'edit'
end
end
+ def resend
+ @outgoing_message = OutgoingMessage.find(params[:id])
+ @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_url(@outgoing_message.info_request)
+ end
+
+
end
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index f7a80476c..cfb6f240d 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_body_controller.rb
@@ -5,69 +5,9 @@
# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
class AdminPublicBodyController < AdminController
- def index
- list
- render :action => 'list'
- end
-
- def _lookup_query_internal
- @locale = self.locale_from_params()
- underscore_locale = @locale.gsub '-', '_'
- I18n.with_locale(@locale) do
- @query = params[:query]
- if @query == ""
- @query = nil
- end
- @page = params[:page]
- if @page == ""
- @page = nil
- end
- @public_bodies = PublicBody.joins(:translations).where(@query.nil? ? "public_body_translations.locale = '#{underscore_locale}'" :
- ["(lower(public_body_translations.name) like lower('%'||?||'%') or
- lower(public_body_translations.short_name) like lower('%'||?||'%') or
- lower(public_body_translations.request_email) like lower('%'||?||'%' )) AND (public_body_translations.locale = '#{underscore_locale}')", @query, @query, @query]).paginate :order => "public_body_translations.name", :page => @page, :per_page => 100
- end
- @public_bodies_by_tag = PublicBody.find_by_tag(@query)
- end
- def list
- self._lookup_query_internal
- end
-
- def mass_tag_add
- self._lookup_query_internal
-
- if params[:new_tag] and params[:new_tag] != ""
- if params[:table_name] == 'exact'
- bodies = @public_bodies_by_tag
- elsif params[:table_name] == 'substring'
- bodies = @public_bodies
- else
- raise "Unknown table_name " + params[:table_name]
- end
- for body in bodies
- body.add_tag_if_not_already_present(params[:new_tag])
- end
- flash[:notice] = "Added tag to table of bodies."
- end
-
- redirect_to admin_body_list_url(:query => @query, :page => @page)
- end
-
- def missing_scheme
- # There might be a way to do this in ActiveRecord, but I can't find it
- @public_bodies = PublicBody.find_by_sql("
- SELECT a.id, a.name, a.url_name, COUNT(*) AS howmany
- FROM public_bodies a JOIN info_requests r ON a.id = r.public_body_id
- WHERE a.publication_scheme = ''
- GROUP BY a.id, a.name, a.url_name
- ORDER BY howmany DESC
- LIMIT 20
- ")
- @stats = {
- "total" => PublicBody.count,
- "entered" => PublicBody.count(:conditions => "publication_scheme != ''")
- }
+ def index
+ lookup_query
end
def show
@@ -111,7 +51,7 @@ class AdminPublicBodyController < AdminController
@change_request.send_response(params[:subject], response_text)
end
flash[:notice] = 'PublicBody was successfully created.'
- redirect_to admin_body_show_url(@public_body)
+ redirect_to admin_body_url(@public_body)
else
render :action => 'new'
end
@@ -147,7 +87,7 @@ class AdminPublicBodyController < AdminController
@change_request.send_response(params[:subject], params[:response])
end
flash[:notice] = 'PublicBody was successfully updated.'
- redirect_to admin_body_show_url(@public_body)
+ redirect_to admin_body_url(@public_body)
else
render :action => 'edit'
end
@@ -161,17 +101,53 @@ class AdminPublicBodyController < AdminController
if public_body.info_requests.size > 0
flash[:notice] = "There are requests associated with the authority, so can't destroy it"
- redirect_to admin_body_show_url(public_body)
+ redirect_to admin_body_url(public_body)
return
end
public_body.tag_string = ""
public_body.destroy
flash[:notice] = "PublicBody was successfully destroyed."
- redirect_to admin_body_list_url
+ redirect_to admin_bodies_url
end
end
+ def mass_tag_add
+ lookup_query
+
+ if params[:new_tag] and params[:new_tag] != ""
+ if params[:table_name] == 'exact'
+ bodies = @public_bodies_by_tag
+ elsif params[:table_name] == 'substring'
+ bodies = @public_bodies
+ else
+ raise "Unknown table_name " + params[:table_name]
+ end
+ for body in bodies
+ body.add_tag_if_not_already_present(params[:new_tag])
+ end
+ flash[:notice] = "Added tag to table of bodies."
+ end
+
+ redirect_to admin_bodies_url(:query => @query, :page => @page)
+ end
+
+ def missing_scheme
+ # There might be a way to do this in ActiveRecord, but I can't find it
+ @public_bodies = PublicBody.find_by_sql("
+ SELECT a.id, a.name, a.url_name, COUNT(*) AS howmany
+ FROM public_bodies a JOIN info_requests r ON a.id = r.public_body_id
+ WHERE a.publication_scheme = ''
+ GROUP BY a.id, a.name, a.url_name
+ ORDER BY howmany DESC
+ LIMIT 20
+ ")
+ @stats = {
+ "total" => PublicBody.count,
+ "entered" => PublicBody.count(:conditions => "publication_scheme != ''")
+ }
+ end
+
def import_csv
@notes = ""
@errors = ""
@@ -251,4 +227,24 @@ class AdminPublicBodyController < AdminController
return csv_contents
end
+ def lookup_query
+ @locale = self.locale_from_params()
+ underscore_locale = @locale.gsub '-', '_'
+ I18n.with_locale(@locale) do
+ @query = params[:query]
+ if @query == ""
+ @query = nil
+ end
+ @page = params[:page]
+ if @page == ""
+ @page = nil
+ end
+ @public_bodies = PublicBody.joins(:translations).where(@query.nil? ? "public_body_translations.locale = '#{underscore_locale}'" :
+ ["(lower(public_body_translations.name) like lower('%'||?||'%') or
+ lower(public_body_translations.short_name) like lower('%'||?||'%') or
+ lower(public_body_translations.request_email) like lower('%'||?||'%' )) AND (public_body_translations.locale = '#{underscore_locale}')", @query, @query, @query]).paginate :order => "public_body_translations.name", :page => @page, :per_page => 100
+ end
+ @public_bodies_by_tag = PublicBody.find_by_tag(@query)
+ end
+
end
diff --git a/app/controllers/admin_raw_email_controller.rb b/app/controllers/admin_raw_email_controller.rb
new file mode 100644
index 000000000..1b3ee2871
--- /dev/null
+++ b/app/controllers/admin_raw_email_controller.rb
@@ -0,0 +1,45 @@
+# app/controllers/admin_raw_email_controller.rb:
+# Controller for managing raw emails from the admin interface.
+#
+# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
+# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
+
+class AdminRawEmailController < AdminController
+
+ def show
+ @raw_email = RawEmail.find(params[:id])
+ respond_to do |format|
+ format.html do
+ # For the holding pen, try to guess where it should be ...
+ @holding_pen = false
+ if (@raw_email.incoming_message.info_request == InfoRequest.holding_pen_request && !@raw_email.incoming_message.empty_from_field?)
+ @holding_pen = true
+
+ # 1. Use domain of email to try and guess which public body it
+ # is associated with, so we can display that.
+ email = @raw_email.incoming_message.from_email
+ domain = PublicBody.extract_domain_from_email(email)
+
+ if domain.nil?
+ @public_bodies = []
+ else
+ @public_bodies = PublicBody.find(:all, :order => "name",
+ :conditions => [ "lower(request_email) like lower('%'||?||'%')", domain ])
+ end
+
+ # 2. Match the email address in the message without matching the hash
+ @info_requests = InfoRequest.guess_by_incoming_email(@raw_email.incoming_message)
+
+ # 3. Give a reason why it's in the holding pen
+ last_event = InfoRequestEvent.find_by_incoming_message_id(@raw_email.incoming_message.id)
+ @rejected_reason = last_event.params[:rejected_reason] || "unknown reason"
+ end
+ end
+ format.text do
+ response.content_type = 'message/rfc822'
+ render :text => @raw_email.data
+ end
+ end
+ end
+
+end
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index 7d2ac2f35..cbf7b9f4f 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -7,11 +7,6 @@
class AdminRequestController < AdminController
def index
- list
- render :action => 'list'
- end
-
- def list
@query = params[:query]
if @query
info_requests = InfoRequest.where(["lower(title) like lower('%'||?||'%')", @query])
@@ -34,36 +29,6 @@ class AdminRequestController < AdminController
:locals => vars_for_explanation)
end
- def resend
- @outgoing_message = OutgoingMessage.find(params[:outgoing_message_id])
- @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
-
def edit
@info_request = InfoRequest.find(params[:id])
end
@@ -107,13 +72,13 @@ class AdminRequestController < AdminController
# expire cached files
expire_for_request(@info_request)
flash[:notice] = 'Request successfully updated.'
- redirect_to admin_request_show_url(@info_request)
+ redirect_to admin_request_url(@info_request)
else
render :action => 'edit'
end
end
- def fully_destroy
+ def destroy
@info_request = InfoRequest.find(params[:id])
user = @info_request.user
@@ -124,36 +89,12 @@ class AdminRequestController < AdminController
expire_for_request(@info_request)
email = user.try(:email) ? user.email : 'This request is external so has no associated user'
flash[:notice] = "Request #{ url_title } has been completely destroyed. Email of user who made request: #{ email }"
- redirect_to admin_request_list_url
- end
-
- def edit_comment
- @comment = Comment.find(params[:id])
- end
-
- def update_comment
- @comment = Comment.find(params[:id])
-
- old_body = @comment.body
- old_visible = @comment.visible
- @comment.visible = params[:comment][:visible] == "true" ? true : false
-
- if @comment.update_attributes(params[:comment])
- @comment.info_request.log_event("edit_comment",
- { :comment_id => @comment.id, :editor => admin_current_user(),
- :old_body => old_body, :body => @comment.body,
- :old_visible => old_visible, :visible => @comment.visible,
- })
- flash[:notice] = 'Comment successfully updated.'
- redirect_to admin_request_show_url(@comment.info_request)
- else
- render :action => 'edit_comment'
- end
+ redirect_to admin_requests_url
end
# change user or public body of a request magically
- def move_request
- info_request = InfoRequest.find(params[:info_request_id])
+ def move
+ info_request = InfoRequest.find(params[:id])
if params[:commit] == 'Move request to user' && !params[:user_url_name].blank?
old_user = info_request.user
destination_user = User.find_by_url_name(params[:user_url_name])
@@ -171,7 +112,7 @@ class AdminRequestController < AdminController
info_request.reindex_request_events
flash[:notice] = "Message has been moved to new user"
end
- redirect_to admin_request_show_url(info_request)
+ 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])
@@ -190,10 +131,10 @@ class AdminRequestController < AdminController
flash[:notice] = "Request has been moved to new body"
end
- redirect_to admin_request_show_url(info_request)
+ redirect_to admin_request_url(info_request)
else
flash[:error] = "Please enter the user or authority to move the request to"
- redirect_to admin_request_show_url(info_request)
+ redirect_to admin_request_url(info_request)
end
end
@@ -217,7 +158,7 @@ class AdminRequestController < AdminController
if !info_request.public_body.is_foi_officer?(user)
flash[:notice] = user.email + " is not an email at the domain @" + info_request.public_body.foi_officer_domain_required + ", so won't be able to upload."
- redirect_to admin_request_show_url(info_request)
+ redirect_to admin_request_url(info_request)
return
end
@@ -230,60 +171,10 @@ class AdminRequestController < AdminController
url = confirm_url(:email_token => post_redirect.email_token)
flash[:notice] = ("Send \"#{name}\" &lt;<a href=\"mailto:#{email}\">#{email}</a>&gt; this URL: <a href=\"#{url}\">#{url}</a> - it will log them in and let them upload a response to this request.").html_safe
- redirect_to admin_request_show_url(info_request)
- end
-
- def show_raw_email
- @raw_email = RawEmail.find(params[:id])
- # For the holding pen, try to guess where it should be ...
- @holding_pen = false
- if (@raw_email.incoming_message.info_request == InfoRequest.holding_pen_request && !@raw_email.incoming_message.empty_from_field?)
- @holding_pen = true
-
- # 1. Use domain of email to try and guess which public body it
- # is associated with, so we can display that.
- email = @raw_email.incoming_message.from_email
- domain = PublicBody.extract_domain_from_email(email)
-
- if domain.nil?
- @public_bodies = []
- else
- @public_bodies = PublicBody.find(:all, :order => "name",
- :conditions => [ "lower(request_email) like lower('%'||?||'%')", domain ])
- end
-
- # 2. Match the email address in the message without matching the hash
- @info_requests = InfoRequest.guess_by_incoming_email(@raw_email.incoming_message)
-
- # 3. Give a reason why it's in the holding pen
- last_event = InfoRequestEvent.find_by_incoming_message_id(@raw_email.incoming_message.id)
- @rejected_reason = last_event.params[:rejected_reason] || "unknown reason"
- end
- end
-
- def download_raw_email
- @raw_email = RawEmail.find(params[:id])
-
- response.content_type = 'message/rfc822'
- render :text => @raw_email.data
- end
-
- # used so due dates get fixed
- def mark_event_as_clarification
- info_request_event = InfoRequestEvent.find(params[:info_request_event_id])
- if info_request_event.event_type != 'response'
- raise Exception("can only mark responses as requires clarification")
- end
- info_request_event.described_state = 'waiting_clarification'
- info_request_event.calculated_state = 'waiting_clarification'
- # TODO: deliberately don't update described_at so doesn't reenter search?
- info_request_event.save!
-
- flash[:notice] = "Old response marked as having been a clarification"
- redirect_to admin_request_show_url(info_request_event.info_request)
+ redirect_to admin_request_url(info_request)
end
- def hide_request
+ def hide
ActiveRecord::Base.transaction do
subject = params[:subject]
explanation = params[:explanation]
@@ -313,7 +204,7 @@ class AdminRequestController < AdminController
end
# expire cached files
expire_for_request(info_request)
- redirect_to admin_request_show_url(info_request)
+ redirect_to admin_request_url(info_request)
end
end
diff --git a/app/controllers/admin_track_controller.rb b/app/controllers/admin_track_controller.rb
index 085c9c6cc..63ee5c12e 100644
--- a/app/controllers/admin_track_controller.rb
+++ b/app/controllers/admin_track_controller.rb
@@ -5,7 +5,8 @@
# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
class AdminTrackController < AdminController
- def list
+
+ def index
@query = params[:query]
if @query
track_things = TrackThing.where(["lower(track_query) like lower('%'||?||'%')", @query])
@@ -13,7 +14,14 @@ class AdminTrackController < AdminController
track_things = TrackThing
end
@admin_tracks = track_things.paginate :order => "created_at desc", :page => params[:page], :per_page => 100
- @popular = ActiveRecord::Base.connection.select_all("select count(*) as count, title, info_request_id from track_things join info_requests on info_request_id = info_requests.id where info_request_id is not null group by info_request_id, title order by count desc limit 10;")
+ @popular = ActiveRecord::Base.connection.select_all("select count(*) as count, title, info_request_id from track_things join info_requests on info_request_id = info_requests.id where info_request_id is not null group by info_request_id, title order by count desc limit 10;")
+ end
+
+ def destroy
+ track_thing = TrackThing.find(params[:id].to_i)
+ track_thing.destroy
+ flash[:notice] = 'Track destroyed'
+ redirect_to admin_user_url(track_thing.tracking_user)
end
private
diff --git a/app/controllers/admin_user_controller.rb b/app/controllers/admin_user_controller.rb
index a6438e151..7ef461594 100644
--- a/app/controllers/admin_user_controller.rb
+++ b/app/controllers/admin_user_controller.rb
@@ -5,12 +5,8 @@
# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
class AdminUserController < AdminController
- def index
- list
- render :action => 'list'
- end
- def list
+ def index
@query = params[:query]
if @query
users = User.where(["lower(name) like lower('%'||?||'%') or
@@ -21,20 +17,11 @@ class AdminUserController < AdminController
@admin_users = users.paginate :order => "name", :page => params[:page], :per_page => 100
end
- def list_banned
- @banned_users = User.paginate :order => "name", :page => params[:page], :per_page => 100,
- :conditions => ["ban_text <> ''"]
- end
-
def show
# Don't use @user as that is any logged in user
@admin_user = User.find(params[:id])
end
- def show_bounce_message
- @admin_user = User.find(params[:id])
- end
-
def edit
@admin_user = User.find(params[:id])
end
@@ -53,17 +40,19 @@ class AdminUserController < AdminController
if @admin_user.valid?
@admin_user.save!
flash[:notice] = 'User successfully updated.'
- redirect_to admin_user_show_url(@admin_user)
+ redirect_to admin_user_url(@admin_user)
else
render :action => 'edit'
end
end
- def destroy_track
- track_thing = TrackThing.find(params[:track_id].to_i)
- track_thing.destroy
- flash[:notice] = 'Track destroyed'
- redirect_to admin_user_show_url(track_thing.tracking_user)
+ def banned
+ @banned_users = User.paginate :order => "name", :page => params[:page], :per_page => 100,
+ :conditions => ["ban_text <> ''"]
+ end
+
+ def show_bounce_message
+ @admin_user = User.find(params[:id])
end
def clear_bounce
@@ -71,7 +60,7 @@ class AdminUserController < AdminController
user.email_bounced_at = nil
user.email_bounce_message = ""
user.save!
- redirect_to admin_user_show_url(user)
+ redirect_to admin_user_url(user)
end
def login_as
@@ -87,16 +76,12 @@ class AdminUserController < AdminController
def clear_profile_photo
@admin_user = User.find(params[:id])
- if !request.post?
- raise "Can only clear profile photo from POST request"
- end
-
if @admin_user.profile_photo
@admin_user.profile_photo.destroy
end
flash[:notice] = "Profile photo cleared"
- redirect_to admin_user_show_url(@admin_user)
+ redirect_to admin_user_url(@admin_user)
end
def modify_comment_visibility
diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb
index 151e53758..d13fea79b 100644
--- a/app/helpers/admin_helper.rb
+++ b/app/helpers/admin_helper.rb
@@ -21,17 +21,17 @@ module AdminHelper
def request_both_links(info_request)
link_to(eye, request_path(info_request), :title => "view request on public website") + " " +
- link_to(info_request.title, admin_request_show_path(info_request), :title => "view full details")
+ link_to(info_request.title, admin_request_path(info_request), :title => "view full details")
end
def public_body_both_links(public_body)
link_to(eye, public_body_path(public_body), :title => "view authority on public website") + " " +
- link_to(h(public_body.name), admin_body_show_path(public_body), :title => "view full details")
+ link_to(h(public_body.name), admin_body_path(public_body), :title => "view full details")
end
def user_both_links(user)
link_to(eye, user_path(user), :title => "view user's page on public website") + " " +
- link_to(h(user.name), admin_user_show_path(user), :title => "view full details")
+ link_to(h(user.name), admin_user_path(user), :title => "view full details")
end
def comment_visibility(comment)
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb
index 3709469cf..44d6c6f5f 100755
--- a/app/helpers/link_to_helper.rb
+++ b/app/helpers/link_to_helper.rb
@@ -116,7 +116,7 @@ module LinkToHelper
if request.is_external?
external_text || (request.external_user_name || _("Anonymous user")) + " (external)"
else
- link_to(internal_text || request.user.name, admin_user_show_url(request.user))
+ link_to(internal_text || request.user.name, admin_user_url(request.user))
end
end
@@ -178,7 +178,7 @@ module LinkToHelper
end
def user_admin_link(user, name="admin", cls=nil)
- link_to name, admin_user_show_url(user), :class => cls
+ link_to name, admin_user_url(user), :class => cls
end
# Tracks. feed can be 'track' or 'feed'
diff --git a/app/mailers/request_mailer.rb b/app/mailers/request_mailer.rb
index 89b76fe97..c9decc6db 100644
--- a/app/mailers/request_mailer.rb
+++ b/app/mailers/request_mailer.rb
@@ -58,7 +58,7 @@ class RequestMailer < ApplicationMailer
user = set_by || info_request.user
@reported_by = user
@url = request_url(info_request)
- @admin_url = admin_request_show_url(info_request)
+ @admin_url = admin_request_url(info_request)
@info_request = info_request
@message = message
diff --git a/app/views/admin_censor_rule/_show.html.erb b/app/views/admin_censor_rule/_show.html.erb
index 46904b3b9..4b37d0cc9 100644
--- a/app/views/admin_censor_rule/_show.html.erb
+++ b/app/views/admin_censor_rule/_show.html.erb
@@ -15,7 +15,7 @@
<td><%=h censor_rule.send(column) %></td>
<% end %>
<td>
- <%= link_to "Edit", admin_rule_edit_path(censor_rule) %>
+ <%= link_to "Edit", edit_admin_censor_rule_path(censor_rule) %>
</td>
</tr>
<% end %>
@@ -25,7 +25,7 @@
<% end %>
<% if defined? info_request %>
- <%= link_to "New censor rule", new_admin_info_request_censor_rule_path(info_request), :class => "btn btn-info" %>
+ <%= link_to "New censor rule", new_admin_request_censor_rule_path(info_request), :class => "btn btn-info" %>
<span class="label label-info">for this request only</span>
<% end %>
diff --git a/app/views/admin_censor_rule/edit.html.erb b/app/views/admin_censor_rule/edit.html.erb
index 230446ed3..ff07987f2 100644
--- a/app/views/admin_censor_rule/edit.html.erb
+++ b/app/views/admin_censor_rule/edit.html.erb
@@ -2,15 +2,14 @@
<h1><%=@title%></h1>
-<%= form_tag admin_rule_update_path(@censor_rule), :class => "form form-horizontal" do %>
+<%= form_tag admin_censor_rule_path(@censor_rule), :method => 'put', :class => "form form-horizontal" do %>
<%= render :partial => 'form', :locals => { :info_request => @censor_rule.info_request, :user => @censor_rule.user } %>
<div class="form-actions">
<%= submit_tag 'Save', :accesskey => 's', :class => "btn btn-primary" %>
</div>
<% end %>
-<%= form_tag admin_rule_destroy_path(@censor_rule), :class => "form form-horizontal" do %>
- <%= hidden_field_tag(:censor_rule_id, @censor_rule.id) %>
+<%= form_tag admin_censor_rule_path(@censor_rule), :method => 'delete', :class => "form form-horizontal" do %>
<div class="form-actions">
Permanent! --&gt; <%= submit_tag "Destroy rule", :class => "btn btn-primary" %>
</div>
diff --git a/app/views/admin_censor_rule/new.html.erb b/app/views/admin_censor_rule/new.html.erb
index 26b3212be..ded31cff2 100644
--- a/app/views/admin_censor_rule/new.html.erb
+++ b/app/views/admin_censor_rule/new.html.erb
@@ -4,7 +4,6 @@
<%= form_for @censor_rule, :url => @form_url, :class => "form form-horizontal" do %>
<%= render :partial => 'form', :locals => { :info_request => @info_request, :user => @censor_user } %>
-
<div class="form-actions">
<%= submit_tag "Create", :class => "btn btn-primary" %>
</div>
diff --git a/app/views/admin_request/edit_comment.html.erb b/app/views/admin_comment/edit.html.erb
index 2cf49a4a8..e3cbd7472 100644
--- a/app/views/admin_request/edit_comment.html.erb
+++ b/app/views/admin_comment/edit.html.erb
@@ -2,12 +2,12 @@
<%= error_messages_for 'comment' %>
-<%= form_tag admin_request_update_comment_path(@comment) do %>
+<%= form_tag admin_comment_path(@comment), :method => 'put' do %>
<p><label for="comment_body">Body of annotation</label><br/>
<%= text_area 'comment', 'body', :rows => 10, :cols => 60 %></p>
- <p><label for="comment_visible">Visible</label>
+ <p><label for="comment_visible">Visible</label>
<%= select('comment', "visible", [["Yes – show comment",true],["No – hide comment",false]]) %>
</p>
@@ -16,7 +16,7 @@
<% end %>
<p>
-<%= link_to 'Show', admin_request_show_path(@comment.info_request) %> |
-<%= link_to 'List all', admin_request_list_path %>
+<%= link_to 'Show request', admin_request_path(@comment.info_request) %> |
+<%= link_to 'List all requests', admin_requests_path %>
</p>
diff --git a/app/views/admin_general/_admin_navbar.html.erb b/app/views/admin_general/_admin_navbar.html.erb
index 15a5e65fa..b6e01f049 100644
--- a/app/views/admin_general/_admin_navbar.html.erb
+++ b/app/views/admin_general/_admin_navbar.html.erb
@@ -12,13 +12,13 @@
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Authorities<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
- <li><%= link_to 'Authorities', admin_body_list_path %></li>
+ <li><%= link_to 'Authorities', admin_bodies_path %></li>
<li><%= link_to 'Categories', admin_categories_path %></li>
</ul>
</li>
- <li><%= link_to 'Requests', admin_request_list_path %></li>
- <li><%= link_to 'Users', admin_user_list_path %></li>
- <li><%= link_to 'Tracks', admin_track_list_path %></li>
+ <li><%= link_to 'Requests', admin_requests_path %></li>
+ <li><%= link_to 'Users', admin_users_path %></li>
+ <li><%= link_to 'Tracks', admin_tracks_path %></li>
<li><%= link_to 'Holidays', admin_holidays_path %></li>
<li><%= link_to 'Log out', signout_path %></li>
</ul>
diff --git a/app/views/admin_general/index.html.erb b/app/views/admin_general/index.html.erb
index ba9396ceb..ba0563bb6 100644
--- a/app/views/admin_general/index.html.erb
+++ b/app/views/admin_general/index.html.erb
@@ -37,9 +37,9 @@
<tr>
<td>
<% if message.get_body_for_quoting.strip.size == 0 %>
- <%= link_to "(no body)", admin_request_show_raw_email_path(message.raw_email_id) %>
+ <%= link_to "(no body)", admin_raw_email_path(message.raw_email_id) %>
<% else %>
- <%= link_to excerpt(message.get_body_for_quoting, "", :radius => 60), admin_request_show_raw_email_path(message.raw_email_id) %>
+ <%= link_to excerpt(message.get_body_for_quoting, "", :radius => 60), admin_raw_email_path(message.raw_email_id) %>
<% end %>
</td>
<td class="span2">
@@ -183,10 +183,10 @@
<div id="new-authorities" class="accordion-body collapse">
<% for @change_request in @new_body_requests %>
<%= render :partial => 'change_request_summary'%>
- <%= form_tag admin_change_request_update_path(@change_request), :class => "form form-horizontal" do %>
+ <%= form_tag admin_change_request_path(@change_request), :method => 'put', :class => "form form-horizontal" do %>
<%= submit_tag 'Close', :class => "btn btn-danger" %>
- <%= link_to("Close and respond", admin_change_request_edit_path(@change_request), :class => 'btn') %>
- <%= link_to("Add authority", admin_body_new_path(:change_request_id => @change_request.id), :class => 'btn btn-primary') %>
+ <%= link_to("Close and respond", edit_admin_change_request_path(@change_request), :class => 'btn') %>
+ <%= link_to("Add authority", new_admin_body_path(:change_request_id => @change_request.id), :class => 'btn btn-primary') %>
<% end %>
<% end %>
@@ -202,10 +202,10 @@
<div id="update-authorities" class="accordion-body collapse">
<% for @change_request in @body_update_requests %>
<%= render :partial => 'change_request_summary' %>
- <%= form_tag admin_change_request_update_path(@change_request), :class => "form form-horizontal" do %>
+ <%= form_tag admin_change_request_path(@change_request), :class => "form form-horizontal", :method => 'put' do %>
<%= submit_tag 'Close', :class => "btn btn-danger" %>
- <%= link_to("Close and respond", admin_change_request_edit_path(@change_request), :class => 'btn') %>
- <%= link_to("Make update", admin_body_edit_path(@change_request.public_body, :change_request_id => @change_request.id), :class => 'btn btn-primary') %>
+ <%= link_to("Close and respond", edit_admin_change_request_path(@change_request), :class => 'btn') %>
+ <%= link_to("Make update", edit_admin_body_path(@change_request.public_body, :change_request_id => @change_request.id), :class => 'btn btn-primary') %>
<% end %>
<% end %>
</div>
diff --git a/app/views/admin_request/_incoming_message_actions.html.erb b/app/views/admin_incoming_message/_actions.html.erb
index 22effcce5..4780ad910 100644
--- a/app/views/admin_request/_incoming_message_actions.html.erb
+++ b/app/views/admin_incoming_message/_actions.html.erb
@@ -1,6 +1,6 @@
<fieldset class="form-horizontal">
<legend>Actions</legend>
- <%= form_tag admin_incoming_redeliver_path, :class => "form form-inline" do %>
+ <%= form_tag redeliver_admin_incoming_message_path(incoming_message), :class => "form form-inline" do %>
<div class="control-group">
<label class="control-label" for="url_title_<%= incoming_message.id %>">Redeliver message to one or more other requests</label>
<div class="controls">
@@ -9,7 +9,6 @@
<% else %>
<%= text_field_tag 'url_title', "", { :size => 20, :id => "url_title_#{incoming_message.id}" } %>
<% end %>
- <%= hidden_field_tag 'redeliver_incoming_message_id', incoming_message.id, :id => nil %>
<%= submit_tag "Redeliver to another request", :class => "btn" %>
<p class="help-block"><code>id</code> or <code>url_title</code>; you can supply more than one, separated by commas</p>
</div>
@@ -18,7 +17,10 @@
<div class="control-group">
<label class="control-label">Generate FOI officer upload URL</label>
<div class="controls">
- <%= link_to 'Generate and take me there', admin_request_generate_upload_url_path(incoming_message.info_request, :incoming_message_id => incoming_message.id), :class => "btn" %>
+ <%= form_tag generate_upload_url_admin_request_path(incoming_message.info_request), :class => "form form-inline" do %>
+ <%= hidden_field_tag 'incoming_message_id', incoming_message.id, :id => nil %>
+ <%= submit_tag "Generate and take me there", :class => "btn" %>
+ <% end %>
</div>
</div>
@@ -29,7 +31,7 @@
</div>
</div>
- <%= form_tag admin_incoming_destroy_path, :class => "form form-inline" do %>
+ <%= form_tag admin_incoming_message_path(incoming_message), :method => 'delete', :class => "form form-inline" do %>
<div class="control-group">
<label class="control-label" for="destroy_message_<%= incoming_message.id %>">Destroy message</label>
<div class="controls">
@@ -44,7 +46,7 @@
<div class="control-group">
<label class="control-label">Inspect email</label>
<div class="controls">
- <%= link_to "View raw email", admin_request_show_raw_email_path(incoming_message.raw_email_id), :class => "btn" %>
+ <%= link_to "View raw email", admin_raw_email_path(incoming_message.raw_email_id), :class => "btn" %>
</div>
</div>
<% end %>
diff --git a/app/views/admin_incoming_message/edit.html.erb b/app/views/admin_incoming_message/edit.html.erb
index 1088edcab..5e172af76 100644
--- a/app/views/admin_incoming_message/edit.html.erb
+++ b/app/views/admin_incoming_message/edit.html.erb
@@ -1,8 +1,8 @@
<%= render :partial => 'intro', :locals => {:incoming_message => @incoming_message } %>
-<%= render :partial => 'admin_request/incoming_message_actions', :locals => { :incoming_message => @incoming_message } %>
+<%= render :partial => 'actions', :locals => { :incoming_message => @incoming_message } %>
<fieldset class="form-horizontal">
<legend>Prominence</legend>
- <%= form_tag admin_incoming_update_path(@incoming_message), :class => "form form-inline" do %>
+ <%= form_tag admin_incoming_message_path(@incoming_message), :method => 'put', :class => "form form-inline" do %>
<div class="control-group">
<label class="control-label" for="incoming_message_prominence"> Prominence</label>
diff --git a/app/views/admin_outgoing_message/edit.html.erb b/app/views/admin_outgoing_message/edit.html.erb
index d5f5f43bf..d84a5ba66 100644
--- a/app/views/admin_outgoing_message/edit.html.erb
+++ b/app/views/admin_outgoing_message/edit.html.erb
@@ -2,7 +2,7 @@
<%= error_messages_for 'outgoing_message' %>
-<%= form_tag admin_outgoing_update_path(@outgoing_message) do %>
+<%= form_tag admin_outgoing_message_path(@outgoing_message), :method => 'put' do %>
<div class="control-group">
<label class="control-label" for="outgoing_message_prominence"> Prominence</label>
<div class="controls">
@@ -36,13 +36,12 @@
<% end %>
<p>
-<%= link_to 'Show', admin_request_show_path(@outgoing_message.info_request) %> |
-<%= link_to 'List all', admin_request_list_path %>
+<%= link_to 'Show', admin_request_path(@outgoing_message.info_request) %> |
+<%= link_to 'List all', admin_requests_path %>
</p>
-<%= form_tag admin_outgoing_destroy_path do %>
+<%= form_tag admin_outgoing_message_path(@outgoing_message), :method => 'delete' do %>
<div>
- <%= hidden_field_tag 'outgoing_message_id', @outgoing_message.id %>
<%= submit_tag "Destroy outgoing message", :class => "btn btn-danger", :confirm => "This is permanent! Are you sure?" %>
</div>
<% end %>
diff --git a/app/views/admin_public_body/_one_list.html.erb b/app/views/admin_public_body/_one_list.html.erb
index 8f1d719ec..8d891d16c 100644
--- a/app/views/admin_public_body/_one_list.html.erb
+++ b/app/views/admin_public_body/_one_list.html.erb
@@ -4,7 +4,7 @@
<div class="accordion-heading accordion-toggle row">
<span class="item-title span6">
<a href="#body_<%=public_body.id%>" data-toggle="collapse" data-parent="requests"><%= chevron_right %></a>
- <%= link_to(public_body.name, admin_body_show_path(public_body), :title => "view full details")%>
+ <%= link_to(public_body.name, admin_body_path(public_body), :title => "view full details")%>
</span>
<span class="item-metadata span6">
<%= render :partial => 'tags', :locals => { :body => public_body} %>
@@ -31,7 +31,7 @@
<% end %>
</div>
-<%= form_tag(admin_body_mass_tag_add_url, :method => "post", :class => "form form-inline" ) do %>
+<%= form_tag(mass_tag_add_admin_bodies_path, :method => "post", :class => "form form-inline" ) do %>
<p>
<%= text_field_tag 'new_tag', params[:new_tag], { :size => 15, :id => "mass_add_tag_new_tag_" + table_name } %>
<%= hidden_field_tag(:query, params[:query], { :id => "mass_add_tag_query_" + table_name } ) %>
diff --git a/app/views/admin_public_body/edit.html.erb b/app/views/admin_public_body/edit.html.erb
index 11b7eec22..dcafbd270 100644
--- a/app/views/admin_public_body/edit.html.erb
+++ b/app/views/admin_public_body/edit.html.erb
@@ -3,7 +3,7 @@
<div class="row">
<div class="span8">
<div id="public_body_form">
- <%= form_for @public_body, :url => admin_body_update_path(@public_body), :html => { :class => "form form-horizontal" } do |f| %>
+ <%= form_for @public_body, :url => admin_body_path(@public_body), :method => 'put', :html => { :class => "form form-horizontal" } do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<div class="form-actions">
<%= f.submit 'Save', :accesskey => 's', :class => "btn btn-success" %></p>
@@ -13,15 +13,14 @@
<div class="row">
<div class="span8">
<div class="well">
- <%= link_to 'Show', admin_body_show_path(@public_body), :class => "btn" %>
- <%= link_to 'List all', admin_body_list_path, :class => "btn" %>
+ <%= link_to 'Show', admin_bodies_path(@public_body), :class => "btn" %>
+ <%= link_to 'List all', admin_bodies_path, :class => "btn" %>
</div>
</div>
</div>
<% if @public_body.info_requests.empty? %>
- <%= form_tag(admin_body_destroy_path(@public_body), :class => "form form-inline") do %>
- <%= hidden_field_tag(:public_body_id, { :value => @public_body.id } ) %>
+ <%= form_tag(admin_body_path(@public_body), :class => "form form-inline", :method => 'delete') do %>
<%= submit_tag _("Destroy {{name}}", :name => @public_body.name), :class => "btn btn-danger" %> (this is permanent!)
<% end %>
<% end %>
diff --git a/app/views/admin_public_body/list.html.erb b/app/views/admin_public_body/index.html.erb
index 3d7d9c4cd..861593bee 100644
--- a/app/views/admin_public_body/list.html.erb
+++ b/app/views/admin_public_body/index.html.erb
@@ -8,10 +8,10 @@
<div class="btn-toolbar">
<div class="btn-group">
- <%= link_to 'New public authority', admin_body_new_path, :class => "btn btn-primary" %>
+ <%= link_to 'New public authority', new_admin_body_path, :class => "btn btn-primary" %>
</div>
<div class="btn-group">
- <%= link_to 'Import from CSV file', admin_body_import_csv_path, :class => "btn btn-warning" %>
+ <%= link_to 'Import from CSV file', import_csv_admin_bodies_path, :class => "btn btn-warning" %>
</div>
</div>
@@ -19,7 +19,7 @@
<%= text_field_tag 'query', params[:query], { :size => 30, :class => "input-large search-query" } %>
<%= submit_tag "Search", :class => "btn" %>
<% if !@query.nil? %>
- <%= link_to 'Show all', admin_body_list_path, :class => "btn" %>
+ <%= link_to 'Show all', admin_bodies_path, :class => "btn" %>
<% end %><br>
(substring search in names and emails; exact match of tags)
<% end %>
diff --git a/app/views/admin_public_body/new.html.erb b/app/views/admin_public_body/new.html.erb
index 24b27d7af..69b1f8503 100644
--- a/app/views/admin_public_body/new.html.erb
+++ b/app/views/admin_public_body/new.html.erb
@@ -4,7 +4,7 @@
<div class="row">
<div class="span8">
<div id="public_body_form">
- <%= form_for @public_body, :as => :public_body, :url => admin_body_create_path, :html => {:class => "form form-horizontal"} do |f| %>
+ <%= form_for @public_body, :as => :public_body, :url => admin_bodies_path, :html => {:class => "form form-horizontal"} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
@@ -14,7 +14,7 @@
<% end %>
<div class="row">
<div class="span8 well">
- <%= link_to 'List all', admin_body_list_path, :class => "btn" %>
+ <%= link_to 'List all', admin_bodies_path, :class => "btn" %>
</div>
</div>
</div>
diff --git a/app/views/admin_public_body/show.html.erb b/app/views/admin_public_body/show.html.erb
index f8161db26..40f341a22 100644
--- a/app/views/admin_public_body/show.html.erb
+++ b/app/views/admin_public_body/show.html.erb
@@ -45,7 +45,7 @@
</tr>
</tbody>
</table>
-<%= link_to _("Edit"), admin_body_edit_path(@public_body), :class => "btn btn-primary" %>
+<%= link_to _("Edit"), edit_admin_body_path(@public_body), :class => "btn btn-primary" %>
<% unless @public_body.url_name.nil? %>
<%=link_to _("Public page"), public_body_path(@public_body), :class => "btn" %>
<% else %>
diff --git a/app/views/admin_public_body_change_requests/edit.html.erb b/app/views/admin_public_body_change_requests/edit.html.erb
index cc9c5b5d9..aaf457084 100644
--- a/app/views/admin_public_body_change_requests/edit.html.erb
+++ b/app/views/admin_public_body_change_requests/edit.html.erb
@@ -1,6 +1,6 @@
<h1><%=@title%></h1>
-<%= form_tag admin_change_request_update_path(@change_request), :class => "form form-horizontal" do %>
+<%= form_tag admin_change_request_path(@change_request), :method => 'put', :class => "form form-horizontal" do %>
<%= render :partial => 'admin_public_body_change_requests/response'%>
<div class="form-actions">
<%= submit_tag 'Close', :accesskey => 'c', :class => "btn btn-primary" %>
diff --git a/app/views/admin_request/show_raw_email.html.erb b/app/views/admin_raw_email/show.html.erb
index da22b6069..f88b00ef0 100644
--- a/app/views/admin_request/show_raw_email.html.erb
+++ b/app/views/admin_raw_email/show.html.erb
@@ -31,7 +31,7 @@
<tr>
<td><strong>Authority:</strong></td>
<td>
- <%= link_to(info_request.public_body.name, admin_body_show_path(info_request.public_body)) %>
+ <%= link_to(info_request.public_body.name, admin_body_path(info_request.public_body)) %>
</td>
</tr>
<tr>
@@ -52,12 +52,12 @@
</p>
<div>
- <%= render :partial => 'incoming_message_actions', :locals => { :incoming_message => @raw_email.incoming_message } %>
+ <%= render :partial => 'admin_incoming_message/actions', :locals => { :incoming_message => @raw_email.incoming_message } %>
</div>
<h2>Raw email</h2>
-<p><%= link_to "Download", admin_request_download_raw_email_path(@raw_email) %></p>
+<p><%= link_to "Download", admin_raw_email_path(@raw_email, :format => 'txt') %></p>
<pre><%=h(@raw_email.data).gsub(/\n/, '<br>').html_safe %></pre>
diff --git a/app/views/admin_request/_some_annotations.html.erb b/app/views/admin_request/_some_annotations.html.erb
index 7adcdc5bb..de470d26b 100644
--- a/app/views/admin_request/_some_annotations.html.erb
+++ b/app/views/admin_request/_some_annotations.html.erb
@@ -1,20 +1,20 @@
<% if comments.any? %>
- <%= form_tag admin_user_modify_comment_visibility_path do %>
+ <%= form_tag modify_comment_visibility_admin_users_path do %>
<div class="accordion" id="comments">
<% comments.each do |comment| %>
<div class="accordion-group">
<div class="accordion-heading">
<%= check_box_tag 'comment_ids[]', comment.id %>
-
+
<a href="#comment_<%= comment.id %>" data-toggle="collapse" data-parent="#comments"><%= chevron_right %></a>
-
- <%= link_to admin_request_edit_comment_path(comment) do %>
+
+ <%= link_to edit_admin_comment_path(comment) do %>
#<%= comment.id %>
--
<%= h(comment.user.name) %>
<%= admin_value(comment.created_at) %>
<% end %>
-
+
<%= comment_visibility(comment) %>
<blockquote class="incoming-message">
@@ -58,4 +58,4 @@
<% end %>
<% else %>
<p>None yet.</p>
-<% end %>
+<% end %>
diff --git a/app/views/admin_request/_some_requests.html.erb b/app/views/admin_request/_some_requests.html.erb
index cff94956d..9a39cd0c0 100644
--- a/app/views/admin_request/_some_requests.html.erb
+++ b/app/views/admin_request/_some_requests.html.erb
@@ -4,10 +4,10 @@
<div class="accordion-heading accordion-toggle row">
<span class="item-title span6">
<a href="#request_<%=info_request.id%>" data-toggle="collapse" data-parent="requests"><%= chevron_right %></a>
- <%= link_to(info_request.title, admin_request_show_path(info_request), :title => "view full details") %>
+ <%= link_to(info_request.title, admin_request_path(info_request), :title => "view full details") %>
</span>
<span class="item-metadata span6">
- <%= user_admin_link_for_request(info_request) %> <%= arrow_right %> <%= link_to("#{info_request.public_body.name}", admin_body_show_path(info_request.public_body)) %>, <%= time_ago_in_words(info_request.updated_at) %> ago
+ <%= user_admin_link_for_request(info_request) %> <%= arrow_right %> <%= link_to("#{info_request.public_body.name}", admin_body_path(info_request.public_body)) %>, <%= time_ago_in_words(info_request.updated_at) %> ago
</span>
</div>
<div id="request_<%=info_request.id%>" class="item-detail accordion-body collapse row">
diff --git a/app/views/admin_request/edit.html.erb b/app/views/admin_request/edit.html.erb
index 552b31bbb..db0b54655 100644
--- a/app/views/admin_request/edit.html.erb
+++ b/app/views/admin_request/edit.html.erb
@@ -2,7 +2,7 @@
<%= error_messages_for 'info_request' %>
-<%= form_tag admin_request_update_path(@info_request) do %>
+<%= form_tag admin_request_path(@info_request), :method => :put do %>
<p><label for="info_request_title"><strong>Title</strong></label> (warning: editing this will break URLs right now)<br/>
<%= text_field 'info_request', 'title', :size => 50 %></p>
@@ -43,15 +43,15 @@
<% end %>
<p>
-<%= link_to 'Show', admin_request_show_path(@info_request) %> |
-<%= link_to 'List all', admin_request_list_path %>
+<%= link_to 'Show', admin_request_path(@info_request) %> |
+<%= link_to 'List all', admin_requests_path %>
</p>
<hr>
<div class="well">
-<%= form_tag admin_request_destroy_path(@info_request) do %>
+<%= form_tag admin_request_path(@info_request), :method => :delete do %>
<p>
<strong>This is permanent and irreversible!</strong> <%= submit_tag 'Destroy request entirely', :class => 'btn btn-danger' %>
<br>Use it mainly if someone posts private information, e.g. made a Data Protection request. It
diff --git a/app/views/admin_request/list.html.erb b/app/views/admin_request/index.html.erb
index 2bd3e3326..2bd3e3326 100644
--- a/app/views/admin_request/list.html.erb
+++ b/app/views/admin_request/index.html.erb
diff --git a/app/views/admin_request/show.html.erb b/app/views/admin_request/show.html.erb
index 9c04badeb..dfb911ea7 100644
--- a/app/views/admin_request/show.html.erb
+++ b/app/views/admin_request/show.html.erb
@@ -2,8 +2,7 @@
<h1><%=@title%></h1>
-<%= form_tag admin_request_move_request_path, { :class => "form form-horizontal" } do %>
- <%= hidden_field_tag 'info_request_id', @info_request.id %>
+<%= form_tag move_admin_request_path(@info_request), { :class => "form form-horizontal" } do %>
<div class="accordion" id="info_request">
<div class="accordion-group">
<div class="accordion-heading">
@@ -16,7 +15,7 @@
<thead>
<tr>
<td colspan="2">
- <%= link_to 'Edit metadata', admin_request_edit_path(@info_request), :class => "btn" %>
+ <%= link_to 'Edit metadata', edit_admin_request_path(@info_request), :class => "btn" %>
</td>
</tr>
</thead>
@@ -101,7 +100,7 @@
<tfoot>
<tr>
<td colspan="2">
- <%= link_to 'Edit metadata', admin_request_edit_path(@info_request), :class => "btn" %>
+ <%= link_to 'Edit metadata', edit_admin_request_path(@info_request), :class => "btn" %>
</td>
</tr>
</tfoot>
@@ -117,11 +116,13 @@
FOI officer upload URL
</label>
<div class="controls">
- <%= link_to 'Generate URL', admin_request_generate_upload_url_path(@info_request), :class => "btn" %>
+ <%= form_tag generate_upload_url_admin_request_path(@info_request), :class => "form form-inline" do %>
+ <%= submit_tag "Generate URL", :class => "btn" %>
+ <% end %>
<p class="help-block">(see also option to generate URLs for individual incoming messages below)</p>
</div>
</div>
- <%= form_tag admin_request_hide_path(@info_request), :class => "form form-inline", :id => "hide_request_form", 'data-info-request-id' => @info_request.id.to_s do %>
+ <%= form_tag hide_admin_request_path(@info_request), :class => "form form-inline", :id => "hide_request_form", 'data-info-request-id' => @info_request.id.to_s do %>
<div class="control-group">
<% if @info_request.is_external? %>
<label class="control-label">Hide the request:</label>
@@ -191,8 +192,7 @@
<tr>
<td>
<% if info_request_event.described_state != 'waiting_clarification' and info_request_event.event_type == 'response' %>
- <%= form_tag admin_request_clarification_path, :class => "form form-inline admin-table-form admin-inline-form" do %>
- <%= hidden_field_tag 'info_request_event_id', info_request_event.id, :id => nil %>
+ <%= form_tag admin_info_request_event_path(info_request_event), :method => 'put', :class => "form form-inline admin-table-form admin-inline-form" do %>
<%= submit_tag "Was clarification request", :class => "btn btn-mini btn-primary" %>
<% end %>
<% end %>
@@ -233,7 +233,7 @@
<div class="accordion-group">
<div class="accordion-heading">
<a href="#outgoing_<%=outgoing_message.id%>" data-toggle="collapse" data-parent="#outgoing_messages"><%= chevron_right %></a>
- <%= link_to admin_outgoing_edit_path(outgoing_message) do %>
+ <%= link_to edit_admin_outgoing_message_path(outgoing_message) do %>
#<%= outgoing_message.id %> -- <%= outgoing_message.status.humanize %> <%= outgoing_message.message_type.humanize %>
<% end %>
<blockquote>
@@ -245,8 +245,7 @@
<tbody>
<tr>
<td colspan="2">
- <%= form_tag admin_request_resend_path, :class => "admin-table-form" do %>
- <%= hidden_field_tag 'outgoing_message_id', outgoing_message.id %>
+ <%= form_tag resend_admin_outgoing_message_path(outgoing_message), :class => "admin-table-form" do %>
<%= submit_tag "Resend", :class => "btn" %>
<% end %>
</td>
@@ -279,7 +278,7 @@
<div class="accordion-group">
<div class="accordion-heading">
<a href="#incoming_<%=incoming_message.id%>" data-toggle="collapse" data-parent="#incoming_messages"><%= chevron_right %></a>
- <%= link_to admin_incoming_edit_path(incoming_message) do %>
+ <%= link_to edit_admin_incoming_message_path(incoming_message) do %>
<%=incoming_message.id%>
--
<%= h(incoming_message.mail_from) %>
@@ -296,7 +295,7 @@
<thead>
<tr>
<td colspan="2" class="well">
- <%= render :partial => 'incoming_message_actions', :locals => { :incoming_message => incoming_message } %>
+ <%= render :partial => 'admin_incoming_message/actions', :locals => { :incoming_message => incoming_message } %>
</td>
</tr>
</thead>
diff --git a/app/views/admin_track/_some_tracks.html.erb b/app/views/admin_track/_some_tracks.html.erb
index e9facfb5d..c17350e4b 100644
--- a/app/views/admin_track/_some_tracks.html.erb
+++ b/app/views/admin_track/_some_tracks.html.erb
@@ -32,9 +32,8 @@
<% if include_destroy %>
<tr>
<td colspan="2">
- <%= form_tag admin_user_destroy_track_path, :class => "form form-inline admin-table-form" do %>
+ <%= form_tag admin_track_path(track_thing), :method => 'delete', :class => "form form-inline admin-table-form" do %>
<div>
- <%= hidden_field_tag 'track_id', track_thing.id %>
<%= submit_tag "Destroy track", :class => "btn btn-warning" %>
</div>
<% end %>
diff --git a/app/views/admin_track/list.html.erb b/app/views/admin_track/index.html.erb
index 5e967a926..2b1dc5737 100644
--- a/app/views/admin_track/list.html.erb
+++ b/app/views/admin_track/index.html.erb
@@ -14,7 +14,7 @@
<h2>Current top tracks:</h2>
<ol>
<% for row in @popular %>
- <li><%= link_to row['title'], admin_request_show_path(row['info_request_id']) %> (<%= row['count'] %> people following)</li>
+ <li><%= link_to row['title'], admin_request_path(row['info_request_id']) %> (<%= row['count'] %> people following)</li>
<% end %>
</ol>
diff --git a/app/views/admin_user/_form.html.erb b/app/views/admin_user/_form.html.erb
index f1edc0927..01273a657 100644
--- a/app/views/admin_user/_form.html.erb
+++ b/app/views/admin_user/_form.html.erb
@@ -41,7 +41,7 @@
user from filing new requests, making annotations or messaging other users;
the text is shown in public on the user's page and when they try to do a
forbidden action; write in the second person (you); see
- <%= link_to 'banned users', admin_user_list_banned_path %> for examples</small>
+ <%= link_to 'banned users', banned_admin_users_path %> for examples</small>
</div>
</div>
</div>
diff --git a/app/views/admin_user/_user_table.html.erb b/app/views/admin_user/_user_table.html.erb
index 57066bf3f..4fd90d5c6 100644
--- a/app/views/admin_user/_user_table.html.erb
+++ b/app/views/admin_user/_user_table.html.erb
@@ -7,7 +7,7 @@
<% if user.admin_level == "super" %>
<span class="label">superuser</span>
<% end %>
- <%= link_to("#{h(user.name)}", admin_user_show_path(user))%>
+ <%= link_to("#{h(user.name)}", admin_user_path(user))%>
<%= link_to("(#{h(user.email)})", "mailto:#{h(user.email)}")%>
</span>
<span class="item-metadata">
diff --git a/app/views/admin_user/list_banned.html.erb b/app/views/admin_user/banned.html.erb
index e535415e6..ee17d9899 100644
--- a/app/views/admin_user/list_banned.html.erb
+++ b/app/views/admin_user/banned.html.erb
@@ -2,7 +2,7 @@
<h1><%=@title%></h1>
-<p><%= link_to 'List all', admin_user_list_path %></p>
+<p><%= link_to 'List all', admin_users_path %></p>
<%= render :partial => 'user_table', :locals => { :users => @banned_users, :banned_column => true } %>
diff --git a/app/views/admin_user/edit.html.erb b/app/views/admin_user/edit.html.erb
index e641a13d6..ed1fb6e08 100644
--- a/app/views/admin_user/edit.html.erb
+++ b/app/views/admin_user/edit.html.erb
@@ -1,11 +1,11 @@
<h1><%=@title%></h1>
-<%= form_tag admin_user_update_path(@admin_user), :class => "form form-horizontal" do %>
+<%= form_tag admin_user_path(@admin_user), :method => 'put', :class => "form form-horizontal" do %>
<%= render :partial => 'form' %>
<div class="form-actions">
<%= submit_tag 'Save', :accesskey => 's', :class => "btn btn-primary" %>
</div>
<% end %>
-<%= link_to 'Show', admin_user_show_path(@admin_user), :class => "btn" %>
-<%= link_to 'List all', admin_user_list_path, :class => "btn" %>
+<%= link_to 'Show', admin_user_path(@admin_user), :class => "btn" %>
+<%= link_to 'List all', admin_users_path, :class => "btn" %>
diff --git a/app/views/admin_user/list.html.erb b/app/views/admin_user/index.html.erb
index b1238f87a..cfb34fd7b 100644
--- a/app/views/admin_user/list.html.erb
+++ b/app/views/admin_user/index.html.erb
@@ -5,7 +5,7 @@
<%= form_tag({}, :method => "get", :class => "form form-search") do %>
<%= text_field_tag 'query', params[:query], { :size => 30, :class => "input-large search-query"} %>
<%= submit_tag "Search", :class => "btn" %> (substring search, names and emails)
- <%= link_to 'Banned users', admin_user_list_banned_path, :class => "btn btn-info" %>
+ <%= link_to 'Banned users', banned_admin_users_path, :class => "btn btn-info" %>
<% end %>
<%= render :partial => 'user_table', :locals => { :users => @admin_users, :banned_column => false } %>
diff --git a/app/views/admin_user/show.html.erb b/app/views/admin_user/show.html.erb
index 6d12aeff5..1e7d885c5 100644
--- a/app/views/admin_user/show.html.erb
+++ b/app/views/admin_user/show.html.erb
@@ -4,7 +4,7 @@
<% if @admin_user.profile_photo %>
<div class="user_photo_on_admin">
- <%= form_tag admin_clear_profile_photo_path(@admin_user), :multipart => true, :class => "form" do %>
+ <%= form_tag clear_profile_photo_admin_user_path(@admin_user), :multipart => true, :class => "form" do %>
<img src="<%= get_profile_photo_url(:url_name => @admin_user.url_name) %>">
<br>
<%= submit_tag "Clear photo", :class => "btn btn-info" %>
@@ -32,13 +32,13 @@
<%=link_to @admin_user.email, "mailto:#{h @admin_user.email}"%>
<% elsif column_name == 'email_bounce_message' %>
<% unless @admin_user.email_bounce_message.empty? %>
- <%= link_to _("See bounce message"), admin_user_show_bounce_path(@admin_user.id) %>
+ <%= link_to _("See bounce message"), show_bounce_message_admin_user_path(@admin_user) %>
<% end %>
<% else %>
<%=h admin_value(value)%>
<% end %>
<% if column_name == 'email_bounced_at' && !@admin_user.email_bounced_at.nil? %>
- <%= form_tag admin_user_clear_bounce_path(@admin_user), :class => "form form-inline" do %>
+ <%= form_tag clear_bounce_admin_user_path(@admin_user), :class => "form form-inline" do %>
<input type="submit" name="action" value="Clear bounce" class="btn btn-info">
<% end %>
<% end %>
@@ -48,11 +48,13 @@
</tbody>
</table>
-
-<%= link_to 'Edit', admin_user_edit_path(@admin_user), :class => "btn btn-primary" %>
+<div class="btn-toolbar">
+<%= link_to 'Edit', edit_admin_user_path(@admin_user), :class => "btn btn-primary" %>
<%= link_to 'Public page', user_path(@admin_user), :class => "btn" %>
-<%= link_to "Log in as #{@admin_user.name} (also confirms their email)", admin_user_login_as_path(@admin_user), :class => "btn btn-info" %>
-
+</div>
+<%= form_tag login_as_admin_user_path(@admin_user), :class => "form form-horizontal" do %>
+ <%= submit_tag "Log in as #{@admin_user.name} (also confirms their email)", :class => "btn btn-info" %>
+<% end %>
<hr>
<h2>Track things</h2>
diff --git a/app/views/comment/_single_comment.html.erb b/app/views/comment/_single_comment.html.erb
index cdcb3b85f..07017dabf 100644
--- a/app/views/comment/_single_comment.html.erb
+++ b/app/views/comment/_single_comment.html.erb
@@ -17,7 +17,7 @@
<p class="event_actions">
<% if !comment.id.nil? %>
<% if !@user.nil? && @user.admin_page_links? %>
- <%= link_to "Admin", admin_request_edit_comment_path(comment) %> |
+ <%= link_to "Admin", edit_admin_comment_path(comment) %> |
<% end %>
<%= link_to "Link to this", comment_path(comment), :class => "link_to_this" %>
<!-- | <%= link_to _('Report abuse'), comment_path(comment) %> -->
diff --git a/app/views/contact_mailer/add_public_body.text.erb b/app/views/contact_mailer/add_public_body.text.erb
index 5baa1fa1a..306a70432 100644
--- a/app/views/contact_mailer/add_public_body.text.erb
+++ b/app/views/contact_mailer/add_public_body.text.erb
@@ -13,7 +13,7 @@
<%= @change_request.notes %>
<%= _('Add the authority:') %>
-<%= admin_body_new_url(:change_request_id => @change_request.id, :only_path => false ) %>
+<%= new_admin_body_url(:change_request_id => @change_request.id, :only_path => false ) %>
<%= _('Close the request and respond:') %>
-<%= admin_change_request_edit_url(:id => @change_request.id, :only_path => false ) %>
+<%= edit_admin_change_request_url(@change_request, :only_path => false ) %>
diff --git a/app/views/contact_mailer/update_public_body_email.text.erb b/app/views/contact_mailer/update_public_body_email.text.erb
index 7d5a3dae0..e849463d0 100644
--- a/app/views/contact_mailer/update_public_body_email.text.erb
+++ b/app/views/contact_mailer/update_public_body_email.text.erb
@@ -10,7 +10,7 @@
<%= @change_request.notes %>
<%= _('Update the address:') %>
-<%= admin_body_edit_path(@change_request.public_body, :change_request_id => @change_request.id, :only_path => false) %>
+<%= edit_admin_body_path(@change_request.public_body, :change_request_id => @change_request.id, :only_path => false) %>
<%= _('Close the request and respond:') %>
-<%= admin_change_request_edit_url(:id => @change_request.id, :only_path => false ) %>
+<%= edit_admin_change_request_url(@change_request, :only_path => false ) %>
diff --git a/app/views/public_body/show.html.erb b/app/views/public_body/show.html.erb
index 011aea535..5ac637a78 100644
--- a/app/views/public_body/show.html.erb
+++ b/app/views/public_body/show.html.erb
@@ -23,7 +23,7 @@
<%=@public_body.type_of_authority(true)%><% if not @public_body.short_name.empty? %>,
<%= _('also called {{public_body_short_name}}', :public_body_short_name => h(@public_body.short_name))%><% end %>
<% if !@user.nil? && @user.admin_page_links? %>
- (<%= link_to _("admin"), admin_body_show_path(@public_body) %>)
+ (<%= link_to _("admin"), admin_body_path(@public_body) %>)
<% end %>
</p>
diff --git a/app/views/request/_incoming_correspondence.html.erb b/app/views/request/_incoming_correspondence.html.erb
index f39d650d8..70bd25c7f 100644
--- a/app/views/request/_incoming_correspondence.html.erb
+++ b/app/views/request/_incoming_correspondence.html.erb
@@ -17,7 +17,7 @@
<p class="event_actions">
<% if !@user.nil? && @user.admin_page_links? %>
- <%= link_to "Admin", admin_incoming_edit_path(incoming_message.id) %> |
+ <%= link_to "Admin", edit_admin_incoming_message_path(incoming_message.id) %> |
<% end %>
<%= link_to _("Link to this"), incoming_message_path(incoming_message), :class => "link_to_this" %>
</p>
diff --git a/app/views/request/show.html.erb b/app/views/request/show.html.erb
index 153b0b861..1383030cd 100644
--- a/app/views/request/show.html.erb
+++ b/app/views/request/show.html.erb
@@ -37,9 +37,9 @@
:user => request_user_link(@info_request, _('An anonymous user')),
:law_used_full => h(@info_request.law_used_full),
:user_admin_link => user_admin_link_for_request(@info_request, _('external'), _('admin')),
- :request_admin_url => admin_request_show_url(@info_request),
+ :request_admin_url => admin_request_url(@info_request),
:public_body_link => public_body_link(@info_request.public_body),
- :public_body_admin_url => admin_body_show_url(@info_request.public_body)) %>
+ :public_body_admin_url => admin_body_url(@info_request.public_body)) %>
<% else %>
<%= _('{{user}} made this {{law_used_full}} request',
:user=>request_user_link(@info_request, _('An anonymous user')),
diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb
index b23f74326..51882b8ef 100644
--- a/app/views/user/show.html.erb
+++ b/app/views/user/show.html.erb
@@ -66,7 +66,7 @@
<p class="subtitle">
<%= _('Joined {{site_name}} in', :site_name=>site_name) %> <%= @display_user.created_at.year %>
<% if !@user.nil? && @user.admin_page_links? %>
- (<%= link_to "admin", admin_user_show_path(@display_user) %>)
+ (<%= link_to "admin", admin_user_path(@display_user) %>)
<% end %>
</p>
diff --git a/config/routes.rb b/config/routes.rb
index 2886c2846..c975d6007 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -169,17 +169,15 @@ Alaveteli::Application.routes.draw do
####
#### AdminPublicBody controller
- match '/admin/missing_scheme' => 'admin_public_body#missing_scheme', :as => :admin_body_missing
- match '/admin/body' => 'admin_public_body#index', :as => :admin_body_index
- match '/admin/body/list' => 'admin_public_body#list', :as => :admin_body_list
- match '/admin/body/show/:id' => 'admin_public_body#show', :as => :admin_body_show
- match '/admin/body/new' => 'admin_public_body#new', :as => :admin_body_new
- match '/admin/body/edit/:id' => 'admin_public_body#edit', :as => :admin_body_edit
- match '/admin/body/update/:id' => 'admin_public_body#update', :as => :admin_body_update
- match '/admin/body/create' => 'admin_public_body#create', :as => :admin_body_create
- match '/admin/body/destroy/:id' => 'admin_public_body#destroy', :as => :admin_body_destroy
- match '/admin/body/import_csv' => 'admin_public_body#import_csv', :as => :admin_body_import_csv
- match '/admin/body/mass_tag_add' => 'admin_public_body#mass_tag_add', :as => :admin_body_mass_tag_add
+ scope '/admin', :as => 'admin' do
+ resources :bodies,
+ :controller => 'admin_public_body' do
+ get 'missing_scheme', :on => :collection
+ post 'mass_tag_add', :on => :collection
+ get 'import_csv', :on => :collection
+ post 'import_csv', :on => :collection
+ end
+ end
####
#### AdminPublicBodyCategory controller
@@ -216,8 +214,11 @@ Alaveteli::Application.routes.draw do
####
#### AdminPublicBodyChangeRequest controller
- match '/admin/change_request/edit/:id' => 'admin_public_body_change_requests#edit', :as => :admin_change_request_edit
- match '/admin/change_request/update/:id' => 'admin_public_body_change_requests#update', :as => :admin_change_request_update
+ scope '/admin', :as => 'admin' do
+ resources :change_requests,
+ :controller => 'admin_public_body_change_requests',
+ :only => [:edit, :update]
+ end
####
#### AdminGeneral controller
@@ -228,81 +229,99 @@ Alaveteli::Application.routes.draw do
####
#### AdminRequest controller
- match '/admin/request' => 'admin_request#index', :as => :admin_request_index
- match '/admin/request/list' => 'admin_request#list', :as => :admin_request_list
- match '/admin/request/show/:id' => 'admin_request#show', :as => :admin_request_show
- match '/admin/request/resend' => 'admin_request#resend', :as => :admin_request_resend
- match '/admin/request/edit/:id' => 'admin_request#edit', :as => :admin_request_edit
- match '/admin/request/update/:id' => 'admin_request#update', :as => :admin_request_update
- match '/admin/request/destroy/:id' => 'admin_request#fully_destroy', :as => :admin_request_destroy
- match '/admin/request/edit_comment/:id' => 'admin_request#edit_comment', :as => :admin_request_edit_comment
- match '/admin/request/update_comment/:id' => 'admin_request#update_comment', :as => :admin_request_update_comment
- match '/admin/request/move_request' => 'admin_request#move_request', :as => :admin_request_move_request
- match '/admin/request/generate_upload_url/:id' => 'admin_request#generate_upload_url', :as => :admin_request_generate_upload_url
- match '/admin/request/show_raw_email/:id' => 'admin_request#show_raw_email', :as => :admin_request_show_raw_email
- match '/admin/request/download_raw_email/:id' => 'admin_request#download_raw_email', :as => :admin_request_download_raw_email
- match '/admin/request/mark_event_as_clarification' => 'admin_request#mark_event_as_clarification', :as => :admin_request_clarification
- match '/admin/request/hide/:id' => 'admin_request#hide_request', :as => :admin_request_hide
- ####
+ scope '/admin', :as => 'admin' do
+ resources :requests,
+ :controller => 'admin_request',
+ :except => [:new, :create] do
+ post 'move', :on => :member
+ post 'generate_upload_url', :on => :member
+ post 'hide', :on => :member
+ resources :censor_rules,
+ :controller => 'admin_censor_rule',
+ :only => [:new, :create],
+ :name_prefix => 'request_'
- #### AdminIncomingMessage controller
- match '/admin/incoming/destroy' => 'admin_incoming_message#destroy', :as => :admin_incoming_destroy
- match '/admin/incoming/redeliver' => 'admin_incoming_message#redeliver', :as => :admin_incoming_redeliver
- match '/admin/incoming/edit/:id' => 'admin_incoming_message#edit', :as => :admin_incoming_edit
- match '/admin/incoming/update/:id' => 'admin_incoming_message#update', :as => :admin_incoming_update
+ end
+ end
####
- #### AdminOutgoingMessage controller
- match '/admin/outgoing/edit/:id' => 'admin_outgoing_message#edit', :as => :admin_outgoing_edit
- match '/admin/outgoing/destroy/:id' => 'admin_outgoing_message#destroy', :as => :admin_outgoing_destroy
- match '/admin/outgoing/update/:id' => 'admin_outgoing_message#update', :as => :admin_outgoing_update
+ #### AdminComment controller
+ scope '/admin', :as => 'admin' do
+ resources :comments,
+ :controller => 'admin_comment',
+ :only => [:edit, :update]
+ end
####
- #### AdminUser controller
- match '/admin/user' => 'admin_user#index', :as => :admin_user_index
- match '/admin/user/list' => 'admin_user#list', :as => :admin_user_list
- match '/admin/user/banned' => 'admin_user#list_banned', :as => :admin_user_list_banned
- match '/admin/user/show/:id' => 'admin_user#show', :as => :admin_user_show
- match '/admin/user/edit/:id' => 'admin_user#edit', :as => :admin_user_edit
- match '/admin/user/show_bounce_message/:id' => 'admin_user#show_bounce_message', :as => :admin_user_show_bounce
- match '/admin/user/update/:id' => 'admin_user#update', :as => :admin_user_update
- match '/admin/user/clear_bounce/:id' => 'admin_user#clear_bounce', :as => :admin_user_clear_bounce
- match '/admin/user/destroy_track' => 'admin_user#destroy_track', :as => :admin_user_destroy_track
- match '/admin/user/login_as/:id' => 'admin_user#login_as', :as => :admin_user_login_as
- match '/admin/user/clear_profile_photo/:id' => 'admin_user#clear_profile_photo', :as => :admin_clear_profile_photo
- match '/admin/user/modify_comment_visibility/:id' => 'admin_user#modify_comment_visibility', :as => 'admin_user_modify_comment_visibility'
+ #### AdminRawEmail controller
+ scope '/admin', :as => 'admin' do
+ resources :raw_emails,
+ :controller => 'admin_raw_email',
+ :only => [:show]
+ end
####
- #### AdminTrack controller
- match '/admin/track/list' => 'admin_track#list', :as => :admin_track_list
- ####
+ #### AdminInfoRequestEvent controller
+ scope '/admin', :as => 'admin' do
+ resources :info_request_events,
+ :controller => 'admin_info_request_event',
+ :only => [:update]
+ end
- #### AdminCensorRule controller
- match '/admin/censor/new' => 'admin_censor_rule#new', :as => :admin_rule_new
- match '/admin/censor/create' => 'admin_censor_rule#create', :as => :admin_rule_create
- match '/admin/censor/edit/:id' => 'admin_censor_rule#edit', :as => :admin_rule_edit
- match '/admin/censor/update/:id' => 'admin_censor_rule#update', :as => :admin_rule_update
- match '/admin/censor/destroy/:censor_rule_id' => 'admin_censor_rule#destroy', :as => :admin_rule_destroy
+ #### AdminIncomingMessage controller
+ scope '/admin', :as => 'admin' do
+ resources :incoming_messages,
+ :controller => 'admin_incoming_message',
+ :only => [:edit, :update, :destroy] do
+ post 'redeliver', :on => :member
+ end
+ end
+ ####
+ #### AdminOutgoingMessage controller
scope '/admin', :as => 'admin' do
- resources :info_requests, :only => [] do
- resources :censor_rules,
- :controller => 'admin_censor_rule',
- :only => [:new, :create],
- :name_prefix => 'info_request_'
+ resources :outgoing_messages,
+ :controller => 'admin_outgoing_message',
+ :only => [:edit, :update, :destroy] do
+ post 'resend', :on => :member
end
end
+ ####
+ #### AdminUser controller
scope '/admin', :as => 'admin' do
- resources :users, :only => [] do
- resources :censor_rules,
- :controller => 'admin_censor_rule',
- :only => [:new, :create],
- :name_prefix => 'user_'
+ resources :users,
+ :controller => 'admin_user',
+ :except => [:new, :create, :destroy] do
+ get 'banned', :on => :collection
+ get 'show_bounce_message', :on => :member
+ post 'clear_bounce', :on => :member
+ post 'login_as', :on => :member
+ post 'clear_profile_photo', :on => :member
+ post 'modify_comment_visibility', :on => :collection
+ resources :censor_rules,
+ :controller => 'admin_censor_rule',
+ :only => [:new, :create],
+ :name_prefix => 'user_'
end
end
####
+ #### AdminTrack controller
+ scope '/admin', :as => 'admin' do
+ resources :tracks,
+ :controller => 'admin_track',
+ :only => [:index, :destroy]
+ end
+ ####
+
+ #### AdminCensorRule controller
+ scope '/admin', :as => 'admin' do
+ resources :censor_rules,
+ :controller => 'admin_censor_rule',
+ :except => [:index, :new, :create]
+ end
+
#### AdminSpamAddresses controller
scope '/admin', :as => 'admin' do
resources :spam_addresses,
diff --git a/spec/controllers/admin_censor_rule_controller_spec.rb b/spec/controllers/admin_censor_rule_controller_spec.rb
index 4df56a92b..68eaecd6a 100644
--- a/spec/controllers/admin_censor_rule_controller_spec.rb
+++ b/spec/controllers/admin_censor_rule_controller_spec.rb
@@ -5,76 +5,68 @@ describe AdminCensorRuleController do
describe 'GET new' do
- it 'returns a successful response' do
- get :new
- expect(response).to be_success
- end
+ context 'request_id param' do
- it 'initializes a new censor rule' do
- get :new
- expect(assigns[:censor_rule]).to be_new_record
- end
+ before do
+ @info_request = FactoryGirl.create(:info_request)
+ get :new, :request_id => @info_request.id, :name_prefix => 'request_'
+ end
- it 'renders the correct template' do
- get :new
- expect(response).to render_template('new')
- end
+ it 'returns a successful response' do
+ expect(response).to be_success
+ end
- it 'sets the URL for the form to POST to' do
- get :new
- expect(assigns[:form_url]).to eq(admin_rule_create_path)
- end
+ it 'initializes a new censor rule' do
+ expect(assigns[:censor_rule]).to be_new_record
+ end
- context 'info_request_id param' do
+ it 'renders the correct template' do
+ expect(response).to render_template('new')
+ end
- it 'finds an info request if the info_request_id param is supplied' do
- info_request = FactoryGirl.create(:info_request)
- get :new, :info_request_id => info_request.id
- expect(assigns[:info_request]).to eq(info_request)
+ it 'finds an info request if the request_id param is supplied' do
+ expect(assigns[:info_request]).to eq(@info_request)
end
it 'associates the info request with the new censor rule' do
- info_request = FactoryGirl.create(:info_request)
- get :new, :info_request_id => info_request.id
- expect(assigns[:censor_rule].info_request).to eq(info_request)
+ expect(assigns[:censor_rule].info_request).to eq(@info_request)
end
it 'sets the URL for the form to POST to' do
- info_request = FactoryGirl.create(:info_request)
- get :new, :info_request_id => info_request.id
- expect(assigns[:form_url]).to eq(admin_info_request_censor_rules_path(info_request))
- end
-
- it 'does not find an info request if no info_request_id param is supplied' do
- get :new
- expect(assigns[:info_request]).to be_nil
+ expect(assigns[:form_url]).to eq(admin_request_censor_rules_path(@info_request))
end
end
context 'user_id param' do
+ before do
+ @user = FactoryGirl.create(:user)
+ get :new, :user_id => @user.id, :name_prefix => 'user_'
+ end
+
+ it 'returns a successful response' do
+ expect(response).to be_success
+ end
+
+ it 'initializes a new censor rule' do
+ expect(assigns[:censor_rule]).to be_new_record
+ end
+
+ it 'renders the correct template' do
+ expect(response).to render_template('new')
+ end
+
it 'finds a user if the user_id param is supplied' do
- user = FactoryGirl.create(:user)
- get :new, :user_id => user.id
- expect(assigns[:censor_user]).to eq(user)
+ expect(assigns[:censor_user]).to eq(@user)
end
it 'associates the user with the new censor rule' do
- user = FactoryGirl.create(:user)
- get :new, :user_id => user.id
- expect(assigns[:censor_rule].user).to eq(user)
+ expect(assigns[:censor_rule].user).to eq(@user)
end
it 'sets the URL for the form to POST to' do
- user = FactoryGirl.create(:user)
- get :new, :user_id => user.id
- expect(assigns[:form_url]).to eq(admin_user_censor_rules_path(user))
- end
-
- it 'does not find a user if no user_id param is supplied' do
- get :new
- expect(assigns[:censor_user]).to be_nil
+ expect(assigns[:form_url]).to eq(admin_user_censor_rules_path(@user))
end
end
@@ -83,256 +75,292 @@ describe AdminCensorRuleController do
describe 'POST create' do
- before(:each) do
- @censor_rule_params = FactoryGirl.build(:global_censor_rule).serializable_hash
- # last_edit_editor gets set in the controller
- @censor_rule_params.delete(:last_edit_editor)
- end
-
- it 'sets the last_edit_editor to the current admin' do
- post :create, :censor_rule => @censor_rule_params
- expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*')
- end
+ context 'request_id param' do
- it 'sets the URL for the form to POST to' do
- post :create, :censor_rule => @censor_rule_params
- expect(assigns[:form_url]).to eq(admin_rule_create_path)
- end
+ before(:each) do
+ @censor_rule_params = FactoryGirl.build(:info_request_censor_rule).serializable_hash
+ # last_edit_editor gets set in the controller
+ @censor_rule_params.delete(:last_edit_editor)
+ @info_request = FactoryGirl.create(:info_request)
+ post :create, :request_id => @info_request.id,
+ :censor_rule => @censor_rule_params,
+ :name_prefix => 'request_'
+ end
- context 'info_request_id param' do
+ it 'sets the last_edit_editor to the current admin' do
+ expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*')
+ end
- it 'finds an info request if the info_request_id param is supplied' do
- info_request = FactoryGirl.create(:info_request)
- post :create, :info_request_id => info_request.id,
- :censor_rule => @censor_rule_params
- expect(assigns[:info_request]).to eq(info_request)
+ it 'finds an info request if the request_id param is supplied' do
+ expect(assigns[:info_request]).to eq(@info_request)
end
it 'associates the info request with the new censor rule' do
- info_request = FactoryGirl.create(:info_request)
- post :create, :info_request_id => info_request.id,
- :censor_rule => @censor_rule_params
- expect(assigns[:censor_rule].info_request).to eq(info_request)
+ expect(assigns[:censor_rule].info_request).to eq(@info_request)
end
it 'sets the URL for the form to POST to' do
- info_request = FactoryGirl.create(:info_request)
- post :create, :info_request_id => info_request.id,
- :censor_rule => @censor_rule_params
- expect(assigns[:form_url]).to eq(admin_info_request_censor_rules_path(info_request))
+ expect(assigns[:form_url]).to eq(admin_request_censor_rules_path(@info_request))
end
- it 'does not find an info request if no info_request_id param is supplied' do
- post :create, :censor_rule => @censor_rule_params
- expect(assigns[:info_request]).to be_nil
- end
+ context 'successfully saving the censor rule' do
- end
+ it 'persists the censor rule' do
+ post :create, :censor_rule => @censor_rule_params,
+ :request_id => @info_request.id,
+ :name_prefix => 'request_'
+ expect(assigns[:censor_rule]).to be_persisted
+ end
- context 'user_id param' do
+ it 'confirms the censor rule is created' do
+ post :create, :censor_rule => @censor_rule_params,
+ :request_id => @info_request.id,
+ :name_prefix => 'request_'
+ msg = 'CensorRule was successfully created.'
+ expect(flash[:notice]).to eq(msg)
+ end
- it 'finds a user if the user_id param is supplied' do
- user = FactoryGirl.create(:user)
- post :create, :user_id => user.id,
- :censor_rule => @censor_rule_params
- expect(assigns[:censor_user]).to eq(user)
- end
+ it 'purges the cache for the info request' do
+ @controller.should_receive(:expire_for_request).
+ with(@info_request)
- it 'associates the user with the new censor rule' do
- user = FactoryGirl.create(:user)
- post :create, :user_id => user.id,
- :censor_rule => @censor_rule_params
- expect(assigns[:censor_rule].user).to eq(user)
- end
+ post :create, :censor_rule => @censor_rule_params,
+ :request_id => @info_request.id,
+ :name_prefix => 'request_'
+ end
- it 'sets the URL for the form to POST to' do
- user = FactoryGirl.create(:user)
- post :create, :user_id => user.id,
- :censor_rule => @censor_rule_params
- expect(assigns[:form_url]).to eq(admin_user_censor_rules_path(user))
+ it 'redirects to the associated info request' do
+ post :create, :censor_rule => @censor_rule_params,
+ :request_id => @info_request.id,
+ :name_prefix => 'request_'
+ expect(response).to redirect_to(
+ admin_request_path(assigns[:censor_rule].info_request)
+ )
+ end
end
- it 'does not find a user if no user_id param is supplied' do
- post :create, :censor_rule => @censor_rule_params
- expect(assigns[:censor_user]).to be_nil
- end
+ context 'unsuccessfully saving the censor rule' do
+
+ before(:each) do
+ CensorRule.any_instance.stub(:save).and_return(false)
+ end
+
+ it 'does not persist the censor rule' do
+ post :create, :censor_rule => @censor_rule_params,
+ :request_id => @info_request.id,
+ :name_prefix => 'request_'
+ expect(assigns[:censor_rule]).to be_new_record
+ end
+ it 'renders the form' do
+ post :create, :censor_rule => @censor_rule_params,
+ :request_id => @info_request.id,
+ :name_prefix => 'request_'
+ expect(response).to render_template('new')
+ end
+
+ end
end
- context 'successfully saving the censor rule' do
+ context 'user_id param' do
before(:each) do
- CensorRule.any_instance.stub(:save).and_return(true)
+ @censor_rule_params = FactoryGirl.build(:user_censor_rule).serializable_hash
+ # last_edit_editor gets set in the controller
+ @censor_rule_params.delete(:last_edit_editor)
+ @user = FactoryGirl.create(:user)
+ post :create, :user_id => @user.id,
+ :censor_rule => @censor_rule_params,
+ :name_prefix => 'user_'
end
- it 'persists the censor rule' do
- pending("This raises an internal error in most cases")
- post :create, :censor_rule => @censor_rule_params
- expect(assigns[:censor_rule]).to be_persisted
+ it 'sets the last_edit_editor to the current admin' do
+ expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*')
end
- it 'confirms the censor rule is created' do
- pending("This raises an internal error in most cases")
- post :create, :censor_rule => @censor_rule_params
- msg = 'CensorRule was successfully created.'
- expect(flash[:notice]).to eq(msg)
+ it 'finds a user if the user_id param is supplied' do
+ expect(assigns[:censor_user]).to eq(@user)
end
- it 'raises an error after creating the rule' do
- expect {
- post :create, :censor_rule => @censor_rule_params
- }.to raise_error 'internal error'
+ it 'associates the user with the new censor rule' do
+ expect(assigns[:censor_rule].user).to eq(@user)
end
- context 'a CensorRule with an associated InfoRequest' do
+ it 'sets the URL for the form to POST to' do
+ expect(assigns[:form_url]).to eq(admin_user_censor_rules_path(@user))
+ end
- before(:each) do
- @censor_rule_params = FactoryGirl.build(:info_request_censor_rule).serializable_hash
- # last_edit_editor gets set in the controller
- @censor_rule_params.delete(:last_edit_editor)
- end
+ context 'successfully saving the censor rule' do
- it 'purges the cache for the info request' do
+ it 'purges the cache for the info request' do
censor_rule = CensorRule.new(@censor_rule_params)
- @controller.should_receive(:expire_for_request).
- with(censor_rule.info_request)
+ @controller.should_receive(:expire_requests_for_user).
+ with(@user)
- post :create, :censor_rule => @censor_rule_params
+ post :create, :censor_rule => @censor_rule_params,
+ :user_id => @user.id,
+ :name_prefix => 'user_'
end
it 'redirects to the associated info request' do
- post :create, :censor_rule => @censor_rule_params
+ post :create, :censor_rule => @censor_rule_params,
+ :user_id => @user.id,
+ :name_prefix => 'user_'
expect(response).to redirect_to(
- admin_request_show_path(assigns[:censor_rule].info_request)
+ admin_user_path(assigns[:censor_rule].user)
)
end
end
- context 'a CensorRule with an associated User' do
+ context 'unsuccessfully saving the censor rule' do
before(:each) do
- @censor_rule_params = FactoryGirl.build(:user_censor_rule).serializable_hash
- # last_edit_editor gets set in the controller
- @censor_rule_params.delete(:last_edit_editor)
+ CensorRule.any_instance.stub(:save).and_return(false)
end
- it 'purges the cache for the info request' do
- censor_rule = CensorRule.new(@censor_rule_params)
- @controller.should_receive(:expire_requests_for_user).
- with(censor_rule.user)
-
- post :create, :censor_rule => @censor_rule_params
+ it 'does not persist the censor rule' do
+ post :create, :censor_rule => @censor_rule_params,
+ :user_id => @user.id,
+ :name_prefix => 'user_'
+ expect(assigns[:censor_rule]).to be_new_record
end
- it 'redirects to the associated info request' do
- post :create, :censor_rule => @censor_rule_params
- expect(response).to redirect_to(
- admin_user_show_path(assigns[:censor_rule].user)
- )
+ it 'renders the form' do
+ post :create, :censor_rule => @censor_rule_params,
+ :user_id => @user.id,
+ :name_prefix => 'user_'
+ expect(response).to render_template('new')
end
end
end
- context 'unsuccessfully saving the censor rule' do
+ end
+
+ describe 'GET edit' do
+
+ context 'a CensorRule with an associated InfoRequest' do
before(:each) do
- CensorRule.any_instance.stub(:save).and_return(false)
+ @censor_rule = FactoryGirl.create(:info_request_censor_rule)
end
- it 'does not persist the censor rule' do
- post :create, :censor_rule => @censor_rule_params
- expect(assigns[:censor_rule]).to be_new_record
+ it 'returns a successful response' do
+ get :edit, :id => @censor_rule.id
+ expect(response).to be_success
end
- it 'renders the form' do
- post :create, :censor_rule => @censor_rule_params
- expect(response).to render_template('new')
+ it 'renders the correct template' do
+ get :edit, :id => @censor_rule.id
+ expect(response).to render_template('edit')
+ end
+
+ it 'finds the correct censor rule to edit' do
+ get :edit, :id => @censor_rule.id
+ expect(assigns[:censor_rule]).to eq(@censor_rule)
end
end
- end
+ context 'a CensorRule with an associated User' do
- describe 'GET edit' do
+ before(:each) do
+ @censor_rule = FactoryGirl.create(:user_censor_rule)
+ end
- before(:each) do
- @censor_rule = FactoryGirl.create(:global_censor_rule)
- end
+ it 'returns a successful response' do
+ get :edit, :id => @censor_rule.id
+ expect(response).to be_success
+ end
- it 'returns a successful response' do
- get :edit, :id => @censor_rule.id
- expect(response).to be_success
- end
+ it 'renders the correct template' do
+ get :edit, :id => @censor_rule.id
+ expect(response).to render_template('edit')
+ end
+
+ it 'finds the correct censor rule to edit' do
+ get :edit, :id => @censor_rule.id
+ expect(assigns[:censor_rule]).to eq(@censor_rule)
+ end
- it 'renders the correct template' do
- get :edit, :id => @censor_rule.id
- expect(response).to render_template('edit')
end
- it 'finds the correct censor rule to edit' do
- get :edit, :id => @censor_rule.id
- expect(assigns[:censor_rule]).to eq(@censor_rule)
+ context 'when editing a global rule' do
+
+ before(:each) do
+ @censor_rule = FactoryGirl.create(:global_censor_rule)
+ end
+
+ it 'shows an error notice' do
+ get :edit, :id => @censor_rule.id
+ flash[:notice].should == 'Only user and request censor rules can be edited'
+ end
+
+ it 'redirects to the admin index' do
+ get :edit, :id => @censor_rule.id
+ expect(response).to redirect_to(admin_general_index_path)
+ end
+
end
end
describe 'PUT update' do
- before(:each) do
- @censor_rule = FactoryGirl.create(:global_censor_rule)
- end
+ context 'a global CensorRule' do
- it 'finds the correct censor rule to edit' do
- put :update, :id => @censor_rule.id,
- :censor_rule => { :text => 'different text' }
+ before(:each) do
+ @censor_rule = FactoryGirl.create(:global_censor_rule)
+ end
- expect(assigns[:censor_rule]).to eq(@censor_rule)
- end
+ it 'shows an error notice' do
+ get :edit, :id => @censor_rule.id
+ flash[:notice].should == 'Only user and request censor rules can be edited'
+ end
- it 'sets the last_edit_editor to the current admin' do
- put :update, :id => @censor_rule.id,
- :censor_rule => { :text => 'different text' }
+ it 'redirects to the admin index' do
+ get :edit, :id => @censor_rule.id
+ expect(response).to redirect_to(admin_general_index_path)
+ end
- expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*')
end
- context 'successfully saving the censor rule' do
+ context 'a CensorRule with an associated InfoRequest' do
before(:each) do
- CensorRule.any_instance.stub(:save).and_return(true)
+ @censor_rule = FactoryGirl.create(:info_request_censor_rule)
end
- it 'updates the censor rule' do
- pending("This raises an internal error in most cases")
+ it 'finds the correct censor rule to edit' do
put :update, :id => @censor_rule.id,
:censor_rule => { :text => 'different text' }
- @censor_rule.reload
- expect(@censor_rule.text).to eq('different text')
+
+ expect(assigns[:censor_rule]).to eq(@censor_rule)
end
- it 'confirms the censor rule is updated' do
- pending("This raises an internal error in most cases")
+ it 'sets the last_edit_editor to the current admin' do
put :update, :id => @censor_rule.id,
:censor_rule => { :text => 'different text' }
- msg = 'CensorRule was successfully updated.'
- expect(flash[:notice]).to eq(msg)
+ expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*')
end
- it 'raises an error after updating the rule' do
- expect {
+ context 'successfully saving the censor rule' do
+
+ it 'updates the censor rule' do
put :update, :id => @censor_rule.id,
:censor_rule => { :text => 'different text' }
- }.to raise_error 'internal error'
- end
-
- context 'a CensorRule with an associated InfoRequest' do
+ @censor_rule.reload
+ expect(@censor_rule.text).to eq('different text')
+ end
- before(:each) do
- @censor_rule = FactoryGirl.create(:info_request_censor_rule)
+ it 'confirms the censor rule is updated' do
+ put :update, :id => @censor_rule.id,
+ :censor_rule => { :text => 'different text' }
+ msg = 'CensorRule was successfully updated.'
+ expect(flash[:notice]).to eq(msg)
end
it 'purges the cache for the info request' do
@@ -348,87 +376,137 @@ describe AdminCensorRuleController do
:censor_rule => { :text => 'different text' }
expect(response).to redirect_to(
- admin_request_show_path(assigns[:censor_rule].info_request)
+ admin_request_path(assigns[:censor_rule].info_request)
)
end
end
- context 'a CensorRule with an associated User' do
+ context 'unsuccessfully saving the censor rule' do
before(:each) do
- @censor_rule = FactoryGirl.create(:user_censor_rule)
+ CensorRule.any_instance.stub(:save).and_return(false)
end
- it 'purges the cache for the info request' do
- @controller.should_receive(:expire_requests_for_user).
- with(@censor_rule.user)
-
+ it 'does not update the censor rule' do
put :update, :id => @censor_rule.id,
:censor_rule => { :text => 'different text' }
+ @censor_rule.reload
+ expect(@censor_rule.text).to eq('some text to redact')
end
- it 'redirects to the associated info request' do
+ it 'renders the form' do
put :update, :id => @censor_rule.id,
:censor_rule => { :text => 'different text' }
- expect(response).to redirect_to(
- admin_user_show_path(assigns[:censor_rule].user)
- )
+ expect(response).to render_template('edit')
end
- end
+ end
+
end
- context 'unsuccessfully saving the censor rule' do
+ context 'a CensorRule with an associated User' do
before(:each) do
- CensorRule.any_instance.stub(:save).and_return(false)
+ @censor_rule = FactoryGirl.create(:user_censor_rule)
end
- it 'does not update the censor rule' do
+ it 'finds the correct censor rule to edit' do
put :update, :id => @censor_rule.id,
:censor_rule => { :text => 'different text' }
- @censor_rule.reload
- expect(@censor_rule.text).to eq('some text to redact')
+
+ expect(assigns[:censor_rule]).to eq(@censor_rule)
end
- it 'renders the form' do
+ it 'sets the last_edit_editor to the current admin' do
put :update, :id => @censor_rule.id,
:censor_rule => { :text => 'different text' }
- expect(response).to render_template('edit')
+ expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*')
+
+ end
+
+
+ context 'successfully saving the censor rule' do
+
+ it 'updates the censor rule' do
+ put :update, :id => @censor_rule.id,
+ :censor_rule => { :text => 'different text' }
+ @censor_rule.reload
+ expect(@censor_rule.text).to eq('different text')
+ end
+
+ it 'confirms the censor rule is updated' do
+ put :update, :id => @censor_rule.id,
+ :censor_rule => { :text => 'different text' }
+ msg = 'CensorRule was successfully updated.'
+ expect(flash[:notice]).to eq(msg)
+ end
+
+ it 'purges the cache for the info request' do
+ @controller.should_receive(:expire_requests_for_user).
+ with(@censor_rule.user)
+
+ put :update, :id => @censor_rule.id,
+ :censor_rule => { :text => 'different text' }
+ end
+
+ it 'redirects to the associated info request' do
+ put :update, :id => @censor_rule.id,
+ :censor_rule => { :text => 'different text' }
+
+ expect(response).to redirect_to(
+ admin_user_path(assigns[:censor_rule].user)
+ )
+ end
end
+ context 'unsuccessfully saving the censor rule' do
+
+ before(:each) do
+ CensorRule.any_instance.stub(:save).and_return(false)
+ end
+
+ it 'does not update the censor rule' do
+ put :update, :id => @censor_rule.id,
+ :censor_rule => { :text => 'different text' }
+ @censor_rule.reload
+ expect(@censor_rule.text).to eq('some text to redact')
+ end
+
+ it 'renders the form' do
+ put :update, :id => @censor_rule.id,
+ :censor_rule => { :text => 'different text' }
+
+ expect(response).to render_template('edit')
+ end
+
+ end
+
end
end
describe 'DELETE destroy' do
- before(:each) do
- @censor_rule = FactoryGirl.create(:global_censor_rule)
- end
+ context 'a global CensorRule' do
- it 'finds the correct censor rule to destroy' do
- pending("This raises an internal error in most cases")
- # TODO: Replace :censor_rule_id with :id
- delete :destroy, :censor_rule_id => @censor_rule.id
- expect(assigns[:censor_rule]).to eq(@censor_rule)
- end
+ before(:each) do
+ @censor_rule = FactoryGirl.create(:global_censor_rule)
+ end
- it 'raises an error after destroying the rule' do
- expect {
- delete :destroy, :censor_rule_id => @censor_rule.id
- }.to raise_error 'internal error'
- end
+ it 'shows an error notice' do
+ get :edit, :id => @censor_rule.id
+ flash[:notice].should == 'Only user and request censor rules can be edited'
+ end
+
+ it 'redirects to the admin index' do
+ get :edit, :id => @censor_rule.id
+ expect(response).to redirect_to(admin_general_index_path)
+ end
- it 'confirms the censor rule is destroyed in all cases' do
- pending("This actually raises an internal error anyway")
- delete :destroy, :censor_rule_id => @censor_rule.id
- msg = 'CensorRule was successfully destroyed.'
- expect(flash[:notice]).to eq(msg)
end
context 'a CensorRule with an associated InfoRequest' do
@@ -437,14 +515,25 @@ describe AdminCensorRuleController do
@censor_rule = FactoryGirl.create(:info_request_censor_rule)
end
+ it 'finds the correct censor rule to destroy' do
+ delete :destroy, :id => @censor_rule.id
+ expect(assigns[:censor_rule]).to eq(@censor_rule)
+ end
+
+ it 'confirms the censor rule is destroyed in all cases' do
+ delete :destroy, :id => @censor_rule.id
+ msg = 'CensorRule was successfully destroyed.'
+ expect(flash[:notice]).to eq(msg)
+ end
+
it 'purges the cache for the info request' do
@controller.should_receive(:expire_for_request).with(@censor_rule.info_request)
- delete :destroy, :censor_rule_id => @censor_rule.id
+ delete :destroy, :id => @censor_rule.id
end
it 'redirects to the associated info request' do
- delete :destroy, :censor_rule_id => @censor_rule.id
- expect(response).to redirect_to(admin_request_show_path(@censor_rule.info_request))
+ delete :destroy, :id => @censor_rule.id
+ expect(response).to redirect_to(admin_request_path(@censor_rule.info_request))
end
end
@@ -455,14 +544,25 @@ describe AdminCensorRuleController do
@censor_rule = FactoryGirl.create(:user_censor_rule)
end
+ it 'finds the correct censor rule to destroy' do
+ delete :destroy, :id => @censor_rule.id
+ expect(assigns[:censor_rule]).to eq(@censor_rule)
+ end
+
+ it 'confirms the censor rule is destroyed in all cases' do
+ delete :destroy, :id => @censor_rule.id
+ msg = 'CensorRule was successfully destroyed.'
+ expect(flash[:notice]).to eq(msg)
+ end
+
it 'purges the cache for the user' do
@controller.should_receive(:expire_requests_for_user).with(@censor_rule.user)
- delete :destroy, :censor_rule_id => @censor_rule.id
+ delete :destroy, :id => @censor_rule.id
end
it 'redirects to the associated info request' do
- delete :destroy, :censor_rule_id => @censor_rule.id
- expect(response).to redirect_to(admin_user_show_path(@censor_rule.user))
+ delete :destroy, :id => @censor_rule.id
+ expect(response).to redirect_to(admin_user_path(@censor_rule.user))
end
end
@@ -474,17 +574,17 @@ end
describe AdminCensorRuleController, "when making censor rules from the admin interface" do
render_views
before { basic_auth_login @request }
-
+
it "should create a censor rule and purge the corresponding request from varnish" do
- ir = info_requests(:fancy_dog_request)
- post :create, :censor_rule => {
+ ir = info_requests(:fancy_dog_request)
+ post :create, :request_id => ir.id,
+ :name_prefix => 'request_',
+ :censor_rule => {
:text => "meat",
:replacement => "tofu",
- :last_edit_comment => "none",
- :info_request_id => ir
+ :last_edit_comment => "none"
}
PurgeRequest.all().first.model_id.should == ir.id
end
-
end
diff --git a/spec/controllers/admin_comment_controller_spec.rb b/spec/controllers/admin_comment_controller_spec.rb
new file mode 100644
index 000000000..f87231e3b
--- /dev/null
+++ b/spec/controllers/admin_comment_controller_spec.rb
@@ -0,0 +1,66 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe AdminCommentController do
+
+ describe :edit do
+
+ before do
+ @comment = FactoryGirl.create(:comment)
+ get :edit, :id => @comment.id
+ end
+
+ it 'renders the edit template' do
+ expect(response).to render_template('edit')
+ end
+
+ it 'gets the comment' do
+ assigns[:comment].should == @comment
+ end
+
+ end
+
+ describe :update do
+
+ context 'on valid data submission' do
+
+ before do
+ @comment = FactoryGirl.create(:comment)
+ atts = FactoryGirl.attributes_for(:comment, :body => 'I am new')
+ put :update, :id => @comment.id, :comment => atts
+ end
+
+ it 'gets the comment' do
+ assigns[:comment].should == @comment
+ end
+
+ it 'updates the comment' do
+ Comment.find(@comment.id).body.should == 'I am new'
+ end
+
+ it 'logs the update event' do
+ most_recent_event = Comment.find(@comment.id).info_request_events.last
+ most_recent_event.event_type.should == 'edit_comment'
+ most_recent_event.comment_id.should == @comment.id
+ end
+
+ it 'shows a success notice' do
+ flash[:notice].should == "Comment successfully updated."
+ end
+
+ it 'redirects to the request page' do
+ response.should redirect_to(admin_request_path(@comment.info_request))
+ end
+ end
+
+ context 'on invalid data submission' do
+
+ it 'renders the edit template' do
+ @comment = FactoryGirl.create(:comment)
+ put :update, :id => @comment.id, :comment => {:body => ''}
+ response.should render_template('edit')
+ end
+
+ end
+ end
+
+end
diff --git a/spec/controllers/admin_incoming_message_controller_spec.rb b/spec/controllers/admin_incoming_message_controller_spec.rb
index 21c744e5b..24a526ca4 100644
--- a/spec/controllers/admin_incoming_message_controller_spec.rb
+++ b/spec/controllers/admin_incoming_message_controller_spec.rb
@@ -17,19 +17,19 @@ describe AdminIncomingMessageController, "when administering incoming messages"
it "destroys the raw email file" do
raw_email = @im.raw_email.filepath
assert_equal File.exists?(raw_email), true
- post :destroy, :incoming_message_id => @im.id
+ post :destroy, :id => @im.id
assert_equal File.exists?(raw_email), false
end
it 'asks the incoming message to fully destroy itself' do
IncomingMessage.stub!(:find).and_return(@im)
@im.should_receive(:fully_destroy)
- post :destroy, :incoming_message_id => @im.id
+ post :destroy, :id => @im.id
end
it 'expires the file cache for the associated info_request' do
@controller.should_receive(:expire_for_request).with(@im.info_request)
- post :destroy, :incoming_message_id => @im.id
+ post :destroy, :id => @im.id
end
end
@@ -46,7 +46,7 @@ describe AdminIncomingMessageController, "when administering incoming messages"
destination_info_request = info_requests(:naughty_chicken_request)
incoming_message = incoming_messages(:useless_incoming_message)
@controller.should_receive(:expire_for_request).with(current_info_request)
- post :redeliver, :redeliver_incoming_message_id => incoming_message.id,
+ post :redeliver, :id => incoming_message.id,
:url_title => destination_info_request.url_title
end
@@ -56,7 +56,7 @@ describe AdminIncomingMessageController, "when administering incoming messages"
current_info_request = info_requests(:fancy_dog_request)
destination_info_request = info_requests(:naughty_chicken_request)
incoming_message = incoming_messages(:useless_incoming_message)
- post :redeliver, :redeliver_incoming_message_id => incoming_message.id,
+ post :redeliver, :id => incoming_message.id,
:url_title => destination_info_request.url_title
end
@@ -130,7 +130,7 @@ describe AdminIncomingMessageController, "when administering incoming messages"
it 'should redirect to the admin info request view' do
make_request
- response.should redirect_to admin_request_show_url(@incoming.info_request)
+ response.should redirect_to admin_request_url(@incoming.info_request)
end
it 'should show a message that the incoming message has been updated' do
diff --git a/spec/controllers/admin_info_request_event_controller_spec.rb b/spec/controllers/admin_info_request_event_controller_spec.rb
new file mode 100644
index 000000000..23300a0b8
--- /dev/null
+++ b/spec/controllers/admin_info_request_event_controller_spec.rb
@@ -0,0 +1,41 @@
+# coding: utf-8
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe AdminInfoRequestEventController do
+
+ describe :update do
+
+ describe 'when handling valid data' do
+
+ before do
+ @info_request_event = FactoryGirl.create(:info_request_event)
+ put :update, :id => @info_request_event
+ end
+
+ it 'gets the info request event' do
+ assigns[:info_request_event].should == @info_request_event
+ end
+
+ it 'sets the described and calculated states on the event' do
+ event = InfoRequestEvent.find(@info_request_event.id)
+ event.described_state.should == 'waiting_clarification'
+ event.calculated_state.should == 'waiting_clarification'
+ end
+
+ it 'shows a success notice' do
+ flash[:notice].should == 'Old response marked as having been a clarification'
+ end
+
+ it 'redirects to the request admin page' do
+ response.should redirect_to(admin_request_url(@info_request_event.info_request))
+ end
+ end
+
+ it 'raises an exception if the event is not a response' do
+ @info_request_event = FactoryGirl.create(:sent_event)
+ lambda{ put :update, :id => @info_request_event }.should raise_error
+ end
+
+ end
+
+end
diff --git a/spec/controllers/admin_outgoing_message_controller_spec.rb b/spec/controllers/admin_outgoing_message_controller_spec.rb
index 0dde53b86..a46a077da 100644
--- a/spec/controllers/admin_outgoing_message_controller_spec.rb
+++ b/spec/controllers/admin_outgoing_message_controller_spec.rb
@@ -79,7 +79,7 @@ describe AdminOutgoingMessageController do
it 'should redirect to the admin info request view' do
make_request
- response.should redirect_to admin_request_show_url(@info_request)
+ response.should redirect_to admin_request_url(@info_request)
end
it 'should show a message that the incoming message has been updated' do
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 095d23245..7de292303 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -272,7 +272,7 @@ describe AdminPublicBodyController, "when destroying a public body" do
it "destroys a public body" do
n = PublicBody.count
post :destroy, { :id => public_bodies(:forlorn_public_body).id }
- response.should redirect_to(:controller=>'admin_public_body', :action=>'list')
+ response.should redirect_to admin_bodies_path
PublicBody.count.should == n - 1
end
@@ -286,7 +286,7 @@ describe AdminPublicBodyController, "when assigning public body tags" do
n = PublicBody.joins(:translations).where([condition, "en"]).count
post :mass_tag_add, { :new_tag => "department", :table_name => "substring" }
request.flash[:notice].should == "Added tag to table of bodies."
- response.should redirect_to(:action=>'list')
+ response.should redirect_to admin_bodies_path
PublicBody.find_by_tag("department").count.should == n
end
end
diff --git a/spec/controllers/admin_raw_email_controller_spec.rb b/spec/controllers/admin_raw_email_controller_spec.rb
new file mode 100644
index 000000000..77c57c38b
--- /dev/null
+++ b/spec/controllers/admin_raw_email_controller_spec.rb
@@ -0,0 +1,30 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe AdminRawEmailController do
+
+ describe :show do
+
+ before do
+ @raw_email = FactoryGirl.create(:incoming_message).raw_email
+ end
+
+ describe 'html version' do
+
+ it 'renders the show template' do
+ get :show, :id => @raw_email.id
+ end
+
+ end
+
+ describe 'text version' do
+
+ it 'sends the email as an RFC-822 attachment' do
+ get :show, :id => @raw_email.id, :format => 'txt'
+ response.content_type.should == 'message/rfc822'
+ response.body.should == @raw_email.data
+ end
+ end
+
+ end
+
+end
diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb
index 7c5253f49..4eb463963 100644
--- a/spec/controllers/admin_request_controller_spec.rb
+++ b/spec/controllers/admin_request_controller_spec.rb
@@ -57,12 +57,12 @@ describe AdminRequestController, "when administering requests" do
it 'expires the file cache for that request' do
info_request = info_requests(:badger_request)
@controller.should_receive(:expire_for_request).with(info_request)
- get :fully_destroy, { :id => info_request }
+ get :destroy, { :id => info_request }
end
it 'uses a different flash message to avoid trying to fetch a non existent user record' do
info_request = info_requests(:external_request)
- post :fully_destroy, { :id => info_request.id }
+ post :destroy, { :id => info_request.id }
request.flash[:notice].should include('external')
end
@@ -77,34 +77,6 @@ describe AdminRequestController, "when administering the holding pen" do
load_raw_emails_data
end
- it "shows a rejection reason for an incoming message from an invalid address" do
- ir = info_requests(:fancy_dog_request)
- ir.allow_new_responses_from = 'authority_only'
- ir.handle_rejected_responses = 'holding_pen'
- ir.save!
- receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "frob@nowhere.com")
- get :show_raw_email, :id => InfoRequest.holding_pen_request.get_last_public_response.raw_email.id
- response.should contain "Only the authority can reply to this request"
- end
-
- it "guesses a misdirected request" do
- ir = info_requests(:fancy_dog_request)
- ir.handle_rejected_responses = 'holding_pen'
- ir.allow_new_responses_from = 'authority_only'
- ir.save!
- mail_to = "request-#{ir.id}-asdfg@example.com"
- receive_incoming_mail('incoming-request-plain.email', mail_to)
- interesting_email = InfoRequest.holding_pen_request.get_last_public_response.raw_email.id
- # now we add another message to the queue, which we're not interested in
- receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "")
- InfoRequest.holding_pen_request.incoming_messages.length.should == 2
- get :show_raw_email, :id => interesting_email
- response.should contain "Could not identify the request"
- assigns[:info_requests][0].should == ir
- end
-
-
-
it "shows a suitable default 'your email has been hidden' message" do
ir = info_requests(:fancy_dog_request)
get :show, :id => ir.id
@@ -119,7 +91,7 @@ describe AdminRequestController, "when administering the holding pen" do
it "hides requests and sends a notification email that it has done so" do
ir = info_requests(:fancy_dog_request)
- post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious"
+ post :hide, :id => ir.id, :explanation => "Foo", :reason => "vexatious"
ir.reload
ir.prominence.should == "requester_only"
ir.described_state.should == "vexatious"
@@ -132,7 +104,7 @@ describe AdminRequestController, "when administering the holding pen" do
it 'expires the file cache for the request' do
ir = info_requests(:fancy_dog_request)
@controller.should_receive(:expire_for_request).with(ir)
- post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious"
+ post :hide, :id => ir.id, :explanation => "Foo", :reason => "vexatious"
end
describe 'when hiding an external request' do
@@ -153,7 +125,7 @@ describe AdminRequestController, "when administering the holding pen" do
end
def make_request(params=@default_params)
- post :hide_request, params
+ post :hide, params
end
it 'should redirect the the admin page for the request' do
diff --git a/spec/controllers/admin_track_controller_spec.rb b/spec/controllers/admin_track_controller_spec.rb
index f2de6c0d3..d29db4966 100644
--- a/spec/controllers/admin_track_controller_spec.rb
+++ b/spec/controllers/admin_track_controller_spec.rb
@@ -1,9 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe AdminTrackController, "when administering tracks" do
- render_views
-
- it "shows the list page" do
- get :list
+
+ it "shows the index page" do
+ get :index
end
end
diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb
index 8b89506f9..e979355cf 100644
--- a/spec/controllers/admin_user_controller_spec.rb
+++ b/spec/controllers/admin_user_controller_spec.rb
@@ -2,13 +2,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe AdminUserController, "when administering users" do
render_views
-
- it "shows the index/list page" do
+
+ it "shows the index page" do
get :index
end
it "searches for 'bob'" do
- get :list, :query => "bob"
+ get :index, :query => "bob"
assigns[:admin_users].should == [ users(:bob_smith_user) ]
end
@@ -51,7 +51,7 @@ describe AdminUserController do
before(:each) do
@user = FactoryGirl.create(:user)
- request.env["HTTP_REFERER"] = admin_user_show_path(@user)
+ request.env["HTTP_REFERER"] = admin_user_path(@user)
end
it 'redirects to the page the admin was previously on' do
@@ -61,7 +61,7 @@ describe AdminUserController do
:comment_ids => comment.id,
:hide_selected => 'hidden' }
- response.should redirect_to(admin_user_show_path(@user))
+ response.should redirect_to(admin_user_path(@user))
end
it 'sets the given comments visibility to hidden' do
diff --git a/spec/controllers/public_body_change_requests_controller_spec.rb b/spec/controllers/public_body_change_requests_controller_spec.rb
index 8fe7befeb..4053b2f40 100644
--- a/spec/controllers/public_body_change_requests_controller_spec.rb
+++ b/spec/controllers/public_body_change_requests_controller_spec.rb
@@ -28,6 +28,7 @@ describe PublicBodyChangeRequestsController, "creating a change request" do
it "should send an email to the site contact address" do
post :create, {:public_body_change_request => @change_request_params}
+ change_request_id = assigns[:change_request].id
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
@@ -37,8 +38,8 @@ describe PublicBodyChangeRequestsController, "creating a change request" do
mail.body.should include('new_body@example.com')
mail.body.should include('New Body')
mail.body.should include("Please")
- mail.body.should include('http://test.host/admin/body/new?change_request_id=')
- mail.body.should include('http://test.host/admin/change_request/edit/')
+ mail.body.should include("http://test.host/admin/bodies/new?change_request_id=#{change_request_id}")
+ mail.body.should include("http://test.host/admin/change_requests/#{change_request_id}/edit")
end
it 'should show a notice' do
@@ -83,6 +84,7 @@ describe PublicBodyChangeRequestsController, "creating a change request" do
it 'should send an email to the site contact address' do
post :create, {:public_body_change_request => @change_request_params}
+ change_request_id = assigns[:change_request].id
deliveries = ActionMailer::Base.deliveries
deliveries.size.should == 1
mail = deliveries[0]
@@ -92,8 +94,8 @@ describe PublicBodyChangeRequestsController, "creating a change request" do
mail.body.should include('new_body@example.com')
mail.body.should include(@public_body.name)
mail.body.should include("Please")
- mail.body.should include("http://test.host/admin/body/edit/#{@public_body.id}?change_request_id=")
- mail.body.should include('http://test.host/admin/change_request/edit/')
+ mail.body.should include("http://test.host/admin/bodies/#{@public_body.id}/edit?change_request_id=#{change_request_id}")
+ mail.body.should include("http://test.host/admin/change_requests/#{change_request_id}/edit")
end
it 'should show a notice' do
diff --git a/spec/factories/incoming_messages.rb b/spec/factories/incoming_messages.rb
index 38ad98394..16930b887 100644
--- a/spec/factories/incoming_messages.rb
+++ b/spec/factories/incoming_messages.rb
@@ -10,6 +10,9 @@ FactoryGirl.define do
FactoryGirl.create(:body_text,
:incoming_message => incoming_message,
:url_part_number => 1)
+
+ incoming_message.raw_email.incoming_message = incoming_message
+ incoming_message.raw_email.data = "somedata"
end
factory :plain_incoming_message do
diff --git a/spec/factories/info_request_events.rb b/spec/factories/info_request_events.rb
new file mode 100644
index 000000000..cdd303ad6
--- /dev/null
+++ b/spec/factories/info_request_events.rb
@@ -0,0 +1,12 @@
+FactoryGirl.define do
+
+ factory :info_request_event do
+ info_request
+ event_type 'response'
+ params_yaml ''
+ factory :sent_event do
+ event_type 'sent'
+ end
+ end
+
+end
diff --git a/spec/integration/admin_spec.rb b/spec/integration/admin_spec.rb
index 8e6351d2c..bdd6e9d8c 100644
--- a/spec/integration/admin_spec.rb
+++ b/spec/integration/admin_spec.rb
@@ -5,29 +5,25 @@ describe "When administering the site" do
before do
AlaveteliConfiguration.stub!(:skip_admin_auth).and_return(false)
+ confirm(:admin_user)
+ @admin = login(:admin_user)
end
it "allows an admin to log in as another user" do
- # First log in as Joe Admin
- confirm(:admin_user)
- admin = login(:admin_user)
-
- # Now fetch the "log in as" link to log in as Bob
- admin.get_via_redirect "/en/admin/user/login_as/#{users(:bob_smith_user).id}"
- admin.response.should be_success
- admin.session[:user_id].should == users(:bob_smith_user).id
+ # post to the "log in as" url to log in as Bob
+ @admin.post_via_redirect "/en/admin/users/#{users(:bob_smith_user).id}/login_as"
+ @admin.response.should be_success
+ @admin.session[:user_id].should == users(:bob_smith_user).id
end
it 'does not allow a non-admin user to login as another user' do
robin = login(:robin_user)
- robin.get_via_redirect "/en/admin/user/login_as/#{users(:bob_smith_user).id}"
+ robin.post_via_redirect "/en/admin/users/#{users(:bob_smith_user).id}/login_as"
robin.response.should be_success
robin.session[:user_id].should_not == users(:bob_smith_user).id
end
it "allows redelivery of an incoming message to a closed request" do
- confirm(:admin_user)
- admin = login(:admin_user)
ir = info_requests(:fancy_dog_request)
close_request(ir)
InfoRequest.holding_pen_request.incoming_messages.length.should == 0
@@ -36,10 +32,9 @@ describe "When administering the site" do
InfoRequest.holding_pen_request.incoming_messages.length.should == 1
new_im = InfoRequest.holding_pen_request.incoming_messages[0]
ir.incoming_messages.length.should == 1
- post_params = {'redeliver_incoming_message_id' => new_im.id,
- 'url_title' => ir.url_title}
- admin.post '/en/admin/incoming/redeliver', post_params
- admin.response.location.should == 'http://www.example.com/en/admin/request/show/101'
+ post_params = { 'url_title' => ir.url_title }
+ @admin.post "/en/admin/incoming_messages/#{new_im.id}/redeliver", post_params
+ @admin.response.location.should == 'http://www.example.com/en/admin/requests/101'
ir = InfoRequest.find_by_url_title(ir.url_title)
ir.incoming_messages.length.should == 2
@@ -47,8 +42,6 @@ describe "When administering the site" do
end
it "allows redelivery of an incoming message to more than one request" do
- confirm(:admin_user)
- admin = login(:admin_user)
ir1 = info_requests(:fancy_dog_request)
close_request(ir1)
@@ -60,15 +53,41 @@ describe "When administering the site" do
InfoRequest.holding_pen_request.incoming_messages.length.should == 1
new_im = InfoRequest.holding_pen_request.incoming_messages[0]
- post_params = {'redeliver_incoming_message_id' => new_im.id,
- 'url_title' => "#{ir1.url_title},#{ir2.url_title}"}
- admin.post '/en/admin/incoming/redeliver', post_params
+ post_params = { 'url_title' => "#{ir1.url_title},#{ir2.url_title}" }
+ @admin.post "/en/admin/incoming_messages/#{new_im.id}/redeliver", post_params
ir1.reload
ir1.incoming_messages.length.should == 2
ir2.reload
ir2.incoming_messages.length.should == 2
- admin.response.location.should == 'http://www.example.com/en/admin/request/show/106'
+ @admin.response.location.should == 'http://www.example.com/en/admin/requests/106'
InfoRequest.holding_pen_request.incoming_messages.length.should == 0
end
+ describe 'when administering the holding pen' do
+
+ it "shows a rejection reason for an incoming message from an invalid address" do
+ ir = FactoryGirl.create(:info_request, :allow_new_responses_from => 'authority_only',
+ :handle_rejected_responses => 'holding_pen')
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "frob@nowhere.com")
+ raw_email = InfoRequest.holding_pen_request.get_last_public_response.raw_email
+ @admin.get "/en/admin/raw_emails/#{raw_email.id}"
+ @admin.response.should contain "Only the authority can reply to this request"
+ end
+
+ it "guesses a misdirected request" do
+ ir = FactoryGirl.create(:info_request, :allow_new_responses_from => 'authority_only',
+ :handle_rejected_responses => 'holding_pen')
+ mail_to = "request-#{ir.id}-asdfg@example.com"
+ receive_incoming_mail('incoming-request-plain.email', mail_to)
+ interesting_email = InfoRequest.holding_pen_request.get_last_public_response.raw_email
+ # now we add another message to the queue, which we're not interested in
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "")
+ InfoRequest.holding_pen_request.incoming_messages.length.should == 2
+ @admin.get "/en/admin/raw_emails/#{interesting_email.id}"
+ @admin.response.should contain "Could not identify the request"
+ @admin.response.should contain ir.title
+ end
+
+
+ end
end
diff --git a/spec/integration/download_request_spec.rb b/spec/integration/download_request_spec.rb
index 638198cde..48b42b11d 100644
--- a/spec/integration/download_request_spec.rb
+++ b/spec/integration/download_request_spec.rb
@@ -56,7 +56,7 @@ describe 'when making a zipfile available' do
admin = login(FactoryGirl.create(:admin_user))
post_data = {:incoming_message => {:prominence => 'requester_only',
:prominence_reason => 'boring'}}
- admin.post_via_redirect "/en/admin/incoming/update/#{info_request.incoming_messages.first.id}", post_data
+ admin.put_via_redirect "/en/admin/incoming_messages/#{info_request.incoming_messages.first.id}", post_data
admin.response.should be_success
# Admin retains the requester only things
@@ -104,7 +104,7 @@ describe 'when making a zipfile available' do
post_data = {:outgoing_message => {:prominence => 'requester_only',
:prominence_reason => 'boring',
:body => 'Some information please'}}
- admin.post_via_redirect "/en/admin/outgoing/update/#{info_request.outgoing_messages.first.id}", post_data
+ admin.put_via_redirect "/en/admin/outgoing_messages/#{info_request.outgoing_messages.first.id}", post_data
admin.response.should be_success
# Admin retains the requester only things
@@ -237,7 +237,7 @@ describe 'when making a zipfile available' do
admin = login(FactoryGirl.create(:admin_user))
post_data = {:incoming_message => {:prominence => 'requester_only',
:prominence_reason => 'boring'}}
- admin.post_via_redirect "/en/admin/incoming/update/#{info_request.incoming_messages.first.id}", post_data
+ admin.put_via_redirect "/en/admin/incoming_messages/#{info_request.incoming_messages.first.id}", post_data
admin.response.should be_success
# Admin retains the requester only things
@@ -285,7 +285,7 @@ describe 'when making a zipfile available' do
post_data = {:outgoing_message => {:prominence => 'requester_only',
:prominence_reason => 'boring',
:body => 'Some information please'}}
- admin.post_via_redirect "/en/admin/outgoing/update/#{info_request.outgoing_messages.first.id}", post_data
+ admin.put_via_redirect "/en/admin/outgoing_messages/#{info_request.outgoing_messages.first.id}", post_data
admin.response.should be_success
# Admin retains the requester only things
diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb
index 110626058..a28b34da6 100644
--- a/spec/integration/errors_spec.rb
+++ b/spec/integration/errors_spec.rb
@@ -131,7 +131,7 @@ describe "When errors occur" do
it 'should show a full trace for general errors' do
InfoRequest.stub!(:find).and_raise("An example error")
- get("/admin/request/show/333")
+ get("/admin/requests/333")
response.body.should have_selector('div[id=traces]')
response.body.should match('An example error')
end
diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb
index eecb984f5..4d04c97d7 100644
--- a/spec/integration/view_request_spec.rb
+++ b/spec/integration/view_request_spec.rb
@@ -33,7 +33,7 @@ describe "When viewing requests" do
# Admin makes the incoming message requester only
post_data = {:incoming_message => {:prominence => 'hidden',
:prominence_reason => 'boring'}}
- admin.post_via_redirect "/admin/incoming/update/#{info_request.incoming_messages.first.id}", post_data
+ admin.put_via_redirect "/admin/incoming_messages/#{info_request.incoming_messages.first.id}", post_data
admin.response.should be_success
cache_directories_exist?(info_request).should be_false
diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb
index 8ba2a7bec..9e98dbc00 100644
--- a/spec/mailers/request_mailer_spec.rb
+++ b/spec/mailers/request_mailer_spec.rb
@@ -427,8 +427,7 @@ describe RequestMailer, 'requires_admin' do
it 'body should contain the full admin URL' do
mail = RequestMailer.requires_admin(@info_request).deliver
-
- mail.body.should include('http://test.host/en/admin/request/show/123')
+ mail.body.should include('http://test.host/en/admin/requests/123')
end
it "body should contain the message from the user" do