Permalink
Browse files

Merge pull request #142 from alphagov/separate-user-specified-and-ori…

…ginating-url-on-long-form-feedback

Separate user-specified and originating url on long form feedback
  • Loading branch information...
fatbusinessman committed Feb 28, 2014
2 parents 0def321 + 1a981ed commit b1ed36e5a0df123457fc48ea1db37e2f6c12933c
@@ -15,7 +15,7 @@ def zendesk_ticket_class
def parse_request_from_params
# remapping link => url while the public form submits the 'url' param
- params[:long_form_contact][:url] ||= params[:long_form_contact][:link]
+ params[:long_form_contact][:user_specified_url] = params[:long_form_contact][:link]
Anonymous::LongFormContact.new(params[:long_form_contact])
end
end
@@ -0,0 +1,5 @@
+class AddUserSpecifiedLinkToAnonymousFeedback < ActiveRecord::Migration
+ def change
+ add_column :anonymous_contacts, :user_specified_url, :text
+ end
+end
@@ -0,0 +1,22 @@
+class MoveAllUserSpecifiedLinksForLongFormFeedback < ActiveRecord::Migration
+ def up
+ ActiveRecord::Base.connection.execute("UPDATE anonymous_contacts
+ SET user_specified_link = url
+ WHERE type = 'Support::Requests::Anonymous::LongFormContact'
+ AND url IS NOT NULL")
+ ActiveRecord::Base.connection.execute("UPDATE anonymous_contacts
+ SET url = '#{Plek.new.website_root}/contact/govuk'
+ WHERE type = 'Support::Requests::Anonymous::LongFormContact'")
+ end
+
+ def down
+ ActiveRecord::Base.connection.execute("UPDATE anonymous_contacts
+ SET url = NULL
+ WHERE type = 'Support::Requests::Anonymous::LongFormContact'")
+ ActiveRecord::Base.connection.execute("UPDATE anonymous_contacts
+ SET url = user_specified_link
+ WHERE type = 'Support::Requests::Anonymous::LongFormContact'
+ AND user_specified_link IS NOT NULL")
+
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20140205172712) do
+ActiveRecord::Schema.define(:version => 20140221155725) do
create_table "anonymous_contacts", :force => true do |t|
t.string "type"
@@ -29,6 +29,7 @@
t.string "personal_information_status"
t.string "slug"
t.integer "service_satisfaction_rating"
+ t.text "user_specified_url"
end
end
@@ -28,8 +28,8 @@ Feature: Anonymous feedback
Scenario: successful long-form anonymous contact (to do with a specific page)
When the user submits the following long-form anonymous contact through the API:
- | Details | Link |
- | xyz | https://www.gov.uk/y |
+ | Details | Link | URL |
+ | xyz | https://www.gov.uk/y | https://www.gov.uk/contact/govuk |
Then the following ticket is raised in ZenDesk:
| Subject |
| Anonymous contact about /y |
@@ -39,7 +39,7 @@ Feature: Anonymous feedback
[Details]
xyz
- [Url]
+ [URL]
https://www.gov.uk/y
[Referrer]
@@ -29,6 +29,7 @@
"user_agent" => @request_details['User agent'],
"javascript_enabled" => (@request_details['JS?'] == "yes"),
"referrer" => @request_details['Referrer'],
+ "url" => @request_details['URL'],
}
}
@@ -4,19 +4,18 @@ module Support
module Requests
module Anonymous
class LongFormContact < AnonymousContact
- attr_accessible :url, :details
+ attr_accessible :url, :details, :user_specified_url
validates_presence_of :details
validates :url, length: { maximum: 2048 }
+ validates :user_specified_url, length: { maximum: 2048 }
validates :details, length: { maximum: 2 ** 16 }
def govuk_link_path
- begin
- uri = URI.parse(url)
- uri.host == 'www.gov.uk' ? uri.path : nil
- rescue URI::InvalidURIError
- nil
- end
+ uri = URI.parse(user_specified_url)
+ uri.host == 'www.gov.uk' ? uri.path : nil
+ rescue URI::InvalidURIError
+ nil
end
end
end
@@ -17,7 +17,7 @@ def tags
def comment_snippets
[
request_label(field: :details),
- request_label(field: :url),
+ request_label(field: :user_specified_url, label: "URL"),
LabelledSnippet.new(on: self, field: :referrer),
LabelledSnippet.new(on: self, field: :user_agent),
LabelledSnippet.new(on: self, field: :javascript_enabled, label: "JavaScript Enabled")
@@ -19,6 +19,9 @@ class LongFormContactTest < Test::Unit::TestCase
should allow_value("a" * 2**16).for(:details)
should_not allow_value("a" * (2**16+1)).for(:details)
+ should allow_value("abc").for(:user_specified_url)
+ should allow_value(nil).for(:user_specified_url)
+
should "not allow random values for javascript_enabled" do
refute LongFormContact.new(javascript_enabled: "abc").javascript_enabled
end
@@ -32,9 +35,9 @@ class LongFormContactTest < Test::Unit::TestCase
end
should "provide the path if a GOV.UK link is specified" do
- assert_equal "/abc", LongFormContact.new(url: "https://www.gov.uk/abc").govuk_link_path
- assert_nil LongFormContact.new(url: "https://www.google.co.uk/ab").govuk_link_path
- assert_nil LongFormContact.new(url: nil).govuk_link_path
+ assert_equal "/abc", LongFormContact.new(user_specified_url: "https://www.gov.uk/abc").govuk_link_path
+ assert_nil LongFormContact.new(user_specified_url: "https://www.google.co.uk/ab").govuk_link_path
+ assert_nil LongFormContact.new(user_specified_url: nil).govuk_link_path
end
end
end

0 comments on commit b1ed36e

Please sign in to comment.