From 5698c3bad4e9a73aa93fc66c555e97a89ec605d7 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 25 Nov 2016 14:34:09 -0500 Subject: [PATCH] make unsubscribing work even if logged out --- app/controllers/notifications_controller.rb | 3 ++- app/controllers/users/sessions_controller.rb | 10 ++++++++++ app/views/layouts/application.html.erb | 6 +++++- doc/metamaps-qa-steps.md | 7 +++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 56a518c1..12a1116c 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -58,7 +58,8 @@ class NotificationsController < ApplicationController # TODO will a logged out user be unsubscribed after logging in? # need to use devise stored_url or whatever if current_user.nil? - return redirect_to sign_in_path, notice: 'Continue to unsubscribe from emails by logging in.' + flash[:notice] = 'Continue to unsubscribe from emails by logging in.' + return redirect_to "#{sign_in_path}?redirect_to=#{unsubscribe_notifications_path}" end if current_user.emails_allowed == false diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index fed670ae..73d6ea73 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -1,4 +1,6 @@ class Users::SessionsController < Devise::SessionsController + after_action :store_location, only: [:new] + protected def after_sign_in_path_for(resource) @@ -11,4 +13,12 @@ class Users::SessionsController < Devise::SessionsController request.referer || root_path end end + + private + + def store_location + if params[:redirect_to] + store_location_for(User, params[:redirect_to]) + end + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 231c76e3..d48ec0a1 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -64,9 +64,13 @@

<% if devise_error_messages? %> <%= devise_error_messages! %> - <% elsif notice %> + <% end %> + <% if notice %> <%= notice %> <% end %> + <% if alert %> + <%= alert %> + <% end %>

diff --git a/doc/metamaps-qa-steps.md b/doc/metamaps-qa-steps.md index a3f136ca..7c5c8480 100644 --- a/doc/metamaps-qa-steps.md +++ b/doc/metamaps-qa-steps.md @@ -32,6 +32,13 @@ Run these tests to be reasonably sure that your code changes haven't broken anyt - Add a number of synapses to one of your maps. Reload to see if they are still there. - Rearrange one of your maps and save the layout. Reload to see if the layout is preserved. +### Unsubscribing from Notifications + + - Log out + - Visit /notifications/unsubscribe. It should redirect you to the login page. + - Log in. + - It should redirect you to the user edit page, and you should be unsubscribed. + ### Misc - Login as admin. Change metacode sets.