Permalink
Browse files

Merge pull request #21 from alphagov/capturing_requester_details_upon…

…_user_creation

Capturing requester details upon user creation
  • Loading branch information...
2 parents f643605 + 5f23dbf commit 386dd200c4e6c036119eca30915a4102477f56c0 @mnowster mnowster committed Dec 5, 2012
View
2 app/controllers/create_new_user_requests_controller.rb
@@ -3,7 +3,7 @@
class CreateNewUserRequestsController < RequestsController
protected
def new_request
- CreateNewUserRequest.new(:requester => Requester.new)
+ CreateNewUserRequest.new(requester: Requester.new, requested_user: RequestedUser.new)
end
def zendesk_ticket_class
View
8 app/models/create_new_user_request.rb
@@ -6,7 +6,9 @@ class CreateNewUserRequest < TablelessModel
include WithRequester
include WithToolRoleChoice
- attr_accessor :user_name, :user_email, :additional_comments
- validates_presence_of :user_name, :user_email
- validates :user_email, :format => {:with => /@/}
+ attr_accessor :requested_user, :additional_comments
+ validates_presence_of :requested_user
+ def requested_user_attributes=(attr)
+ self.requested_user = RequestedUser.new(attr)
+ end
end
View
8 app/models/requested_user.rb
@@ -0,0 +1,8 @@
+require 'tableless_model'
+
+class RequestedUser < TablelessModel
+ attr_accessor :name, :email, :job, :phone
+
+ validates_presence_of :name, :email, :job
+ validates :email, :format => {:with => /@/}
+end
View
6 app/models/requester.rb
@@ -1,8 +1,8 @@
require 'tableless_model'
class Requester < TablelessModel
- attr_accessor :name, :email, :job, :phone
+ attr_accessor :email
- validates_presence_of :name, :email, :job
- validates :email, :format => {:with => /^[\w\d]+[^@]*@[\w\d]+[^@]*\.[\w\d]+[^@]*$/}
+ validates_presence_of :email
+ validates :email, :format => {:with => /@/}
end
View
10 app/views/create_new_user_requests/_request_details.html.erb
@@ -1,11 +1,7 @@
<%= render :partial => 'support/tool_role_choice', :locals => {:f => f} %>
<div id="user_details" %>
- <%= f.inputs "User details" do %>
- <%= f.input :user_name, :label => "Name", :required => true, :input_html => {:class => "span6", :"aria-required" => true } %>
+ <%= render :partial => 'requested_user_details', :locals => {:f => f} %>
+</div>
- <%= f.input :user_email, :as => :email, :label => "Email", :required => true, :input_html => {:class => "span6", :"aria-required" => true } %>
-
- <%= f.input :additional_comments, :as => :text, :label => "Additional comments", :input_html => {:class => "span6", :rows => 6, :cols => 50 } %>
- <% end %>
-</div>
+<%= f.input :additional_comments, :as => :text, :label => "Additional comments", :input_html => {:class => "span6", :rows => 6, :cols => 50 } %>
View
8 app/views/create_new_user_requests/_requested_user_details.html.erb
@@ -0,0 +1,8 @@
+<%= f.semantic_fields_for :requested_user do |r| %>
+ <%= r.inputs :name => "User details" do %>
+ <%= r.input :name, :label => "Name", :required => true, :input_html => {:"aria-required" => true, :class => "span6"} %>
+ <%= r.input :email, :label => "Email", :as => :email, :required => true, :input_html => {:"aria-required" => true, :class => "span6"} %>
+ <%= r.input :job, :label => "Job title", :required => true, :input_html => {:"aria-required" => true, :class => "span6"} %>
+ <%= r.input :phone, :label => "Phone number", :as => :phone, :required => false, :input_html => {:class => "span6"} %>
+ <% end %>
+<% end %>
View
7 app/views/support/_requester.html.erb
@@ -1,8 +1,3 @@
<%= f.semantic_fields_for :requester do |r| %>
- <%= r.inputs :name => "Your details" do %>
- <%= r.input :name, :label => "Name", :required => true, :input_html => {:"aria-required" => true, :class => "span6"} %>
- <%= r.input :email, :label => "Email", :as => :email, :required => true, :input_html => {:"aria-required" => true, :class => "span6"} %>
- <%= r.input :job, :label => "Job title", :required => true, :input_html => {:"aria-required" => true, :class => "span6"} %>
- <%= r.input :phone, :label => "Phone number", :as => :phone, :input_html => {:"aria-required" => true, :class => "span6"} %>
- <% end %>
+ <%= r.input :email, :label => "Your email", :as => :email, :required => true, :input_html => {:"aria-required" => true, :class => "span6"} %>
<% end %>
View
8 features/campaign_requests.feature
@@ -5,16 +5,16 @@ Feature: Campaign requests
Background:
* the following user has SSO access:
- | Name | Email | Job title | Phone |
- | John Smith | john.smith@email.com | Developer | 12345 |
+ | Name | Email |
+ | John Smith | john.smith@email.com |
Scenario: successful campaign request
When the user submits the following campaign request:
| Campaign title | ERG ref number | Start date | Description | Affiliated group | Info URL | Additional comments |
| Workplace pensions | 123456 | 01-01-2020 | Pensions | AXA | https://www.gov.uk | Some comment |
Then the following ticket is raised in ZenDesk:
- | Subject | Requester email | Requester name | Phone | Job title |
- | Campaign | john.smith@email.com | John Smith | 12345 | Developer |
+ | Subject | Requester email |
+ | Campaign | john.smith@email.com |
And the ticket is tagged with "campaign"
And the comment on the ticket is:
"""
View
8 features/content_change_requests.feature
@@ -5,17 +5,17 @@ Feature: Content change requests
Background:
* the following user has SSO access:
- | Name | Email | Job title | Phone |
- | John Smith | john.smith@email.com | Developer | 12345 |
+ | Name | Email |
+ | John Smith | john.smith@email.com |
Scenario: successful Mainstream content change request
When the user submits the following content change request:
| Context | Details of change | URL 1 | URL 2 | Needed by date | Not before date | Reason |
| Mainstream (business/citizen) | Out of date XX YY | http://gov.uk/X | http://gov.uk/Y | 31-12-2020 | 01-12-2020 | New law |
Then the following ticket is raised in ZenDesk:
- | Subject | Requester email | Requester name | Phone | Job title |
- | Content change request | john.smith@email.com | John Smith | 12345 | Developer |
+ | Subject | Requester email |
+ | Content change request | john.smith@email.com |
And the time constraints on the ticket are:
| Need by date | Not before date |
| 31-12-2020 | 01-12-2020 |
View
22 features/create_new_user_requests.feature
@@ -6,28 +6,34 @@ Feature: Create new user requests
Background:
* the following user has SSO access:
- | Name | Email | Job title | Phone |
- | John Smith | john.smith@email.com | Developer | 12345 |
+ | Name | Email |
+ | John Smith | john.smith@email.com |
Scenario: successful create user request for publisher
When the user submits the following create user request:
- | Tool/Role | User's name | User's email | Additional comments |
- | Departmental Contact Form | Bob Fields | bob@gov.uk | XXXX |
+ | Tool/Role | User's name | User's email | User's job title | User's phone | Additional comments |
+ | Departmental Contact Form | Bob Fields | bob@gov.uk | Editor | 12345 | XXXX |
Then the following ticket is raised in ZenDesk:
- | Subject | Requester email | Requester name | Phone | Job title |
- | Create new user | john.smith@email.com | John Smith | 12345 | Developer |
+ | Subject | Requester email |
+ | Create new user | john.smith@email.com |
And the ticket is tagged with "new_user"
And the comment on the ticket is:
"""
[Tool/Role]
Departmental Contact Form
- [User name]
+ [Requested user's name]
Bob Fields
- [User email]
+ [Requested user's email]
bob@gov.uk
+ [Requested user's job title]
+ Editor
+
+ [Requested user's phone number]
+ 12345
+
[Additional comments]
XXXX
"""
View
8 features/general_requests.feature
@@ -5,16 +5,16 @@ Feature: General requests
Background:
* the following user has SSO access:
- | Name | Email | Job title | Phone |
- | John Smith | john.smith@email.com | Developer | 12345 |
+ | Name | Email |
+ | John Smith | john.smith@email.com |
Scenario: successful request
When the user submits the following general request:
| Details | URL |
| The site is down | https://www.gov.uk |
Then the following ticket is raised in ZenDesk:
- | Subject | Requester email | Requester name | Phone | Job title |
- | Govt Agency General Issue | john.smith@email.com | John Smith | 12345 | Developer |
+ | Subject | Requester email |
+ | Govt Agency General Issue | john.smith@email.com |
And the ticket is tagged with "govt_agency_general"
And the comment on the ticket is:
"""
View
8 features/new_feature_requests.feature
@@ -5,17 +5,17 @@ Feature: New feature requests
Background:
* the following user has SSO access:
- | Name | Email | Job title | Phone |
- | John Smith | john.smith@email.com | Developer | 12345 |
+ | Name | Email |
+ | John Smith | john.smith@email.com |
Scenario: successful request
When the user submits the following new feature request:
| Context | User need | URL of example | Needed by date | Not before date | Reason |
| Inside Government | Information on XYZ | http://www.example.com | 31-12-2020 | 01-12-2020 | Legal requirement |
Then the following ticket is raised in ZenDesk:
- | Subject | Requester email | Requester name | Phone | Job title |
- | New Feature Request | john.smith@email.com | John Smith | 12345 | Developer |
+ | Subject | Requester email |
+ | New Feature Request | john.smith@email.com |
And the time constraints on the ticket are:
| Need by date | Not before date |
| 31-12-2020 | 01-12-2020 |
View
10 features/step_definitions/request_steps.rb
@@ -1,8 +1,5 @@
When /^the user fills out their details$/ do
- fill_in "Name", :with => @user_details["Name"]
- fill_in "Email", :with => @user_details["Email"]
- fill_in "Job title", :with => @user_details["Job title"]
- fill_in "Phone number", :with => @user_details["Phone"]
+ fill_in "Your email", :with => @user_details["Email"]
end
When /^the user fills out the time constraints$/ do
@@ -97,9 +94,12 @@
within("#user_details") do
fill_in "Name", :with => @request_details["User's name"]
fill_in "Email", :with => @request_details["User's email"]
- fill_in "Additional comments", :with => @request_details["Additional comments"]
+ fill_in "Job title", :with => @request_details["User's job title"]
+ fill_in "Phone number", :with => @request_details["User's phone"]
end
+ fill_in "Additional comments", :with => @request_details["Additional comments"]
+
step "the user submits the request successfully"
end
View
3 features/step_definitions/zendesk_steps.rb
@@ -4,9 +4,6 @@
assert_equal expected_ticket_props["Subject"], @raised_ticket.subject if expected_ticket_props["Subject"]
assert_equal expected_ticket_props["Requester email"], @raised_ticket.email if expected_ticket_props["Requester email"]
- assert_equal expected_ticket_props["Requester name"], @raised_ticket.name if expected_ticket_props["Requester name"]
- assert_equal expected_ticket_props["Job title"], @raised_ticket.job if expected_ticket_props["Job title"]
- assert_equal expected_ticket_props["Phone"], @raised_ticket.phone if expected_ticket_props["Phone"]
end
Then /^the ticket is tagged with "(.*?)"$/ do |expected_tags|
View
10 lib/create_new_user_request_zendesk_ticket.rb
@@ -15,8 +15,14 @@ def comment_snippets
[
CommentSnippet.new(on: @request, field: :formatted_tool_role,
label: "Tool/Role"),
- CommentSnippet.new(on: @request, field: :user_name),
- CommentSnippet.new(on: @request, field: :user_email),
+ CommentSnippet.new(on: @request.requested_user, field: :name,
+ label: "Requested user's name"),
+ CommentSnippet.new(on: @request.requested_user, field: :email,
+ label: "Requested user's email"),
+ CommentSnippet.new(on: @request.requested_user, field: :job,
+ label: "Requested user's job title"),
+ CommentSnippet.new(on: @request.requested_user, field: :phone,
+ label: "Requested user's phone number"),
CommentSnippet.new(on: @request, field: :additional_comments)
]
end
View
10 lib/zendesk_ticket.rb
@@ -10,11 +10,7 @@ def initialize(request)
@requester = request.requester
end
- def_delegators :@requester, :name, :email, :job
-
- def phone
- remove_space_from_phone_number(@requester.phone)
- end
+ def_delegators :@requester, :email
def comment
applicable_snippets = comment_snippets.select(&:applies?)
@@ -55,9 +51,5 @@ def has_value?(param, target = nil)
target ||= @request
target.respond_to?(param) and not target.send(param).blank?
end
-
- def remove_space_from_phone_number(number)
- number.gsub(/\s+/, "")
- end
end
View
10 lib/zendesk_tickets.rb
@@ -6,9 +6,7 @@ def initialize(client)
end
def self.field_ids
- { job: "21487987",
- phone: "21471291",
- needed_by_date: "21485833",
+ { needed_by_date: "21485833",
not_before_date: "21502036" }
end
@@ -17,10 +15,8 @@ def raise_ticket(ticket_to_raise)
:subject => ticket_to_raise.subject,
:description => "Created via Govt API",
:priority => "normal",
- :requester => {"locale_id" => 1, "name" => ticket_to_raise.name, "email" => ticket_to_raise.email},
- :fields => [{"id" => ZendeskTickets.field_ids[:job], "value" => ticket_to_raise.job},
- {"id" => ZendeskTickets.field_ids[:phone], "value" => ticket_to_raise.phone},
- {"id" => ZendeskTickets.field_ids[:needed_by_date], "value" => ticket_to_raise.needed_by_date},
+ :requester => {"locale_id" => 1, "email" => ticket_to_raise.email},
+ :fields => [{"id" => ZendeskTickets.field_ids[:needed_by_date], "value" => ticket_to_raise.needed_by_date},
{"id" => ZendeskTickets.field_ids[:not_before_date], "value" => ticket_to_raise.not_before_date}],
:tags => ticket_to_raise.tags,
:comment => {:value => ticket_to_raise.comment})
View
18 test/test_data.rb
@@ -12,8 +12,7 @@ def valid_content_change_request_params
def valid_create_new_user_request_params
{ "create_new_user_request" =>
{ "requester_attributes" => valid_requester_params,
- "user_name"=>"subject",
- "user_email"=>"subject@digital.cabinet-office.gov.uk",
+ "requested_user_attributes" => valid_requested_user_params,
"tool_role" => "govt_form",
"additional_comments"=>"" }
}
@@ -39,11 +38,16 @@ def valid_general_request_params
end
def valid_requester_params
- { "name"=>"Testing",
- "email"=>"testing@digital.cabinet-office.gov.uk",
- "job"=>"dev",
- "phone"=>"",
- }
+ { "email"=>"testing@digital.cabinet-office.gov.uk" }
+ end
+
+ def valid_requested_user_params
+ {
+ "name"=>"subject",
+ "email"=>"subject@digital.cabinet-office.gov.uk",
+ "job"=>"editor",
+ "phone"=>"12345",
+ }
end
def valid_time_constraint_params
View
6 test/unit/models/create_new_user_request_test.rb
@@ -2,12 +2,8 @@
class CreateNewUserRequestTest < Test::Unit::TestCase
should validate_presence_of(:requester)
- should validate_presence_of(:user_name)
- should validate_presence_of(:user_email)
+ should validate_presence_of(:requested_user)
should validate_presence_of(:tool_role)
- should allow_value("ab@c.com").for(:user_email)
- should_not allow_value("ab").for(:user_email)
-
should allow_value("a comment").for(:additional_comments)
end
View
12 test/unit/models/requested_user_test.rb
@@ -0,0 +1,12 @@
+require 'test_helper'
+
+class RequestedUserTest < Test::Unit::TestCase
+ should validate_presence_of(:name)
+ should validate_presence_of(:email)
+ should validate_presence_of(:job)
+
+ should allow_value("07911111").for(:phone)
+
+ should allow_value("ab@c.com").for(:email)
+ should_not allow_value("ab").for(:email)
+end
View
4 test/unit/models/requester_test.rb
@@ -1,11 +1,7 @@
require 'test_helper'
class RequesterTest < Test::Unit::TestCase
- should validate_presence_of(:name)
should validate_presence_of(:email)
- should validate_presence_of(:job)
-
- should allow_value("07911111").for(:phone)
should allow_value("ab@c.com").for(:email)
should_not allow_value("ab").for(:email)
View
16 test/unit/zendesk/zendesk_ticket_test.rb
@@ -19,18 +19,8 @@ def with_time_constraint(attributes)
context "content change request" do
should "set the requester details correctly" do
- ticket = new_ticket(
- with_requester(
- :name => "John Smith",
- :email => "ab@c.com",
- :job => "Developer",
- :phone => "123456"
- )
- )
- assert_equal "John Smith", ticket.name
+ ticket = new_ticket(with_requester(email: "ab@c.com"))
assert_equal "ab@c.com", ticket.email
- assert_equal "Developer", ticket.job
- assert_equal "123456", ticket.phone
end
context "with time constraints" do
@@ -44,9 +34,5 @@ def with_time_constraint(attributes)
new_ticket(with_time_constraint(not_before_date: "03-02-2001")).not_before_date
end
end
-
- should "remove spaces from the tel number" do
- assert_equal "12345678", new_ticket(with_requester(:phone => "1234 5678")).phone
- end
end
end

0 comments on commit 386dd20

Please sign in to comment.