From 27cac47804a0b250eac7a6b5d97167596760d822 Mon Sep 17 00:00:00 2001 From: James Mead Date: Wed, 9 Aug 2023 13:55:17 +0100 Subject: [PATCH 1/4] Add user research recruitment banner Trello: https://trello.com/c/yGMU3sR2 We're only showing the banner on the dashboard so that we don't overwhelm people by showing it everywhere. We're using larger, bold text and a "start" button [1] to make the "Find out more" CTA stand out over the "Hide this" button. Ideally we'd have used the GOV.UK Components button [2] for the two buttons. However, the `govuk-button--inverse` CSS class [3] is not supported by the component and there's no easy way to override it. Instead of using that component, we're explicitly writing out the HTML that it would have generated. It would be worth opening a PR to add an `inverse` property to the GOV.UK Components button so we can avoid this duplication. [1]: https://design-system.service.gov.uk/components/button/#start-buttons [2]: https://components.publishing.service.gov.uk/component-guide/button [3]: https://design-system.service.gov.uk/components/button/#buttons-on-dark-backgrounds --- .../_user_research_recruitment_banner.scss | 22 ++++++++++++ app/assets/stylesheets/application.scss | 1 + app/views/layouts/admin_layout.html.erb | 2 ++ app/views/root/index.html.erb | 23 +++++++++++++ .../user_research_recruitment_banner_test.rb | 34 +++++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 app/assets/stylesheets/_user_research_recruitment_banner.scss create mode 100644 test/integration/user_research_recruitment_banner_test.rb diff --git a/app/assets/stylesheets/_user_research_recruitment_banner.scss b/app/assets/stylesheets/_user_research_recruitment_banner.scss new file mode 100644 index 000000000..e38d13f74 --- /dev/null +++ b/app/assets/stylesheets/_user_research_recruitment_banner.scss @@ -0,0 +1,22 @@ +.user-research-recruitment-banner { + background-color: $govuk-brand-colour; + @include govuk-responsive-padding(8, "top"); +} + +.user-research-recruitment-banner__divider { + border-bottom: 1px solid govuk-colour("white"); +} + +.user-research-recruitment-banner__title { + color: govuk-colour("white"); + @include govuk-responsive-margin(5, "bottom"); +} + +.user-research-recruitment-banner__intro { + color: govuk-colour("white"); +} + +.user-research-recruitment-banner__buttons { + @include govuk-responsive-padding(6, "bottom"); + align-items: center; +} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 0c2e82fdb..5f596438c 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -1,4 +1,5 @@ @import "govuk_publishing_components/all_components"; +@import "user_research_recruitment_banner"; // TODO: move into component .gem-c-success-alert, diff --git a/app/views/layouts/admin_layout.html.erb b/app/views/layouts/admin_layout.html.erb index 5f68cd388..e6ff12650 100644 --- a/app/views/layouts/admin_layout.html.erb +++ b/app/views/layouts/admin_layout.html.erb @@ -11,6 +11,8 @@ navigation_items: navigation_items, }%> + <%= yield(:user_research_recruitment_banner) %> +
<% if yield(:back_link).present? %> <%= render "govuk_publishing_components/components/back_link", href: yield(:back_link) %> diff --git a/app/views/root/index.html.erb b/app/views/root/index.html.erb index 5af694e18..0de36a672 100644 --- a/app/views/root/index.html.erb +++ b/app/views/root/index.html.erb @@ -1,5 +1,28 @@ <% content_for :title, "Your applications" %> + <% content_for :user_research_recruitment_banner do %> +
+
+
+

Help us improve GOV.UK Publishing

+

We're holding research sessions to make Publishing work better.

