Permalink
Browse files

Merge pull request #52 from alphagov/removing_need_to_specify_request…

…er_email

Removing need to specify requester email
  • Loading branch information...
2 parents 3ebef65 + 4ec3652 commit e0fbcf58c27588341512a6a1b528a48fecba577d @benilovj benilovj committed Mar 13, 2013
Showing with 206 additions and 74 deletions.
  1. +1 −0 Gemfile
  2. +18 −0 Gemfile.lock
  3. +1 −0 app/assets/javascripts/application.js
  4. +1 −1 app/controllers/create_new_user_requests_controller.rb
  5. +1 −1 app/controllers/remove_user_requests_controller.rb
  6. +8 −0 app/controllers/requests_controller.rb
  7. +0 −23 app/models/read_only_user.rb
  8. +3 −1 app/models/shared/requester.rb
  9. +42 −0 app/models/user.rb
  10. +1 −1 app/views/analytics_requests/new.html.erb
  11. +1 −1 app/views/campaign_requests/new.html.erb
  12. +1 −1 app/views/content_change_requests/new.html.erb
  13. +0 −2 app/views/create_new_user_requests/new.html.erb
  14. +1 −1 app/views/general_requests/new.html.erb
  15. +18 −0 app/views/layouts/application.html.erb
  16. +1 −1 app/views/new_feature_requests/new.html.erb
  17. +0 −2 app/views/remove_user_requests/new.html.erb
  18. +3 −0 app/views/support/_collaborators.html.erb
  19. +0 −6 app/views/support/_requester.html.erb
  20. +9 −0 config/application.rb
  21. +1 −1 config/initializers/gds-sso.rb
  22. +7 −0 config/redis.yml
  23. +1 −1 features/general_requests.feature
  24. +2 −2 features/remove_user_requests.feature
  25. +0 −18 features/step_definitions/request_steps.rb
  26. +3 −2 features/step_definitions/user_steps.rb
  27. +2 −1 lib/zendesk_ticket.rb
  28. +1 −1 lib/zendesk_tickets.rb
  29. +13 −1 test/functional/requests_controller_test.rb
  30. +16 −1 test/functional/support_controller_test.rb
  31. +4 −4 test/test_helper.rb
  32. +2 −0 test/unit/models/requester_test.rb
  33. +42 −0 test/unit/models/user_test.rb
  34. +2 −1 test/unit/zendesk/zendesk_ticket_test.rb
