make unsubscribing work even if logged out

This commit is contained in:
Devin Howard 2016-11-25 14:34:09 -05:00
parent 4629ebf8f9
commit 5698c3bad4
4 changed files with 24 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -64,9 +64,13 @@
<p id="toast" class="toast">
<% if devise_error_messages? %>
<%= devise_error_messages! %>
<% elsif notice %>
<% end %>
<% if notice %>
<%= notice %>
<% end %>
<% if alert %>
<%= alert %>
<% end %>
</p>
<div id="loading"></div>
</div>

View file

@ -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.