+ <%= form_tag "#" do %> +
+ + +
+ <% end %> +
+
+ <% end %> +
diff --git a/test/integration/user_research_recruitment_banner_test.rb b/test/integration/user_research_recruitment_banner_test.rb new file mode 100644 index 000000000..9e8a20699 --- /dev/null +++ b/test/integration/user_research_recruitment_banner_test.rb @@ -0,0 +1,34 @@ +require "test_helper" + +class UserResearchRecruitmentBannerTest < ActionDispatch::IntegrationTest + should "not display the banner on the login page" do + visit new_user_session_path + + assert_not has_content?(user_research_recruitment_banner_title) + end + + should "display the banner on the dashboard" do + user = create(:user, name: "user-name", email: "user@example.com") + visit new_user_session_path + signin_with(user) + + assert has_content?(user_research_recruitment_banner_title) + assert has_css?("form", text: "Find out more") + end + + should "not display the banner on any page other than the dashboard" do + user = create(:user, name: "user-name", email: "user@example.com") + visit new_user_session_path + signin_with(user) + + click_on "Change your email or password" + + assert_not has_content?(user_research_recruitment_banner_title) + end + +private + + def user_research_recruitment_banner_title + "Help us improve GOV.UK Publishing" + end +end From 1ec726345a47cfa87293db231e156982ce0749b7 Mon Sep 17 00:00:00 2001 From: James Mead Date: Wed, 9 Aug 2023 14:13:53 +0100 Subject: [PATCH 2/4] Allow users to hide the user research recruitment banner Trello: https://trello.com/c/yGMU3sR2 We set a session cookie to hide the banner until the user restarts their browser. --- app/controllers/root_controller.rb | 7 ++++ .../user_research_recruitment_controller.rb | 11 ++++++ app/views/root/index.html.erb | 6 ++-- config/routes.rb | 2 ++ ...er_research_recruitment_controller_test.rb | 35 +++++++++++++++++++ .../user_research_recruitment_banner_test.rb | 26 ++++++++++++++ 6 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 app/controllers/user_research_recruitment_controller.rb create mode 100644 test/controllers/user_research_recruitment_controller_test.rb diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index 70ea029f4..d0d9ecab4 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -14,4 +14,11 @@ def index def signin_required @application = ::Doorkeeper::Application.find_by(id: session.delete(:signin_missing_for_application)) end + +private + + def show_user_research_recruitment_banner? + !cookies[:dismiss_user_research_recruitment_banner] + end + helper_method :show_user_research_recruitment_banner? end diff --git a/app/controllers/user_research_recruitment_controller.rb b/app/controllers/user_research_recruitment_controller.rb new file mode 100644 index 000000000..67abc19a7 --- /dev/null +++ b/app/controllers/user_research_recruitment_controller.rb @@ -0,0 +1,11 @@ +class UserResearchRecruitmentController < ApplicationController + before_action :authenticate_user! + skip_after_action :verify_authorized + + def update + if params[:choice] == "dismiss-banner" + cookies[:dismiss_user_research_recruitment_banner] = true + redirect_to root_path + end + end +end diff --git a/app/views/root/index.html.erb b/app/views/root/index.html.erb index 0de36a672..89b09ab94 100644 --- a/app/views/root/index.html.erb +++ b/app/views/root/index.html.erb @@ -1,12 +1,13 @@ <% content_for :title, "Your applications" %> +<% if show_user_research_recruitment_banner? %> <% content_for :user_research_recruitment_banner do %>

Help us improve GOV.UK Publishing

We're holding research sessions to make Publishing work better.

