Permalink
Browse files

Merge pull request #25 from alphagov/ccing_request_collaborators

Ccing request collaborators
  • Loading branch information...
2 parents dbbc930 + bfc13a6 commit b3e0cbd455603b70e1beaa3c697640ec2b8eb113 @jamiecobbett jamiecobbett committed Dec 11, 2012
View
@@ -5,4 +5,24 @@ class Requester < TablelessModel
validates_presence_of :email
validates :email, :format => {:with => /@/}
+
+ validate :collaborator_emails_are_all_valid
+
+ def collaborator_emails
+ @collaborator_emails || []
+ end
+
+ def collaborator_emails=(emails_as_string)
+ @collaborator_emails = emails_as_string.split(",").collect(&:strip)
+ end
+
+ def collaborator_emails_are_all_valid
+ unless collaborator_emails.blank?
+ collaborator_emails.each do |collaborator_email|
+ unless collaborator_email =~ /@/
+ errors.add(:collaborator_emails, "#{collaborator_email} is not a valid email")
+ end
+ end
+ end
+ end
end
@@ -2,14 +2,14 @@
<%= content_for :header, "Request GDS support for a campaign" %>
<div class="well">
- <%= semantic_form_for @request, :url => { :action => "create" }, :html => { :novalidate => false} do |f| %>
+ <%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render :partial => "support/requester", :locals => {:f => f} %>
+ <%= render partial: "support/requester", locals: { f: f, show_collaborators: true } %>
- <%= render :partial => "campaign_details", :locals => {:f => f} %>
+ <%= render partial: "campaign_details", locals: { f: f } %>
- <%= f.input :additional_comments, :as => :text, :label => "Additional comments", :input_html => {:class => "span6", :rows => 6, :cols => 50 } %>
+ <%= f.input :additional_comments, as: :text, label: "Additional comments", input_html: { class: "span6", rows: 6, cols: 50 } %>
- <%= f.action :submit, :label => "Submit", :button_html => {:class => "btn btn-success"} %>
+ <%= f.action :submit, label: "Submit", button_html: { class: "btn btn-success" } %>
<% end %>
</div>
@@ -19,19 +19,19 @@
</div>
<div class="well">
- <%= semantic_form_for @request, :url => { :action => "create" }, :html => { :novalidate => false } do |f| %>
+ <%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render :partial => "support/requester", :locals => {:f => f} %>
+ <%= render partial: "support/requester", locals: { f: f, show_collaborators: true } %>
- <%= render :partial => "request_details", :locals => {:f => f} %>
+ <%= render partial: "request_details", locals: { f: f} %>
- <%= render :partial => "support/time_constraint", :locals => {:f => f} %>
+ <%= render partial: "support/time_constraint", locals: { f: f } %>
<div class="alert alert-info alert-block">
<p>If your request is urgent, please fill in this form then call 07827 992603 to let us know. (It's ONLY urgent when the public or the government is facing immediate and significant financial, legal or physical risk.)</p>
</div>
- <%= f.action :submit, :label => "Submit", :button_html => {:class => "btn btn-success"} %>
+ <%= f.action :submit, label: "Submit", button_html: { class: "btn btn-success" } %>
<% end %>
</div>
@@ -2,12 +2,12 @@
<%= content_for :header, "Create a new user account" %>
<div class="well">
- <%= semantic_form_for @request, :url => { :action => "create" }, :html => { :novalidate => false} do |f| %>
+ <%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render :partial => "support/requester", :locals => {:f => f} %>
+ <%= render partial: "support/requester", locals: { f: f, show_collaborators: false } %>
- <%= render :partial => "request_details", :locals => {:f => f} %>
+ <%= render partial: "request_details", locals: { f: f } %>
- <%= f.action :submit, :label => "Submit", :button_html => {:class => "btn btn-success"} %>
+ <%= f.action :submit, label: "Submit", button_html: { class: "btn btn-success" } %>
<% end %>
</div>
@@ -6,12 +6,12 @@
</div>
<div class="well">
- <%= semantic_form_for @request, :url => { :action => "create" }, :html => { :novalidate => false} do |f| %>
+ <%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render :partial => "support/requester", :locals => {:f => f} %>
+ <%= render partial: "support/requester", locals: { f: f, show_collaborators: true } %>
- <%= render :partial => "request_details", :locals => {:f => f} %>
+ <%= render partial: "request_details", locals: { f: f } %>
- <%= f.action :submit, :label => "Submit", :button_html => {:class => "btn btn-success"} %>
+ <%= f.action :submit, label: "Submit", button_html: { class: "btn btn-success" } %>
<% end %>
</div>
@@ -4,12 +4,12 @@
<div class="well">
<%= semantic_form_for @request, :url => { :action => "create" }, :html => { :novalidate => false } do |f| %>
- <%= render :partial => "support/requester", :locals => {:f => f} %>
+ <%= render partial: "support/requester", locals: { f: f, show_collaborators: true } %>
- <%= render :partial => "request_details", :locals => {:f => f} %>
+ <%= render partial: "request_details", locals: { f: f } %>
- <%= render :partial => "support/time_constraint", :locals => {:f => f} %>
+ <%= render partial: "support/time_constraint", locals: { f: f } %>
- <%= f.action :submit, :label => "Submit", :button_html => {:class => "btn btn-success"} %>
+ <%= f.action :submit, label: "Submit", button_html: { class: "btn btn-success" } %>
<% end %>
</div>
@@ -2,12 +2,12 @@
<%= content_for :header, "Request to remove user access" %>
<div class="well">
- <%= semantic_form_for @request, :url => { :action => "create" }, :html => { :novalidate => false} do |f| %>
+ <%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render :partial => "support/requester", :locals => {:f => f} %>
+ <%= render partial: "support/requester", locals: { f: f, show_collaborators: false } %>
- <%= render :partial => "request_details", :locals => {:f => f} %>
+ <%= render partial: "request_details", locals: { f: f } %>
- <%= f.action :submit, :label => "Submit", :button_html => {:class => "btn btn-success"} %>
+ <%= f.action :submit, label: "Submit", button_html: { class: "btn btn-success" } %>
<% end %>
</div>
@@ -1,3 +1,6 @@
<%= f.semantic_fields_for :requester do |r| %>
<%= r.input :email, :label => "Your email", :as => :email, :required => true, :input_html => {:"aria-required" => true, :class => "span6"} %>
+ <% if show_collaborators %>
+ <%= r.input :collaborator_emails, :label => "Should anybody else be copied in on this request? (comma-separated list of emails)",:required => false, :input_html => {:class => "span6", :value => r.object.collaborator_emails.join(", ") } %>
+ <% end %>
<% end %>
View
@@ -10,7 +10,7 @@ def initialize(request)
@requester = request.requester
end
- def_delegators :@requester, :email
+ def_delegators :@requester, :email, :collaborator_emails
def comment
applicable_snippets = comment_snippets.select(&:applies?)
@@ -38,14 +38,6 @@ def inside_government_tag_if_needed
end
private
-
- def inside_government_tag
- if has_value?(:inside_government) and @request.inside_government == "yes"
- ["inside_government"]
- else
- []
- end
- end
def has_value?(param, target = nil)
target ||= @request
View
@@ -16,6 +16,7 @@ def raise_ticket(ticket_to_raise)
:description => "Created via Govt API",
:priority => "normal",
:requester => {"locale_id" => 1, "email" => ticket_to_raise.email},
+ :collaborators => ticket_to_raise.collaborator_emails,
: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,
@@ -95,5 +95,14 @@ def prevent_implicit_rendering
assert_equal ['tag_a', 'tag_b'], @zendesk_api.ticket.tags
assert_redirected_to "/acknowledge"
end
+
+ should "set collaborators if they're set on the request" do
+ params = valid_params_for_test_request.tap do |p|
+ p["test_request"]["requester_attributes"].merge!("collaborator_emails" => "ab@c.com, def@g.com")
+ end
+
+ post :create, params
+ assert_equal ["ab@c.com", "def@g.com"], @zendesk_api.ticket.collaborators
+ end
end
end
@@ -5,4 +5,13 @@ class RequesterTest < Test::Unit::TestCase
should allow_value("ab@c.com").for(:email)
should_not allow_value("ab").for(:email)
+
+ should allow_value("").for(:collaborator_emails)
+ should allow_value("ab@c.com").for(:collaborator_emails)
+ should allow_value("ab@c.com, de@f.com").for(:collaborator_emails)
+ should_not allow_value("ab, de@f.com").for(:collaborator_emails)
+
+ should "have an empty list of collaborator emails if not set" do
+ assert_equal [], Requester.new.collaborator_emails
+ end
end
@@ -17,7 +17,7 @@ def with_time_constraint(attributes)
{time_constraint: OpenStruct.new(attributes)}
end
- context "content change request" do
+ context "any request" do
should "set the requester details correctly" do
ticket = new_ticket(with_requester(email: "ab@c.com"))
assert_equal "ab@c.com", ticket.email
@@ -34,5 +34,12 @@ def with_time_constraint(attributes)
new_ticket(with_time_constraint(not_before_date: "03-02-2001")).not_before_date
end
end
+
+ context "with collaborators set" do
+ should "be passed through" do
+ ticket = new_ticket(with_requester(collaborator_emails: ["ab@c.com", "de@f.com"]))
+ assert_equal ["ab@c.com", "de@f.com"], ticket.collaborator_emails
+ end
+ end
end
end
@@ -14,7 +14,7 @@ def create(options)
@options = options
end
- [:subject, :tags, :description].each do |property|
+ [:subject, :tags, :description, :collaborators].each do |property|
define_method(property) do
@options[property]
end

0 comments on commit b3e0cbd

Please sign in to comment.