View
@@ -24,6 +24,7 @@ if ENV['GDS_ZENDESK_DEV']
else
gem "gds_zendesk", '0.0.5'
end
+gem 'redis-rails', '3.2.3'
group :development do
gem "quiet_assets", "1.0.2"
View
@@ -184,6 +184,23 @@ GEM
rake (10.0.3)
rdoc (3.12.1)
json (~> 1.4)
+ redis (3.0.2)
+ redis-actionpack (3.2.3)
+ actionpack (~> 3.2.3)
+ redis-rack (~> 1.4.0)
+ redis-store (~> 1.1.0)
+ redis-activesupport (3.2.3)
+ activesupport (~> 3.2.3)
+ redis-store (~> 1.1.0)
+ redis-rack (1.4.2)
+ rack (~> 1.4.1)
+ redis-store (~> 1.1.0)
+ redis-rails (3.2.3)
+ redis-actionpack (~> 3.2.3)
+ redis-activesupport (~> 3.2.3)
+ redis-store (~> 1.1.0)
+ redis-store (1.1.3)
+ redis (>= 2.2.0)
rubyzip (0.9.9)
sass (3.2.5)
sass-rails (3.2.6)
@@ -261,6 +278,7 @@ DEPENDENCIES
poltergeist (= 0.7.0)
quiet_assets (= 1.0.2)
rails (= 3.2.12)
+ redis-rails (= 3.2.3)
sass-rails (~> 3.2.3)
shoulda (~> 3.3.2)
therubyracer (~> 0.9.4)
@@ -13,6 +13,7 @@
//= require jquery
//= require jquery_ujs
//= require jquery.ui.datepicker
+//= require twitter/bootstrap/dropdown
//= require twitter/bootstrap/collapse
//= require_tree .
@@ -5,7 +5,7 @@
class CreateNewUserRequestsController < RequestsController
protected
def new_request
- CreateNewUserRequest.new(requester: Requester.new, requested_user: RequestedUser.new)
+ CreateNewUserRequest.new(requested_user: RequestedUser.new)
end
def zendesk_ticket_class
@@ -3,7 +3,7 @@
class RemoveUserRequestsController < RequestsController
protected
def new_request
- RemoveUserRequest.new(:requester => Requester.new, :time_constraint => TimeConstraint.new)
+ RemoveUserRequest.new(time_constraint: TimeConstraint.new)
end
def zendesk_ticket_class
@@ -8,6 +8,8 @@ def new
def create
@request = parse_request_from_params
+ set_logged_in_user_as_requester_on(@request)
+
if @request.valid?
process_valid_request(@request)
else
@@ -21,6 +23,12 @@ def process_valid_request(submitted_request)
end
private
+ def set_logged_in_user_as_requester_on(request)
+ request.requester ||= Requester.new
+ request.requester.name = current_user.name
+ request.requester.email = current_user.email
+ end
+
def raise_ticket(ticket)
ticket = ZendeskTickets.new(GDS_ZENDESK_CLIENT).raise_ticket(ticket)
@@ -1,23 +0,0 @@
-require 'gds-sso/user'
-
-class ReadOnlyUser < OpenStruct
- def self.attr_accessible(*args)
- end
-
- include GDS::SSO::User
-
- def self.find_by_uid(uid)
- ReadOnlyUser.new(uid: uid)
- end
-
- def self.create!(auth_hash, options={})
- ReadOnlyUser.new(auth_hash)
- end
-
- def update_attribute(*args)
- end
-
- def update_attributes(params, hash)
- ReadOnlyUser.new(params)
- end
-end
@@ -1,12 +1,14 @@
require 'shared/tableless_model'
class Requester < TablelessModel
- attr_accessor :email
+ attr_accessor :email, :name
validates_presence_of :email
validates :email, format: { with: /@/ }
+ validates_presence_of :name
+
validate :collaborator_emails_are_all_valid
def email=(new_email)
View
@@ -0,0 +1,42 @@
+require 'gds-sso/user'
+
+class User < OpenStruct
+ def self.attr_accessible(*args)
+ end
+
+ include GDS::SSO::User
+
+ def self.find_by_uid(uid)
+ auth_hash = Rails.cache.fetch(prefixed_key(uid))
+ auth_hash ? User.new(auth_hash) : nil
+ end
+
+ def self.create!(auth_hash, options={})
+ Rails.cache.write(prefixed_key(auth_hash["uid"]), auth_hash)
+ User.new(auth_hash)
+ end
+
+ def remotely_signed_out?
+ remotely_signed_out
+ end
+
+ def update_attribute(key, value)
+ if uid
+ old_attributes = Rails.cache.fetch(self.class.prefixed_key(uid))
+ new_attributes = old_attributes.merge(key => value)
+ Rails.cache.write(self.class.prefixed_key(new_attributes["uid"]), new_attributes)
+ end
+ send("#{key}=", value)
+ end
+
+ def update_attributes(params, hash)
+ params.each do |key, value|
+ send("#{key}=", value)
+ end
+ Rails.cache.write(self.class.prefixed_key(params["uid"]), params)
+ end
+
+ def self.prefixed_key(key)
+ "users-#{key}"
+ end
+end
@@ -4,7 +4,7 @@
<div class="well">
<%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render partial: "support/requester", locals: { f: f, show_collaborators: true } %>
+ <%= render partial: "support/collaborators", locals: { f: f, show_collaborators: true } %>
<%= render partial: "support/request_context", locals: { f: f } %>
@@ -4,7 +4,7 @@
<div class="well">
<%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render partial: "support/requester", locals: { f: f, show_collaborators: true } %>
+ <%= render partial: "support/collaborators", locals: { f: f } %>
<%= render partial: "campaign_details", locals: { f: f } %>
@@ -21,7 +21,7 @@
<div class="well">
<%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render partial: "support/requester", locals: { f: f, show_collaborators: true } %>
+ <%= render partial: "support/collaborators", locals: { f: f } %>
<%= render partial: "request_details", locals: { f: f} %>
@@ -4,8 +4,6 @@
<div class="well">
<%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render partial: "support/requester", locals: { f: f, show_collaborators: false } %>
-
<%= render partial: "request_details", locals: { f: f } %>
<%= f.action :submit, label: "Submit", button_html: { class: "btn btn-success" } %>
@@ -12,7 +12,7 @@
<div class="well">
<%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render partial: "support/requester", locals: { f: f, show_collaborators: true } %>
+ <%= render partial: "support/collaborators", locals: { f: f } %>
<%= render partial: "request_details", locals: { f: f } %>
@@ -16,6 +16,24 @@
<div class="navbar-inner">
<div class="container-fluid">
<%= link_to 'GOV.UK Support', root_path, :class => "brand" %>
+ <ul class="nav pull-right">
+ <li class="dropdown">
+ <a href="#"
+ class="dropdown-toggle"
+ data-toggle="dropdown">
+ Services
+ <b class="caret"></b>
+ </a>
+ <ul class="dropdown-menu">
+ <li><a href="http://digital.cabinetoffice.gov.uk/">GDS blog</a></li>
+ <li><a href="http://wiki.digital.cabinet-office.gov.uk/">GDS wiki</a></li>
+ <li class="divider"></li>
+ <li><%= link_to 'Sign out', gds_sign_out_path %></li>
+ </ul>
+ </li>
+ </ul>
+
+ <p id="logged-in-user" class="navbar-text pull-right">Signed in as <a href="<%= Plek.current.find('signon') %>"><%= current_user.name %></a></p>
</div>
</div>
</header>
@@ -4,7 +4,7 @@
<div class="well">
<%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render partial: "support/requester", locals: { f: f, show_collaborators: true } %>
+ <%= render partial: "support/collaborators", locals: { f: f } %>
<%= render partial: "request_details", locals: { f: f } %>
@@ -4,8 +4,6 @@
<div class="well">
<%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= render partial: "support/requester", locals: { f: f, show_collaborators: false } %>
-
<%= render partial: "request_details", locals: { f: f } %>
<%= f.action :submit, label: "Submit", button_html: { class: "btn btn-success" } %>
@@ -0,0 +1,3 @@
+<%= f.semantic_fields_for :requester do |r| %>
+ <%= 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 %>
@@ -1,6 +0,0 @@
-<%= 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
@@ -8,6 +8,8 @@
require "sprockets/railtie"
require "rails/test_unit/railtie"
+require 'yaml'
+
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
@@ -49,6 +51,13 @@ class Application < Rails::Application
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
+ redis_config = YAML.load_file(File.join(Rails.root, "config", "redis.yml"))[Rails.env]
+ config.cache_store = [
+ :redis_store,
+ "redis://#{redis_config['host']}:#{redis_config['port']}",
+ { expires_in: 24.hours, namespace: "support-#{Rails.env}" }
+ ]
+
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
@@ -1,5 +1,5 @@
GDS::SSO.config do |config|
- config.user_model = 'ReadOnlyUser'
+ config.user_model = 'User'
config.oauth_id = 'abcdefghjasndjkasndsupport'
config.oauth_secret = 'secret'
config.default_scope = "Support"
View
@@ -0,0 +1,7 @@
+development:
+ host: localhost
+ port: 6379
+
+test:
+ host: localhost
+ port: 6379
@@ -14,7 +14,7 @@ Feature: General requests
| The site is down | https://www.gov.uk |
Then the following ticket is raised in ZenDesk:
| Subject | Requester email | Requester name |
- | Govt Agency General Issue | john.smith@email.com | john.smith@email.com |
+ | Govt Agency General Issue | john.smith@email.com | John Smith |
And the ticket is tagged with "govt_form govt_agency_general"
And the comment on the ticket is:
"""
@@ -5,8 +5,8 @@ Feature: Remove 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 remove user request for publisher
When the user submits the following remove user request:
@@ -1,7 +1,3 @@
-When /^the user fills out their details$/ do
- fill_in "Your email", :with => @user_details["Email"]
-end
-
When /^the user fills out the time constraints$/ do
fill_in "MUST be published by", :with => @request_details["Needed by date"]
fill_in "MUST NOT be published BEFORE", :with => @request_details["Not before date"]
@@ -22,8 +18,6 @@
assert page.has_content?("Report a problem")
- step "the user fills out their details"
-
fill_in "Details", :with => @request_details['Details']
fill_in "URL (if applicable)", :with => @request_details['URL']
@@ -39,8 +33,6 @@
assert page.has_content?("Request a new feature/need")
- step "the user fills out their details"
-
within "#request-context" do
choose @request_details["Context"]
end
@@ -61,8 +53,6 @@
assert page.has_content?("Request a change")
- step "the user fills out their details"
-
within "#request-context" do
choose @request_details["Context"]
end
@@ -85,8 +75,6 @@
assert page.has_content?("Create a new user account")
- step "the user fills out their details"
-
within "#tool-role-choice" do
choose @request_details["Tool/Role"]
end
@@ -112,8 +100,6 @@
assert page.has_content?("Request to remove user access")
- step "the user fills out their details"
-
within "#tool-role-choice" do
choose @request_details["Tool/Role"]
end
@@ -138,8 +124,6 @@
assert page.has_content?("Request GDS support for a campaign")
- step "the user fills out their details"
-
fill_in "Campaign title", :with => @request_details["Campaign title"]
fill_in "ERG reference number", :with => @request_details["ERG ref number"]
fill_in "Start date", :with => @request_details["Start date"]
@@ -161,8 +145,6 @@
assert page.has_content?("Request analytics reports from GDS")
- step "the user fills out their details"
-
within "#request-context" do
choose @request_details["Context"]
end
Oops, something went wrong.

0 comments on commit e0fbcf5

Please sign in to comment.