- <%= form_tag "#" do %> + <%= form_tag user_research_recruitment_update_path, method: :put do %>
-
@@ -22,6 +23,7 @@
<% end %> +<% end %>
diff --git a/config/routes.rb b/config/routes.rb index 7103862cb..97a0b5e86 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -77,4 +77,6 @@ get "/signin-required" => "root#signin_required" root to: "root#index" + + put "/user-research-recruitment/update" => "user_research_recruitment#update" end diff --git a/test/controllers/user_research_recruitment_controller_test.rb b/test/controllers/user_research_recruitment_controller_test.rb new file mode 100644 index 000000000..afc07d3b5 --- /dev/null +++ b/test/controllers/user_research_recruitment_controller_test.rb @@ -0,0 +1,35 @@ +require "test_helper" + +class UserResearchRecruitmentControllerTest < ActionController::TestCase + attr_reader :choice + + context "#update" do + context "when user clicks the button to dismiss the banner" do + setup do + @choice = "dismiss-banner" + end + + should "require signed in users" do + put :update, params: { choice: } + + assert_redirected_to new_user_session_path + end + + should "set session cookie" do + sign_in create(:user) + + put :update, params: { choice: } + + assert cookies[:dismiss_user_research_recruitment_banner] + end + + should "redirect to root path" do + sign_in create(:user) + + put :update, params: { choice: } + + assert_redirected_to root_path + end + end + end +end diff --git a/test/integration/user_research_recruitment_banner_test.rb b/test/integration/user_research_recruitment_banner_test.rb index 9e8a20699..5c3195717 100644 --- a/test/integration/user_research_recruitment_banner_test.rb +++ b/test/integration/user_research_recruitment_banner_test.rb @@ -26,6 +26,32 @@ class UserResearchRecruitmentBannerTest < ActionDispatch::IntegrationTest assert_not has_content?(user_research_recruitment_banner_title) end + should "hide the banner until the next session" do + user = create(:user, name: "user-name", email: "user@example.com") + + using_session("Session 1") do + visit new_user_session_path + signin_with(user) + + assert has_content?(user_research_recruitment_banner_title) + + within ".user-research-recruitment-banner" do + click_on "Hide this" + end + + visit root_path + + assert_not has_content?(user_research_recruitment_banner_title) + end + + using_session("Session 2") do + visit new_user_session_path + signin_with(user) + + assert has_content?(user_research_recruitment_banner_title) + end + end + private def user_research_recruitment_banner_title From bf4af439b7bc09ba591c3d9d01f396e66b07eecb Mon Sep 17 00:00:00 2001 From: James Mead Date: Wed, 9 Aug 2023 14:23:02 +0100 Subject: [PATCH 3/4] Hide user research recruitment banner permanently Trello: https://trello.com/c/yGMU3sR2 If the user clicks on "Find out more" then we assume that they've completed the Google Form and therefore we don't want to annoy them by continuing to show them the recruitment banner. To achieve this we set User#current_user.user_research_recruitment_banner_hidden to true before sending them off to the Google Form. --- app/controllers/root_controller.rb | 2 +- .../user_research_recruitment_controller.rb | 8 ++++- app/views/root/index.html.erb | 2 +- ...arch_recruitment_banner_hidden_to_users.rb | 5 +++ db/schema.rb | 3 +- ...er_research_recruitment_controller_test.rb | 35 ++++++++++++++---- .../user_research_recruitment_banner_test.rb | 36 ++++++++++++++++++- 7 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20230804094159_add_user_research_recruitment_banner_hidden_to_users.rb diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index d0d9ecab4..297c303f8 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -18,7 +18,7 @@ def signin_required private def show_user_research_recruitment_banner? - !cookies[:dismiss_user_research_recruitment_banner] + !cookies[:dismiss_user_research_recruitment_banner] && !current_user.user_research_recruitment_banner_hidden? end helper_method :show_user_research_recruitment_banner? end diff --git a/app/controllers/user_research_recruitment_controller.rb b/app/controllers/user_research_recruitment_controller.rb index 67abc19a7..a34ac90e2 100644 --- a/app/controllers/user_research_recruitment_controller.rb +++ b/app/controllers/user_research_recruitment_controller.rb @@ -1,9 +1,15 @@ class UserResearchRecruitmentController < ApplicationController + USER_RESEARCH_RECRUITMENT_FORM_URL = "https://docs.google.com/forms/d/1Bdu_GqOrSR4j6mbuzXkFTQg6FRktRMQc8Y-q879Mny8/viewform".freeze + before_action :authenticate_user! skip_after_action :verify_authorized def update - if params[:choice] == "dismiss-banner" + case params[:choice] + when "participate" + current_user.update!(user_research_recruitment_banner_hidden: true) + redirect_to USER_RESEARCH_RECRUITMENT_FORM_URL, allow_other_host: true + when "dismiss-banner" cookies[:dismiss_user_research_recruitment_banner] = true redirect_to root_path end diff --git a/app/views/root/index.html.erb b/app/views/root/index.html.erb index 89b09ab94..efeb971fd 100644 --- a/app/views/root/index.html.erb +++ b/app/views/root/index.html.erb @@ -9,7 +9,7 @@

We're holding research sessions to make Publishing work better.

<%= form_tag user_research_recruitment_update_path, method: :put do %>
-