Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cookies message #10

Merged
merged 2 commits into from Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions app/assets/stylesheets/custom.scss
Expand Up @@ -10,3 +10,40 @@
content: none;
}
}

.cookies-message {
background: #e3e2e3;
bottom: 0;
color: $text;
left: 0;
padding: $line-height;
padding-bottom: $line-height / 2;
pointer-events: none;
position: fixed;
width: 100%;
z-index: 100;

p {
font-size: $small-font-size;
padding-top: $line-height / 2;

@include breakpoint(large) {
display: inline-block;
}
}

.button {
background: $brand;
color: #fff;
pointer-events: auto;

@include breakpoint(large) {
float: right;
margin-left: $line-height / 2;
}
}
}

.footer {
background: $brand;
}
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -14,6 +14,7 @@ class ApplicationController < ActionController::Base
before_action :set_locale
before_action :track_email_campaign
before_action :set_return_url
before_action :accept_cookies

check_authorization unless: :devise_controller?
self.responder = ApplicationResponder
Expand Down Expand Up @@ -68,6 +69,10 @@ def set_layout
end
end

def accept_cookies
session[:cookies_accepted] ||= params[:cookies_accepted]
end

def set_debate_votes(debates)
@debate_votes = current_user ? current_user.debate_votes(debates) : {}
end
Expand Down
7 changes: 7 additions & 0 deletions app/views/layouts/_cookies.html.erb
@@ -0,0 +1,7 @@
<% unless session[:cookies_accepted] %>
<div id="cookies_message" class="cookies-message">
<p><strong><%= t("cookies.message") %></strong></p>
<%= link_to t("cookies.more_info"), page_path("cookies"), class: "button", target: "_blank" %>
<%= link_to t("cookies.accept"), request.params.merge(cookies_accepted: true), class: "button" %>
</div>
<% end %>
4 changes: 0 additions & 4 deletions app/views/layouts/_footer.html.erb
@@ -1,10 +1,6 @@
<footer>
<div class="row">
<div class="small-12 medium-6 column">
<h1 class="logo">
<%= image_tag(image_path_for("logo_footer.png"), alt: "") %>
</h1>

<p class="info">
<%= sanitize(content_block("footer", I18n.locale)) %>
</p>
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -47,6 +47,7 @@
<%= render "layouts/link_to_top" %>
<% end %>
<%= render "layouts/cookies" %>
<div class="push"></div>
</div>
<div class="footer">
Expand Down
4 changes: 4 additions & 0 deletions config/locales/custom/en/general.yml
Expand Up @@ -60,3 +60,7 @@ en:
vote_registered: "Your vote has been registered correctly."
shared:
expired: "Expired"
cookies:
message: "Your experience on this website was improving with using cookies"
accept: "Accept cookies"
more_info: "More information"
4 changes: 4 additions & 0 deletions config/locales/custom/nl/general.yml
Expand Up @@ -514,3 +514,7 @@ nl:
submit_button: "Stuur melding"
info_about_receivers: "Deze melding stuur je naar <strong>%{count} mensen</strong> en is te zien op %{proposal_page}.<br> Meldingen worden niet direct gestuurd, maar de gebruikers ontvangen periodiek een email met alle meldingen omtrent jouw initiatief."
proposal_page: "de pagina van het initiatief"
cookies:
message: "Uw ervaring op deze website zat verbeteren na het toelaten van cookies"
accept: "Cookies toestaan"
more_info: "Meer informatie"
62 changes: 62 additions & 0 deletions spec/system/cookies_spec.rb
@@ -0,0 +1,62 @@
require "rails_helper"

describe "Cookies message" do
scenario "Show cookies message" do
visit root_path

within "#cookies_message" do
expect(page).to have_content("Your experience on this website was improving with using cookies")
expect(page).to have_link "Accept cookies", href: root_path(cookies_accepted: true)
expect(page).to have_link "More information", href: page_path("cookies")
end
end

scenario "Hide cookies message when accept" do
visit root_path

within "#cookies_message" do
click_link "Accept cookies"
end

expect(page).to have_current_path(root_path(cookies_accepted: true))

expect(page).not_to have_selector "#cookies_message"
expect(page).not_to have_content "Your experience on this website was improving with using cookies"
expect(page).not_to have_link "Accept cookies", href: root_path(cookies_accepted: true)
expect(page).not_to have_link "More information", href: page_path("cookies")

visit debates_path

expect(page).not_to have_selector "#cookies_message"

visit proposals_path

expect(page).not_to have_selector "#cookies_message"
end

scenario "Maintain current url when accept" do
visit proposals_path

within "#cookies_message" do
click_link "Accept cookies"
end

expect(page).to have_current_path(proposals_path(cookies_accepted: true))
end

scenario "Maintain existing params when accept" do
budget = create(:budget)
group = create(:budget_group, budget: budget)
heading = create(:budget_heading, group: group)
create(:budget_investment, heading: heading)

visit budget_investments_path(budget, heading_id: heading.id)

within "#cookies_message" do
click_link "Accept cookies"
end

expect(page).to have_current_path(budget_investments_path(budget, heading_id: heading.id,
cookies_accepted: true))
end
end